svn commit: r1761150 - in /ofbiz/trunk: applications/content/src/main/java/org/apache/ofbiz/content/cms/ applications/datamodel/entitydef/ framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ specialpurpose/cmssite/ specialpurpose/cmssite/we...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1761150 - in /ofbiz/trunk: applications/content/src/main/java/org/apache/ofbiz/content/cms/ applications/datamodel/entitydef/ framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ specialpurpose/cmssite/ specialpurpose/cmssite/we...

pranayp
Author: pranayp
Date: Sat Sep 17 08:03:19 2016
New Revision: 1761150

URL: http://svn.apache.org/viewvc?rev=1761150&view=rev
Log:
Implemented: Multisite support in specialpurpose/cmssite
(OFBIZ-7120)

This is the first patch from the ticket and is for the implementation done to support the multisite feature in specialpurpose/cmssite component.

Thanks Mohammed Rehan Khan for the contribution.


Modified:
    ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java
    ofbiz/trunk/applications/datamodel/entitydef/product-entitymodel.xml
    ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
    ofbiz/trunk/specialpurpose/cmssite/ofbiz-component.xml
    ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/WEB-INF/web.xml

Modified: ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java?rev=1761150&r1=1761149&r2=1761150&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java (original)
+++ ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java Sat Sep 17 08:03:19 2016
@@ -66,6 +66,8 @@ public class CmsEvents {
         LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
         ServletContext servletContext = request.getSession().getServletContext();
         HttpSession session = request.getSession();
+        Writer writer = null;
+        Locale locale = UtilHttp.getLocale(request);
 
         String webSiteId = (String) session.getAttribute("webSiteId");
         if (webSiteId == null) {
@@ -97,6 +99,26 @@ public class CmsEvents {
 
         String pathInfo = null;
 
+        String displayMaintenancePage = (String) session.getAttribute("displayMaintenancePage");
+        if (UtilValidate.isNotEmpty(displayMaintenancePage) && "Y".equalsIgnoreCase(displayMaintenancePage)) {
+            try {
+                writer = response.getWriter();
+                GenericValue webSiteContent = EntityQuery.use(delegator).from("WebSiteContent").where("webSiteId", webSiteId, "webSiteContentTypeId", "MAINTENANCE_PAGE").filterByDate().queryFirst();
+                if (webSiteContent != null) {
+                    ContentWorker.renderContentAsText(dispatcher, delegator, webSiteContent.getString("contentId"), writer, null, locale, "text/html", null, null, true);
+                    return "success";
+                } else {
+                    request.setAttribute("_ERROR_MESSAGE_", "Not able to display maintenance page for [" + webSiteId + "]");
+                    return "error";
+                }
+            } catch (GenericEntityException e) {
+                Debug.logError(e, module);
+            } catch (IOException e) {
+                throw new GeneralRuntimeException(String.format("Error in the response writer/output stream while rendering content [%s]", contentId), e);
+            } catch (GeneralException e) {
+                throw new GeneralRuntimeException(String.format("Error rendering content [%s]", contentId), e);
+            }
+        } else {
         // If an override view is present then use that in place of request.getPathInfo()
         String overrideViewUri = (String) request.getAttribute("_CURRENT_CHAIN_VIEW_");
         if (UtilValidate.isNotEmpty(overrideViewUri)) {
@@ -114,8 +136,8 @@ public class CmsEvents {
             } // if called through the default request, there is no request in pathinfo
         }
 
-        // if path info is null; check for a default content
-        if (pathInfo == null) {
+        // if path info is null or path info is / (i.e application mounted on root); check for a default content
+        if (pathInfo == null || "/".equals(pathInfo)) {
             GenericValue defaultContent = null;
             try {
                 defaultContent = EntityQuery.use(delegator).from("WebSiteContent")
@@ -169,9 +191,6 @@ public class CmsEvents {
                 }
             }
 
-            // process through CMS -- using the mapKey (for now)
-            Locale locale = UtilHttp.getLocale(request);
-
             // get the contentId/mapKey from URL
             if (contentId == null) {
                 if (Debug.verboseOn()) Debug.logVerbose("Current PathInfo: " + pathInfo, module);
@@ -267,7 +286,7 @@ public class CmsEvents {
                 response.setStatus(statusCode);
 
                 try {
-                    Writer writer = response.getWriter();
+                    writer = response.getWriter();
                     // TODO: replace "screen" to support dynamic rendering of different output
                     FormStringRenderer formStringRenderer = new MacroFormRenderer(EntityUtilProperties.getPropertyValue("widget", "screen.formrenderer", delegator), request, response);
                     templateMap.put("formStringRenderer", formStringRenderer);
@@ -311,6 +330,7 @@ public class CmsEvents {
                 return "error";
             }
         }
+        }
         String siteName = null;
         GenericValue webSite = null;
         try {

Modified: ofbiz/trunk/applications/datamodel/entitydef/product-entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/datamodel/entitydef/product-entitymodel.xml?rev=1761150&r1=1761149&r2=1761150&view=diff
==============================================================================
--- ofbiz/trunk/applications/datamodel/entitydef/product-entitymodel.xml (original)
+++ ofbiz/trunk/applications/datamodel/entitydef/product-entitymodel.xml Sat Sep 17 08:03:19 2016
@@ -4386,6 +4386,9 @@ under the License.
     <extend-entity entity-name="WebSite">
         <field name="productStoreId" type="id"></field>
         <field name="allowProductStoreChange" type="indicator"><description>Allow change of ProductStore for this WebSite (webapp). Defaults to N (no).</description></field>
+        <field name="hostedPathAlias" type="short-varchar"><description>For WebSites hosted on webapp using the WebSiteFilter, indicates the path this WebSite will be hosted on</description></field>
+        <field name="isDefault" type="indicator"><description>If Y then it is default WebSite</description></field>
+        <field name="displayMaintenancePage" type="indicator"><description>If set to Y, redirect user to site maintenance page</description></field>
         <relation type="one" fk-name="WEB_SITE_PRDS" rel-entity-name="ProductStore">
             <key-map field-name="productStoreId"/>
         </relation>

Modified: ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java?rev=1761150&r1=1761149&r2=1761150&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java Sat Sep 17 08:03:19 2016
@@ -1200,6 +1200,24 @@ public class RequestHandler {
         String controlPath = (String) request.getAttribute("_CONTROL_PATH_");
         newURL.append(controlPath);
 
+        Delegator delegator = (Delegator) request.getAttribute("delegator");
+        String webSiteId = WebSiteWorker.getWebSiteId(request);
+        if (webSiteId != null) {
+            try {
+                GenericValue webSiteValue = EntityQuery.use(delegator).from("WebSite").where("webSiteId", webSiteId).cache().queryOne();
+                if (webSiteValue != null) {
+                    ServletContext application = ((ServletContext) request.getAttribute("servletContext"));
+                    String domainName = request.getLocalName();
+                    if (application.getAttribute("MULTI_SITE_ENABLED") != null && UtilValidate.isNotEmpty(webSiteValue.getString("hostedPathAlias")) && !domainName.equals(webSiteValue.getString("httpHost"))) {
+                        newURL.append('/');
+                        newURL.append(webSiteValue.getString("hostedPathAlias"));
+                    }
+                }
+            } catch (GenericEntityException e) {
+                Debug.logWarning(e, "Problems with WebSite entity", module);
+            }
+        }
+
         // now add the actual passed url, but if it doesn't start with a / add one first
         if (!url.startsWith("/")) {
             newURL.append("/");

Modified: ofbiz/trunk/specialpurpose/cmssite/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/cmssite/ofbiz-component.xml?rev=1761150&r1=1761149&r2=1761150&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/cmssite/ofbiz-component.xml (original)
+++ ofbiz/trunk/specialpurpose/cmssite/ofbiz-component.xml Sat Sep 17 08:03:19 2016
@@ -22,6 +22,11 @@ under the License.
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
     <resource-loader name="main" type="component"/>
+
+    <!-- load single or multiple external libraries -->
+    <classpath type="jar" location="build/lib/*"/>
+
+    <entity-resource type="data" reader-name="demo" loader="main" location="data/CmsMultiSiteDemoData.xml"/>
     <entity-resource type="data" reader-name="demo" loader="main" location="data/CmsSiteDemoData.xml"/>
 
     <webapp name="cmssite" title="CMS Site" menu-name="secondary" app-bar-display="false"

Modified: ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/WEB-INF/web.xml?rev=1761150&r1=1761149&r2=1761150&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/WEB-INF/web.xml (original)
+++ ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/WEB-INF/web.xml Sat Sep 17 08:03:19 2016
@@ -24,11 +24,6 @@ under the License.
     <description>CMS Site for the Apache OFBiz Project</description>
 
     <context-param>
-        <description>A unique ID used to look up the WebSite entity</description>
-        <param-name>webSiteId</param-name>
-        <param-value>CmsSite</param-value>
-    </context-param>
-    <context-param>
         <description>A unique name used to identify/recognize the local dispatcher for the Service Engine</description>
         <param-name>localDispatcherName</param-name>
         <param-value>CmsSite</param-value>
@@ -65,10 +60,16 @@ under the License.
             <param-value>/cms/cms</param-value>
         </init-param>
     </filter>
+    <filter>
+        <display-name>WebSiteFilter</display-name>
+        <filter-name>WebSiteFilter</filter-name>
+        <filter-class>org.apache.ofbiz.cmssite.multisite.WebSiteFilter</filter-class>
+    </filter>
     <filter-mapping>
         <filter-name>ContextFilter</filter-name>
             <url-pattern>/*</url-pattern>
     </filter-mapping>
+    <filter-mapping><filter-name>WebSiteFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping>
 
     <listener><listener-class>org.apache.ofbiz.webapp.control.ControlEventListener</listener-class></listener>
     <!-- NOTE: not all app servers support mounting implementations of the HttpSessionActivationListener interface -->
@@ -87,7 +88,7 @@ under the License.
 
     <servlet-mapping>
         <servlet-name>ControlServlet</servlet-name>
-        <url-pattern>/cms/*</url-pattern>
+        <url-pattern>/*</url-pattern>
     </servlet-mapping>
 
     <session-config>