gatein SVN: r466 - in portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal: webui/workspace and 1 other directory.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2009-10-30 17:04:13 -0400 (Fri, 30 Oct 2009)
New Revision: 466
Modified:
portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
Log:
move the close() of the portal request writer in order to make it work whatever the kind of request is
Modified: portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
===================================================================
--- portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2009-10-30 20:42:31 UTC (rev 465)
+++ portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2009-10-30 21:04:13 UTC (rev 466)
@@ -19,6 +19,7 @@
package org.exoplatform.portal.application;
+import org.exoplatform.commons.utils.Safe;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.web.WebAppController;
@@ -112,6 +113,11 @@
}
finally
{
+
+ // We close the writer here once and for all
+ Safe.close(context.getWriter());
+
+ //
try
{
for (ApplicationLifecycle lifecycle : lifecycles)
Modified: portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
===================================================================
--- portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2009-10-30 20:42:31 UTC (rev 465)
+++ portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2009-10-30 21:04:13 UTC (rev 466)
@@ -424,91 +424,84 @@
{
Writer w = context.getWriter();
- try
+ //
+ if (!context.useAjax())
{
- if (!context.useAjax())
+ super.processRender(context);
+ }
+ else
+ {
+ PortalRequestContext pcontext = (PortalRequestContext)context;
+
+ UIMaskWorkspace uiMaskWS = getChildById(UIPortalApplication.UI_MASK_WS_ID);
+ if (uiMaskWS.isUpdated())
+ pcontext.addUIComponentToUpdateByAjax(uiMaskWS);
+ if (getUIPopupMessages().hasMessage())
{
- super.processRender(context);
+ pcontext.addUIComponentToUpdateByAjax(getUIPopupMessages());
}
- else
- {
- PortalRequestContext pcontext = (PortalRequestContext)context;
- UIMaskWorkspace uiMaskWS = getChildById(UIPortalApplication.UI_MASK_WS_ID);
- if (uiMaskWS.isUpdated())
- pcontext.addUIComponentToUpdateByAjax(uiMaskWS);
- if (getUIPopupMessages().hasMessage())
+ Set<UIComponent> list = context.getUIComponentToUpdateByAjax();
+ List<UIPortlet> uiPortlets = new ArrayList<UIPortlet>(3);
+ List<UIComponent> uiDataComponents = new ArrayList<UIComponent>(5);
+
+ if (list != null)
+ {
+ for (UIComponent uicomponent : list)
{
- pcontext.addUIComponentToUpdateByAjax(getUIPopupMessages());
+ if (uicomponent instanceof UIPortlet)
+ uiPortlets.add((UIPortlet)uicomponent);
+ else
+ uiDataComponents.add(uicomponent);
}
+ }
+ w.write("<div class=\"PortalResponse\">");
+ w.write("<div class=\"PortalResponseData\">");
+ for (UIComponent uicomponent : uiDataComponents)
+ {
+ if (log.isDebugEnabled())
+ log.debug("AJAX call: Need to refresh the UI component " + uicomponent.getName());
+ renderBlockToUpdate(uicomponent, context, w);
+ }
+ w.write("</div>");
- Set<UIComponent> list = context.getUIComponentToUpdateByAjax();
- List<UIPortlet> uiPortlets = new ArrayList<UIPortlet>(3);
- List<UIComponent> uiDataComponents = new ArrayList<UIComponent>(5);
-
- if (list != null)
+ if (!context.getFullRender())
+ {
+ for (UIPortlet uiPortlet : uiPortlets)
{
- for (UIComponent uicomponent : list)
- {
- if (uicomponent instanceof UIPortlet)
- uiPortlets.add((UIPortlet)uicomponent);
- else
- uiDataComponents.add(uicomponent);
- }
- }
- w.write("<div class=\"PortalResponse\">");
- w.write("<div class=\"PortalResponseData\">");
- for (UIComponent uicomponent : uiDataComponents)
- {
if (log.isDebugEnabled())
- log.debug("AJAX call: Need to refresh the UI component " + uicomponent.getName());
- renderBlockToUpdate(uicomponent, context, w);
- }
- w.write("</div>");
+ log.debug("AJAX call: Need to refresh the Portlet " + uiPortlet.getId());
- if (!context.getFullRender())
- {
- for (UIPortlet uiPortlet : uiPortlets)
- {
- if (log.isDebugEnabled())
- log.debug("AJAX call: Need to refresh the Portlet " + uiPortlet.getId());
+ w.write("<div class=\"PortletResponse\" style=\"display: none\">");
+ w.append("<div class=\"PortletResponsePortletId\">" + uiPortlet.getId() + "</div>");
+ w.append("<div class=\"PortletResponseData\">");
- w.write("<div class=\"PortletResponse\" style=\"display: none\">");
- w.append("<div class=\"PortletResponsePortletId\">" + uiPortlet.getId() + "</div>");
- w.append("<div class=\"PortletResponseData\">");
+ /*
+ * If the portlet is using our UI framework or supports it then it
+ * will return a set of block to updates. If there is not block to
+ * update the javascript client will see that as a full refresh of the
+ * content part
+ */
+ uiPortlet.processRender(context);
- /*
- * If the portlet is using our UI framework or supports it then it
- * will return a set of block to updates. If there is not block to
- * update the javascript client will see that as a full refresh of the
- * content part
- */
- uiPortlet.processRender(context);
-
- w.append("</div>");
- w.append("<div class=\"PortletResponseScript\"></div>");
- w.write("</div>");
- }
+ w.append("</div>");
+ w.append("<div class=\"PortletResponseScript\"></div>");
+ w.write("</div>");
}
+ }
- w.write("<div class=\"PortalResponseScript\">");
- w.write(pcontext.getJavascriptManager().getJavascript());
- w.write("eXo.core.Browser.onLoad();\n");
- w.write(pcontext.getJavascriptManager().getCustomizedOnLoadScript());
- String skin = getAddSkinScript(list);
- if (skin != null)
- {
- w.write(skin);
- }
- w.write("</div>");
- w.write("</div>");
+ w.write("<div class=\"PortalResponseScript\">");
+ w.write(pcontext.getJavascriptManager().getJavascript());
+ w.write("eXo.core.Browser.onLoad();\n");
+ w.write(pcontext.getJavascriptManager().getCustomizedOnLoadScript());
+ String skin = getAddSkinScript(list);
+ if (skin != null)
+ {
+ w.write(skin);
}
+ w.write("</div>");
+ w.write("</div>");
}
- finally
- {
- //
- w.close();
- }
}
private String getAddSkinScript(Set<UIComponent> updateComponents)
15 years, 1 month
gatein SVN: r465 - in portal/branches/performance/component/scripting/src: test/java/org/exoplatform/groovyscript and 1 other directory.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2009-10-30 16:42:31 -0400 (Fri, 30 Oct 2009)
New Revision: 465
Modified:
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
Log:
fix gtmpl bug where a line comment was propagated to the markup
Modified: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java 2009-10-30 19:05:32 UTC (rev 464)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java 2009-10-30 20:42:31 UTC (rev 465)
@@ -82,8 +82,6 @@
{
case STRING:
accumulatedText.append("\n");
-// script.appendText(accumulatedText.toString());
-// accumulatedText.setLength(0);
break;
case SCRIPTLET:
script.appendGroovy("\n");
@@ -112,6 +110,7 @@
}
break;
case SCRIPTLET:
+ script.appendGroovy("\n");
break;
case EXPR:
script.appendGroovy("}\");");
@@ -204,6 +203,7 @@
}
else
{
+/*
String code = Integer.toHexString(c);
switch (code.length())
{
@@ -222,6 +222,8 @@
break;
}
builder.append("\\u").append(code);
+*/
+ builder.append(c);
}
}
return "public static final " + GroovyText.class.getName() + " " + name + " = new " + GroovyText.class.getName() + "(\"" + builder + "\");";
Modified: portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
===================================================================
--- portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2009-10-30 19:05:32 UTC (rev 464)
+++ portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2009-10-30 20:42:31 UTC (rev 465)
@@ -48,7 +48,6 @@
public void testFoo() throws Exception
{
GroovyTemplate template = new GroovyTemplate("a");
-// System.out.println("template = " + template.getGroovyText());
String render = template.render();
assertEquals("a", render);
}
@@ -56,7 +55,6 @@
public void testBar() throws Exception
{
GroovyTemplate template = new GroovyTemplate("<%='a'%>");
-// System.out.println("template = " + template.getGroovyText());
String render = template.render();
assertEquals("a", render);
}
@@ -64,7 +62,6 @@
public void testFooBar() throws Exception
{
GroovyTemplate template = new GroovyTemplate("a<%='b'%>c");
-// System.out.println("template = " + template.getGroovyText());
String render = template.render();
assertEquals("abc", render);
}
@@ -72,7 +69,6 @@
public void testJuu() throws Exception
{
GroovyTemplate template = new GroovyTemplate("<% out.print(\"a\"); %>");
-// System.out.println("template = " + template.getGroovyText());
String render = template.render();
assertEquals("a", render);
}
@@ -102,10 +98,18 @@
"a\n" +
"<% if (true) {\n %>" +
"b\n" +
- "<% } %>\n"
- );
+ "<% } %>");
+ String s = template.render();
+ assertEquals("a\nb\n", s);
}
+ public void testLineComment() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<% // foo %>a\nb");
+ String s = template.render();
+ assertEquals("a\nb", s);
+ }
+
public void testContextResolution() throws Exception
{
GroovyTemplate template = new GroovyTemplate("<%= foo %>");
15 years, 1 month
gatein SVN: r464 - in portal/branches/wsrp-integration: component/portal/src/main/java/org/exoplatform/portal and 17 other directories.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2009-10-30 15:05:32 -0400 (Fri, 30 Oct 2009)
New Revision: 464
Added:
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Codec.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeSkin.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigDeployer.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/RenderingException.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Resource.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceRenderer.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleSkin.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Skin.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfig.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinKey.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinURL.java
portal/branches/wsrp-integration/packaging/profiles.xml.template
Removed:
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Codec.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeSkin.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigDeployer.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/RenderingException.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Resource.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceRenderer.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleSkin.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Skin.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfig.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinKey.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinURL.java
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/skin/
portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/conf/script/
portal/branches/wsrp-integration/portlet/exoadmin/src/main/webapp/WEB-INF/conf/script/
portal/branches/wsrp-integration/portlet/web/src/main/webapp/WEB-INF/conf/script/
portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/script/groovy/SkinConfigScript.groovy
Modified:
portal/branches/wsrp-integration/component/portal/src/main/java/conf/portal/configuration.xml
portal/branches/wsrp-integration/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java
portal/branches/wsrp-integration/packaging/profiles.xml
portal/branches/wsrp-integration/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java
portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_en.properties
portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_fr.properties
portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_ru.properties
portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_uk.properties
portal/branches/wsrp-integration/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/GroupManagement.java
portal/branches/wsrp-integration/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupExplorer.java
portal/branches/wsrp-integration/web/eXoResources/src/main/webapp/javascript/eXo/webui/UITabbedDashboard.js
portal/branches/wsrp-integration/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl
portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/application/ResourceRequestFilter.java
portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java
portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletForm.java
portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java
portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java
portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UISkinSelector.java
portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/util/PortalDataMapper.java
portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java
portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
Log:
- Merge changes from trunk revision 441 to 462.
Modified: portal/branches/wsrp-integration/component/portal/src/main/java/conf/portal/configuration.xml
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/conf/portal/configuration.xml 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/conf/portal/configuration.xml 2009-10-30 19:05:32 UTC (rev 464)
@@ -90,7 +90,7 @@
</component>
<component>
- <type>org.exoplatform.portal.skin.SkinService</type>
+ <type>org.exoplatform.portal.resource.SkinService</type>
</component>
<external-component-plugins>
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource)
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,38 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import org.gatein.wci.WebAppEvent;
-import org.gatein.wci.WebAppListener;
-
-/**
- *
- * Created by eXoPlatform SAS
- *
- * Author: Minh Hoang TO - hoang281283(a)gmail.com
- *
- * Sep 16, 2009
- */
-public abstract class AbstractResourceHandler implements WebAppListener
-{
-
- abstract public void onEvent(WebAppEvent event);
-
-}
\ No newline at end of file
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,38 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import org.gatein.wci.WebAppEvent;
+import org.gatein.wci.WebAppListener;
+
+/**
+ *
+ * Created by eXoPlatform SAS
+ *
+ * Author: Minh Hoang TO - hoang281283(a)gmail.com
+ *
+ * Sep 16, 2009
+ */
+public abstract class AbstractResourceHandler implements WebAppListener
+{
+
+ abstract public void onEvent(WebAppEvent event);
+
+}
\ No newline at end of file
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Codec.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/Codec.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Codec.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,111 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import org.exoplatform.commons.utils.CharEncoder;
-import org.exoplatform.commons.utils.CharsetCharEncoder;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-
-/**
- * A codec for names. It is a modified version of the percent encoding algorithm that translates
- * underscores to their percent counterpart and slash to underscores. Therefore slash chars are
- * never seen as the %2F string as it can cause some issues on tomcat when it is used in an URI.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-class Codec
-{
-
- private Codec()
- {
- }
-
- private static final char[][] table = new char[256][];
-
- static
- {
- char[] a = "0123456789ABCDEF".toCharArray();
- for (int b = 0; b < 256; b++)
- {
- int b1 = (b & 0xF0) >> 4;
- int b2 = b & 0x0F;
- table[b] = new char[]{a[b1], a[b2]};
- }
- }
-
- public static String decode(String s)
- {
- try
- {
- s = s.replace("_", "%2F");
- return URLDecoder.decode(s, "UTF8");
- }
- catch (UnsupportedEncodingException e)
- {
- throw new Error(e);
- }
- }
-
- public static void encode(Appendable appendable, String s) throws IOException
- {
- for (int i = 0; i < s.length(); i++)
- {
- char c = s.charAt(i);
- if (Character.isLetter(c))
- {
- appendable.append(c);
- }
- else
- {
- switch (c)
- {
- case 'A' :
- case '.' :
- case '-' :
- case '*' :
- appendable.append(c);
- break;
- case ' ' :
- appendable.append('+');
- break;
- case '/' :
- appendable.append('_');
- break;
- default :
- CharEncoder encoder = CharsetCharEncoder.getUTF8();
- byte[] bytes = encoder.encode(c);
- appendable.append('%');
- for (byte b : bytes)
- {
- for (char cc : table[b])
- {
- appendable.append(cc);
- }
- }
- }
- }
- }
- }
-
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Codec.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/Codec.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Codec.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Codec.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,111 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import org.exoplatform.commons.utils.CharEncoder;
+import org.exoplatform.commons.utils.CharsetCharEncoder;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+
+/**
+ * A codec for names. It is a modified version of the percent encoding algorithm that translates
+ * underscores to their percent counterpart and slash to underscores. Therefore slash chars are
+ * never seen as the %2F string as it can cause some issues on tomcat when it is used in an URI.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+class Codec
+{
+
+ private Codec()
+ {
+ }
+
+ private static final char[][] table = new char[256][];
+
+ static
+ {
+ char[] a = "0123456789ABCDEF".toCharArray();
+ for (int b = 0; b < 256; b++)
+ {
+ int b1 = (b & 0xF0) >> 4;
+ int b2 = b & 0x0F;
+ table[b] = new char[]{a[b1], a[b2]};
+ }
+ }
+
+ public static String decode(String s)
+ {
+ try
+ {
+ s = s.replace("_", "%2F");
+ return URLDecoder.decode(s, "UTF8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new Error(e);
+ }
+ }
+
+ public static void encode(Appendable appendable, String s) throws IOException
+ {
+ for (int i = 0; i < s.length(); i++)
+ {
+ char c = s.charAt(i);
+ if (Character.isLetter(c))
+ {
+ appendable.append(c);
+ }
+ else
+ {
+ switch (c)
+ {
+ case 'A' :
+ case '.' :
+ case '-' :
+ case '*' :
+ appendable.append(c);
+ break;
+ case ' ' :
+ appendable.append('+');
+ break;
+ case '/' :
+ appendable.append('_');
+ break;
+ default :
+ CharEncoder encoder = CharsetCharEncoder.getUTF8();
+ byte[] bytes = encoder.encode(c);
+ appendable.append('%');
+ for (byte b : bytes)
+ {
+ for (char cc : table[b])
+ {
+ appendable.append(cc);
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,80 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-class CompositeResourceResolver implements ResourceResolver
-{
-
- /** . */
- private final Map<SkinKey, SkinConfig> skins;
-
- /**
- * The name of the portal container
- */
- private final String portalContainerName;
-
- public CompositeResourceResolver(String portalContainerName, Map<SkinKey, SkinConfig> skins)
- {
- this.portalContainerName = portalContainerName;
- this.skins = skins;
- }
-
- public Resource resolve(String path)
- {
- if (path.startsWith("/" + portalContainerName + "/resource/") && path.endsWith(".css"))
- {
- final StringBuffer sb = new StringBuffer();
- String encoded = path.substring(("/" + portalContainerName + "/resource/").length());
- String blah[] = encoded.split("/");
- int len = (blah.length >> 1) << 1;
- for (int i = 0; i < len; i += 2)
- {
- String name = Codec.decode(blah[i]);
- String module = Codec.decode(blah[i + 1]);
- SkinKey key = new SkinKey(module, name);
- SkinConfig skin = skins.get(key);
- if (skin != null)
- {
- sb.append("@import url(").append(skin.getCSSPath()).append(");").append("\n");
- }
- }
- return new Resource(path)
- {
- @Override
- public Reader read()
- {
- return new StringReader(sb.toString());
- }
- };
- }
- else
- {
- return null;
- }
- }
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,80 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+class CompositeResourceResolver implements ResourceResolver
+{
+
+ /** . */
+ private final Map<SkinKey, SkinConfig> skins;
+
+ /**
+ * The name of the portal container
+ */
+ private final String portalContainerName;
+
+ public CompositeResourceResolver(String portalContainerName, Map<SkinKey, SkinConfig> skins)
+ {
+ this.portalContainerName = portalContainerName;
+ this.skins = skins;
+ }
+
+ public Resource resolve(String path)
+ {
+ if (path.startsWith("/" + portalContainerName + "/resource/") && path.endsWith(".css"))
+ {
+ final StringBuffer sb = new StringBuffer();
+ String encoded = path.substring(("/" + portalContainerName + "/resource/").length());
+ String blah[] = encoded.split("/");
+ int len = (blah.length >> 1) << 1;
+ for (int i = 0; i < len; i += 2)
+ {
+ String name = Codec.decode(blah[i]);
+ String module = Codec.decode(blah[i + 1]);
+ SkinKey key = new SkinKey(module, name);
+ SkinConfig skin = skins.get(key);
+ if (skin != null)
+ {
+ sb.append("@import url(").append(skin.getCSSPath()).append(");").append("\n");
+ }
+ }
+ return new Resource(path)
+ {
+ @Override
+ public Reader read()
+ {
+ return new StringReader(sb.toString());
+ }
+ };
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeSkin.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeSkin.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeSkin.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,113 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import org.exoplatform.commons.utils.PropertyManager;
-import org.exoplatform.services.resources.Orientation;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.TreeMap;
-
-/**
- * A composite skin.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-class CompositeSkin implements Skin
-{
-
- /** . */
- private final SkinService service;
-
- /** . */
- private final String id;
-
- /** . */
- private final String urlPrefix;
-
- CompositeSkin(SkinService service, Collection<SkinConfig> skins)
- {
- TreeMap<String, SkinConfig> urlSkins = new TreeMap<String, SkinConfig>();
- for (SkinConfig skin : skins)
- {
- urlSkins.put(skin.getCSSPath(), skin);
- }
-
- //
- final StringBuilder builder = new StringBuilder();
- builder.append("/").append(service.portalContainerName).append("/resource");
-
- //
- final StringBuilder id = new StringBuilder();
-
- //
- try
- {
- for (SkinConfig cfg : urlSkins.values())
- {
- StringBuilder encodedName = new StringBuilder();
- Codec.encode(encodedName, cfg.getName());
- StringBuilder encodedModule = new StringBuilder();
- Codec.encode(encodedModule, cfg.getModule());
-
- //
- id.append(encodedName).append(encodedModule);
- builder.append("/").append(encodedName).append("/").append(encodedModule);
- }
- }
- catch (IOException e)
- {
- throw new Error(e);
- }
-
- //
- this.service = service;
- this.id = id.toString();
- this.urlPrefix = builder.toString();
- }
-
- public String getId()
- {
- return id;
- }
-
- public SkinURL createURL()
- {
- return new SkinURL()
- {
-
- Orientation orientation;
-
- public void setOrientation(Orientation orientation)
- {
- this.orientation = orientation;
- }
-
- @Override
- public String toString()
- {
- return urlPrefix + "/" + (PropertyManager.isDevelopping() ? "style" : service.id)
- + service.getSuffix(orientation);
- }
- };
- }
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeSkin.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeSkin.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeSkin.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeSkin.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,113 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import org.exoplatform.commons.utils.PropertyManager;
+import org.exoplatform.services.resources.Orientation;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.TreeMap;
+
+/**
+ * A composite skin.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+class CompositeSkin implements Skin
+{
+
+ /** . */
+ private final SkinService service;
+
+ /** . */
+ private final String id;
+
+ /** . */
+ private final String urlPrefix;
+
+ CompositeSkin(SkinService service, Collection<SkinConfig> skins)
+ {
+ TreeMap<String, SkinConfig> urlSkins = new TreeMap<String, SkinConfig>();
+ for (SkinConfig skin : skins)
+ {
+ urlSkins.put(skin.getCSSPath(), skin);
+ }
+
+ //
+ final StringBuilder builder = new StringBuilder();
+ builder.append("/").append(service.portalContainerName).append("/resource");
+
+ //
+ final StringBuilder id = new StringBuilder();
+
+ //
+ try
+ {
+ for (SkinConfig cfg : urlSkins.values())
+ {
+ StringBuilder encodedName = new StringBuilder();
+ Codec.encode(encodedName, cfg.getName());
+ StringBuilder encodedModule = new StringBuilder();
+ Codec.encode(encodedModule, cfg.getModule());
+
+ //
+ id.append(encodedName).append(encodedModule);
+ builder.append("/").append(encodedName).append("/").append(encodedModule);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new Error(e);
+ }
+
+ //
+ this.service = service;
+ this.id = id.toString();
+ this.urlPrefix = builder.toString();
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public SkinURL createURL()
+ {
+ return new SkinURL()
+ {
+
+ Orientation orientation;
+
+ public void setOrientation(Orientation orientation)
+ {
+ this.orientation = orientation;
+ }
+
+ @Override
+ public String toString()
+ {
+ return urlPrefix + "/" + (PropertyManager.isDevelopping() ? "style" : service.id)
+ + service.getSuffix(orientation);
+ }
+ };
+ }
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigDeployer.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigDeployer.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigDeployer.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,133 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import org.exoplatform.container.PortalContainer;
-import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
-import org.exoplatform.portal.resource.config.xml.SkinConfigParser;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.gatein.wci.WebAppEvent;
-import org.gatein.wci.WebAppLifeCycleEvent;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.servlet.ServletContext;
-
-/**
- *
- * Created by eXoPlatform SAS
- *
- * Author: Minh Hoang TO - hoang281283(a)gmail.com
- *
- * Sep 16, 2009
- */
-public class GateinSkinConfigDeployer extends AbstractResourceHandler
-{
-
- private final SkinService skinService;
-
- private static final String GATEIN_CONFIG_RESOURCE = "/WEB-INF/gatein-resources.xml";
-
- private static Log LOG = ExoLogger.getExoLogger(GateinSkinConfigDeployer.class);
-
- /**
- * The name of the portal container
- */
- private final String portalContainerName;
-
- public GateinSkinConfigDeployer(String portalContainerName, SkinService _skinService)
- {
- this.skinService = _skinService;
- this.portalContainerName = portalContainerName;
- }
-
- @Override
- public void onEvent(WebAppEvent event)
- {
- if (event instanceof WebAppLifeCycleEvent)
- {
- WebAppLifeCycleEvent waEvent = (WebAppLifeCycleEvent)event;
- if (waEvent.getType() == WebAppLifeCycleEvent.ADDED)
- {
- ServletContext scontext = null;
- try
- {
- scontext = event.getWebApp().getServletContext();
- InputStream is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
- if (is == null)
- return;
- try
- {
- is.close();
- }
- catch (Exception ex)
- {
- // ignore me
- }
- final PortalContainerPostInitTask task = new PortalContainerPostInitTask()
- {
-
- public void execute(ServletContext scontext, PortalContainer portalContainer)
- {
- register(scontext, portalContainer);
- }
- };
- PortalContainer.addInitTask(scontext, task, portalContainerName);
- }
- catch (Exception ex)
- {
- LOG.error("An error occurs while registering '" + GATEIN_CONFIG_RESOURCE + "' from the context '"
- + (scontext == null ? "unknown" : scontext.getServletContextName()) + "'", ex);
- }
- }
- }
- }
-
- private void register(ServletContext scontext, PortalContainer container)
- {
- InputStream is = null;
- try
- {
- is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
- SkinConfigParser.processConfigResource(is, skinService, scontext);
- }
- catch (Exception ex)
- {
- LOG.error("An error occurs while registering '" + GATEIN_CONFIG_RESOURCE + "' from the context '"
- + (scontext == null ? "unknown" : scontext.getServletContextName()) + "'", ex);
- }
- finally
- {
- if (is != null)
- {
- try
- {
- is.close();
- }
- catch (IOException e)
- {
- // ignore me
- }
- }
- }
- }
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigDeployer.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigDeployer.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigDeployer.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigDeployer.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,132 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
+import org.exoplatform.portal.resource.config.xml.SkinConfigParser;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.gatein.wci.WebAppEvent;
+import org.gatein.wci.WebAppLifeCycleEvent;
+
+import javax.servlet.ServletContext;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ *
+ * Created by eXoPlatform SAS
+ *
+ * Author: Minh Hoang TO - hoang281283(a)gmail.com
+ *
+ * Sep 16, 2009
+ */
+public class GateinSkinConfigDeployer extends AbstractResourceHandler
+{
+
+ private final SkinService skinService;
+
+ private static final String GATEIN_CONFIG_RESOURCE = "/WEB-INF/gatein-resources.xml";
+
+ private static Log LOG = ExoLogger.getExoLogger(GateinSkinConfigDeployer.class);
+
+ /**
+ * The name of the portal container
+ */
+ private final String portalContainerName;
+
+ public GateinSkinConfigDeployer(String portalContainerName, SkinService _skinService)
+ {
+ this.skinService = _skinService;
+ this.portalContainerName = portalContainerName;
+ }
+
+ @Override
+ public void onEvent(WebAppEvent event)
+ {
+ if (event instanceof WebAppLifeCycleEvent)
+ {
+ WebAppLifeCycleEvent waEvent = (WebAppLifeCycleEvent)event;
+ if (waEvent.getType() == WebAppLifeCycleEvent.ADDED)
+ {
+ ServletContext scontext = null;
+ try
+ {
+ scontext = event.getWebApp().getServletContext();
+ InputStream is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
+ if (is == null)
+ return;
+ try
+ {
+ is.close();
+ }
+ catch (Exception ex)
+ {
+ // ignore me
+ }
+ final PortalContainerPostInitTask task = new PortalContainerPostInitTask()
+ {
+
+ public void execute(ServletContext scontext, PortalContainer portalContainer)
+ {
+ register(scontext, portalContainer);
+ }
+ };
+ PortalContainer.addInitTask(scontext, task, portalContainerName);
+ }
+ catch (Exception ex)
+ {
+ LOG.error("An error occurs while registering '" + GATEIN_CONFIG_RESOURCE + "' from the context '"
+ + (scontext == null ? "unknown" : scontext.getServletContextName()) + "'", ex);
+ }
+ }
+ }
+ }
+
+ private void register(ServletContext scontext, PortalContainer container)
+ {
+ InputStream is = null;
+ try
+ {
+ is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
+ SkinConfigParser.processConfigResource(is, skinService, scontext);
+ }
+ catch (Exception ex)
+ {
+ LOG.error("An error occurs while registering '" + GATEIN_CONFIG_RESOURCE + "' from the context '"
+ + (scontext == null ? "unknown" : scontext.getServletContextName()) + "'", ex);
+ }
+ finally
+ {
+ if (is != null)
+ {
+ try
+ {
+ is.close();
+ }
+ catch (IOException e)
+ {
+ // ignore me
+ }
+ }
+ }
+ }
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,80 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import javax.servlet.ServletContext;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-class MainResourceResolver implements ResourceResolver
-{
-
- final Map<String, SimpleResourceContext> contexts;
-
- final CopyOnWriteArrayList<ResourceResolver> resolvers;
-
- final Map<SkinKey, SkinConfig> skins;
-
- public MainResourceResolver(String portalContainerName, Map<SkinKey, SkinConfig> skins)
- {
- this.skins = skins;
- this.contexts = new HashMap<String, SimpleResourceContext>();
- this.resolvers = new CopyOnWriteArrayList<ResourceResolver>();
-
- //
- resolvers.add(new CompositeResourceResolver(portalContainerName, skins));
- }
-
- SimpleResourceContext registerContext(ServletContext servletContext)
- {
- String key = "/" + servletContext.getServletContextName();
- SimpleResourceContext ctx = contexts.get(key);
- if (ctx == null)
- {
- ctx = new SimpleResourceContext(key, servletContext);
- contexts.put(ctx.getContextPath(), ctx);
- }
- return ctx;
- }
-
- public Resource resolve(String path)
- {
- for (ResourceResolver resolver : resolvers)
- {
- Resource res = resolver.resolve(path);
- if (res != null)
- {
- return res;
- }
- }
-
- //
- int i1 = path.indexOf("/", 2);
- String targetedContextPath = path.substring(0, i1);
- SimpleResourceContext context = contexts.get(targetedContextPath);
- return context.getResource(path.substring(i1));
- }
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,79 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import javax.servlet.ServletContext;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+class MainResourceResolver implements ResourceResolver
+{
+
+ final Map<String, SimpleResourceContext> contexts;
+
+ final CopyOnWriteArrayList<ResourceResolver> resolvers;
+
+ final Map<SkinKey, SkinConfig> skins;
+
+ public MainResourceResolver(String portalContainerName, Map<SkinKey, SkinConfig> skins)
+ {
+ this.skins = skins;
+ this.contexts = new HashMap<String, SimpleResourceContext>();
+ this.resolvers = new CopyOnWriteArrayList<ResourceResolver>();
+
+ //
+ resolvers.add(new CompositeResourceResolver(portalContainerName, skins));
+ }
+
+ SimpleResourceContext registerContext(ServletContext servletContext)
+ {
+ String key = "/" + servletContext.getServletContextName();
+ SimpleResourceContext ctx = contexts.get(key);
+ if (ctx == null)
+ {
+ ctx = new SimpleResourceContext(key, servletContext);
+ contexts.put(ctx.getContextPath(), ctx);
+ }
+ return ctx;
+ }
+
+ public Resource resolve(String path)
+ {
+ for (ResourceResolver resolver : resolvers)
+ {
+ Resource res = resolver.resolve(path);
+ if (res != null)
+ {
+ return res;
+ }
+ }
+
+ //
+ int i1 = path.indexOf("/", 2);
+ String targetedContextPath = path.substring(0, i1);
+ SimpleResourceContext context = contexts.get(targetedContextPath);
+ return context.getResource(path.substring(i1));
+ }
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/RenderingException.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/RenderingException.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/RenderingException.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,49 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-/**
- * Signal an exception during rendering.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public class RenderingException extends Exception
-{
-
- public RenderingException()
- {
- }
-
- public RenderingException(String message)
- {
- super(message);
- }
-
- public RenderingException(String message, Throwable cause)
- {
- super(message, cause);
- }
-
- public RenderingException(Throwable cause)
- {
- super(cause);
- }
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/RenderingException.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/RenderingException.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/RenderingException.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/RenderingException.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,49 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+/**
+ * Signal an exception during rendering.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class RenderingException extends Exception
+{
+
+ public RenderingException()
+ {
+ }
+
+ public RenderingException(String message)
+ {
+ super(message);
+ }
+
+ public RenderingException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public RenderingException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Resource.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/Resource.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Resource.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,85 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import java.io.IOException;
-import java.io.Reader;
-
-/**
- * Represents a resource.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public abstract class Resource
-{
-
- private final String contextPath;
-
- private final String parentPath;
-
- private final String fileName;
-
- public Resource(String path)
- {
- int index = path.indexOf("/", 2);
- String relativeCSSPath = path.substring(index);
- int index2 = relativeCSSPath.lastIndexOf("/") + 1;
-
- //
- this.contextPath = path.substring(0, index);
- this.parentPath = relativeCSSPath.substring(0, index2);
- this.fileName = relativeCSSPath.substring(index2);
- }
-
- public Resource(String contextPath, String parentPath, String fileName)
- {
- this.contextPath = contextPath;
- this.parentPath = parentPath;
- this.fileName = fileName;
- }
-
- public final String getPath()
- {
- return getContextPath() + getParentPath() + getFileName();
- }
-
- public final String getContextPath()
- {
- return contextPath;
- }
-
- public final String getParentPath()
- {
- return parentPath;
- }
-
- public final String getFileName()
- {
- return fileName;
- }
-
- public final String getResourcePath()
- {
- return getParentPath() + getFileName();
- }
-
- public abstract Reader read() throws IOException;
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Resource.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/Resource.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Resource.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Resource.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,85 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * Represents a resource.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public abstract class Resource
+{
+
+ private final String contextPath;
+
+ private final String parentPath;
+
+ private final String fileName;
+
+ public Resource(String path)
+ {
+ int index = path.indexOf("/", 2);
+ String relativeCSSPath = path.substring(index);
+ int index2 = relativeCSSPath.lastIndexOf("/") + 1;
+
+ //
+ this.contextPath = path.substring(0, index);
+ this.parentPath = relativeCSSPath.substring(0, index2);
+ this.fileName = relativeCSSPath.substring(index2);
+ }
+
+ public Resource(String contextPath, String parentPath, String fileName)
+ {
+ this.contextPath = contextPath;
+ this.parentPath = parentPath;
+ this.fileName = fileName;
+ }
+
+ public final String getPath()
+ {
+ return getContextPath() + getParentPath() + getFileName();
+ }
+
+ public final String getContextPath()
+ {
+ return contextPath;
+ }
+
+ public final String getParentPath()
+ {
+ return parentPath;
+ }
+
+ public final String getFileName()
+ {
+ return fileName;
+ }
+
+ public final String getResourcePath()
+ {
+ return getParentPath() + getFileName();
+ }
+
+ public abstract Reader read() throws IOException;
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceRenderer.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceRenderer.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceRenderer.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,47 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-/**
- * An interface defining the renderer contract for a resource.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public interface ResourceRenderer
-{
-
- /**
- * Returns an appendable for the performing the rendering of the resource.
- *
- * @return the appendable
- */
- Appendable getAppendable();
-
- /**
- * Instruct the renderer about the expiration time in seconds. A non positive value
- * means that no caching should be performed. The expiration value is relative to the
- * date of the request.
- *
- * @param seconds the value in seconds
- */
- void setExpiration(long seconds);
-
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceRenderer.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceRenderer.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceRenderer.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceRenderer.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,47 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+/**
+ * An interface defining the renderer contract for a resource.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public interface ResourceRenderer
+{
+
+ /**
+ * Returns an appendable for the performing the rendering of the resource.
+ *
+ * @return the appendable
+ */
+ Appendable getAppendable();
+
+ /**
+ * Instruct the renderer about the expiration time in seconds. A non positive value
+ * means that no caching should be performed. The expiration value is relative to the
+ * date of the request.
+ *
+ * @param seconds the value in seconds
+ */
+ void setExpiration(long seconds);
+
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,39 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-/**
- * A resource resolver for char based resources.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public interface ResourceResolver
-{
-
- /**
- * Returns a reader for the provided path or null if the resource cannot be resolved.
- *
- * @param path the path
- * @return a reader
- */
- Resource resolve(String path);
-
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+/**
+ * A resource resolver for char based resources.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public interface ResourceResolver
+{
+
+ /**
+ * Returns a reader for the provided path or null if the resource cannot be resolved.
+ *
+ * @param path the path
+ * @return a reader
+ */
+ Resource resolve(String path);
+
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,78 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.servlet.ServletContext;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-class SimpleResourceContext
-{
-
- private final String contextPath;
-
- private final ServletContext context;
-
- public SimpleResourceContext(String contextPath, ServletContext context)
- {
- this.contextPath = contextPath;
- this.context = context;
- }
-
- public Resource getResource(String path)
- {
- int i2 = path.lastIndexOf("/") + 1;
- String targetedParentPath = path.substring(0, i2);
- String targetedFileName = path.substring(i2);
- try
- {
- final URL url = context.getResource(path);
- if (url != null)
- {
- return new Resource(contextPath, targetedParentPath, targetedFileName)
- {
- @Override
- public Reader read() throws IOException
- {
- return new InputStreamReader(url.openStream());
- }
- };
- }
- }
- catch (MalformedURLException e)
- {
- e.printStackTrace();
- }
- return null;
- }
-
- public String getContextPath()
- {
- return contextPath;
- }
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,77 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import javax.servlet.ServletContext;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+class SimpleResourceContext
+{
+
+ private final String contextPath;
+
+ private final ServletContext context;
+
+ public SimpleResourceContext(String contextPath, ServletContext context)
+ {
+ this.contextPath = contextPath;
+ this.context = context;
+ }
+
+ public Resource getResource(String path)
+ {
+ int i2 = path.lastIndexOf("/") + 1;
+ String targetedParentPath = path.substring(0, i2);
+ String targetedFileName = path.substring(i2);
+ try
+ {
+ final URL url = context.getResource(path);
+ if (url != null)
+ {
+ return new Resource(contextPath, targetedParentPath, targetedFileName)
+ {
+ @Override
+ public Reader read() throws IOException
+ {
+ return new InputStreamReader(url.openStream());
+ }
+ };
+ }
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public String getContextPath()
+ {
+ return contextPath;
+ }
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleSkin.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleSkin.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleSkin.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,91 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import org.exoplatform.services.resources.Orientation;
-
-/**
- * An implementation of the skin config.
- *
- * Created by The eXo Platform SAS
- * Jan 19, 2007
- */
-class SimpleSkin implements SkinConfig
-{
-
- private final SkinService service_;
-
- private final String module_;
-
- private final String name_;
-
- private final String cssPath_;
-
- private final String id_;
-
- public SimpleSkin(SkinService service, String module, String name, String cssPath)
- {
- service_ = service;
- module_ = module;
- name_ = name;
- cssPath_ = cssPath;
- id_ = module.replace('/', '_');
- }
-
- public String getId()
- {
- return id_;
- }
-
- public String getModule()
- {
- return module_;
- }
-
- public String getCSSPath()
- {
- return cssPath_;
- }
-
- public String getName()
- {
- return name_;
- }
-
- public SkinURL createURL()
- {
- return new SkinURL()
- {
-
- Orientation orientation = null;
-
- public void setOrientation(Orientation orientation)
- {
- this.orientation = orientation;
- }
-
- @Override
- public String toString()
- {
- return cssPath_.replaceAll("\\.css$", service_.getSuffix(orientation));
- }
- };
- }
-}
\ No newline at end of file
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleSkin.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleSkin.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleSkin.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SimpleSkin.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,91 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import org.exoplatform.services.resources.Orientation;
+
+/**
+ * An implementation of the skin config.
+ *
+ * Created by The eXo Platform SAS
+ * Jan 19, 2007
+ */
+class SimpleSkin implements SkinConfig
+{
+
+ private final SkinService service_;
+
+ private final String module_;
+
+ private final String name_;
+
+ private final String cssPath_;
+
+ private final String id_;
+
+ public SimpleSkin(SkinService service, String module, String name, String cssPath)
+ {
+ service_ = service;
+ module_ = module;
+ name_ = name;
+ cssPath_ = cssPath;
+ id_ = module.replace('/', '_');
+ }
+
+ public String getId()
+ {
+ return id_;
+ }
+
+ public String getModule()
+ {
+ return module_;
+ }
+
+ public String getCSSPath()
+ {
+ return cssPath_;
+ }
+
+ public String getName()
+ {
+ return name_;
+ }
+
+ public SkinURL createURL()
+ {
+ return new SkinURL()
+ {
+
+ Orientation orientation = null;
+
+ public void setOrientation(Orientation orientation)
+ {
+ this.orientation = orientation;
+ }
+
+ @Override
+ public String toString()
+ {
+ return cssPath_.replaceAll("\\.css$", service_.getSuffix(orientation));
+ }
+ };
+ }
+}
\ No newline at end of file
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Skin.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/Skin.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Skin.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,45 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-/**
- * A skin.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public interface Skin
-{
-
- /**
- * Returns the skin id.
- *
- * @return the skin id
- */
- String getId();
-
- /**
- * Creates and return a skin URL.
- *
- * @return the skin URL
- */
- SkinURL createURL();
-
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Skin.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/Skin.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Skin.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/Skin.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,45 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+/**
+ * A skin.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public interface Skin
+{
+
+ /**
+ * Returns the skin id.
+ *
+ * @return the skin id
+ */
+ String getId();
+
+ /**
+ * Creates and return a skin URL.
+ *
+ * @return the skin URL
+ */
+ SkinURL createURL();
+
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfig.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfig.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfig.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,52 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-/**
- * Extends a skin with additional information.
- *
- * Created by The eXo Platform SAS
- * Jan 19, 2007
- */
-public interface SkinConfig extends Skin
-{
-
- /**
- * Returns the skin name
- *
- * @return the skin name
- */
- String getName();
-
- /**
- * Returns the skin module.
- *
- * @return the module
- */
- String getModule();
-
- /**
- * Returns the css path.
- *
- * @return the css path
- */
- String getCSSPath();
-
-}
\ No newline at end of file
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfig.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfig.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfig.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfig.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,52 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+/**
+ * Extends a skin with additional information.
+ *
+ * Created by The eXo Platform SAS
+ * Jan 19, 2007
+ */
+public interface SkinConfig extends Skin
+{
+
+ /**
+ * Returns the skin name
+ *
+ * @return the skin name
+ */
+ String getName();
+
+ /**
+ * Returns the skin module.
+ *
+ * @return the module
+ */
+ String getModule();
+
+ /**
+ * Returns the css path.
+ *
+ * @return the css path
+ */
+ String getCSSPath();
+
+}
\ No newline at end of file
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,139 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import groovy.lang.Binding;
-import groovy.lang.GroovyShell;
-
-import org.exoplatform.container.PortalContainer;
-import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.gatein.wci.WebAppEvent;
-import org.gatein.wci.WebAppLifeCycleEvent;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.servlet.ServletContext;
-
-/**
- * Created by The eXo Platform SAS
- * Jan 19, 2007
- */
-
-public class SkinConfigDeployer extends AbstractResourceHandler
-{
-
- /**
- * Logger
- */
- private static final Log LOG = ExoLogger.getLogger(SkinConfigDeployer.class);
-
- /** . */
- private final SkinService skinService;
-
- /**
- * The name of the portal container
- */
- private final String portalContainerName;
-
- public SkinConfigDeployer(String portalContainerName, SkinService skinService)
- {
- this.skinService = skinService;
- this.portalContainerName = portalContainerName;
- }
-
- public void onEvent(WebAppEvent event)
- {
- if (event instanceof WebAppLifeCycleEvent)
- {
- WebAppLifeCycleEvent waEvent = (WebAppLifeCycleEvent)event;
- if (waEvent.getType() == WebAppLifeCycleEvent.ADDED)
- {
- ServletContext scontext = null;
- try
- {
- scontext = event.getWebApp().getServletContext();
- InputStream is = scontext.getResourceAsStream("/WEB-INF/conf/script/groovy/SkinConfigScript.groovy");
- if (is == null)
- return;
- try
- {
- is.close();
- }
- catch (Exception ex)
- {
- // ignore me
- }
- final PortalContainerPostInitTask task = new PortalContainerPostInitTask()
- {
-
- public void execute(ServletContext scontext, PortalContainer portalContainer)
- {
- register(scontext, portalContainer);
- }
- };
- PortalContainer.addInitTask(scontext, task, portalContainerName);
- }
- catch (Exception ex)
- {
- LOG.error("An error occurs while registering 'SkinConfigScript.groovy' from the context '"
- + (scontext == null ? "unknown" : scontext.getServletContextName()) + "'", ex);
- }
- }
- }
- }
-
- private void register(ServletContext scontext, PortalContainer container)
- {
- InputStream is = null;
- try
- {
- is = scontext.getResourceAsStream("/WEB-INF/conf/script/groovy/SkinConfigScript.groovy");
- Binding binding = new Binding();
- binding.setVariable("SkinService", skinService);
- binding.setVariable("ServletContext", scontext);
- binding.setVariable("ServletContextName", scontext.getServletContextName());
- binding.setVariable("PortalContainerName", container.getName());
- GroovyShell shell = new GroovyShell(binding);
- shell.evaluate(is);
- }
- catch (Exception ex)
- {
- LOG.error("An error occurs while processing 'SkinConfigScript.groovy' from the context '"
- + scontext.getServletContextName() + "'", ex);
- }
- finally
- {
- if (is != null)
- {
- try
- {
- is.close();
- }
- catch (IOException e)
- {
- // ignore me
- }
- }
- }
- }
-}
\ No newline at end of file
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,137 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import groovy.lang.Binding;
+import groovy.lang.GroovyShell;
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.gatein.wci.WebAppEvent;
+import org.gatein.wci.WebAppLifeCycleEvent;
+
+import javax.servlet.ServletContext;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Created by The eXo Platform SAS
+ * Jan 19, 2007
+ */
+
+public class SkinConfigDeployer extends AbstractResourceHandler
+{
+
+ /**
+ * Logger
+ */
+ private static final Log LOG = ExoLogger.getLogger(SkinConfigDeployer.class);
+
+ /** . */
+ private final SkinService skinService;
+
+ /**
+ * The name of the portal container
+ */
+ private final String portalContainerName;
+
+ public SkinConfigDeployer(String portalContainerName, SkinService skinService)
+ {
+ this.skinService = skinService;
+ this.portalContainerName = portalContainerName;
+ }
+
+ public void onEvent(WebAppEvent event)
+ {
+ if (event instanceof WebAppLifeCycleEvent)
+ {
+ WebAppLifeCycleEvent waEvent = (WebAppLifeCycleEvent)event;
+ if (waEvent.getType() == WebAppLifeCycleEvent.ADDED)
+ {
+ ServletContext scontext = null;
+ try
+ {
+ scontext = event.getWebApp().getServletContext();
+ InputStream is = scontext.getResourceAsStream("/WEB-INF/conf/script/groovy/SkinConfigScript.groovy");
+ if (is == null)
+ return;
+ try
+ {
+ is.close();
+ }
+ catch (Exception ex)
+ {
+ // ignore me
+ }
+ final PortalContainerPostInitTask task = new PortalContainerPostInitTask()
+ {
+
+ public void execute(ServletContext scontext, PortalContainer portalContainer)
+ {
+ register(scontext, portalContainer);
+ }
+ };
+ PortalContainer.addInitTask(scontext, task, portalContainerName);
+ }
+ catch (Exception ex)
+ {
+ LOG.error("An error occurs while registering 'SkinConfigScript.groovy' from the context '"
+ + (scontext == null ? "unknown" : scontext.getServletContextName()) + "'", ex);
+ }
+ }
+ }
+ }
+
+ private void register(ServletContext scontext, PortalContainer container)
+ {
+ InputStream is = null;
+ try
+ {
+ is = scontext.getResourceAsStream("/WEB-INF/conf/script/groovy/SkinConfigScript.groovy");
+ Binding binding = new Binding();
+ binding.setVariable("SkinService", skinService);
+ binding.setVariable("ServletContext", scontext);
+ binding.setVariable("ServletContextName", scontext.getServletContextName());
+ binding.setVariable("PortalContainerName", container.getName());
+ GroovyShell shell = new GroovyShell(binding);
+ shell.evaluate(is);
+ }
+ catch (Exception ex)
+ {
+ LOG.error("An error occurs while processing 'SkinConfigScript.groovy' from the context '"
+ + scontext.getServletContextName() + "'", ex);
+ }
+ finally
+ {
+ if (is != null)
+ {
+ try
+ {
+ is.close();
+ }
+ catch (IOException e)
+ {
+ // ignore me
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinKey.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinKey.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinKey.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,98 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-/**
- * A key for skin config lookup.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-class SkinKey
-{
-
- private final String module;
-
- private final String name;
-
- private final int hashCode;
-
- /**
- * Creates a new skin key.
- *
- * @param module the skin base
- * @param name the skin name
- * @throws IllegalArgumentException if any argument is null
- */
- public SkinKey(String module, String name) throws IllegalArgumentException
- {
- if (module == null)
- {
- throw new IllegalArgumentException("No null base accepted");
- }
- if (name == null)
- {
- throw new IllegalArgumentException("No null skin name accepted");
- }
-
- //
- this.module = module;
- this.name = name;
- this.hashCode = module.hashCode() * 41 + name.hashCode();
- }
-
- public String getModule()
- {
- return module;
- }
-
- public String getName()
- {
- return name;
- }
-
- public int hashCode()
- {
- return hashCode;
- }
-
- public boolean equals(Object obj)
- {
- if (obj == null)
- {
- return false;
- }
- if (obj == this)
- {
- return true;
- }
- if (obj instanceof SkinKey)
- {
- SkinKey that = (SkinKey)obj;
- return that.module.equals(module) && that.name.equals(name);
- }
- return false;
- }
-
- public String toString()
- {
- return "SkinKey[base=" + module + ",name=" + name + "]";
- }
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinKey.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinKey.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinKey.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinKey.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,98 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+/**
+ * A key for skin config lookup.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+class SkinKey
+{
+
+ private final String module;
+
+ private final String name;
+
+ private final int hashCode;
+
+ /**
+ * Creates a new skin key.
+ *
+ * @param module the skin base
+ * @param name the skin name
+ * @throws IllegalArgumentException if any argument is null
+ */
+ public SkinKey(String module, String name) throws IllegalArgumentException
+ {
+ if (module == null)
+ {
+ throw new IllegalArgumentException("No null base accepted");
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException("No null skin name accepted");
+ }
+
+ //
+ this.module = module;
+ this.name = name;
+ this.hashCode = module.hashCode() * 41 + name.hashCode();
+ }
+
+ public String getModule()
+ {
+ return module;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public int hashCode()
+ {
+ return hashCode;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof SkinKey)
+ {
+ SkinKey that = (SkinKey)obj;
+ return that.module.equals(module) && that.name.equals(name);
+ }
+ return false;
+ }
+
+ public String toString()
+ {
+ return "SkinKey[base=" + module + ",name=" + name + "]";
+ }
+}
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,557 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import org.exoplatform.commons.utils.PropertyManager;
-import org.exoplatform.commons.utils.Safe;
-import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.management.annotations.Managed;
-import org.exoplatform.management.annotations.ManagedDescription;
-import org.exoplatform.management.annotations.ManagedName;
-import org.exoplatform.management.jmx.annotations.NameTemplate;
-import org.exoplatform.management.jmx.annotations.Property;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.exoplatform.services.resources.Orientation;
-import org.gatein.wci.impl.DefaultServletContainerFactory;
-import org.picocontainer.Startable;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.servlet.ServletContext;
-
-@Managed
-@NameTemplate({@Property(key = "view", value = "portal"), @Property(key = "service", value = "management"),
- @Property(key = "type", value = "skin")})
-@ManagedDescription("Skin service")
-public class SkinService implements Startable
-{
-
- protected static Log log = ExoLogger.getLogger("portal.SkinService");
-
- private static final Map<Orientation, String> suffixMap = new EnumMap<Orientation, String>(Orientation.class);
-
- static
- {
- suffixMap.put(Orientation.LT, "-lt.css");
- suffixMap.put(Orientation.RT, "-rt.css");
- suffixMap.put(Orientation.TL, "-lt.css");
- suffixMap.put(Orientation.TR, "-lt.css");
- }
-
- private static final String LEFT_P = "\\(";
-
- private static final String RIGHT_P = "\\)";
-
- /** Immutable and therefore thread safe. */
- private static final Pattern IMPORT_PATTERN =
- Pattern.compile("(@import\\s+" + "url" + LEFT_P + "['\"]?" + ")([^'\"]+.css)(" + "['\"]?" + RIGHT_P + "\\s*;)");
-
- /** Immutable and therefore thread safe. */
- private static final Pattern BACKGROUND_PATTERN =
- Pattern.compile("(background.*:.*url" + LEFT_P + "['\"]?" + ")([^'\"]+)(" + "['\"]?" + RIGHT_P + ".*;)");
-
- /** Immutable and therefore thread safe. */
- private static final Pattern LT = Pattern.compile("/\\*\\s*orientation=lt\\s*\\*/");
-
- /** Immutable and therefore thread safe. */
- private static final Pattern RT = Pattern.compile("/\\*\\s*orientation=rt\\s*\\*/");
-
- /** One month caching. */
- private static final int ONE_MONTH = 2592000;
-
- /** One hour caching. */
- private static final int ONE_HOUR = 3600;
-
- /** The deployer. */
- private final AbstractResourceHandler deployer;
-
- private final Map<SkinKey, SkinConfig> portalSkins_;
-
- private final Map<SkinKey, SkinConfig> skinConfigs_;
-
- private final HashSet<String> availableSkins_;
-
- private final Map<String, String> ltCache;
-
- private final Map<String, String> rtCache;
-
- private final Map<String, Set<String>> portletThemes_;
-
- private final MainResourceResolver mainResolver;
-
- /**
- * The name of the portal container
- */
- final String portalContainerName;
-
- /**
- * An id used for caching request. The id life cycle is the same than the class instance because
- * we consider css will change until server is restarted. Of course this only applies for the
- * developing mode set to false.
- */
- final String id = Long.toString(System.currentTimeMillis());
-
- /** Temporary hack. */
- //private static final List<String> skinBlackList = Arrays.asList("Vista", "Mac");
- private static final List<String> skinBlackList = new ArrayList<String>();
-
- public SkinService(ExoContainerContext context)
- {
- portalSkins_ = new LinkedHashMap<SkinKey, SkinConfig>();
- skinConfigs_ = new LinkedHashMap<SkinKey, SkinConfig>(20);
- availableSkins_ = new HashSet<String>(5);
- ltCache = new ConcurrentHashMap<String, String>();
- rtCache = new ConcurrentHashMap<String, String>();
- portletThemes_ = new HashMap<String, Set<String>>();
- portalContainerName = context.getPortalContainerName();
- mainResolver = new MainResourceResolver(portalContainerName, skinConfigs_);
- //deployer = new SkinConfigDeployer(portalContainerName, this);
- deployer = new GateinSkinConfigDeployer(portalContainerName, this);
- }
-
- public void addCategoryTheme(String categoryName)
- {
- if (!portletThemes_.containsKey(categoryName))
- portletThemes_.put(categoryName, new HashSet<String>());
- }
-
- public void addPortalSkin(String module, String skinName, String cssPath, ServletContext scontext)
- {
- addPortalSkin(module, skinName, cssPath, scontext, false);
- }
-
- /**
- * Register the stylesheet for a portal Skin.
- *
- * @param module skin module identifier
- * @param skinName skin name
- * @param cssPath path uri to the css file. This is relative to the root context, use leading '/'
- * @param scontext the webapp's {@link javax.servlet.ServletContext}
- * @param overwrite if any previous skin should be replaced by that one
- */
- public void addPortalSkin(String module, String skinName, String cssPath, ServletContext scontext, boolean overwrite)
- {
-
- // Triggers a put if absent
- mainResolver.registerContext(scontext);
-
- availableSkins_.add(skinName);
- SkinKey key = new SkinKey(module, skinName);
- SkinConfig skinConfig = portalSkins_.get(key);
- if (skinConfig == null || overwrite)
- {
- skinConfig = new SimpleSkin(this, module, skinName, cssPath);
- portalSkins_.put(key, skinConfig);
- }
- }
-
- public void addPortalSkin(String module, String skinName, String cssPath, String cssData)
- {
- SkinKey key = new SkinKey(module, skinName);
- SkinConfig skinConfig = portalSkins_.get(key);
- if (skinConfig == null)
- {
- portalSkins_.put(key, new SimpleSkin(this, module, skinName, cssPath));
- }
- ltCache.put(cssPath, cssData);
- rtCache.put(cssPath, cssData);
- }
-
- public void addSkin(String module, String skinName, String cssPath, ServletContext scontext)
- {
- addSkin(module, skinName, cssPath, scontext, false);
- }
-
- /**
- * Merge several skins into one single skin.
- *
- * @param skins the skins to merge
- * @return the merged skin
- */
- public Skin merge(Collection<SkinConfig> skins)
- {
- return new CompositeSkin(this, skins);
- }
-
- /**
- * Add a resource resolver to plug external resolvers.
- *
- * @param resolver a resolver to add
- */
- public void addResourceResolver(ResourceResolver resolver)
- {
- mainResolver.resolvers.addIfAbsent(resolver);
- }
-
- public void addSkin(String module, String skinName, String cssPath, ServletContext scontext, boolean overwrite)
- {
- // Triggers a put if absent
- mainResolver.registerContext(scontext);
-
- availableSkins_.add(skinName);
- SkinKey key = new SkinKey(module, skinName);
- SkinConfig skinConfig = skinConfigs_.get(key);
- if (skinConfig == null || overwrite)
- {
- skinConfig = new SimpleSkin(this, module, skinName, cssPath);
- skinConfigs_.put(key, skinConfig);
- }
- }
-
- public void addSkin(String module, String skinName, String cssPath, String cssData)
- {
- //
- availableSkins_.add(skinName);
- SkinKey key = new SkinKey(module, skinName);
- SkinConfig skinConfig = skinConfigs_.get(key);
- if (skinConfig == null)
- {
- skinConfigs_.put(key, new SimpleSkin(this, module, skinName, cssPath));
- }
- ltCache.put(cssPath, cssData);
- rtCache.put(cssPath, cssData);
- }
-
- public void addTheme(String categoryName, List<String> themesName)
- {
- if (!portletThemes_.containsKey(categoryName))
- portletThemes_.put(categoryName, new HashSet<String>());
- Set<String> catThemes = portletThemes_.get(categoryName);
- for (String theme : themesName)
- catThemes.add(theme);
- }
-
- /**
- * Get names of all the currently registered skins.
- *
- * @return an unmodifiable Set of the currently registered skins
- */
- public Set<String> getAvailableSkinNames()
- {
- return availableSkins_;
- }
-
- /**
- * Return the CSS content of the file specified by the given URI.
- *
- * @param cssPath path of the css to find
- * @return the css
- */
- public String getCSS(String cssPath)
- {
- try
- {
- final StringBuilder sb = new StringBuilder();
- renderCSS(new ResourceRenderer()
- {
- public Appendable getAppendable()
- {
- return sb;
- }
-
- public void setExpiration(long seconds)
- {
-
- }
- }, cssPath);
- return sb.toString();
- }
- catch (IOException e)
- {
- log.error("Error while rendering css " + cssPath, e);
- return null;
- }
- catch (RenderingException e)
- {
- log.error("Error while rendering css " + cssPath, e);
- return null;
- }
- }
-
- public void renderCSS(ResourceRenderer renderer, String path) throws RenderingException, IOException
- {
- Orientation orientation = Orientation.LT;
- if (path.endsWith("-lt.css"))
- {
- path = path.substring(0, path.length() - "-lt.css".length()) + ".css";
- }
- else if (path.endsWith("-rt.css"))
- {
- path = path.substring(0, path.length() - "-rt.css".length()) + ".css";
- orientation = Orientation.RT;
- }
-
- // Try cache first
- if (!PropertyManager.isDevelopping())
- {
-
- if (path.startsWith("/" + portalContainerName + "/resource"))
- {
- renderer.setExpiration(ONE_MONTH);
- }
- else
- {
- renderer.setExpiration(ONE_HOUR);
- }
-
- //
- Map<String, String> cache = orientation == Orientation.LT ? ltCache : rtCache;
- String css = cache.get(path);
- if (css == null)
- {
- StringBuilder sb = new StringBuilder();
- processCSS(sb, path, orientation, true);
- css = sb.toString();
- cache.put(path, css);
- }
- renderer.getAppendable().append(css);
- }
- else
- {
- processCSS(renderer.getAppendable(), path, orientation, false);
- }
- }
-
- public String getMergedCSS(String cssPath)
- {
- return ltCache.get(cssPath);
- }
-
- public Collection<SkinConfig> getPortalSkins(String skinName)
- {
- Set<SkinKey> keys = portalSkins_.keySet();
- Collection<SkinConfig> portalSkins = new ArrayList<SkinConfig>();
- for (SkinKey key : keys)
- {
- if (key.getName().equals(skinName))
- portalSkins.add(portalSkins_.get(key));
- }
- return portalSkins;
- }
-
- public Map<String, Set<String>> getPortletThemes()
- {
- return portletThemes_;
- }
-
- public SkinConfig getSkin(String module, String skinName)
- {
- SkinConfig config = skinConfigs_.get(new SkinKey(module, skinName));
- if (config == null)
- skinConfigs_.get(new SkinKey(module, "Default"));
- return config;
- }
-
- public void invalidatePortalSkinCache(String portalName, String skinName)
- {
- SkinKey key = new SkinKey(portalName, skinName);
- skinConfigs_.remove(key);
- }
-
- public void remove(String module, String skinName) throws Exception
- {
- SkinKey key;
- if (skinName.length() == 0)
- key = new SkinKey(module, "Default");
- else
- key = new SkinKey(module, skinName);
- skinConfigs_.remove(key);
- }
-
- public int size()
- {
- return skinConfigs_.size();
- }
-
- private void processCSS(Appendable appendable, String cssPath, Orientation orientation, boolean merge)
- throws RenderingException, IOException
- {
- Resource skin = mainResolver.resolve(cssPath);
- processCSSRecursively(appendable, merge, skin, orientation);
- }
-
- private void processCSSRecursively(Appendable appendable, boolean merge, Resource skin, Orientation orientation)
- throws RenderingException, IOException
- {
-
- // The root URL for the entry
- String basePath = skin.getContextPath() + skin.getParentPath();
-
- //
- String line = "";
- Reader tmp = skin.read();
- if (tmp == null)
- {
- throw new RenderingException("No skin resolved for path " + skin.getResourcePath());
- }
- BufferedReader reader = new BufferedReader(tmp);
- try
- {
- while ((line = reader.readLine()) != null)
- {
- Matcher matcher = IMPORT_PATTERN.matcher(line);
- if (matcher.find())
- {
- String includedPath = matcher.group(2);
- if (includedPath.startsWith("/"))
- {
- if (merge)
- {
- Resource ssskin = mainResolver.resolve(includedPath);
- processCSSRecursively(appendable, merge, ssskin, orientation);
- }
- else
- {
- appendable.append(matcher.group(1)).append(
- includedPath.substring(0, includedPath.length() - ".css".length())).append(
- getSuffix(orientation)).append(matcher.group(3)).append("\n");
- }
- }
- else
- {
- if (merge)
- {
- String path = skin.getContextPath() + skin.getParentPath() + includedPath;
- Resource ssskin = mainResolver.resolve(path);
- processCSSRecursively(appendable, merge, ssskin, orientation);
- }
- else
- {
- appendable.append(matcher.group(1));
- appendable.append(basePath);
- appendable.append(includedPath.substring(0, includedPath.length() - ".css".length()));
- appendable.append(getSuffix(orientation));
- appendable.append(matcher.group(3));
- }
- }
- }
- else
- {
- if (orientation == null || wantInclude(line, orientation))
- {
- append(line, basePath, appendable);
- }
- }
- }
- }
- finally
- {
- Safe.close(reader);
- }
- }
-
- /**
- * Filter what if it's annotated with the alternative orientation.
- *
- * @param line the line to include
- * @param orientation the orientation
- * @return true if the line is included
- */
- private boolean wantInclude(String line, Orientation orientation)
- {
- Pattern orientationPattern = orientation == Orientation.LT ? RT : LT;
- Matcher matcher2 = orientationPattern.matcher(line);
- return !matcher2.find();
- }
-
- private void append(String line, String basePath, Appendable appendable) throws IOException
- {
- // Rewrite background url pattern
- Matcher matcher = BACKGROUND_PATTERN.matcher(line);
- if (matcher.find() && !matcher.group(2).startsWith("\"/") && !matcher.group(2).startsWith("'/")
- && !matcher.group(2).startsWith("/"))
- {
- appendable.append(matcher.group(1)).append(basePath).append(matcher.group(2)).append(matcher.group(3)).append(
- '\n');
- }
- else
- {
- appendable.append(line).append('\n');
- }
- }
-
- String getSuffix(Orientation orientation)
- {
- if (orientation == null)
- {
- orientation = Orientation.LT;
- }
- return suffixMap.get(orientation);
- }
-
- @Managed
- @ManagedDescription("The list of registered skins identifiers")
- public String[] getSkinList()
- {
- // get all available skin
- List<String> availableSkin = new ArrayList<String>();
- for (String skin : availableSkins_)
- {
- availableSkin.add(skin);
- }
- // sort skin name asc
- Collections.sort(availableSkin);
-
- return availableSkin.toArray(new String[availableSkin.size()]);
- }
-
- @Managed
- @ManagedDescription("Reload all skins")
- public void reloadSkins()
- {
- // remove all ltCache, rtCache
- ltCache.clear();
- rtCache.clear();
- }
-
- @Managed
- @ManagedDescription("Reload a specified skin")
- public void reloadSkin(@ManagedDescription("The skin id") @ManagedName("skinId") String skinId)
- {
- ltCache.remove(skinId);
- rtCache.remove(skinId);
- }
-
- public void start()
- {
- DefaultServletContainerFactory.getInstance().getServletContainer().addWebAppListener(deployer);
- }
-
- public void stop()
- {
- DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(deployer);
- }
-}
\ No newline at end of file
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,556 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import org.exoplatform.commons.utils.PropertyManager;
+import org.exoplatform.commons.utils.Safe;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.management.annotations.Managed;
+import org.exoplatform.management.annotations.ManagedDescription;
+import org.exoplatform.management.annotations.ManagedName;
+import org.exoplatform.management.jmx.annotations.NameTemplate;
+import org.exoplatform.management.jmx.annotations.Property;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.resources.Orientation;
+import org.gatein.wci.impl.DefaultServletContainerFactory;
+import org.picocontainer.Startable;
+
+import javax.servlet.ServletContext;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+@Managed
+@NameTemplate({@Property(key = "view", value = "portal"), @Property(key = "service", value = "management"),
+ @Property(key = "type", value = "skin")})
+@ManagedDescription("Skin service")
+public class SkinService implements Startable
+{
+
+ protected static Log log = ExoLogger.getLogger("portal.SkinService");
+
+ private static final Map<Orientation, String> suffixMap = new EnumMap<Orientation, String>(Orientation.class);
+
+ static
+ {
+ suffixMap.put(Orientation.LT, "-lt.css");
+ suffixMap.put(Orientation.RT, "-rt.css");
+ suffixMap.put(Orientation.TL, "-lt.css");
+ suffixMap.put(Orientation.TR, "-lt.css");
+ }
+
+ private static final String LEFT_P = "\\(";
+
+ private static final String RIGHT_P = "\\)";
+
+ /** Immutable and therefore thread safe. */
+ private static final Pattern IMPORT_PATTERN =
+ Pattern.compile("(@import\\s+" + "url" + LEFT_P + "['\"]?" + ")([^'\"]+.css)(" + "['\"]?" + RIGHT_P + "\\s*;)");
+
+ /** Immutable and therefore thread safe. */
+ private static final Pattern BACKGROUND_PATTERN =
+ Pattern.compile("(background.*:.*url" + LEFT_P + "['\"]?" + ")([^'\"]+)(" + "['\"]?" + RIGHT_P + ".*;)");
+
+ /** Immutable and therefore thread safe. */
+ private static final Pattern LT = Pattern.compile("/\\*\\s*orientation=lt\\s*\\*/");
+
+ /** Immutable and therefore thread safe. */
+ private static final Pattern RT = Pattern.compile("/\\*\\s*orientation=rt\\s*\\*/");
+
+ /** One month caching. */
+ private static final int ONE_MONTH = 2592000;
+
+ /** One hour caching. */
+ private static final int ONE_HOUR = 3600;
+
+ /** The deployer. */
+ private final AbstractResourceHandler deployer;
+
+ private final Map<SkinKey, SkinConfig> portalSkins_;
+
+ private final Map<SkinKey, SkinConfig> skinConfigs_;
+
+ private final HashSet<String> availableSkins_;
+
+ private final Map<String, String> ltCache;
+
+ private final Map<String, String> rtCache;
+
+ private final Map<String, Set<String>> portletThemes_;
+
+ private final MainResourceResolver mainResolver;
+
+ /**
+ * The name of the portal container
+ */
+ final String portalContainerName;
+
+ /**
+ * An id used for caching request. The id life cycle is the same than the class instance because
+ * we consider css will change until server is restarted. Of course this only applies for the
+ * developing mode set to false.
+ */
+ final String id = Long.toString(System.currentTimeMillis());
+
+ /** Temporary hack. */
+ //private static final List<String> skinBlackList = Arrays.asList("Vista", "Mac");
+ private static final List<String> skinBlackList = new ArrayList<String>();
+
+ public SkinService(ExoContainerContext context)
+ {
+ portalSkins_ = new LinkedHashMap<SkinKey, SkinConfig>();
+ skinConfigs_ = new LinkedHashMap<SkinKey, SkinConfig>(20);
+ availableSkins_ = new HashSet<String>(5);
+ ltCache = new ConcurrentHashMap<String, String>();
+ rtCache = new ConcurrentHashMap<String, String>();
+ portletThemes_ = new HashMap<String, Set<String>>();
+ portalContainerName = context.getPortalContainerName();
+ mainResolver = new MainResourceResolver(portalContainerName, skinConfigs_);
+ //deployer = new SkinConfigDeployer(portalContainerName, this);
+ deployer = new GateinSkinConfigDeployer(portalContainerName, this);
+ }
+
+ public void addCategoryTheme(String categoryName)
+ {
+ if (!portletThemes_.containsKey(categoryName))
+ portletThemes_.put(categoryName, new HashSet<String>());
+ }
+
+ public void addPortalSkin(String module, String skinName, String cssPath, ServletContext scontext)
+ {
+ addPortalSkin(module, skinName, cssPath, scontext, false);
+ }
+
+ /**
+ * Register the stylesheet for a portal Skin.
+ *
+ * @param module skin module identifier
+ * @param skinName skin name
+ * @param cssPath path uri to the css file. This is relative to the root context, use leading '/'
+ * @param scontext the webapp's {@link javax.servlet.ServletContext}
+ * @param overwrite if any previous skin should be replaced by that one
+ */
+ public void addPortalSkin(String module, String skinName, String cssPath, ServletContext scontext, boolean overwrite)
+ {
+
+ // Triggers a put if absent
+ mainResolver.registerContext(scontext);
+
+ availableSkins_.add(skinName);
+ SkinKey key = new SkinKey(module, skinName);
+ SkinConfig skinConfig = portalSkins_.get(key);
+ if (skinConfig == null || overwrite)
+ {
+ skinConfig = new SimpleSkin(this, module, skinName, cssPath);
+ portalSkins_.put(key, skinConfig);
+ }
+ }
+
+ public void addPortalSkin(String module, String skinName, String cssPath, String cssData)
+ {
+ SkinKey key = new SkinKey(module, skinName);
+ SkinConfig skinConfig = portalSkins_.get(key);
+ if (skinConfig == null)
+ {
+ portalSkins_.put(key, new SimpleSkin(this, module, skinName, cssPath));
+ }
+ ltCache.put(cssPath, cssData);
+ rtCache.put(cssPath, cssData);
+ }
+
+ public void addSkin(String module, String skinName, String cssPath, ServletContext scontext)
+ {
+ addSkin(module, skinName, cssPath, scontext, false);
+ }
+
+ /**
+ * Merge several skins into one single skin.
+ *
+ * @param skins the skins to merge
+ * @return the merged skin
+ */
+ public Skin merge(Collection<SkinConfig> skins)
+ {
+ return new CompositeSkin(this, skins);
+ }
+
+ /**
+ * Add a resource resolver to plug external resolvers.
+ *
+ * @param resolver a resolver to add
+ */
+ public void addResourceResolver(ResourceResolver resolver)
+ {
+ mainResolver.resolvers.addIfAbsent(resolver);
+ }
+
+ public void addSkin(String module, String skinName, String cssPath, ServletContext scontext, boolean overwrite)
+ {
+ // Triggers a put if absent
+ mainResolver.registerContext(scontext);
+
+ availableSkins_.add(skinName);
+ SkinKey key = new SkinKey(module, skinName);
+ SkinConfig skinConfig = skinConfigs_.get(key);
+ if (skinConfig == null || overwrite)
+ {
+ skinConfig = new SimpleSkin(this, module, skinName, cssPath);
+ skinConfigs_.put(key, skinConfig);
+ }
+ }
+
+ public void addSkin(String module, String skinName, String cssPath, String cssData)
+ {
+ //
+ availableSkins_.add(skinName);
+ SkinKey key = new SkinKey(module, skinName);
+ SkinConfig skinConfig = skinConfigs_.get(key);
+ if (skinConfig == null)
+ {
+ skinConfigs_.put(key, new SimpleSkin(this, module, skinName, cssPath));
+ }
+ ltCache.put(cssPath, cssData);
+ rtCache.put(cssPath, cssData);
+ }
+
+ public void addTheme(String categoryName, List<String> themesName)
+ {
+ if (!portletThemes_.containsKey(categoryName))
+ portletThemes_.put(categoryName, new HashSet<String>());
+ Set<String> catThemes = portletThemes_.get(categoryName);
+ for (String theme : themesName)
+ catThemes.add(theme);
+ }
+
+ /**
+ * Get names of all the currently registered skins.
+ *
+ * @return an unmodifiable Set of the currently registered skins
+ */
+ public Set<String> getAvailableSkinNames()
+ {
+ return availableSkins_;
+ }
+
+ /**
+ * Return the CSS content of the file specified by the given URI.
+ *
+ * @param cssPath path of the css to find
+ * @return the css
+ */
+ public String getCSS(String cssPath)
+ {
+ try
+ {
+ final StringBuilder sb = new StringBuilder();
+ renderCSS(new ResourceRenderer()
+ {
+ public Appendable getAppendable()
+ {
+ return sb;
+ }
+
+ public void setExpiration(long seconds)
+ {
+
+ }
+ }, cssPath);
+ return sb.toString();
+ }
+ catch (IOException e)
+ {
+ log.error("Error while rendering css " + cssPath, e);
+ return null;
+ }
+ catch (RenderingException e)
+ {
+ log.error("Error while rendering css " + cssPath, e);
+ return null;
+ }
+ }
+
+ public void renderCSS(ResourceRenderer renderer, String path) throws RenderingException, IOException
+ {
+ Orientation orientation = Orientation.LT;
+ if (path.endsWith("-lt.css"))
+ {
+ path = path.substring(0, path.length() - "-lt.css".length()) + ".css";
+ }
+ else if (path.endsWith("-rt.css"))
+ {
+ path = path.substring(0, path.length() - "-rt.css".length()) + ".css";
+ orientation = Orientation.RT;
+ }
+
+ // Try cache first
+ if (!PropertyManager.isDevelopping())
+ {
+
+ if (path.startsWith("/" + portalContainerName + "/resource"))
+ {
+ renderer.setExpiration(ONE_MONTH);
+ }
+ else
+ {
+ renderer.setExpiration(ONE_HOUR);
+ }
+
+ //
+ Map<String, String> cache = orientation == Orientation.LT ? ltCache : rtCache;
+ String css = cache.get(path);
+ if (css == null)
+ {
+ StringBuilder sb = new StringBuilder();
+ processCSS(sb, path, orientation, true);
+ css = sb.toString();
+ cache.put(path, css);
+ }
+ renderer.getAppendable().append(css);
+ }
+ else
+ {
+ processCSS(renderer.getAppendable(), path, orientation, false);
+ }
+ }
+
+ public String getMergedCSS(String cssPath)
+ {
+ return ltCache.get(cssPath);
+ }
+
+ public Collection<SkinConfig> getPortalSkins(String skinName)
+ {
+ Set<SkinKey> keys = portalSkins_.keySet();
+ Collection<SkinConfig> portalSkins = new ArrayList<SkinConfig>();
+ for (SkinKey key : keys)
+ {
+ if (key.getName().equals(skinName))
+ portalSkins.add(portalSkins_.get(key));
+ }
+ return portalSkins;
+ }
+
+ public Map<String, Set<String>> getPortletThemes()
+ {
+ return portletThemes_;
+ }
+
+ public SkinConfig getSkin(String module, String skinName)
+ {
+ SkinConfig config = skinConfigs_.get(new SkinKey(module, skinName));
+ if (config == null)
+ skinConfigs_.get(new SkinKey(module, "Default"));
+ return config;
+ }
+
+ public void invalidatePortalSkinCache(String portalName, String skinName)
+ {
+ SkinKey key = new SkinKey(portalName, skinName);
+ skinConfigs_.remove(key);
+ }
+
+ public void remove(String module, String skinName) throws Exception
+ {
+ SkinKey key;
+ if (skinName.length() == 0)
+ key = new SkinKey(module, "Default");
+ else
+ key = new SkinKey(module, skinName);
+ skinConfigs_.remove(key);
+ }
+
+ public int size()
+ {
+ return skinConfigs_.size();
+ }
+
+ private void processCSS(Appendable appendable, String cssPath, Orientation orientation, boolean merge)
+ throws RenderingException, IOException
+ {
+ Resource skin = mainResolver.resolve(cssPath);
+ processCSSRecursively(appendable, merge, skin, orientation);
+ }
+
+ private void processCSSRecursively(Appendable appendable, boolean merge, Resource skin, Orientation orientation)
+ throws RenderingException, IOException
+ {
+
+ // The root URL for the entry
+ String basePath = skin.getContextPath() + skin.getParentPath();
+
+ //
+ String line = "";
+ Reader tmp = skin.read();
+ if (tmp == null)
+ {
+ throw new RenderingException("No skin resolved for path " + skin.getResourcePath());
+ }
+ BufferedReader reader = new BufferedReader(tmp);
+ try
+ {
+ while ((line = reader.readLine()) != null)
+ {
+ Matcher matcher = IMPORT_PATTERN.matcher(line);
+ if (matcher.find())
+ {
+ String includedPath = matcher.group(2);
+ if (includedPath.startsWith("/"))
+ {
+ if (merge)
+ {
+ Resource ssskin = mainResolver.resolve(includedPath);
+ processCSSRecursively(appendable, merge, ssskin, orientation);
+ }
+ else
+ {
+ appendable.append(matcher.group(1)).append(
+ includedPath.substring(0, includedPath.length() - ".css".length())).append(
+ getSuffix(orientation)).append(matcher.group(3)).append("\n");
+ }
+ }
+ else
+ {
+ if (merge)
+ {
+ String path = skin.getContextPath() + skin.getParentPath() + includedPath;
+ Resource ssskin = mainResolver.resolve(path);
+ processCSSRecursively(appendable, merge, ssskin, orientation);
+ }
+ else
+ {
+ appendable.append(matcher.group(1));
+ appendable.append(basePath);
+ appendable.append(includedPath.substring(0, includedPath.length() - ".css".length()));
+ appendable.append(getSuffix(orientation));
+ appendable.append(matcher.group(3));
+ }
+ }
+ }
+ else
+ {
+ if (orientation == null || wantInclude(line, orientation))
+ {
+ append(line, basePath, appendable);
+ }
+ }
+ }
+ }
+ finally
+ {
+ Safe.close(reader);
+ }
+ }
+
+ /**
+ * Filter what if it's annotated with the alternative orientation.
+ *
+ * @param line the line to include
+ * @param orientation the orientation
+ * @return true if the line is included
+ */
+ private boolean wantInclude(String line, Orientation orientation)
+ {
+ Pattern orientationPattern = orientation == Orientation.LT ? RT : LT;
+ Matcher matcher2 = orientationPattern.matcher(line);
+ return !matcher2.find();
+ }
+
+ private void append(String line, String basePath, Appendable appendable) throws IOException
+ {
+ // Rewrite background url pattern
+ Matcher matcher = BACKGROUND_PATTERN.matcher(line);
+ if (matcher.find() && !matcher.group(2).startsWith("\"/") && !matcher.group(2).startsWith("'/")
+ && !matcher.group(2).startsWith("/"))
+ {
+ appendable.append(matcher.group(1)).append(basePath).append(matcher.group(2)).append(matcher.group(3)).append(
+ '\n');
+ }
+ else
+ {
+ appendable.append(line).append('\n');
+ }
+ }
+
+ String getSuffix(Orientation orientation)
+ {
+ if (orientation == null)
+ {
+ orientation = Orientation.LT;
+ }
+ return suffixMap.get(orientation);
+ }
+
+ @Managed
+ @ManagedDescription("The list of registered skins identifiers")
+ public String[] getSkinList()
+ {
+ // get all available skin
+ List<String> availableSkin = new ArrayList<String>();
+ for (String skin : availableSkins_)
+ {
+ availableSkin.add(skin);
+ }
+ // sort skin name asc
+ Collections.sort(availableSkin);
+
+ return availableSkin.toArray(new String[availableSkin.size()]);
+ }
+
+ @Managed
+ @ManagedDescription("Reload all skins")
+ public void reloadSkins()
+ {
+ // remove all ltCache, rtCache
+ ltCache.clear();
+ rtCache.clear();
+ }
+
+ @Managed
+ @ManagedDescription("Reload a specified skin")
+ public void reloadSkin(@ManagedDescription("The skin id") @ManagedName("skinId") String skinId)
+ {
+ ltCache.remove(skinId);
+ rtCache.remove(skinId);
+ }
+
+ public void start()
+ {
+ DefaultServletContainerFactory.getInstance().getServletContainer().addWebAppListener(deployer);
+ }
+
+ public void stop()
+ {
+ DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(deployer);
+ }
+}
\ No newline at end of file
Deleted: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinURL.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinURL.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinURL.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,46 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import org.exoplatform.services.resources.Orientation;
-
-/**
- * The URL of a skin.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public interface SkinURL
-{
-
- /**
- * Sets the orientation on the skin URL.
- *
- * @param orientation the orientation
- */
- void setOrientation(Orientation orientation);
-
- /**
- * This method is used to compute the path of a CSS.
- *
- * @return the CSS path, containing the orientation suffix.
- */
- String toString();
-}
Copied: portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinURL.java (from rev 462, portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinURL.java)
===================================================================
--- portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinURL.java (rev 0)
+++ portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/resource/SkinURL.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,46 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import org.exoplatform.services.resources.Orientation;
+
+/**
+ * The URL of a skin.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public interface SkinURL
+{
+
+ /**
+ * Sets the orientation on the skin URL.
+ *
+ * @param orientation the orientation
+ */
+ void setOrientation(Orientation orientation);
+
+ /**
+ * This method is used to compute the path of a CSS.
+ *
+ * @return the CSS path, containing the orientation suffix.
+ */
+ String toString();
+}
Modified: portal/branches/wsrp-integration/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java
===================================================================
--- portal/branches/wsrp-integration/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -21,7 +21,6 @@
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
-
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
import org.exoplatform.services.log.ExoLogger;
@@ -32,11 +31,10 @@
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.picocontainer.Startable;
+import javax.servlet.ServletContext;
import java.io.IOException;
import java.io.InputStream;
-import javax.servlet.ServletContext;
-
/**
* Created by The eXo Platform SAS
* Jan 19, 2007
@@ -45,6 +43,8 @@
public class JavascriptDeployer implements WebAppListener, Startable
{
+ private static final String GATEIN_CONFIG_RESOURCE = "/WEB-INF/gatein-resources.xml";
+
/**
* Logger
*/
@@ -87,6 +87,7 @@
scontext = event.getWebApp().getServletContext();
InputStream is = scontext.getResourceAsStream("/WEB-INF/conf/script/groovy/JavascriptScript.groovy");
+ //InputStream is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
if (is == null)
return;
try
@@ -122,6 +123,7 @@
try
{
is = scontext.getResourceAsStream("/WEB-INF/conf/script/groovy/JavascriptScript.groovy");
+ //is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
Binding binding = new Binding();
binding.setVariable("JavascriptService", javascriptService);
binding.setVariable("ServletContext", scontext);
Modified: portal/branches/wsrp-integration/packaging/profiles.xml
===================================================================
--- portal/branches/wsrp-integration/packaging/profiles.xml 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/packaging/profiles.xml 2009-10-30 19:05:32 UTC (rev 464)
@@ -22,7 +22,7 @@
<profilesXml>
<profiles>
<profile>
- <id>exo-projects</id>
+ <id>gatein-projects</id>
<properties>
<!--
Replace with the directory where uncompressed Tomcat 6 and/or JBoss 5.1 can be found
@@ -30,10 +30,18 @@
ex: On Linux '/home/user/AS'
-->
<exo.projects.directory.dependencies>REPLACE_WITH_YOUR_OWN_DIRECTORY</exo.projects.directory.dependencies>
+
+ <!--
+ If you want that the server is deployed always at the same place (not in packaging/pkg/target/<server> dir)
+ Uncomment and Replace with the directory you prefer
+ -->
+ <!--
+ <gatein.working.dir>REPLACE_WITH_SERVER_DIR</gatein.working.dir>
+ -->
<!--
Replace with the name of the directory containing Tomcat 6
-->
- <exo.projects.app.tomcat.version>apache-tomcat-6.0.20</exo.projects.app.tomcat.version>
+ <exo.projects.app.tomcat.version>tomcat-6.0.20</exo.projects.app.tomcat.version>
<!--
Replace with the name of the directory containing JBoss AS 5.1
-->
@@ -43,6 +51,6 @@
</profiles>
<activeProfiles>
- <activeProfile>exo-projects</activeProfile>
+ <activeProfile>gatein-projects</activeProfile>
</activeProfiles>
</profilesXml>
Copied: portal/branches/wsrp-integration/packaging/profiles.xml.template (from rev 462, portal/trunk/packaging/profiles.xml.template)
===================================================================
--- portal/branches/wsrp-integration/packaging/profiles.xml.template (rev 0)
+++ portal/branches/wsrp-integration/packaging/profiles.xml.template 2009-10-30 19:05:32 UTC (rev 464)
@@ -0,0 +1,57 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+-->
+
+<profilesXml>
+ <profiles>
+ <profile>
+ <id>gatein-projects</id>
+ <properties>
+ <!--
+ Replace with the directory where uncompressed Tomcat 6 and/or JBoss 5.1 can be found
+ ex: On Windows 'c:/AS'
+ ex: On Linux '/home/user/AS'
+ -->
+ <exo.projects.directory.dependencies>REPLACE_WITH_YOUR_OWN_DIRECTORY</exo.projects.directory.dependencies>
+
+ <!--
+ If you want that the server is deployed always at the same place (not in packaging/pkg/target/<server> dir)
+ Uncomment and Replace with the directory you prefer
+ -->
+ <!--
+ <gatein.working.dir>REPLACE_WITH_SERVER_DIR</gatein.working.dir>
+ -->
+
+ <!--
+ Replace with the name of the directory containing Tomcat 6
+ -->
+ <exo.projects.app.tomcat.version>apache-tomcat-6.0.20</exo.projects.app.tomcat.version>
+ <!--
+ Replace with the name of the directory containing JBoss AS 5.1
+ -->
+ <exo.projects.app.jboss.version>jboss-5.1.0.GA</exo.projects.app.jboss.version>
+ </properties>
+ </profile>
+ </profiles>
+
+ <activeProfiles>
+ <activeProfile>gatein-projects</activeProfile>
+ </activeProfiles>
+</profilesXml>
Modified: portal/branches/wsrp-integration/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java
===================================================================
--- portal/branches/wsrp-integration/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -209,6 +209,25 @@
}
}
+ private boolean validateName(String label)
+ {
+ label = label.trim();
+ if (Character.isDigit(label.charAt(0)) || label.charAt(0) == '-')
+ {
+ return false;
+ }
+ for (int i = 0; i < label.length(); i++)
+ {
+ char c = label.charAt(i);
+ if (Character.isLetter(c) || Character.isDigit(c) || c == '_' || c == '-' || Character.isSpaceChar(c))
+ {
+ continue;
+ }
+ return false;
+ }
+ return true;
+ }
+
private boolean nameExisted(String nodeName)
{
for (PageNode node : pageNavigation.getNodes())
@@ -313,6 +332,11 @@
UITabPaneDashboard tabPane = event.getSource();
WebuiRequestContext context = event.getRequestContext();
String newTabLabel = context.getRequestParameter(UIComponent.OBJECTID);
+ if (!tabPane.validateName(newTabLabel))
+ {
+ context.getUIApplication().addMessage(new ApplicationMessage("UITabPaneDashboard.msg.wrongTabName", null));
+ return;
+ }
String newNodeName = tabPane.createNewPageNode(newTabLabel);
//If new node is created with success, then redirect to it
@@ -342,6 +366,11 @@
WebuiRequestContext context = event.getRequestContext();
int nodeIndex = Integer.parseInt(context.getRequestParameter(UIComponent.OBJECTID));
String newTabLabel = context.getRequestParameter(RENAMED_TAB_LABEL_PARAMETER);
+ if (!tabPane.validateName(newTabLabel))
+ {
+ context.getUIApplication().addMessage(new ApplicationMessage("UITabPaneDashboard.msg.wrongTabName", null));
+ return;
+ }
String newNodeName = tabPane.renamePageNode(nodeIndex, newTabLabel);
//If page node is renamed with success, then redirect to new URL
Modified: portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_en.properties
===================================================================
--- portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_en.properties 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_en.properties 2009-10-30 19:05:32 UTC (rev 464)
@@ -20,4 +20,5 @@
UITabPaneDashboard.action.addNewDashboard=Add Dashboard
UITabPaneDashboard.action.switchShowRange=Switch Range
UITabPaneDashboard.msg.deleteTab=Really want to remove this dashboard?
-UITabPaneDashboard.msg.cannotDeleteLastTab=Can not delete the last tab.
\ No newline at end of file
+UITabPaneDashboard.msg.cannotDeleteLastTab=Can not delete the last tab.
+UITabPaneDashboard.msg.wrongTabName=Only alpha, digit, underscore, dash and space characters allowed.
\ No newline at end of file
Modified: portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_fr.properties
===================================================================
--- portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_fr.properties 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_fr.properties 2009-10-30 19:05:32 UTC (rev 464)
@@ -20,4 +20,5 @@
UITabPaneDashboard.action.addNewDashboard =Ajoute Dashboard
UITabPaneDashboard.action.switchShowRange =Decale
UITabPaneDashboard.msg.deleteTab=Really want to remove this dashboard?
-UITabPaneDashboard.msg.cannotDeleteLastTab=Can not delete the last tab.
\ No newline at end of file
+UITabPaneDashboard.msg.cannotDeleteLastTab=Can not delete the last tab.
+UITabPaneDashboard.msg.wrongTabName=Only alpha, digit, underscore, dash and space characters allowed.
\ No newline at end of file
Modified: portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_ru.properties
===================================================================
--- portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_ru.properties 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_ru.properties 2009-10-30 19:05:32 UTC (rev 464)
@@ -20,4 +20,5 @@
UITabPaneDashboard.action.addNewDashboard=Добавить доску
UITabPaneDashboard.action.switchShowRange=Изменить область
UITabPaneDashboard.msg.deleteTab=Вы действительно хотите удалить эту доску?
-UITabPaneDashboard.msg.cannotDeleteLastTab=Can not delete the last tab.
\ No newline at end of file
+UITabPaneDashboard.msg.cannotDeleteLastTab=Can not delete the last tab.
+UITabPaneDashboard.msg.wrongTabName=Only alpha, digit, underscore, dash and space characters allowed.
\ No newline at end of file
Modified: portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_uk.properties
===================================================================
--- portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_uk.properties 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/dashboard/TabbedDashboardPortlet_uk.properties 2009-10-30 19:05:32 UTC (rev 464)
@@ -20,4 +20,5 @@
UITabPaneDashboard.action.addNewDashboard =Додати панель інструментів
UITabPaneDashboard.action.switchShowRange =Перемикач діапазону
UITabPaneDashboard.msg.deleteTab=Really want to remove this dashboard?
-UITabPaneDashboard.msg.cannotDeleteLastTab=Can not delete the last tab.
\ No newline at end of file
+UITabPaneDashboard.msg.cannotDeleteLastTab=Can not delete the last tab.
+UITabPaneDashboard.msg.wrongTabName=Only alpha, digit, underscore, dash and space characters allowed.
\ No newline at end of file
Modified: portal/branches/wsrp-integration/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/GroupManagement.java
===================================================================
--- portal/branches/wsrp-integration/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/GroupManagement.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/GroupManagement.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -146,6 +146,8 @@
{
if (username == null)
username = org.exoplatform.portal.webui.util.Util.getPortalRequestContext().getRemoteUser();
+ if (username.equals(getUserACL().getSuperUser()))
+ return true;
return isMemberOfGroup(username, getUserACL().getAdminGroups());
}
Modified: portal/branches/wsrp-integration/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupExplorer.java
===================================================================
--- portal/branches/wsrp-integration/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupExplorer.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupExplorer.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -25,9 +25,9 @@
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.EventConfig;
import org.exoplatform.webui.core.UIBreadcumbs;
+import org.exoplatform.webui.core.UIBreadcumbs.LocalPath;
import org.exoplatform.webui.core.UIContainer;
import org.exoplatform.webui.core.UITree;
-import org.exoplatform.webui.core.UIBreadcumbs.LocalPath;
import org.exoplatform.webui.event.Event;
import org.exoplatform.webui.event.EventListener;
@@ -121,7 +121,8 @@
sibblingsGroup_ = service.getGroupHandler().findGroups(parentGroup);
// if not administrator
- if (!GroupManagement.isAdministrator(null))
+ String username = org.exoplatform.portal.webui.util.Util.getPortalRequestContext().getRemoteUser();
+ if (!GroupManagement.isSuperUserOfGroup(username, groupId))
{
childrenGroup_ = GroupManagement.getRelatedGroups(null, childrenGroup_);
sibblingsGroup_ = GroupManagement.getRelatedGroups(null, sibblingsGroup_);
Modified: portal/branches/wsrp-integration/web/eXoResources/src/main/webapp/javascript/eXo/webui/UITabbedDashboard.js
===================================================================
--- portal/branches/wsrp-integration/web/eXoResources/src/main/webapp/javascript/eXo/webui/UITabbedDashboard.js 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/web/eXoResources/src/main/webapp/javascript/eXo/webui/UITabbedDashboard.js 2009-10-30 19:05:32 UTC (rev 464)
@@ -51,7 +51,7 @@
href += "&uicomponent=UITabPaneDashboard";
href += "&op=RenameTabLabel";
href += "&objectId=" + nodeIndex;
- href += "&newTabLabel=" + newTabLabel;
+ href += "&newTabLabel=" + encodeURIComponent(newTabLabel);
window.location = href;
return;
}
@@ -83,6 +83,7 @@
inputElement.style.border = "1px solid #b7b7b7";
inputElement.style.width = "95px";
inputElement.onkeypress = eXo.webui.UITabbedDashboard.renameTabLabel;
+ inputElement.setAttribute('maxLength', 50);
inputElement.onblur = function() {
prNode.replaceChild(eXo.webui.UITabbedDashboard.backupElement, inputElement);
};
Deleted: portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/script/groovy/SkinConfigScript.groovy
===================================================================
--- portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/script/groovy/SkinConfigScript.groovy 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/script/groovy/SkinConfigScript.groovy 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,42 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-/***************************HomePagePortlet**************************************************/
-SkinService.addSkin(
- "web/HomePagePortlet",
- "Default",
- "/" + ServletContextName + "/templates/skin/webui/component/UIHomePagePortlet/DefaultStylesheet.css",
- ServletContext
-) ;
-
-SkinService.addSkin(
- "web/HomePagePortlet",
- "Vista",
- "/" + ServletContextName + "/templates/skin/webui/component/UIHomePagePortlet/DefaultStylesheet.css",
- ServletContext
-) ;
-
-SkinService.addSkin(
- "web/HomePagePortlet",
- "Mac",
- "/" + ServletContextName + "/templates/skin/webui/component/UIHomePagePortlet/DefaultStylesheet.css",
- ServletContext
-) ;
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
\ No newline at end of file
Modified: portal/branches/wsrp-integration/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl
===================================================================
--- portal/branches/wsrp-integration/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl 2009-10-30 19:05:32 UTC (rev 464)
@@ -37,7 +37,6 @@
<div class="id"><%=uicomponent.getId();%></div>
<div class="title"><%=_ctx.appRes("UIPortlet.label.title");%></div>
<div class="description">
-
<%if(uicomponent.getDescription() != null) {%>
<%=uicomponent.getDescription();%>
<%} else {%>
@@ -67,22 +66,12 @@
<div class="CenterBackground">
<div class="GardientBackground">
<%
- String displayName = uicomponent.getDisplayName();
- if(displayName != null) {
- String htmlDisplayName = ""; int count = 1;
- for(c in displayName){
- if(c=="\n"){
- c="<br/>";
- count++;
- }
- htmlDisplayName+=c;
- if(count>5) break;
- }
- %>
- <%=htmlDisplayName;%>
- <%} else {%>
- <%= _ctx.appRes("UIPortlet.label.portletContent"); %>
- <%}%>
+ try {
+ String portletName = uicomponent.getProducedOfferedPortlet().getInfo().getName();
+ print _ctx.getRequestContext().getApplicationResourceBundle().getString("UIPortlet.description." + portletName);
+ } catch(Exception e){
+ print uicomponent.getDisplayName();
+ }%>
</div>
</div>
</div>
Modified: portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/application/ResourceRequestFilter.java
===================================================================
--- portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/application/ResourceRequestFilter.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/application/ResourceRequestFilter.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -26,13 +26,21 @@
import org.exoplatform.commons.utils.TextEncoder;
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.web.AbstractFilter;
-import org.exoplatform.portal.skin.ResourceRenderer;
-import org.exoplatform.portal.skin.SkinService;
+import org.exoplatform.portal.resource.ResourceRenderer;
+import org.exoplatform.portal.resource.SkinService;
import org.exoplatform.services.cache.ExoCache;
import org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import javax.imageio.ImageIO;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
@@ -47,15 +55,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
-import javax.imageio.ImageIO;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
public class ResourceRequestFilter extends AbstractFilter
{
Modified: portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java
===================================================================
--- portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -1,16 +1,16 @@
/**
* Copyright (C) 2009 eXo Platform SAS.
- *
+ *
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -71,13 +71,15 @@
protected static Log log = ExoLogger.getLogger("portal:UIPortletActionListener");
/**
- * The process action listener is called when an ActionURL generated by the portlet container has been invoked by the
- * client
- * <p/>
- * The call is delegated to the portlet container iteself using the method portletContainer.processAction(...). It
- * returns an object of type ActionOutput that contains several information such as the next window state and portlet
- * modes (if they have to change) as well as a list of Events to be broadcasted to the other portlets located in the
- * same portal page
+ * The process action listener is called when an ActionURL generated by the
+ * portlet container has been invoked by the client
+ *
+ * The call is delegated to the portlet container iteself using the method
+ * portletContainer.processAction(...). It returns an object of type
+ * ActionOutput that contains several information such as the next window
+ * state and portlet modes (if they have to change) as well as a list of
+ * Events to be broadcasted to the other portlets located in the same portal
+ * page
*/
static public class ProcessActionActionListener<S, C extends Serializable, I> extends
EventListener<UIPortlet<S, C, I>>
@@ -225,8 +227,8 @@
}
/**
- * This method is used to set the next portlet window state if this one needs to be modified because of the incoming
- * request
+ * This method is used to set the next portlet window state if this one needs to
+ * be modified because of the incoming request
*/
public static void setNextState(UIPortlet uiPortlet, WindowState state)
{
@@ -260,7 +262,10 @@
}
}
- /** This method is used to set the next portlet mode if this one needs to be modified because of the incoming request */
+ /**
+ * This method is used to set the next portlet mode if this one needs to
+ * be modified because of the incoming request
+ */
public static void setNextMode(UIPortlet uiPortlet, PortletMode portletMode)
{
if (portletMode != null)
@@ -281,18 +286,21 @@
}
/**
- * The serveResource() method defined in the JSR 286 specs has several goals: - provide binary output like images to
- * be displayed in the portlet (in the previous spec - JSR 168 - a servlet was needed) - provide text output that
- * does not impact the entire portal rendering, it is for instance usefull when dealing with Javascript to return
- * some JSON structures
- * <p/>
- * The method delegates the call to the portlet container serverResource method after filling the ResourceInput
- * object with the current request state.
- * <p/>
- * This returns a ResourceOutput object that can content binary or text contentType
- * <p/>
- * Finally the content is set in the portal response writer or outputstream depending on the type; the
- * processRender() method of the portal is not called as we set the response as complete
+ * The serveResource() method defined in the JSR 286 specs has several goals:
+ * - provide binary output like images to be displayed in the portlet (in the previous
+ * spec - JSR 168 - a servlet was needed)
+ * - provide text output that does not impact the entire portal rendering, it is for
+ * instance usefull when dealing with Javascript to return some JSON structures
+ *
+ * The method delegates the call to the portlet container serverResource method after
+ * filling the ResourceInput object with the current request state.
+ *
+ * This returns a ResourceOutput object that can content binary or text contentType
+ *
+ * Finally the content is set in the portal response writer or outputstream depending
+ * on the type; the processRender() method of the portal is not called as we set the
+ * response as complete
+ *
*/
static public class ServeResourceActionListener<S, C extends Serializable, I> extends
EventListener<UIPortlet<S, C, I>>
@@ -444,11 +452,11 @@
}
/**
- * This method is called when the javax.portlet.Event is supported by the current portlet stored in the Portlet
- * Caontainer
- * <p/>
- * The processEvent() method can also generates IPC events and hence the portal itself will call the
- * ProcessEventsActionListener once again
+ * This method is called when the javax.portlet.Event is supported by the
+ * current portlet stored in the Portlet Caontainer
+ *
+ * The processEvent() method can also generates IPC events and hence the
+ * portal itself will call the ProcessEventsActionListener once again
*/
public static <S, C extends Serializable, I> List<javax.portlet.Event> processEvent(UIPortlet<S, C, I> uiPortlet,
javax.portlet.Event event)
@@ -580,9 +588,11 @@
}
/**
- * This listener is called when a RenderURL url has been generated by the portlet container. In that case it means
- * that the render() method of a targeted portlet will be directly called and that the existing navigational state
- * will be reset by removing all the Render Parameters from the cache map located in the UIPortlet
+ * This listener is called when a RenderURL url has been generated by the
+ * portlet container. In that case it means that the render() method of a
+ * targeted portlet will be directly called and that the existing navigational
+ * state will be reset by removing all the Render Parameters from the cache
+ * map located in the UIPortlet
*/
static public class RenderActionListener extends EventListener<UIPortlet>
{
@@ -602,11 +612,11 @@
}
/**
- * This method is called by the process action and render action listeners, aka during the processDecode() phase of
- * our UI framework
- * <p/>
- * It goes throughs all the request parameters and add to the public render parameters Map the one that are supported
- * by the targeted portlet
+ * This method is called by the process action and render action listeners,
+ * aka during the processDecode() phase of our UI framework
+ *
+ * It goes throughs all the request parameters and add to the public render
+ * parameters Map the one that are supported by the targeted portlet
*/
static public void setupPublicRenderParams(UIPortlet uiPortlet, Map<String, String[]> requestParams)
{
@@ -693,7 +703,10 @@
}
}
- /** This listener is called when the portlet mode of a portlet has to be changed. */
+ /**
+ * This listener is called when the portlet mode of a portlet has to be
+ * changed.
+ */
static public class ChangePortletModeActionListener extends EventListener<UIPortlet>
{
public void execute(Event<UIPortlet> event) throws Exception
@@ -724,9 +737,10 @@
}
/**
- * This listener is called when the portlet edit form (which tells information about the portlet width or height as
- * well as if the info bar and its content should be shown) is invoked.
- * <p/>
+ * This listener is called when the portlet edit form (which tells information
+ * about the portlet width or height as well as if the info bar and its
+ * content should be shown) is invoked.
+ *
* It places the form in the portal black mask
*/
static public class EditPortletActionListener extends EventListener<UIPortlet>
Modified: portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletForm.java
===================================================================
--- portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletForm.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletForm.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -27,7 +27,7 @@
import org.exoplatform.portal.pom.spi.wsrp.WSRP;
import org.exoplatform.portal.pom.spi.wsrp.WSRPPortletStateType;
import org.exoplatform.portal.portlet.PortletExceptionHandleService;
-import org.exoplatform.portal.skin.SkinService;
+import org.exoplatform.portal.resource.SkinService;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.portal.webui.workspace.UIMaskWorkspace;
import org.exoplatform.portal.webui.workspace.UIPortalApplication;
Modified: portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java
===================================================================
--- portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -26,7 +26,7 @@
import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.config.model.PortalProperties;
-import org.exoplatform.portal.skin.SkinService;
+import org.exoplatform.portal.resource.SkinService;
import org.exoplatform.portal.webui.application.UIApplicationList;
import org.exoplatform.portal.webui.application.UIPortlet;
import org.exoplatform.portal.webui.container.UIContainerList;
Modified: portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java
===================================================================
--- portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -26,7 +26,7 @@
import org.exoplatform.portal.config.model.PageNavigation;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.config.model.PortalProperties;
-import org.exoplatform.portal.skin.SkinService;
+import org.exoplatform.portal.resource.SkinService;
import org.exoplatform.portal.webui.util.PortalDataMapper;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.portal.webui.workspace.UIMaskWorkspace;
Modified: portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UISkinSelector.java
===================================================================
--- portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UISkinSelector.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UISkinSelector.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -19,7 +19,7 @@
package org.exoplatform.portal.webui.portal;
-import org.exoplatform.portal.skin.SkinService;
+import org.exoplatform.portal.resource.SkinService;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.portal.webui.workspace.UIMaskWorkspace;
import org.exoplatform.portal.webui.workspace.UIPortalApplication;
Modified: portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/util/PortalDataMapper.java
===================================================================
--- portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/util/PortalDataMapper.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/util/PortalDataMapper.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -182,7 +182,7 @@
return model;
}
- static private Page toPageModel(UIPage uiPage)
+ static public Page toPageModel(UIPage uiPage)
{
Page model = new Page(uiPage.getStorageId());
toContainer(model, uiPage);
Modified: portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java
===================================================================
--- portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -21,7 +21,9 @@
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.config.UserACL;
+import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.webui.page.UIPage;
import org.exoplatform.portal.webui.page.UIPageBody;
import org.exoplatform.portal.webui.page.UIPageCreationWizard;
import org.exoplatform.portal.webui.page.UISiteBody;
@@ -29,6 +31,7 @@
import org.exoplatform.portal.webui.portal.UIPortal;
import org.exoplatform.portal.webui.portal.UIPortalComposer;
import org.exoplatform.portal.webui.portal.UIPortalForm;
+import org.exoplatform.portal.webui.util.PortalDataMapper;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.webui.event.Event;
@@ -64,6 +67,18 @@
UIPortalToolPanel uiToolPanel = uiWorkingWS.findFirstComponentOfType(UIPortalToolPanel.class);
uiToolPanel.setShowMaskLayer(false);
UIPageBody pageBody = uiWorkingWS.findFirstComponentOfType(UIPageBody.class);
+
+ // check edit permission for page
+ UIPage uiPage = (UIPage) pageBody.getUIComponent();
+ Page page = PortalDataMapper.toPageModel(uiPage);
+
+ UserACL userACL = uiApp.getApplicationComponent(UserACL.class);
+ if (!userACL.hasEditPermission(page))
+ {
+ uiApp.addMessage(new ApplicationMessage("UIPortalManagement.msg.Invalid-editPermission", null));
+ return;
+ }
+
uiToolPanel.setWorkingComponent(pageBody.getUIComponent());
event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingWS);
Util.getPortalRequestContext().setFullRender(true);
Modified: portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
===================================================================
--- portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2009-10-30 18:31:16 UTC (rev 463)
+++ portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2009-10-30 19:05:32 UTC (rev 464)
@@ -23,10 +23,10 @@
import org.exoplatform.portal.config.DataStorage;
import org.exoplatform.portal.config.UserPortalConfig;
import org.exoplatform.portal.config.model.Container;
-import org.exoplatform.portal.skin.Skin;
-import org.exoplatform.portal.skin.SkinConfig;
-import org.exoplatform.portal.skin.SkinService;
-import org.exoplatform.portal.skin.SkinURL;
+import org.exoplatform.portal.resource.Skin;
+import org.exoplatform.portal.resource.SkinConfig;
+import org.exoplatform.portal.resource.SkinService;
+import org.exoplatform.portal.resource.SkinURL;
import org.exoplatform.portal.webui.application.UIPortlet;
import org.exoplatform.portal.webui.page.UISiteBody;
import org.exoplatform.portal.webui.portal.PageNodeEvent;
15 years, 1 month
gatein SVN: r463 - portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2009-10-30 14:31:16 -0400 (Fri, 30 Oct 2009)
New Revision: 463
Modified:
portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java
Log:
- Use public navigational state updates given by the portlet container instead of inferring it from the portal state.
- Removed now unused getRenderParameterMap method on UIPortlet.
Modified: portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
===================================================================
--- portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java 2009-10-30 18:31:16 UTC (rev 463)
@@ -49,7 +49,6 @@
import org.gatein.common.i18n.LocalizedString;
import org.gatein.common.net.media.MediaType;
import org.gatein.pc.api.Mode;
-import org.gatein.pc.api.ParametersStateString;
import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.PortletContext;
import org.gatein.pc.api.PortletInvoker;
@@ -151,7 +150,7 @@
private List<String> supportedPublicParams_;
private boolean portletInPortal_ = true;
private StateString navigationalState;
-// private Map<String, String[]> publicNavigationalStateChanges;
+ private Map<String, String[]> publicNavigationalStateChanges;
public UIPortlet()
{
@@ -650,11 +649,10 @@
}
// Navigational state
- StateString navigationalState = ParametersStateString.create(getRenderParameterMap());
invocation.setNavigationalState(navigationalState);
// Public navigational state
- invocation.setPublicNavigationalState(this.getPublicParameters());
+ invocation.setPublicNavigationalState(publicNavigationalStateChanges);
// Mode
invocation.setMode(Mode.create(getCurrentPortletMode().toString()));
@@ -717,44 +715,6 @@
return invocation;
}
- /** This method returns all the parameters supported by the targeted portlets, both the private and public ones */
- private Map<String, String[]> getRenderParameterMap()
- {
- Map<String, String[]> publicParams = getPublicParameters();
- Map<String, String[]> renderParams;
-
- if (navigationalState == null)
- {
- return publicParams;
- }
- else
- {
- if (navigationalState instanceof ParametersStateString)
- {
- // if the navigational state is not opaque, retrieve the parameter map
- ParametersStateString parametersStateString = (ParametersStateString)navigationalState;
- renderParams = parametersStateString.getParameters();
- }
- else
- {
- // if we have an opaque navigation state, just add it as it to the param map under the proper key
- renderParams = new HashMap<String, String[]>(publicParams.size() + 1);
- renderParams.put(ExoPortletInvocationContext.NAVIGATIONAL_STATE_PARAM_NAME, new String[]{navigationalState.getStringValue()});
- }
-
- /*
- * handle public params to only get the one supported by the targeted
- * portlet
- */
- Map<String, String[]> allParams = new HashMap<String, String[]>(renderParams);
- allParams.putAll(publicParams);
-
- return allParams;
- }
- }
-
- //
-
public void update(PropertyChange... changes) throws Exception
{
PortletContext portletContext = getPortletContext();
@@ -880,8 +840,8 @@
this.navigationalState = navigationalState;
}
- /*void setPublicNavigationalStateUpdates(Map<String, String[]> publicNavigationalStateUpdates)
+ void setPublicNavigationalStateUpdates(Map<String, String[]> publicNavigationalStateUpdates)
{
this.publicNavigationalStateChanges = publicNavigationalStateUpdates;
- }*/
-}
+ }
+}
\ No newline at end of file
Modified: portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java
===================================================================
--- portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java 2009-10-30 15:47:22 UTC (rev 462)
+++ portal/branches/wsrp-integration/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java 2009-10-30 18:31:16 UTC (rev 463)
@@ -153,8 +153,7 @@
setNextMode(uiPortlet, mode);
// set the public params
- HttpServletRequest request = prcontext.getRequest();
- setupPublicRenderParams(uiPortlet, request.getParameterMap());
+ setupPublicRenderParams(uiPortlet, navStateResponse.getPublicNavigationalStateUpdates());
/*
* Cache the render parameters in the UI portlet component to handle the
@@ -166,10 +165,8 @@
//
StateString navigationalState = navStateResponse.getNavigationalState();
uiPortlet.setNavigationalState(navigationalState);
+ uiPortlet.setPublicNavigationalStateUpdates(navStateResponse.getPublicNavigationalStateUpdates());
- // todo: this might be needed for a proper handling of PRPs but need to understand UIPortlet behavior better first
-// uiPortlet.setPublicNavigationalStateUpdates(navStateResponse.getPublicNavigationalStateUpdates());
-
//
/*
15 years, 1 month
gatein SVN: r462 - portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2009-10-30 11:47:22 -0400 (Fri, 30 Oct 2009)
New Revision: 462
Modified:
portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java
Log:
- close the stream when the portlet has finished the rendering
Modified: portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java
===================================================================
--- portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java 2009-10-30 15:38:54 UTC (rev 461)
+++ portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java 2009-10-30 15:47:22 UTC (rev 462)
@@ -20,6 +20,7 @@
package org.exoplatform.webui.application.portlet;
import org.exoplatform.commons.utils.PortalPrinter;
+import org.exoplatform.commons.utils.Safe;
import org.exoplatform.resolver.ApplicationResourceResolver;
import org.exoplatform.resolver.PortletResourceResolver;
import org.exoplatform.services.log.ExoLogger;
@@ -246,6 +247,11 @@
}
finally
{
+
+ // Close the writer
+ Safe.close(context.getWriter());
+
+ //
try
{
for (ApplicationLifecycle<RequestContext> lifecycle : getApplicationLifecycle())
15 years, 1 month
gatein SVN: r461 - in portal/branches/performance: webui/core/src/main/java/org/exoplatform/webui/application/portlet and 1 other directory.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2009-10-30 11:38:54 -0400 (Fri, 30 Oct 2009)
New Revision: 461
Modified:
portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/config/model/PageNode.java
portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java
Log:
- actually use no additional buffer for now as it requires a flush when rendering a portlet
- GTNPORTAL-132 : Set label as resolved label when a PageNode is created from a NavigationNodeData object
Modified: portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/config/model/PageNode.java
===================================================================
--- portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/config/model/PageNode.java 2009-10-30 15:15:19 UTC (rev 460)
+++ portal/branches/performance/component/portal/src/main/java/org/exoplatform/portal/config/model/PageNode.java 2009-10-30 15:38:54 UTC (rev 461)
@@ -69,6 +69,7 @@
//
this.uri = nav.getURI();
this.label = nav.getLabel();
+ this.resolvedLabel = label;
this.icon = nav.getIcon();
this.name = nav.getName();
this.startPublicationDate = nav.getStartPublicationDate();
Modified: portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java
===================================================================
--- portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java 2009-10-30 15:15:19 UTC (rev 460)
+++ portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java 2009-10-30 15:38:54 UTC (rev 461)
@@ -281,10 +281,7 @@
{
RenderResponse renderRes = (RenderResponse)res;
renderRes.setContentType("text/html; charset=UTF-8");
-
- // We use 2048 as the underlying PC will initialize by default
- // a ByteArrayOutputStream that has a size of 32
- w = new PortalPrinter(renderRes.getPortletOutputStream(), true, 512);
+ w = new PortalPrinter(renderRes.getPortletOutputStream(), true, 0);
}
if (context != null)
{
15 years, 1 month
gatein SVN: r460 - portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2009-10-30 11:15:19 -0400 (Fri, 30 Oct 2009)
New Revision: 460
Modified:
portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java
Log:
use a 512 byte buffer for portlet output
Modified: portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java
===================================================================
--- portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java 2009-10-30 14:38:36 UTC (rev 459)
+++ portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java 2009-10-30 15:15:19 UTC (rev 460)
@@ -281,7 +281,10 @@
{
RenderResponse renderRes = (RenderResponse)res;
renderRes.setContentType("text/html; charset=UTF-8");
- w = new PortalPrinter(renderRes.getPortletOutputStream(), true, 0);
+
+ // We use 2048 as the underlying PC will initialize by default
+ // a ByteArrayOutputStream that has a size of 32
+ w = new PortalPrinter(renderRes.getPortletOutputStream(), true, 512);
}
if (context != null)
{
15 years, 1 month
gatein SVN: r459 - in portal/branches/performance: component/common/src/test/java/org/exoplatform/commons/utils and 9 other directories.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2009-10-30 10:38:36 -0400 (Fri, 30 Oct 2009)
New Revision: 459
Added:
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/BinaryOutput.java
portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/TestBufferingOutputStream.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/BaseScript.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplateEngine.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyText.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/LineBreakItem.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/OutputStreamWriterGroovyPrinter.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/SectionItem.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/SectionType.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateCompiler.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateSection.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TextItem.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/WriterGroovyPrinter.java
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateCompiler.java
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateParser.java
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
portal/branches/performance/component/scripting/src/test/resources/
portal/branches/performance/component/scripting/src/test/resources/UIPortalApplication.gtmpl
Removed:
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/text/SimpleTemplateEngine.java
Modified:
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharEncoder.java
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharsetCharEncoder.java
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharsetTextEncoder.java
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/OutputStreamPrinter.java
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/Printer.java
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/TableCharEncoder.java
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/Text.java
portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/TextEncoder.java
portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/TestPrinter.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/commons/utils/PortalPrinter.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java
portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java
portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletRequestContext.java
portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java
Log:
GTNPORTAL-142 : Optimized Groovy Template Engine
Added: portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/BinaryOutput.java
===================================================================
--- portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/BinaryOutput.java (rev 0)
+++ portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/BinaryOutput.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.commons.utils;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public interface BinaryOutput
+{
+
+ Charset getCharset();
+
+ void write(byte b) throws IOException;
+
+ void write(byte[] bytes) throws IOException;
+
+ void write(byte[] b, int off, int len) throws IOException;
+
+}
Modified: portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharEncoder.java
===================================================================
--- portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharEncoder.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharEncoder.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -19,6 +19,8 @@
package org.exoplatform.commons.utils;
+import java.nio.charset.Charset;
+
/**
* A char encoder that encodes chars to a suite of bytes. No assumptions must be made about the
* statefullness nature of an encoder as some encoder may be statefull and some encoder may be stateless.
@@ -36,4 +38,11 @@
* @return the serie of bytes corresponding to the encoded char
*/
byte[] encode(char c);
+
+ /**
+ * Returns the charset that will perform the encoding.
+ *
+ * @return the charset for encoding
+ */
+ Charset getCharset();
}
Modified: portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharsetCharEncoder.java
===================================================================
--- portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharsetCharEncoder.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharsetCharEncoder.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -61,6 +61,11 @@
this.arrays = new byte[][]{new byte[0], new byte[1], new byte[2], new byte[3], new byte[4], new byte[5]};
}
+ public Charset getCharset()
+ {
+ return charset;
+ }
+
public byte[] encode(char c)
{
/*
Modified: portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharsetTextEncoder.java
===================================================================
--- portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharsetTextEncoder.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/CharsetTextEncoder.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -52,6 +52,11 @@
this(new TableCharEncoder(new CharsetCharEncoder(Charset.forName(encoding))));
}
+ public Charset getCharset()
+ {
+ return charEncoder.getCharset();
+ }
+
public void encode(char c, OutputStream out) throws IOException
{
if (c > -1 && c < 128)
Modified: portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/OutputStreamPrinter.java
===================================================================
--- portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/OutputStreamPrinter.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/OutputStreamPrinter.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.charset.Charset;
/**
* <p>An extension of {@link Printer} that encodes the text with a provided encoder and sends the resulting
@@ -48,7 +49,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
* @version $Revision$
*/
-public class OutputStreamPrinter extends Printer
+public class OutputStreamPrinter extends Printer implements BinaryOutput
{
private final IOFailureFlow failureFlow;
@@ -84,6 +85,7 @@
* @param encoder the encoder
* @param out the output
* @param flushOnClose flush when stream is closed
+ * @param bufferSize the size of the buffer
* @throws IllegalArgumentException if any argument is null
*/
public OutputStreamPrinter(TextEncoder encoder, OutputStream out, boolean flushOnClose, int bufferSize) throws IllegalArgumentException
@@ -105,13 +107,14 @@
}
/**
- * Builds a new instance.
+ * Builds a new instance with the specified parameters and the delegate output.
*
* @param encoder the encoder
* @param out the output
* @param failureFlow the control flow failureFlow
* @param ignoreOnFailure the behavior on failure
* @param flushOnClose flush when stream is closed
+ * @param bufferSize the buffer size
* @throws IllegalArgumentException if any argument is null
*/
public OutputStreamPrinter(
@@ -155,12 +158,17 @@
this.flushOnClose = flushOnClose;
}
+ public final Charset getCharset()
+ {
+ return encoder.getCharset();
+ }
+
/**
* Returns the failure flow.
*
* @return the failure flow
*/
- public IOFailureFlow getFailureFlow()
+ public final IOFailureFlow getFailureFlow()
{
return failureFlow;
}
@@ -170,19 +178,19 @@
*
* @return the ignore on failure property
*/
- public boolean getIgnoreOnFailure()
+ public final boolean getIgnoreOnFailure()
{
return ignoreOnFailure;
}
- public boolean isFailed()
+ public final boolean isFailed()
{
return failed;
}
// Bytes access interface
- public void write(byte b) throws IOException
+ public final void write(byte b) throws IOException
{
if (!failed)
{
@@ -197,7 +205,7 @@
}
}
- public void write(byte[] bytes) throws IOException
+ public final void write(byte[] bytes) throws IOException
{
if (!failed)
{
@@ -212,7 +220,7 @@
}
}
- public void write(byte[] b, int off, int len) throws IOException
+ public final void write(byte[] b, int off, int len) throws IOException
{
if (!failed)
{
@@ -230,7 +238,9 @@
//
@Override
- public void write(int c) throws IOException
+ // Note that the parent method has a synchronisation that we want to avoid
+ // for performance reasons
+ public final void write(int c) throws IOException
{
if (!failed)
{
@@ -246,7 +256,7 @@
}
@Override
- public void write(char[] cbuf) throws IOException
+ public final void write(char[] cbuf) throws IOException
{
if (!failed)
{
@@ -262,7 +272,7 @@
}
@Override
- public void write(String str) throws IOException
+ public final void write(String str) throws IOException
{
if (!failed)
{
@@ -278,7 +288,9 @@
}
@Override
- public void write(String str, int off, int len) throws IOException
+ // Note that the parent method has a synchronisation that we want to avoid
+ // for performance reasons
+ public final void write(String str, int off, int len) throws IOException
{
if (!failed)
{
@@ -293,7 +305,7 @@
}
}
- public void write(char[] cbuf, int off, int len) throws IOException
+ public final void write(char[] cbuf, int off, int len) throws IOException
{
if (!failed)
{
@@ -308,7 +320,7 @@
}
}
- public void flush() throws IOException
+ public final void flush() throws IOException
{
if (!failed && !flushOnClose)
{
@@ -323,7 +335,7 @@
}
}
- public void close() throws IOException
+ public final void close() throws IOException
{
try
{
Modified: portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/Printer.java
===================================================================
--- portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/Printer.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/Printer.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -19,7 +19,6 @@
package org.exoplatform.commons.utils;
-import java.io.IOException;
import java.io.Writer;
/**
@@ -30,47 +29,7 @@
*/
public abstract class Printer extends Writer
{
-
public Printer()
{
}
-
- public final void println(Object o)
- {
- print(o);
- println();
- }
-
- public final void println()
- {
- try
- {
- write('\n');
- }
- catch (IOException ignore)
- {
- }
- }
-
- public final void print(Object o)
- {
- try
- {
- if (o == null)
- {
- write("null");
- }
- else if (o instanceof Text)
- {
- ((Text)o).writeTo(this);
- }
- else
- {
- write(o.toString());
- }
- }
- catch (IOException ignore)
- {
- }
- }
}
\ No newline at end of file
Modified: portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/TableCharEncoder.java
===================================================================
--- portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/TableCharEncoder.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/TableCharEncoder.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -19,6 +19,8 @@
package org.exoplatform.commons.utils;
+import java.nio.charset.Charset;
+
/**
* A char encoder that use a table to cache the result produced by a delegate char encoder. This encoder
* is stateless and should only be composed with stateless char encoder otherwise an unexpected result
@@ -47,6 +49,11 @@
this.table = new byte[MAX + 1][];
}
+ public Charset getCharset()
+ {
+ return charEncoder.getCharset();
+ }
+
public byte[] encode(char c)
{
byte[] bytes = table[c];
Modified: portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/Text.java
===================================================================
--- portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/Text.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/Text.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -20,11 +20,12 @@
package org.exoplatform.commons.utils;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.io.Writer;
+import java.nio.charset.Charset;
/**
* Represents text that can have several internal representations in order to minimize serialization when it is possible.
+ * The bytes returned by the byte oriented method must returned the data encoded with the UTF-8 encoding.
*
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
* @version $Revision$
@@ -36,12 +37,13 @@
* Create a text object from the provided byte array.
*
* @param bytes the markup as bytes
+ * @param charset the charset
* @return the text object
* @throws IllegalArgumentException if the bytes is null
*/
- public static Text create(byte[] bytes) throws IllegalArgumentException
+ public static Text create(byte[] bytes, Charset charset) throws IllegalArgumentException
{
- return new Bytes(bytes);
+ return new Bytes(bytes, charset);
}
/**
@@ -61,7 +63,6 @@
*
* @param s the markup as bytes
* @return the text object
- * @todo provide an optimized subclass but it's not much used for now
* @throws IllegalArgumentException if the string is null
*/
public static Text create(String s) throws IllegalArgumentException
@@ -69,59 +70,46 @@
return new Chars(s.toCharArray());
}
- public abstract byte[] getBytes();
-
- public abstract char[] getChars();
-
- public abstract void appendTo(Appendable appendable) throws IOException;
-
public abstract void writeTo(Writer writer) throws IOException;
private static class Bytes extends Text
{
+ /** . */
private final byte[] bytes;
- private Bytes(byte[] bytes)
- {
- this.bytes = bytes;
- }
+ /** . */
+ private final Charset charset;
- public byte[] getBytes()
- {
- return bytes;
- }
+ /** . */
+ private volatile String s;
- public char[] getChars()
+ private Bytes(byte[] bytes, Charset charset)
{
- try
- {
- return new String(bytes, "utf-8").toCharArray();
- }
- catch (java.io.UnsupportedEncodingException e)
- {
- return new String(bytes).toCharArray();
- }
+ this.bytes = bytes;
+ this.charset = charset;
}
- public void appendTo(Appendable appendable) throws IOException
+ public void writeTo(Writer writer) throws IOException
{
- for (char c : getChars())
+ if (writer instanceof BinaryOutput)
{
- appendable.append(c);
+ BinaryOutput osw = (BinaryOutput)writer;
+ if (charset.equals(osw.getCharset()))
+ {
+ osw.write(bytes);
+ return;
+ }
}
- }
-
- public void writeTo(Writer writer) throws IOException
- {
- for (char c : getChars())
+ if (s == null)
{
- writer.append(c);
+ s = new String(bytes, charset);
}
+ writer.append(s);
}
}
- private static class Chars extends Text implements CharSequence
+ private static class Chars extends Text
{
/** Inclusive from index. */
@@ -147,73 +135,11 @@
this.count = count;
}
- public byte[] getBytes()
- {
- String s = new String(chars, offset, count);
- try
- {
- return s.getBytes("UTF-8");
- }
- catch (UnsupportedEncodingException e)
- {
- return s.getBytes();
- }
- }
-
- public char[] getChars()
- {
- // Recompute the internal state
- if (offset > 0 || count < chars.length)
- {
- char[] tmp = new char[count];
- System.arraycopy(chars, offset, tmp, 0, count);
- chars = tmp;
- offset = 0;
- }
- return chars;
- }
-
public void writeTo(Writer writer) throws IOException
{
writer.write(chars, offset, count);
}
- public void appendTo(Appendable appendable) throws IOException
- {
- appendable.append(this);
- }
-
- public int length()
- {
- return count;
- }
-
- public char charAt(int index)
- {
- return chars[index - offset];
- }
-
- public CharSequence subSequence(int start, int end)
- {
- if (start < 0)
- {
- throw new ArrayIndexOutOfBoundsException("Start index cannot be negative");
- }
- if (end < 0)
- {
- throw new ArrayIndexOutOfBoundsException("End index cannot be negative");
- }
- if (start > end)
- {
- throw new ArrayIndexOutOfBoundsException("Start index cannot be greater than the end index");
- }
- if (end > count)
- {
- throw new ArrayIndexOutOfBoundsException("End index cannot be greater than the sequence length");
- }
- return new Chars(chars, offset + start, end - start);
- }
-
@Override
public String toString()
{
Modified: portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/TextEncoder.java
===================================================================
--- portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/TextEncoder.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/common/src/main/java/org/exoplatform/commons/utils/TextEncoder.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.charset.Charset;
/**
* A text encoder that encodes text to an output stream. No assumptions must be made about the
@@ -32,6 +33,13 @@
public interface TextEncoder
{
+ /**
+ * Returns the charset that will perform the encoding.
+ *
+ * @return the charset for encoding
+ */
+ Charset getCharset();
+
void encode(char c, OutputStream out) throws IOException;
void encode(char[] chars, int off, int len, OutputStream out) throws IOException;
Added: portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/TestBufferingOutputStream.java
===================================================================
--- portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/TestBufferingOutputStream.java (rev 0)
+++ portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/TestBufferingOutputStream.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.commons.utils;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class TestBufferingOutputStream extends TestCase
+{
+
+ private ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ private BufferingOutputStream out = new BufferingOutputStream(bytes, 5);
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ bytes = new ByteArrayOutputStream();
+ out = new BufferingOutputStream(bytes, 5);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ bytes = null;
+ out = null;
+ }
+
+ public void testCtorIAE()
+ {
+ try
+ {
+ new BufferingOutputStream(bytes, 0);
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ try
+ {
+ new BufferingOutputStream(bytes, -1);
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testCtorNPE()
+ {
+ try
+ {
+ new BufferingOutputStream(null, 1);
+ }
+ catch (NullPointerException e)
+ {
+ }
+ }
+
+ public void testStreamClose() throws Exception
+ {
+ final AtomicBoolean closed = new AtomicBoolean(false);
+ BufferingOutputStream out = new BufferingOutputStream(new ByteArrayOutputStream()
+ {
+ @Override
+ public void close() throws IOException
+ {
+ closed.set(true);
+ super.close();
+ }
+ }, 1);
+ out.close();
+ assertTrue(closed.get());
+ try
+ {
+ out.write(0);
+ }
+ catch (IOException ignore)
+ {
+ }
+ try
+ {
+ out.write(new byte[]{0});
+ }
+ catch (IOException ignore)
+ {
+ }
+ try
+ {
+ out.flush();
+ }
+ catch (IOException ignore)
+ {
+ }
+ try
+ {
+ out.close();
+ }
+ catch (IOException ignore)
+ {
+ }
+ }
+
+ public void testFlush() throws Exception
+ {
+ out.write(0);
+ assertBytes();
+ out.flush();
+ assertBytes(0);
+ out.write(new byte[]{1, 2, 3, 4});
+ assertBytes();
+ out.close();
+ assertBytes(1, 2, 3, 4);
+ }
+
+ public void testWriteByte() throws Exception
+ {
+ out.write(0);
+ assertBytes();
+ out.close();
+ assertBytes(0);
+ }
+
+ public void testAlmostFill() throws Exception
+ {
+ out.write(new byte[]{0, 1, 2, 3});
+ assertBytes();
+ out.close();
+ assertBytes(0, 1, 2, 3);
+ }
+
+ public void testFill() throws Exception
+ {
+ out.write(new byte[]{0, 1, 2, 3, 4});
+ assertBytes(0, 1, 2, 3, 4);
+ out.close();
+ assertBytes();
+ }
+
+ public void testBufferOverflowWithByte() throws Exception
+ {
+ out.write(new byte[]{0, 1, 2, 3});
+ assertBytes();
+ out.write(4);
+ assertBytes();
+ out.write(5);
+ assertBytes(0, 1, 2, 3, 4);
+ out.close();
+ assertBytes(5);
+ }
+ public void testBufferOverflowWithArray() throws Exception
+ {
+ out.write(new byte[]{0, 1, 2, 3});
+ assertBytes();
+ out.write(new byte[]{4});
+ assertBytes(0, 1, 2, 3);
+ out.close();
+ assertBytes(4);
+ }
+
+ public void testBufferOverflowWithLongArray() throws Exception
+ {
+ out.write(new byte[]{0, 1, 2, 3});
+ assertBytes();
+ out.write(new byte[]{4, 5, 6, 7, 8, 9});
+ assertBytes(0, 1, 2, 3, 4, 5, 6, 7, 8);
+ out.close();
+ assertBytes(9);
+ }
+
+ public void testBufferOverflowWithVeryLongArray() throws Exception
+ {
+ out.write(new byte[]{0, 1, 2, 3});
+ assertBytes();
+ out.write(new byte[]{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14});
+ assertBytes(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
+ out.close();
+ assertBytes(14);
+ }
+
+ private void assertBytes(int... expectedBytes)
+ {
+ int len = expectedBytes.length;
+ assertEquals(len, bytes.size());
+ if (len > 0)
+ {
+ byte[] actualBytes = bytes.toByteArray();
+ for (int i = 0;i < len;i++)
+ {
+ int expectedByte = expectedBytes[i];
+ byte actualByte = actualBytes[i];
+ assertEquals("Was expecting byte at index " + i + " to be equals to " + expectedByte + " instead of " + actualByte, expectedByte, actualByte);
+ }
+ bytes.reset();
+ }
+ }
+
+}
Modified: portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/TestPrinter.java
===================================================================
--- portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/TestPrinter.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/common/src/test/java/org/exoplatform/commons/utils/TestPrinter.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -44,6 +44,7 @@
printer = null;
}
+/*
public void testPrintNull()
{
printer.print(null);
@@ -73,6 +74,7 @@
printer.println();
assertEquals("\n", printer.buffer.toString());
}
+*/
public void testWriteNull() throws IOException
{
Modified: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/commons/utils/PortalPrinter.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/commons/utils/PortalPrinter.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/commons/utils/PortalPrinter.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -20,7 +20,6 @@
package org.exoplatform.commons.utils;
import java.io.OutputStream;
-import java.nio.charset.Charset;
/**
* The portal printer convert char to bytes based on a charset encoder.
@@ -34,21 +33,8 @@
/** The optimized encoder. */
private static final TextEncoder encoder = new CharsetTextEncoder(new TableCharEncoder(CharsetCharEncoder.getUTF8()));
- /** The charset used. */
- private static final Charset charset = Charset.forName("UTF8");
-
public PortalPrinter(OutputStream out, boolean flushOnClose, int bufferSize) throws IllegalArgumentException
{
super(encoder, out, flushOnClose, bufferSize);
}
-
- /**
- * Returns the charset used for the conversion
- *
- * @return the charset used
- */
- public Charset getCharset()
- {
- return charset;
- }
}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/BaseScript.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/BaseScript.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/BaseScript.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import groovy.lang.Binding;
+import groovy.lang.Script;
+
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public abstract class BaseScript extends Script
+{
+
+ GroovyPrinter printer;
+
+ protected BaseScript()
+ {
+ }
+
+ protected BaseScript(Binding binding)
+ {
+ super(binding);
+ }
+
+ @Override
+ public void println(Object o)
+ {
+ printer.println(o);
+ }
+
+ @Override
+ public void println()
+ {
+ printer.println();
+ }
+
+ @Override
+ public void print(Object o)
+ {
+ printer.print(o);
+ }
+
+ public void flush()
+ {
+ try
+ {
+ printer.flush();
+ }
+ catch (IOException e)
+ {
+ //TODO: need to check again
+ // e.printStackTrace();
+ }
+ }
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import org.exoplatform.commons.utils.Text;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public abstract class GroovyPrinter extends Writer
+{
+
+ public final void println(Object o)
+ {
+ print(o);
+ println();
+ }
+
+ public final void println()
+ {
+ try
+ {
+ write('\n');
+ }
+ catch (IOException ignore)
+ {
+ }
+ }
+
+ public final void print(Object o)
+ {
+ try
+ {
+ if (o == null)
+ {
+ write("null");
+ }
+ else if (o instanceof Text)
+ {
+ ((Text)o).writeTo(this);
+ }
+ else
+ {
+ write(o.toString());
+ }
+ }
+ catch (IOException ignore)
+ {
+ }
+ }
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScriptBuilder.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,230 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class GroovyScriptBuilder
+{
+
+ /** . */
+ private SectionType currentType = null;
+
+ /** . */
+ private StringBuilder accumulatedText = new StringBuilder();
+
+ /** . */
+ private Script script = new Script();
+
+ public void begin(SectionType sectionType)
+ {
+ if (sectionType == null)
+ {
+ throw new NullPointerException();
+ }
+ if (currentType != null)
+ {
+ throw new IllegalStateException();
+ }
+ this.currentType = sectionType;
+
+ //
+ switch (currentType)
+ {
+ case STRING:
+ break;
+ case SCRIPTLET:
+ break;
+ case EXPR:
+ script.appendGroovy(";out.print(\"${");
+ break;
+ }
+ }
+
+ public void append(String text)
+ {
+ switch (currentType)
+ {
+ case STRING:
+ accumulatedText.append(text);
+ break;
+ case SCRIPTLET:
+ script.appendGroovy(text);
+ break;
+ case EXPR:
+ script.appendGroovy(text);
+ break;
+ }
+ }
+
+ public void lineBreak()
+ {
+ switch (currentType)
+ {
+ case STRING:
+ accumulatedText.append("\n");
+// script.appendText(accumulatedText.toString());
+// accumulatedText.setLength(0);
+ break;
+ case SCRIPTLET:
+ script.appendGroovy("\n");
+ break;
+ case EXPR:
+ script.appendGroovy("\n");
+ break;
+ }
+ }
+
+ public void end()
+ {
+ if (currentType == null)
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ switch (currentType)
+ {
+ case STRING:
+ if (accumulatedText.length() > 0)
+ {
+ script.appendText(accumulatedText.toString());
+ accumulatedText.setLength(0);
+ }
+ break;
+ case SCRIPTLET:
+ break;
+ case EXPR:
+ script.appendGroovy("}\");");
+ break;
+ }
+
+ //
+ this.currentType = null;
+ }
+
+ public String getScript()
+ {
+ return script.toString();
+ }
+
+
+
+ private static class Script
+ {
+
+ /** . */
+ private StringBuilder out = new StringBuilder();
+
+ /** . */
+ private List<TextContant> textMethods = new ArrayList<TextContant>();
+
+ /** . */
+ private int methodCount = 0;
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(out.toString());
+ builder.append("\n");
+ builder.append("public class Constants\n");
+ builder.append("{\n");
+ for (TextContant method : textMethods)
+ {
+ builder.append(method.getDeclaration()).append("\n");
+ }
+ builder.append("}\n");
+ return builder.toString();
+ }
+
+ public void appendText(String text)
+ {
+ TextContant m = new TextContant("s" + methodCount++, text);
+ out.append(";out.print(Constants.").append(m.name).append(");\n");
+ textMethods.add(m);
+ }
+
+ public void appendGroovy(String s)
+ {
+ out.append(s);
+ }
+ }
+
+ /**
+ * This object encapsulate the generation of a method that outputs the specified text.
+ */
+ private static class TextContant
+ {
+
+ /** . */
+ private final String name;
+
+ /** . */
+ private final String text;
+
+ private TextContant(String name, String text)
+ {
+ this.name = name;
+ this.text = text;
+ }
+
+ public String getDeclaration()
+ {
+ StringBuilder builder = new StringBuilder("");
+ for (int i = 0;i < text.length();i++)
+ {
+ char c = text.charAt(i);
+ if (c == '\n')
+ {
+ builder.append("\\n");
+ }
+ else if (c == '\"')
+ {
+ builder.append("\\\"");
+ }
+ else
+ {
+ String code = Integer.toHexString(c);
+ switch (code.length())
+ {
+ default:
+ throw new AssertionError();
+ case 1:
+ code = "000" + code;
+ break;
+ case 2:
+ code = "00" + code;
+ break;
+ case 3:
+ code = "0" + code;
+ break;
+ case 4:
+ break;
+ }
+ builder.append("\\u").append(code);
+ }
+ }
+ return "public static final " + GroovyText.class.getName() + " " + name + " = new " + GroovyText.class.getName() + "(\"" + builder + "\");";
+ }
+ }
+}
\ No newline at end of file
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import groovy.lang.Binding;
+import groovy.lang.GroovyClassLoader;
+import groovy.lang.GroovyCodeSource;
+import groovy.lang.Writable;
+import groovy.text.Template;
+import org.codehaus.groovy.control.CompilationFailedException;
+import org.codehaus.groovy.control.CompilerConfiguration;
+import org.codehaus.groovy.runtime.InvokerHelper;
+import org.exoplatform.commons.utils.OutputStreamPrinter;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class GroovyTemplate implements Template
+{
+
+ private static String read(Reader reader) throws IOException
+ {
+ StringBuilder builder = new StringBuilder();
+ char[] chars = new char[256];
+ for (int s = reader.read(chars);s != -1; s = reader.read(chars))
+ {
+ builder.append(chars, 0, s);
+ }
+ return builder.toString();
+ }
+
+ /** . */
+ private final String name;
+
+ /** . */
+ private final String scriptText;
+
+ /** . */
+ private final String groovyText;
+
+ /** . */
+ private final Class<?> scriptClass;
+
+ public GroovyTemplate(String name, Reader scriptReader) throws IOException
+ {
+ this(name, read(scriptReader));
+ }
+
+ public GroovyTemplate(Reader scriptReader) throws IOException
+ {
+ this(read(scriptReader));
+ }
+
+ public GroovyTemplate(String scriptText) throws IOException
+ {
+ this(null, scriptText);
+ }
+
+ public GroovyTemplate(String name, String scriptText) throws IOException
+ {
+ if (name == null)
+ {
+ name = "fic";
+ }
+
+ //
+ TemplateCompiler compiler = new TemplateCompiler();
+ String groovyText = compiler.compile(scriptText);
+
+ //
+ CompilerConfiguration config = new CompilerConfiguration();
+ config.setScriptBaseClass(BaseScript.class.getName());
+ byte[] bytes = groovyText.getBytes(config.getSourceEncoding());
+ InputStream in = new ByteArrayInputStream(bytes);
+ GroovyCodeSource gcs = new GroovyCodeSource(in, name, "/groovy/shell");
+ GroovyClassLoader loader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader(), config);
+
+ Class<?> scriptClass;
+ try
+ {
+ scriptClass = loader.parseClass(gcs, false);
+ }
+ catch (CompilationFailedException e)
+ {
+ System.out.println("Could not compile script <<<" + groovyText + ">>>");
+ throw e;
+ }
+ catch (ClassFormatError e)
+ {
+ System.out.println("Could not compile script <<<" + groovyText + ">>>");
+ throw e;
+ }
+
+ //
+ this.name = name;
+ this.scriptText = scriptText;
+ this.groovyText = groovyText;
+ this.scriptClass = scriptClass;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getScriptText()
+ {
+ return scriptText;
+ }
+
+ public String getGroovyText()
+ {
+ return groovyText;
+ }
+
+ public void render(GroovyPrinter writer) throws IOException
+ {
+ render(writer, null);
+ }
+
+ public void render(GroovyPrinter writer, Map binding) throws IOException
+ {
+ Writable writable = make(binding);
+ writable.writeTo(writer);
+ }
+
+ public String render() throws IOException
+ {
+ return render((Map)null);
+ }
+
+ public String render(Map binding) throws IOException
+ {
+ StringWriter buffer = new StringWriter();
+ WriterGroovyPrinter printer = new WriterGroovyPrinter(buffer);
+ render(printer, binding);
+ printer.close();
+ return buffer.toString();
+ }
+
+ public Writable make()
+ {
+ return make(null);
+ }
+
+ public Writable make(final Map binding)
+ {
+ Writable writable = new Writable()
+ {
+ /**
+ * Write the template document with the set binding applied to the writer.
+ *
+ * @see groovy.lang.Writable#writeTo(java.io.Writer)
+ */
+ public Writer writeTo(Writer writer)
+ {
+ Binding context;
+ if (binding == null)
+ context = new Binding();
+ else
+ context = new Binding(binding);
+
+ //
+ BaseScript script = (BaseScript)InvokerHelper.createScript(scriptClass, context);
+ if (writer instanceof OutputStreamPrinter)
+ {
+ script.printer = new OutputStreamWriterGroovyPrinter((OutputStreamPrinter)writer);
+ }
+ else
+ {
+ script.printer = new WriterGroovyPrinter(writer);
+ }
+ script.setProperty("out", script.printer);
+ script.run();
+ script.flush();
+ return writer;
+ }
+ };
+
+ //
+ return writable;
+ }
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplateEngine.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplateEngine.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplateEngine.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import groovy.text.Template;
+import groovy.text.TemplateEngine;
+import org.codehaus.groovy.control.CompilationFailedException;
+
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class GroovyTemplateEngine extends TemplateEngine
+{
+
+ @Override
+ public Template createTemplate(Reader reader) throws CompilationFailedException, ClassNotFoundException, IOException
+ {
+ return new GroovyTemplate(reader);
+ }
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyText.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyText.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyText.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import org.exoplatform.commons.utils.BinaryOutput;
+import org.exoplatform.commons.utils.Text;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.nio.charset.Charset;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class GroovyText extends Text
+{
+
+ /** . */
+ private final String s;
+
+ /** . */
+ private final byte[] bytes;
+
+ /** . */
+ private static final Charset UTF_8 = Charset.forName("UTF-8");
+
+ public GroovyText(String s)
+ {
+ try
+ {
+ this.s = s;
+ this.bytes = s.getBytes("UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new UndeclaredThrowableException(e);
+ }
+ }
+
+ @Override
+ public void writeTo(Writer writer) throws IOException
+ {
+ if (writer instanceof BinaryOutput)
+ {
+ BinaryOutput osw = (BinaryOutput)writer;
+ if (UTF_8.equals(osw.getCharset()))
+ {
+ osw.write(bytes);
+ return;
+ }
+ }
+ writer.append(s);
+ }
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/LineBreakItem.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/LineBreakItem.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/LineBreakItem.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class LineBreakItem extends SectionItem
+{
+
+ public LineBreakItem()
+ {
+ }
+
+ @Override
+ public String toString()
+ {
+ return "LineBreak[]";
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return obj == this || obj instanceof LineBreakItem;
+ }
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/OutputStreamWriterGroovyPrinter.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/OutputStreamWriterGroovyPrinter.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/OutputStreamWriterGroovyPrinter.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import org.exoplatform.commons.utils.BinaryOutput;
+import org.exoplatform.commons.utils.OutputStreamPrinter;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class OutputStreamWriterGroovyPrinter extends GroovyPrinter implements BinaryOutput
+{
+
+ /** . */
+ private final OutputStreamPrinter out;
+
+ public OutputStreamWriterGroovyPrinter(OutputStreamPrinter out)
+ {
+ if (out == null)
+ {
+ throw new NullPointerException();
+ }
+ this.out = out;
+ }
+
+ public Charset getCharset()
+ {
+ return out.getCharset();
+ }
+
+ public void write(byte[] bytes) throws IOException
+ {
+ out.write(bytes);
+ }
+
+ public void write(byte[] b, int off, int len) throws IOException
+ {
+ out.write(b, off, len);
+ }
+
+ public void write(byte b) throws IOException
+ {
+ out.write(b);
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException
+ {
+ out.write(cbuf, off, len);
+ }
+
+ @Override
+ public void flush() throws IOException
+ {
+ out.flush();
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ out.close();
+ }
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/SectionItem.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/SectionItem.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/SectionItem.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public abstract class SectionItem
+{
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/SectionType.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/SectionType.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/SectionType.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public enum SectionType
+{
+
+ STRING,
+
+ SCRIPTLET,
+
+ EXPR
+
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateCompiler.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateCompiler.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateCompiler.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class TemplateCompiler
+{
+
+ public String compile(String script) throws IOException
+ {
+ List<TemplateSection> sections = new TemplateParser().parse(script);
+ return compile(sections);
+ }
+
+ public String compile(List<TemplateSection> sections)
+ {
+ GroovyScriptBuilder scriptBuilder = new GroovyScriptBuilder();
+ for (TemplateSection section : sections)
+ {
+ scriptBuilder.begin(section.getType());
+ for (SectionItem item : section.getItems())
+ {
+ if (item instanceof TextItem)
+ {
+ scriptBuilder.append(((TextItem)item).getData());
+ }
+ else
+ {
+ scriptBuilder.lineBreak();
+ }
+ }
+ scriptBuilder.end();
+ }
+ return scriptBuilder.getScript();
+ }
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateParser.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,255 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class TemplateParser
+{
+
+ private enum Status
+ {
+ TEXT,
+
+ EXPR,
+
+ SCRIPTLET,
+
+ START_ANGLE,
+
+ SCRIPLET_OR_EXPR,
+
+ MAYBE_SCRIPLET_END,
+
+ MAYBE_EXPR_END,
+
+ MAYBE_GSTRING_EXPR,
+
+ GSTRING_CURLY_EXPR,
+
+ GSTRING_EXPR
+ }
+
+ public List<TemplateSection> parse(String s) throws IOException
+ {
+ return parse(new StringReader(s));
+ }
+
+ public List<TemplateSection> parse(Reader reader) throws IOException
+ {
+ if (!reader.markSupported())
+ {
+ reader = new BufferedReader(reader);
+ }
+
+ //
+ ArrayList<TemplateSection> sections = new ArrayList<TemplateSection>();
+ StringBuilder accumulator = new StringBuilder();
+
+ //
+ Status status = Status.TEXT;
+ int c;
+ while ((c = reader.read()) != -1)
+ {
+ switch (status)
+ {
+ case TEXT:
+ if (c == '<')
+ {
+ status = Status.START_ANGLE;
+ }
+ else if (c == '$')
+ {
+ status = Status.MAYBE_GSTRING_EXPR;
+ }
+ else
+ {
+ accumulator.append((char)c);
+ }
+ break;
+ case EXPR:
+ if (c == '%')
+ {
+ status = Status.MAYBE_EXPR_END;
+ }
+ else
+ {
+ accumulator.append((char)c);
+ }
+ break;
+ case SCRIPTLET:
+ if (c == '%')
+ {
+ status = Status.MAYBE_SCRIPLET_END;
+ }
+ else
+ {
+ accumulator.append((char)c);
+ }
+ break;
+ case START_ANGLE:
+ if (c == '%')
+ {
+ status = Status.SCRIPLET_OR_EXPR;
+ }
+ else
+ {
+ status = Status.TEXT;
+ accumulator.append('<').append((char)c);
+ }
+ break;
+ case SCRIPLET_OR_EXPR:
+ if (accumulator.length() > 0)
+ {
+ sections.add(new TemplateSection(SectionType.STRING, accumulator.toString()));
+ accumulator.setLength(0);
+ }
+ if (c == '=')
+ {
+ status = Status.EXPR;
+ }
+ else if (c == '%')
+ {
+ status = Status.MAYBE_SCRIPLET_END;
+ }
+ else
+ {
+ status = Status.SCRIPTLET;
+ accumulator.append((char)c);
+ }
+ break;
+ case MAYBE_SCRIPLET_END:
+ if (c == '>')
+ {
+ status = Status.TEXT;
+ sections.add(new TemplateSection(SectionType.SCRIPTLET, accumulator.toString()));
+ accumulator.setLength(0);
+ }
+ else if (c == '%')
+ {
+ accumulator.append('%');
+ }
+ else
+ {
+ status = Status.SCRIPTLET;
+ accumulator.append('%').append((char)c);
+ }
+ break;
+ case MAYBE_EXPR_END:
+ if (c == '>')
+ {
+ status = Status.TEXT;
+ sections.add(new TemplateSection(SectionType.EXPR, accumulator.toString()));
+ accumulator.setLength(0);
+ }
+ else if (c == '%')
+ {
+ accumulator.append('%');
+ }
+ else
+ {
+ status = Status.EXPR;
+ accumulator.append('%').append((char)c);
+ }
+ break;
+ case MAYBE_GSTRING_EXPR:
+ if (c == '{')
+ {
+ if (accumulator.length() > 0)
+ {
+ sections.add(new TemplateSection(SectionType.STRING, accumulator.toString()));
+ accumulator.setLength(0);
+ }
+ status = Status.GSTRING_CURLY_EXPR;
+ }
+ else if (Character.isJavaIdentifierStart((char)c))
+ {
+ if (accumulator.length() > 0)
+ {
+ sections.add(new TemplateSection(SectionType.STRING, accumulator.toString()));
+ accumulator.setLength(0);
+ }
+ status = Status.GSTRING_EXPR;
+ accumulator.append((char)c);
+ }
+ else
+ {
+ accumulator.append('$').append((char)c);
+ }
+ break;
+ case GSTRING_CURLY_EXPR:
+ if (c == '}')
+ {
+ sections.add(new TemplateSection(SectionType.EXPR, accumulator.toString()));
+ accumulator.setLength(0);
+ status = Status.TEXT;
+ }
+ else
+ {
+ accumulator.append((char)c);
+ }
+ break;
+ case GSTRING_EXPR:
+ if (c == '.' || Character.isJavaIdentifierPart((char)c))
+ {
+ accumulator.append((char)c);
+ }
+ else
+ {
+ sections.add(new TemplateSection(SectionType.EXPR, accumulator.toString()));
+ accumulator.setLength(0);
+ status = Status.TEXT;
+ accumulator.append((char)c);
+ }
+ break;
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ // Last section
+ if (accumulator.length() > 0)
+ {
+ switch (status)
+ {
+ case TEXT:
+ sections.add(new TemplateSection(SectionType.STRING, accumulator.toString()));
+ accumulator.setLength(0);
+ break;
+ case GSTRING_EXPR:
+ sections.add(new TemplateSection(SectionType.EXPR, accumulator.toString()));
+ accumulator.setLength(0);
+ break;
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ //
+ return Collections.unmodifiableList(sections);
+ }
+}
\ No newline at end of file
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateSection.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateSection.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateSection.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class TemplateSection
+{
+
+ /** . */
+ private final SectionType type;
+
+ /** . */
+ private final List<SectionItem> items;
+
+ public TemplateSection(SectionType type, String text)
+ {
+ if (type == null)
+ {
+ throw new NullPointerException();
+ }
+ if (text == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ // Now we process the line breaks
+ ArrayList<SectionItem> sections = new ArrayList<SectionItem>();
+
+ // on Windows, "\r\n" is a new line
+ text = text.replaceAll("\r\n", "\n");
+
+ //
+ int from = 0;
+ while (true)
+ {
+ int to = text.indexOf('\n', from);
+
+ //
+ if (to != -1)
+ {
+ String chunk = text.substring(from, to);
+ sections.add(new TextItem(chunk));
+ sections.add(new LineBreakItem());
+ from = to + 1;
+ }
+ else
+ {
+ String chunk = text.substring(from);
+ sections.add(new TextItem(chunk));
+ break;
+ }
+ }
+
+ //
+ this.type = type;
+ this.items = Collections.unmodifiableList(sections);
+ }
+
+ public SectionType getType()
+ {
+ return type;
+ }
+
+ public List<SectionItem> getItems()
+ {
+ return items;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof TemplateSection)
+ {
+ TemplateSection that = (TemplateSection)obj;
+ return type == that.type && items.equals(that.items);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "TextSection[type=" + type + ",text=" + items + "]";
+ }
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TextItem.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TextItem.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TextItem.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class TextItem extends SectionItem
+{
+
+ /** . */
+ private final String data;
+
+ public TextItem(String data)
+ {
+ if (data == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ this.data = data;
+ }
+
+ public String getData()
+ {
+ return data;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof TextItem)
+ {
+ TextItem that = (TextItem)obj;
+ return data.equals(that.data);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "DataText[data=" + data + "]";
+ }
+}
Added: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/WriterGroovyPrinter.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/WriterGroovyPrinter.java (rev 0)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/WriterGroovyPrinter.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class WriterGroovyPrinter extends GroovyPrinter
+{
+
+ /** . */
+ private Writer writer;
+
+ public WriterGroovyPrinter(Writer writer)
+ {
+ if (writer == null)
+ {
+ throw new NullPointerException();
+ }
+ this.writer = writer;
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException
+ {
+ writer.write(cbuf, off, len);
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ writer.close();
+ }
+
+ @Override
+ public void flush() throws IOException
+ {
+ writer.flush();
+ }
+}
Deleted: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/text/SimpleTemplateEngine.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/text/SimpleTemplateEngine.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/text/SimpleTemplateEngine.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -1,324 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.groovyscript.text;
-
-import groovy.lang.Binding;
-import groovy.lang.GroovyClassLoader;
-import groovy.lang.GroovyCodeSource;
-import groovy.lang.GroovyShell;
-import groovy.lang.Script;
-import groovy.lang.Writable;
-import groovy.text.Template;
-import groovy.text.TemplateEngine;
-
-import org.codehaus.groovy.control.CompilationFailedException;
-import org.codehaus.groovy.control.CompilerConfiguration;
-import org.codehaus.groovy.runtime.InvokerHelper;
-import org.exoplatform.commons.utils.Printer;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.Map;
-
-/**
- * This simple template engine uses JSP <% %> script and <%= %> expression syntax. It also lets you use normal groovy expressions in
- * the template text much like the new JSP EL functionality. The variable 'out' is bound to the writer that the template is being written to.
- *
- * @author sam
- * @author Christian Stein
- */
-public class SimpleTemplateEngine extends TemplateEngine
-{
-
- private final boolean verbose;
-
- public SimpleTemplateEngine()
- {
- this(false);
- }
-
- public SimpleTemplateEngine(boolean verbose)
- {
- this.verbose = verbose;
- }
-
- public Template createTemplate(Reader reader) throws CompilationFailedException, IOException
- {
- SimpleTemplate template = new SimpleTemplate();
- GroovyShell shell = new GroovyShell(Thread.currentThread().getContextClassLoader());
- String script = template.parse(reader);
- if (verbose)
- {
- System.out.println("\n-- script source --");
- System.out.print(script);
- System.out.println("\n-- script end --\n");
- }
-
- //
- CompilerConfiguration config = new CompilerConfiguration();
- config.setScriptBaseClass(ExoScript.class.getName());
- byte[] bytes = script.getBytes(config.getSourceEncoding());
- InputStream in = new ByteArrayInputStream(bytes);
- GroovyCodeSource gcs = new GroovyCodeSource(in, "fic", "/groovy/shell");
- GroovyClassLoader loader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader(), config);
- loader.parseClass(gcs, false);
- template.scriptClass = loader.parseClass(script);
- return template;
- }
-
- public static abstract class ExoScript extends Script
- {
-
- private Printer printer;
-
- protected ExoScript()
- {
- }
-
- protected ExoScript(Binding binding)
- {
- super(binding);
- }
-
- @Override
- public void println(Object o)
- {
- printer.println(o);
- }
-
- @Override
- public void println()
- {
- printer.println();
- }
-
- @Override
- public void print(Object o)
- {
- printer.print(o);
- }
-
- public void flush()
- {
- try
- {
- printer.flush();
- }
- catch (IOException e)
- {
- //TODO: need to check again
- // e.printStackTrace();
- }
- }
- }
-
- private static class SimpleTemplate implements Template
- {
-
- protected Class scriptClass;
-
- public Writable make()
- {
- return make(null);
- }
-
- public Writable make(final Map map)
- {
- return new Writable()
- {
- /**
- * Write the template document with the set binding applied to the writer.
- *
- * @see groovy.lang.Writable#writeTo(java.io.Writer)
- */
- public Writer writeTo(Writer writer)
- {
- Binding context;
- if (map == null)
- context = new Binding();
- else
- context = new Binding(map);
-
- //
- ExoScript script = (ExoScript)InvokerHelper.createScript(scriptClass, context);
- script.printer = (Printer)writer;
- script.setProperty("out", script.printer);
- script.run();
- script.flush();
- return writer;
- }
-
- /**
- * Convert the template and binding into a result String.
- *
- * @see java.lang.Object#toString()
- */
- public String toString()
- {
- try
- {
- StringWriter sw = new StringWriter();
- writeTo(sw);
- return sw.toString();
- }
- catch (Exception e)
- {
- return e.toString();
- }
- }
- };
- }
-
- /**
- * Parse the text document looking for <% or <%= and then call out to the appropriate handler, otherwise copy the text directly
- * into the script while escaping quotes.
- *
- * @param reader
- * @throws IOException
- */
- protected String parse(Reader reader) throws IOException
- {
- if (!reader.markSupported())
- {
- reader = new BufferedReader(reader);
- }
- StringWriter sw = new StringWriter();
- startScript(sw);
- int c;
- while ((c = reader.read()) != -1)
- {
- if (c == '<')
- {
- reader.mark(1);
- c = reader.read();
- if (c != '%')
- {
- sw.write('<');
- reader.reset();
- continue;
- }
- reader.mark(1);
- c = reader.read();
- if (c == '=')
- groovyExpression(reader, sw);
- else
- {
- reader.reset();
- groovySection(reader, sw);
- }
- continue; // at least '<' is consumed ... read next chars.
- }
- if (c == '\"')
- sw.write('\\');
- /*
- * Handle raw new line characters.
- */
- if (c == '\n' || c == '\r')
- {
- if (c == '\r')
- { // on Windows, "\r\n" is a new line.
- reader.mark(1);
- c = reader.read();
- if (c != '\n')
- reader.reset();
- }
- sw.write("\\n\");\nout.print(\"");
- continue;
- }
- sw.write(c);
- }
- endScript(sw);
- String result = sw.toString();
- return result;
- }
-
- private void startScript(StringWriter sw)
- {
- sw.write("/* Generated by SimpleTemplateEngine */\n");
- sw.write("out.print(\"");
- }
-
- private void endScript(StringWriter sw)
- {
- sw.write("\");\n");
- }
-
- /**
- * Closes the currently open write and writes out the following text as a GString expression until it reaches an end %>.
- *
- * @param reader
- * @param sw
- * @throws IOException
- */
- private void groovyExpression(Reader reader, StringWriter sw) throws IOException
- {
- sw.write("\");out.print(\"${");
- int c;
- while ((c = reader.read()) != -1)
- {
- if (c == '%')
- {
- c = reader.read();
- if (c == '>')
- break;
- sw.write('%');
- }
- if (c != '\n' && c != '\r')
- sw.write(c);
- }
- sw.write("}\");\nout.print(\"");
- }
-
- /**
- * Closes the currently open write and writes the following text as normal Groovy script code until it reaches an end %>.
- *
- * @param reader
- * @param sw
- * @throws IOException
- */
- private void groovySection(Reader reader, StringWriter sw) throws IOException
- {
- sw.write("\");");
- int c;
- while ((c = reader.read()) != -1)
- {
- if (c == '%')
- {
- c = reader.read();
- if (c == '>')
- break;
- sw.write('%');
- }
- /* Don't eat EOL chars in sections - as they are valid instruction separators.
- * See http://jira.codehaus.org/browse/GROOVY-980
- */
- // if (c != '\n' && c != '\r') {
- sw.write(c);
- //}
- }
- sw.write(";\nout.print(\"");
- }
- }
-}
Modified: portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java
===================================================================
--- portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -22,8 +22,10 @@
import groovy.lang.Writable;
import groovy.text.Template;
+import groovy.text.TemplateEngine;
import org.exoplatform.commons.utils.IOUtil;
import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.groovyscript.GroovyTemplateEngine;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -45,7 +47,7 @@
public class TemplateService
{
- private SimpleTemplateEngine engine_;
+ private TemplateEngine engine_;
private ExoCache<String, Template> templatesCache_;
@@ -56,7 +58,7 @@
public TemplateService(InitParams params, TemplateStatisticService statisticService, CacheService cservice)
throws Exception
{
- engine_ = new SimpleTemplateEngine();
+ engine_ = new GroovyTemplateEngine();
this.statisticService = statisticService;
templatesCache_ = cservice.getCacheInstance(TemplateService.class.getName());
getTemplatesCache().setLiveTime(10000);
Added: portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateCompiler.java
===================================================================
--- portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateCompiler.java (rev 0)
+++ portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateCompiler.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import junit.framework.TestCase;
+import org.exoplatform.groovyscript.TemplateCompiler;
+
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class TestTemplateCompiler extends TestCase
+{
+
+ /** . */
+ private final TemplateCompiler compiler = new TemplateCompiler();
+
+ public void testFoo() throws IOException
+ {
+// assertEquals("", compiler.compile(""));
+// assertEquals("out.print(\"a\");", compiler.compile("a"));
+// assertEquals("out.print(\"a\n\");\nout.print(\"b\");", compiler.compile("a\nb"));
+// assertEquals("", compiler.compile("<%%>"));
+// assertEquals("a", compiler.compile("<%a%>"));
+// assertEquals("a\nb", compiler.compile("<%a\nb%>"));
+ }
+}
Added: portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateParser.java
===================================================================
--- portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateParser.java (rev 0)
+++ portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateParser.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import junit.framework.TestCase;
+import org.exoplatform.groovyscript.TemplateSection;
+import org.exoplatform.groovyscript.SectionType;
+import org.exoplatform.groovyscript.TemplateParser;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class TestTemplateParser extends TestCase
+{
+
+ /** . */
+ private TemplateParser parser = new TemplateParser();
+
+ public void testEmpty() throws IOException
+ {
+ assertEquals(Collections.<TemplateSection>emptyList(), parser.parse(""));
+ }
+
+ public void testText() throws IOException
+ {
+ assertEquals(Arrays.<TemplateSection>asList(new TemplateSection(SectionType.STRING, "a")), parser.parse("a"));
+ }
+
+ public void testSingleEmptyScriplet() throws IOException
+ {
+ assertEquals(Arrays.<TemplateSection>asList(new TemplateSection(SectionType.SCRIPTLET, "")), parser.parse("<%%>"));
+ }
+
+ public void testSingleEmptyExpression() throws IOException
+ {
+ assertEquals(Arrays.<TemplateSection>asList(new TemplateSection(SectionType.EXPR, "")), parser.parse("<%=%>"));
+ }
+
+ public void testSingleScriplet() throws IOException
+ {
+ assertEquals(Arrays.<TemplateSection>asList(new TemplateSection(SectionType.SCRIPTLET, "a")), parser.parse("<%a%>"));
+ }
+
+ public void testSingleExpression() throws IOException
+ {
+ assertEquals(Arrays.<TemplateSection>asList(new TemplateSection(SectionType.EXPR, "a")), parser.parse("<%=a%>"));
+ }
+
+ public void testPercentScriplet() throws IOException
+ {
+ assertEquals(Arrays.<TemplateSection>asList(new TemplateSection(SectionType.SCRIPTLET, "%")), parser.parse("<%%%>"));
+ }
+
+ public void testPercentExpression() throws IOException
+ {
+ assertEquals(Arrays.<TemplateSection>asList(new TemplateSection(SectionType.EXPR, "%")), parser.parse("<%=%%>"));
+ }
+
+ public void testStartAngleBracketScriplet() throws IOException
+ {
+ assertEquals(Arrays.<TemplateSection>asList(new TemplateSection(SectionType.SCRIPTLET, "<")), parser.parse("<%<%>"));
+ }
+
+ public void testStartAngleBracketExpression() throws IOException
+ {
+ assertEquals(Arrays.<TemplateSection>asList(new TemplateSection(SectionType.EXPR, "<")), parser.parse("<%=<%>"));
+ }
+
+ public void testSimpleScript() throws IOException
+ {
+ assertEquals(Arrays.<TemplateSection>asList(
+ new TemplateSection(SectionType.STRING, "a"),
+ new TemplateSection(SectionType.SCRIPTLET, "b"),
+ new TemplateSection(SectionType.STRING, "c")
+ ), parser.parse("a<%b%>c"));
+ }
+
+ public void testSimpleScript2() throws IOException
+ {
+ assertEquals(Arrays.<TemplateSection>asList(
+ new TemplateSection(SectionType.STRING, "a"),
+ new TemplateSection(SectionType.EXPR, "b"),
+ new TemplateSection(SectionType.STRING, "c")
+ ), parser.parse("a<%=b%>c"));
+ }
+}
Added: portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
===================================================================
--- portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java (rev 0)
+++ portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.groovyscript;
+
+import junit.framework.TestCase;
+import org.exoplatform.commons.utils.CharsetTextEncoder;
+import org.exoplatform.commons.utils.OutputStreamPrinter;
+import org.exoplatform.groovyscript.GroovyTemplate;
+import org.exoplatform.groovyscript.OutputStreamWriterGroovyPrinter;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class TestTemplateRendering extends TestCase
+{
+
+ public void testOutputStreamWriter() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("a<%='b'%>c<%out.print('d');%>e");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ OutputStreamPrinter writer = new OutputStreamPrinter(CharsetTextEncoder.getUTF8(), baos);
+ OutputStreamWriterGroovyPrinter printer = new OutputStreamWriterGroovyPrinter(writer);
+ template.render(printer);
+ printer.close();
+ assertEquals("abcde", baos.toString("UTF-8"));
+ }
+
+ public void testFoo() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("a");
+// System.out.println("template = " + template.getGroovyText());
+ String render = template.render();
+ assertEquals("a", render);
+ }
+
+ public void testBar() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<%='a'%>");
+// System.out.println("template = " + template.getGroovyText());
+ String render = template.render();
+ assertEquals("a", render);
+ }
+
+ public void testFooBar() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("a<%='b'%>c");
+// System.out.println("template = " + template.getGroovyText());
+ String render = template.render();
+ assertEquals("abc", render);
+ }
+
+ public void testJuu() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<% out.print(\"a\"); %>");
+// System.out.println("template = " + template.getGroovyText());
+ String render = template.render();
+ assertEquals("a", render);
+ }
+
+ public void testLineBreak() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("\n");
+ String render = template.render();
+ assertEquals("\n", render);
+ }
+
+ public void testMultiLine() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate(
+ "a\n" +
+ "b\n" +
+ "<%= 'c' %>\n" +
+ "d"
+ );
+ String render = template.render();
+ assertEquals("a\nb\nc\nd", render);
+ }
+
+ public void testIf() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate(
+ "a\n" +
+ "<% if (true) {\n %>" +
+ "b\n" +
+ "<% } %>\n"
+ );
+ }
+
+ public void testContextResolution() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<%= foo %>");
+ Map<String, String> context = new HashMap<String, String>();
+ context.put("foo", "bar");
+ String s = template.render(context);
+ assertEquals("bar", s);
+ }
+
+ public void testGString() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("$foo");
+ Map<String, String> context = new HashMap<String, String>();
+ context.put("foo", "bar");
+ String s = template.render(context);
+ assertEquals("bar", s);
+ }
+
+ public void testGString2() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("$foo\"");
+ Map<String, String> context = new HashMap<String, String>();
+ context.put("foo", "bar");
+ String s = template.render(context);
+ assertEquals("bar\"", s);
+ }
+
+ public void testQuote() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("\"");
+ String s = template.render();
+ assertEquals("\"", s);
+ }
+
+ public void testFooFoo() throws Exception
+ {
+ InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("UIPortalApplication.gtmpl");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] buffer = new byte[256];
+ for (int l = in.read(buffer);l != -1;l = in.read(buffer))
+ {
+ baos.write(buffer, 0, l);
+ }
+ String gtmpl = baos.toString("UTF-8");
+ GroovyTemplate template = new GroovyTemplate(gtmpl);
+ }
+}
Added: portal/branches/performance/component/scripting/src/test/resources/UIPortalApplication.gtmpl
===================================================================
--- portal/branches/performance/component/scripting/src/test/resources/UIPortalApplication.gtmpl (rev 0)
+++ portal/branches/performance/component/scripting/src/test/resources/UIPortalApplication.gtmpl 2009-10-30 14:38:36 UTC (rev 459)
@@ -0,0 +1,134 @@
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<%
+ def rcontext = _ctx.getRequestContext() ;
+ String docBase = rcontext.getRequestContextPath() ;
+ String skin = uicomponent.getSkin();
+ def portalSkins = uicomponent.getPortalSkins() ;
+ def portletSkins = uicomponent.getPortletSkins() ;
+ def scriptsPaths = uicomponent.getJavascriptURLs();
+ def lang = uicomponent.getLocale().getLanguage();
+ def title = rcontext.getTitle();
+ def metaInformation = rcontext.getMetaInformation();
+%>
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$lang" lang="$lang" dir="$dir">
+ <head id="head">
+ <title><%=title%></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <%
+ if(metaInformation!= null) {
+ Iterator<String> keys = metaInformation.keySet().iterator();
+ while(keys.hasNext()) {
+ String metaName = keys.next();
+ String metaContent = metaInformation.get(metaName);
+ %>
+ <meta name="<%=metaName%>" content="<%=metaContent%>" />
+ <% } } %>
+
+ <link rel="shortcut icon" type="image/x-icon" href="<%=docBase%>/favicon.ico" />
+ <%for(skinConfig in portalSkins) {
+ def url = skinConfig.createURL();
+ url.setOrientation(orientation);
+ %>
+ <link id="${skinConfig.id}" rel="stylesheet" type="text/css" href="$url" />
+ <%}%>
+ <%for(portletSkin in portletSkins) {
+ def url = portletSkin.createURL();
+ url.setOrientation(orientation);
+ %>
+ <link id="${portletSkin.id}" rel="stylesheet" type="text/css" href= "$url" />
+ <%}%>
+ <script type="text/javascript">
+ // This variable must be used only to initialize other variables otherwise
+ // please use eXo.env.portal.context or eXo.env.portal.context instead
+ // Those 2 last variables cannot be used to initialize variables because
+ // we cannot be sure that they will be initialized before initializing your script
+ var currentContext = '<%=docBase%>' ;
+ </script>
+ <%if(org.exoplatform.commons.utils.PropertyManager.isDevelopping()) {
+ for(path in scriptsPaths) { %>
+ <script type="text/javascript" src="<%=path%>"></script>
+ <% }
+ } else {
+ %>
+ <script type="text/javascript" src="<%=docBase%>/javascript/merged.js"></script>
+ <%}%>
+ <script type="text/javascript">
+ eXo.env.portal.context = '<%=docBase%>' ;
+ <%if(rcontext.getAccessPath() == 0) {%>
+ eXo.env.portal.accessMode = 'public' ;
+ <%} else {%>
+ eXo.env.portal.accessMode = 'private' ;
+ <%}%>
+ eXo.env.portal.portalName = '<%=rcontext.getPortalOwner()%>' ;
+ eXo.env.server.context = '<%=docBase%>' ;
+ eXo.env.server.portalBaseURL = '<%=rcontext.getURLBuilder().getBaseURL()%>' ;
+ eXo.env.client.skin = '$skin' ;
+ <%
+ String sessionAliveLevel = (portal == null ? null : portal.sessionAlive) ;
+ boolean canKeepState = sessionAliveLevel == null ? false : !sessionAliveLevel.equals(PortalProperties.SESSION_NEVER) ;
+ %>
+
+ eXo.portal.portalMode = <%= uicomponent.getModeState() %>;
+
+ eXo.session.level = '$sessionAliveLevel';
+ eXo.session.canKeepState = $canKeepState;
+ eXo.session.isOpen = $uicomponent.isSessionOpen ;
+ eXo.session.itvTime = ${(rcontext).getRequest().getSession().getMaxInactiveInterval()} ;
+ </script>
+ <script type="text/javascript" src="/eXoResources/javascript/eXo/i18n/I18NMessage.js"></script>
+ <script type="text/javascript" src="/eXoResources/javascript/eXo/i18n/MessageResource_<%=lang%>.js"></script>
+ </head>
+
+ <body style="height: 100%;">
+ <%
+ /*Hide All Popup Menu when click on document*/
+ rcontext.getJavascriptManager().addOnLoadJavascript('eXo.core.DOMUtil.hideElements');
+ //rcontext.getJavascriptManager().addOnResizeJavascript('eXo.core.UIMaskLayer.resizeMaskLayer');
+ %>
+
+ <div class="$uicomponent.skin" id="UIPortalApplication" style="!height: 100%;">
+
+ <div class="AjaxLoadingMask" id="AjaxLoadingMask" style="display: none; margin: auto;">
+ <div class="LoadingContainer">
+ <div class="CenterLoadingContainer">
+ <div class="LoadingText"><%=_ctx.appRes("UIPortalApplication.label.Loading")%></div>
+ <div class="LoadingProgressBar"><span></span></div>
+
+ <div class="UIAction">
+ <table class="ActionContainer">
+ <tr>
+ <td>
+ <div onclick="javascript:ajaxAbort();" class="ActionButton LightBlueStyle">
+ <div class="ButtonLeft">
+ <div class="ButtonRight">
+ <div class="ButtonMiddle">
+ <a href="javascript:void(0);"><%=_ctx.appRes("UIPortalApplication.label.Abort")%></a>
+ </div>
+ </div>
+ </div>
+ </div>
+ </td>
+ </tr>
+ </table>
+ </div>
+
+ </div>
+ </div>
+ </div>
+
+ <%uicomponent.renderChildren();%>
+ </div>
+
+
+
+ <script type="text/javascript">
+ <%=rcontext.getJavascriptManager().getJavascript()%>
+ eXo.core.Browser.onLoad();
+ <%=rcontext.getJavascriptManager().getCustomizedOnLoadScript();%>
+ <%if(canKeepState && uicomponent.isSessionOpen) {%> eXo.session.itvInit() ;<%}%>
+ </script>
+ </body>
+</html>
Modified: portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java
===================================================================
--- portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -19,6 +19,7 @@
package org.exoplatform.webui.application.portlet;
+import org.exoplatform.commons.utils.PortalPrinter;
import org.exoplatform.resolver.ApplicationResourceResolver;
import org.exoplatform.resolver.PortletResourceResolver;
import org.exoplatform.services.log.ExoLogger;
@@ -275,12 +276,12 @@
{
String attributeName = getApplicationId() + "$PortletRequest";
PortletRequestContext context = (PortletRequestContext)parentAppRequestContext.getAttribute(attributeName);
- Writer w = null;
+ PortalPrinter w = null;
if (res instanceof RenderResponse)
{
RenderResponse renderRes = (RenderResponse)res;
renderRes.setContentType("text/html; charset=UTF-8");
- w = renderRes.getWriter();
+ w = new PortalPrinter(renderRes.getPortletOutputStream(), true, 0);
}
if (context != null)
{
Modified: portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletRequestContext.java
===================================================================
--- portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletRequestContext.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletRequestContext.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -75,7 +75,8 @@
{
request_ = req;
response_ = res;
- writer_ = HtmlValidator.DEBUG_MODE ? new WriterPrinter(new HtmlValidator(writer)) : new WriterPrinter(writer);
+// writer_ = HtmlValidator.DEBUG_MODE ? new WriterPrinter(new HtmlValidator(writer)) : new WriterPrinter(writer);
+ writer_ = writer;
windowId_ = req.getWindowID();
}
Modified: portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java
===================================================================
--- portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java 2009-10-30 10:54:06 UTC (rev 458)
+++ portal/branches/performance/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java 2009-10-30 14:38:36 UTC (rev 459)
@@ -42,6 +42,7 @@
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
import java.io.Serializable;
+import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
@@ -175,7 +176,18 @@
if (response instanceof FragmentResponse)
{
FragmentResponse fragmentResponse = (FragmentResponse)response;
- markup = Text.create(fragmentResponse.getContent());
+ switch (fragmentResponse.getType())
+ {
+ case FragmentResponse.TYPE_CHARS:
+ markup = Text.create(fragmentResponse.getContent());
+ break;
+ case FragmentResponse.TYPE_BYTES:
+ markup = Text.create(fragmentResponse.getBytes(), Charset.forName("UTF-8"));
+ break;
+ case FragmentResponse.TYPE_EMPTY:
+ markup = Text.create("");
+ break;
+ }
portletTitle = fragmentResponse.getTitle();
if (fragmentResponse.getProperties() != null
&& fragmentResponse.getProperties().getTransportHeaders() != null)
@@ -262,6 +274,7 @@
}
catch (Throwable ex)
{
+ ex.printStackTrace();
}
}
}
15 years, 1 month
gatein SVN: r458 - in portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui: workspace and 1 other directory.
by do-not-reply@jboss.org
Author: tam_nguyen
Date: 2009-10-30 06:54:06 -0400 (Fri, 30 Oct 2009)
New Revision: 458
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/util/PortalDataMapper.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java
Log:
GTNPORTAL-110
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/util/PortalDataMapper.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/util/PortalDataMapper.java 2009-10-30 10:35:24 UTC (rev 457)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/util/PortalDataMapper.java 2009-10-30 10:54:06 UTC (rev 458)
@@ -182,7 +182,7 @@
return model;
}
- static private Page toPageModel(UIPage uiPage)
+ static public Page toPageModel(UIPage uiPage)
{
Page model = new Page(uiPage.getStorageId());
toContainer(model, uiPage);
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java 2009-10-30 10:35:24 UTC (rev 457)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java 2009-10-30 10:54:06 UTC (rev 458)
@@ -21,7 +21,9 @@
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.config.UserACL;
+import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.webui.page.UIPage;
import org.exoplatform.portal.webui.page.UIPageBody;
import org.exoplatform.portal.webui.page.UIPageCreationWizard;
import org.exoplatform.portal.webui.page.UISiteBody;
@@ -29,8 +31,10 @@
import org.exoplatform.portal.webui.portal.UIPortal;
import org.exoplatform.portal.webui.portal.UIPortalComposer;
import org.exoplatform.portal.webui.portal.UIPortalForm;
+import org.exoplatform.portal.webui.util.PortalDataMapper;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.web.application.ApplicationMessage;
+import org.exoplatform.webui.core.UIComponent;
import org.exoplatform.webui.event.Event;
import org.exoplatform.webui.event.EventListener;
@@ -64,6 +68,18 @@
UIPortalToolPanel uiToolPanel = uiWorkingWS.findFirstComponentOfType(UIPortalToolPanel.class);
uiToolPanel.setShowMaskLayer(false);
UIPageBody pageBody = uiWorkingWS.findFirstComponentOfType(UIPageBody.class);
+
+ // check edit permission for page
+ UIPage uiPage = (UIPage) pageBody.getUIComponent();
+ Page page = PortalDataMapper.toPageModel(uiPage);
+
+ UserACL userACL = uiApp.getApplicationComponent(UserACL.class);
+ if (!userACL.hasEditPermission(page))
+ {
+ uiApp.addMessage(new ApplicationMessage("UIPortalManagement.msg.Invalid-editPermission", null));
+ return;
+ }
+
uiToolPanel.setWorkingComponent(pageBody.getUIComponent());
event.getRequestContext().addUIComponentToUpdateByAjax(uiWorkingWS);
Util.getPortalRequestContext().setFullRender(true);
15 years, 1 month
gatein SVN: r457 - portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component.
by do-not-reply@jboss.org
Author: liem_nguyen
Date: 2009-10-30 06:35:24 -0400 (Fri, 30 Oct 2009)
New Revision: 457
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/GroupManagement.java
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupExplorer.java
Log:
GTNPORTAL-70 Can't add user into group in specical case
Modified: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/GroupManagement.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/GroupManagement.java 2009-10-30 09:43:53 UTC (rev 456)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/GroupManagement.java 2009-10-30 10:35:24 UTC (rev 457)
@@ -146,6 +146,8 @@
{
if (username == null)
username = org.exoplatform.portal.webui.util.Util.getPortalRequestContext().getRemoteUser();
+ if (username.equals(getUserACL().getSuperUser()))
+ return true;
return isMemberOfGroup(username, getUserACL().getAdminGroups());
}
Modified: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupExplorer.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupExplorer.java 2009-10-30 09:43:53 UTC (rev 456)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupExplorer.java 2009-10-30 10:35:24 UTC (rev 457)
@@ -121,7 +121,8 @@
sibblingsGroup_ = service.getGroupHandler().findGroups(parentGroup);
// if not administrator
- if (!GroupManagement.isAdministrator(null))
+ String username = org.exoplatform.portal.webui.util.Util.getPortalRequestContext().getRemoteUser();
+ if (!GroupManagement.isSuperUserOfGroup(username, groupId))
{
childrenGroup_ = GroupManagement.getRelatedGroups(null, childrenGroup_);
sibblingsGroup_ = GroupManagement.getRelatedGroups(null, sibblingsGroup_);
15 years, 1 month