Author: hansbak
Date: Wed Aug 3 07:12:29 2011 New Revision: 1153366 URL: http://svn.apache.org/viewvc?rev=1153366&view=rev Log: improve the alternative seo friendly content url: some url's where not recognized Modified: ofbiz/trunk/applications/content/script/org/ofbiz/content/content/ContentServices.xml ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java Modified: ofbiz/trunk/applications/content/script/org/ofbiz/content/content/ContentServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/script/org/ofbiz/content/content/ContentServices.xml?rev=1153366&r1=1153365&r2=1153366&view=diff ============================================================================== --- ofbiz/trunk/applications/content/script/org/ofbiz/content/content/ContentServices.xml (original) +++ ofbiz/trunk/applications/content/script/org/ofbiz/content/content/ContentServices.xml Wed Aug 3 07:12:29 2011 @@ -1328,29 +1328,62 @@ <select-field field-name="contentIdStart"/> <select-field field-name="dataResourceId"/> <select-field field-name="localeString"/> + <select-field field-name="drObjectInfo"/> <select-field field-name="caFromDate"/> <select-field field-name="caThruDate"/> </entity-condition> <filter-list-by-date list="contentAssocDataResources" from-field-name="caFromDate" thru-field-name="caThruDate"/> <if-empty field="contentAssocDataResources"> <if-not-empty field="content.contentName"> - <set field="createSimpleTextContentContext.localeString" from-field="localeString"/> - <set field="createSimpleTextContentContext.text" from-field="content.contentName"/> - <call-service service-name="createSimpleTextContent" in-map-name="createSimpleTextContentContext" include-user-login="true" break-on-error="false"> - <result-to-field result-name="contentId" field="contentIdTo"/> - </call-service> - <if-not-empty field="contentIdTo"> - <set field="createContentAssocCtx.contentId" from-field="content.contentId"/> - <set field="createContentAssocCtx.contentIdTo" from-field="contentIdTo"/> - <set field="createContentAssocCtx.contentAssocTypeId" value="ALTERNATIVE_URL"/> - <call-service service-name="createContentAssoc" in-map-name="createContentAssocCtx" include-user-login="true" break-on-error="false"/> + <call-class-method method-name="invalidCharacter" class-name="org.ofbiz.common.UrlServletHelper" ret-field="uri"> + <field field="content.contentName"/> + </call-class-method> + <if-not-empty field="uri"> + <sequenced-id sequence-name="DataResource" field="dataResourceCtx.dataResourceId"/> + <set field="dataResourceCtx.dataResourceTypeId" value="URL_RESOURCE"/> + <set field="dataResourceCtx.localeString" from-field="localeString"/> + <set field="dataResourceCtx.objectInfo" value="/${uri}-${content.contentId}-content"/> + <set field="dataResourceCtx.statusId" value="CTNT_IN_PROGRESS"/> + <call-service service-name="createDataResource" in-map-name="dataResourceCtx" break-on-error="false" include-user-login="true"> + <result-to-field result-name="dataResourceId" field="dataResourceId"/> + </call-service> + <if-not-empty field="dataResourceId"> + <set field="contentCtx.dataResourceId" from-field="dataResourceId"/> + <set field="contentCtx.statusId" value="CTNT_IN_PROGRESS"/> + <set field="contentCtx.localeString" from-field="localeString"/> + <call-service service-name="createContent" in-map-name="contentCtx" break-on-error="false" include-user-login="true"> + <result-to-field result-name="contentId" field="contentIdTo"/> + </call-service> + <if-not-empty field="contentIdTo"> + <set field="createContentAssocCtx.contentId" from-field="content.contentId"/> + <set field="createContentAssocCtx.contentIdTo" from-field="contentIdTo"/> + <set field="createContentAssocCtx.contentAssocTypeId" value="ALTERNATIVE_URL"/> + <call-service service-name="createContentAssoc" in-map-name="createContentAssocCtx" include-user-login="true" break-on-error="false"/> + </if-not-empty> + </if-not-empty> + <set field="contentCreated" value="Y"/> + <field-to-result field="contentCreated" result-name="contentCreated"/> </if-not-empty> - <set field="contentCreated" value="Y"/> - <field-to-result field="contentCreated" result-name="contentCreated"/> </if-not-empty> <else> - <set field="contentCreated" value="N"/> - <field-to-result field="contentCreated" result-name="contentCreated"/> + <if-empty field="contentAssocDataResources[0].drObjectInfo"> + <if-not-empty field="content.contentName"> + <call-class-method method-name="invalidCharacter" class-name="org.ofbiz.common.UrlServletHelper" ret-field="uri"> + <field field="content.contentName"/> + </call-class-method> + <if-not-empty field="uri"> + <set field="dataResourceCtx.dataResourceId" from-field="contentAssocDataResources[0].dataResourceId"/> + <set field="dataResourceCtx.objectInfo" value="/${uri}-${content.contentId}-content"/> + <call-service service-name="updateDataResource" in-map-name="dataResourceCtx" break-on-error="false" include-user-login="true"/> + <set field="contentCreated" value="Y"/> + <field-to-result field="contentCreated" result-name="contentCreated"/> + </if-not-empty> + </if-not-empty> + <else> + <set field="contentCreated" value="N"/> + <field-to-result field="contentCreated" result-name="contentCreated"/> + </else> + </if-empty> </else> </if-empty> </iterate> Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java?rev=1153366&r1=1153365&r2=1153366&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java Wed Aug 3 07:12:29 2011 @@ -20,7 +20,6 @@ package org.ofbiz.content.content; import java.io.IOException; -import java.util.Iterator; import java.util.List; import java.util.Set; @@ -36,6 +35,7 @@ import javax.servlet.http.HttpServletRes import javolution.util.FastList; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; @@ -46,6 +46,7 @@ import org.ofbiz.entity.condition.Entity import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.webapp.control.ContextFilter; +import org.owasp.esapi.errors.EncodingException; public class ContentUrlFilter extends ContextFilter { public final static String module = ContentUrlFilter.class.getName(); @@ -68,24 +69,16 @@ public class ContentUrlFilter extends Co StringBuffer pathInfoBuffer = UtilHttp.getFullRequestUrl(httpRequest); String pathInfo = pathInfoBuffer.toString(); if (UtilValidate.isNotEmpty(pathInfo)) { - String alternativeUrl = pathInfo.substring(pathInfo.lastIndexOf("/") + 1); + String alternativeUrl = pathInfo.substring(pathInfo.lastIndexOf("/")); if (alternativeUrl.endsWith("-content")) { try { - List<EntityCondition> expr = FastList.newInstance(); - expr.add(EntityCondition.makeCondition("caContentAssocTypeId", EntityOperator.EQUALS, "ALTERNATIVE_URL")); - expr.add(EntityCondition.makeCondition("caThruDate", EntityOperator.EQUALS, null)); - Set<String> fieldsToSelect = UtilMisc.toSet("contentIdStart", "dataResourceId", "caFromDate", "caThruDate", "caCreatedDate"); - List<GenericValue> contentAssocDataResources = delegator.findList("ContentAssocDataResourceViewTo", EntityCondition.makeCondition(expr), fieldsToSelect, UtilMisc.toList("-caCreatedDate"), null, true); - Iterator<GenericValue> contentAssocDateResourceIter = contentAssocDataResources.iterator(); - while (contentAssocDateResourceIter.hasNext()) { - GenericValue contentAssocDateResource = contentAssocDateResourceIter.next(); - GenericValue electronicText = delegator.findByPrimaryKey("ElectronicText", UtilMisc.toMap("dataResourceId", contentAssocDateResource.getString("dataResourceId"))); - if (UtilValidate.isEmpty(electronicText) || UtilValidate.isEmpty(electronicText.get("textData"))) { - continue; - } - if (alternativeUrl.equalsIgnoreCase(UrlServletHelper.invalidCharacter(electronicText.getString("textData")) + "-" + contentAssocDateResource.getString("contentIdStart") + "-content")) { - urlContentId = contentAssocDateResource.getString("contentIdStart"); - break; + List<GenericValue> contentDataResourceViews = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("drObjectInfo", alternativeUrl)); + if (contentDataResourceViews.size() > 0) { + GenericValue contentDataResourceView = EntityUtil.getFirst(contentDataResourceViews); + List<GenericValue> contents = EntityUtil.filterByDate(delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentAssocTypeId", "ALTERNATIVE_URL", "contentIdTo", contentDataResourceView.getString("contentId")))); + if (contents.size() > 0) { + GenericValue content = EntityUtil.getFirst(contents); + urlContentId = content.getString("contentId"); } } } catch (Exception e) { @@ -123,19 +116,15 @@ public class ContentUrlFilter extends Co expr.add(EntityCondition.makeCondition("caContentAssocTypeId", EntityOperator.EQUALS, "ALTERNATIVE_URL")); expr.add(EntityCondition.makeCondition("caThruDate", EntityOperator.EQUALS, null)); expr.add(EntityCondition.makeCondition("contentIdStart", EntityOperator.EQUALS, contentId)); - Set<String> fieldsToSelect = UtilMisc.toSet("contentIdStart", "dataResourceId", "caFromDate", "caThruDate", "caCreatedDate"); - List<GenericValue> contentAssocDataResources = delegator.findList("ContentAssocDataResourceViewTo", EntityCondition.makeCondition(expr), fieldsToSelect, UtilMisc.toList("-caCreatedDate"), null, true); + Set<String> fieldsToSelect = UtilMisc.toSet("contentIdStart", "drObjectInfo", "dataResourceId", "caFromDate", "caThruDate", "caCreatedDate"); + List<GenericValue> contentAssocDataResources = delegator.findList("ContentAssocDataResourceViewTo", EntityCondition.makeCondition(expr), fieldsToSelect, UtilMisc.toList("-caFromDate"), null, true); if (contentAssocDataResources.size() > 0) { GenericValue contentAssocDataResource = EntityUtil.getFirst(contentAssocDataResources); - GenericValue electronicText = delegator.findByPrimaryKey("ElectronicText", UtilMisc.toMap("dataResourceId", contentAssocDataResource.get("dataResourceId"))); - if (UtilValidate.isNotEmpty(electronicText) || UtilValidate.isNotEmpty(electronicText.get("textData"))) { - String textData = UrlServletHelper.invalidCharacter(electronicText.getString("textData")) + "-" + contentId + "-content"; - StringBuilder urlBuilder = new StringBuilder(); - urlBuilder.append(request.getSession().getServletContext().getContextPath()); - if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') { - urlBuilder.append("/"); - } - url = urlBuilder.append(textData).toString(); + url = contentAssocDataResource.getString("drObjectInfo"); + try { + url = StringUtil.defaultWebEncoder.decodeFromURL(url); + } catch (EncodingException e) { + Debug.logError(e, module); } } } catch (Exception e) { Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java?rev=1153366&r1=1153365&r2=1153366&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java Wed Aug 3 07:12:29 2011 @@ -260,6 +260,7 @@ public class UrlServletHelper extends Co str = str.replace("ã", "-"); str = str.replace("â", "-"); str = str.replace("ï¼", "-"); + str = str.replace("â", ""); while(str.startsWith("-")){ str = str.substring(1); } |
Free forum by Nabble | Edit this page |