Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added behavior options for easier debugging

  • Loading branch information...
commit 5032b4e6af2f7ca0716df84c34c99fc9efb5b914 1 parent 2921e59
mMoossen authored
View
30 com.alkacon.opencms.weboptimization/resources/manifest.xml
@@ -4,7 +4,7 @@
<info>
<creator>Admin</creator>
<opencms_version>7.0.5</opencms_version>
- <createdate>Tue, 24 Mar 2009 10:32:20 GMT</createdate>
+ <createdate>Sat, 02 Jan 2010 20:10:46 GMT</createdate>
<infoproject>Offline</infoproject>
<export_version>7</export_version>
</info>
@@ -14,7 +14,7 @@
<group>Alkacon OAMP</group>
<class/>
<description><![CDATA[This module allows to compress js and css files, as well as to create image sprites, on the fly.]]></description>
- <version>1.0.0</version>
+ <version>1.0.1</version>
<authorname><![CDATA[Alkacon Software GmbH]]></authorname>
<authoremail><![CDATA[info@alkacon.com]]></authoremail>
<datecreated/>
@@ -917,6 +917,26 @@
<accesscontrol/>
</file>
<file>
+ <source>system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-behaviour.xsd</source>
+ <destination>system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-behaviour.xsd</destination>
+ <type>plain</type>
+ <uuidstructure>07fb4c8c-f7be-11de-8684-e30a09549266</uuidstructure>
+ <uuidresource>07fb4c8d-f7be-11de-8684-e30a09549266</uuidresource>
+ <datelastmodified>Sat, 02 Jan 2010 17:08:19 GMT</datelastmodified>
+ <userlastmodified>Admin</userlastmodified>
+ <datecreated>Sat, 02 Jan 2010 16:44:01 GMT</datecreated>
+ <usercreated>Admin</usercreated>
+ <flags>0</flags>
+ <properties>
+ <property>
+ <name>Title</name>
+ <value><![CDATA[behaviour schema]]></value>
+ </property>
+ </properties>
+ <relations/>
+ <accesscontrol/>
+ </file>
+ <file>
<source>system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-css-options.xsd</source>
<destination>system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-css-options.xsd</destination>
<type>plain</type>
@@ -942,7 +962,7 @@
<type>plain</type>
<uuidstructure>4d27f2de-de0a-11de-8ac1-e30a09549266</uuidstructure>
<uuidresource>4d27f2df-de0a-11de-8ac1-e30a09549266</uuidresource>
- <datelastmodified>Tue, 17 Mar 2009 19:32:24 GMT</datelastmodified>
+ <datelastmodified>Sat, 02 Jan 2010 17:05:11 GMT</datelastmodified>
<userlastmodified>Admin</userlastmodified>
<datecreated>Mon, 16 Mar 2009 09:10:32 GMT</datecreated>
<usercreated>Admin</usercreated>
@@ -1002,7 +1022,7 @@
<type>plain</type>
<uuidstructure>4d27f2de-120a-11de-8ac1-e30a09549266</uuidstructure>
<uuidresource>4d27f2df-120a-11de-8ac1-e30a09549266</uuidresource>
- <datelastmodified>Tue, 17 Mar 2009 19:32:24 GMT</datelastmodified>
+ <datelastmodified>Sat, 02 Jan 2010 17:04:42 GMT</datelastmodified>
<userlastmodified>Admin</userlastmodified>
<datecreated>Mon, 16 Mar 2009 09:10:32 GMT</datecreated>
<usercreated>Admin</usercreated>
@@ -1062,7 +1082,7 @@
<type>plain</type>
<uuidstructure>4d27f2de-120a-5fde-84c1-e30a09549266</uuidstructure>
<uuidresource>4d27f2df-120a-5fde-84c1-e30a09549266</uuidresource>
- <datelastmodified>Mon, 23 Mar 2009 22:07:10 GMT</datelastmodified>
+ <datelastmodified>Sat, 02 Jan 2010 17:05:32 GMT</datelastmodified>
<userlastmodified>Admin</userlastmodified>
<datecreated>Mon, 16 Mar 2009 09:10:32 GMT</datecreated>
<usercreated>Admin</usercreated>
View
8 ....opencms.weboptimization/classes/com/alkacon/opencms/weboptimization/workplace.properties
@@ -18,6 +18,7 @@ label.AlkaconOptimizedJs.Resource = Resource
label.AlkaconOptimizedJsResource.Path = Path
label.AlkaconOptimizedJsResource.Options = Options
+label.AlkaconOptimizedJsResource.Behaviour = Behaviour
label.AlkaconOptimizedJsOption.LineBreakPos = Line Break Position
label.AlkaconOptimizedJsOption.PreserveSemi = Preserve Semicolons
@@ -29,6 +30,7 @@ label.AlkaconOptimizedCss.Resource = Resource
label.AlkaconOptimizedCssResource.Path = Path
label.AlkaconOptimizedCssResource.Options = Options
+label.AlkaconOptimizedCssResource.Behaviour = Behaviour
label.AlkaconOptimizedCssOption.LineBreakPos = Line Break Position
@@ -38,7 +40,13 @@ label.AlkaconSprite.Resource = Resource
label.AlkaconSpriteResource.Path = Path
label.AlkaconSpriteResource.Position = Position
label.AlkaconSpriteResource.Selector = Css Selector
+label.AlkaconSpriteResource.Behaviour = Behaviour
label.AlkaconSpritePosition.X = X
label.AlkaconSpritePosition.Y = Y
+label.AlkaconOptimizedBehaviour.Online = Online
+label.AlkaconOptimizedBehaviour.Offline = Offline
+
+label.AlkaconOptimizedBehaviour.original = Original
+label.AlkaconOptimizedBehaviour.optimized = Optimized
View
5 ...encms.weboptimization/classes/com/alkacon/opencms/weboptimization/workplace_de.properties
@@ -18,6 +18,7 @@ label.AlkaconOptimizedJs.Resource = Ressource
label.AlkaconOptimizedJsResource.Path = Pfad
label.AlkaconOptimizedJsResource.Options = Optionen
+label.AlkaconOptimizedJsResource.Behaviour = Verhalten
label.AlkaconOptimizedJsOption.LineBreakPos = Zeilenumbruchsspalte
label.AlkaconOptimizedJsOption.PreserveSemi = Semikolons erhalten
@@ -29,6 +30,7 @@ label.AlkaconOptimizedCss.Resource = Ressource
label.AlkaconOptimizedCssResource.Path = Pfad
label.AlkaconOptimizedCssResource.Options = Optionen
+label.AlkaconOptimizedCssResource.Behaviour = Verhalten
label.AlkaconOptimizedCssOption.LineBreakPos = Zeilenumbruchsspalte
@@ -38,7 +40,10 @@ label.AlkaconSprite.Resource = Ressource
label.AlkaconSpriteResource.Path = Pfad
label.AlkaconSpriteResource.Position = Position
label.AlkaconSpriteResource.Selector = Css Selektor
+label.AlkaconSpriteResource.Behaviour = Verhalten
label.AlkaconSpritePosition.X = X
label.AlkaconSpritePosition.Y = Y
+label.AlkaconOptimizedBehaviour.original = Original
+label.AlkaconOptimizedBehaviour.optimized = Optimiert
View
34 ...ources/system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-behaviour.xsd
@@ -0,0 +1,34 @@
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+
+ <xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>
+
+ <xsd:element name="AlkaconOptimizedBehaviours" type="OpenCmsAlkaconOptimizedBehaviours"/>
+
+ <xsd:complexType name="OpenCmsAlkaconOptimizedBehaviours">
+ <xsd:sequence>
+ <xsd:element name="AlkaconOptimizedBehaviour" type="OpenCmsAlkaconOptimizedBehaviour" minOccurs="0" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="OpenCmsAlkaconOptimizedBehaviour">
+ <xsd:sequence>
+ <xsd:element name="Offline" type="OpenCmsString" minOccurs="1" maxOccurs="1" />
+ <xsd:element name="Online" type="OpenCmsString" minOccurs="1" maxOccurs="1" />
+ </xsd:sequence>
+ <xsd:attribute name="language" type="OpenCmsLocale" use="optional"/>
+ </xsd:complexType>
+
+ <xsd:annotation>
+ <xsd:appinfo>
+ <resourcebundle name="com.alkacon.opencms.weboptimization.workplace"/>
+ <layouts>
+ <layout element="Offline" widget="RadioSelectWidget" configuration="original*:${key.label.AlkaconOptimizedBehaviour.original}|optimized:${key.label.AlkaconOptimizedBehaviour.optimized}" />
+ <layout element="Online" widget="RadioSelectWidget" configuration="original:${key.label.AlkaconOptimizedBehaviour.original}|optimized*:${key.label.AlkaconOptimizedBehaviour.optimized}" />
+ </layouts>
+ <defaults>
+ <default element="Offline" value="original"/>
+ <default element="Online" value="optimized"/>
+ </defaults>
+ </xsd:appinfo>
+ </xsd:annotation>
+</xsd:schema>
View
2  ...ces/system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-css-resource.xsd
@@ -2,6 +2,7 @@
<xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>
<xsd:include schemaLocation="opencms://system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-css-options.xsd"/>
+ <xsd:include schemaLocation="opencms://system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-behaviour.xsd"/>
<xsd:element name="AlkaconOptimizedCssResources" type="OpenCmsAlkaconOptimizedCssResources"/>
@@ -15,6 +16,7 @@
<xsd:sequence>
<xsd:element name="Path" type="OpenCmsVfsFile" minOccurs="1" maxOccurs="1" />
<xsd:element name="Options" type="OpenCmsAlkaconOptimizedCssOption" minOccurs="0" maxOccurs="1" />
+ <xsd:element name="Behaviour" type="OpenCmsAlkaconOptimizedBehaviour" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="language" type="OpenCmsLocale" use="optional"/>
</xsd:complexType>
View
2  ...rces/system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-js-resource.xsd
@@ -2,6 +2,7 @@
<xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>
<xsd:include schemaLocation="opencms://system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-js-options.xsd"/>
+ <xsd:include schemaLocation="opencms://system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-behaviour.xsd"/>
<xsd:element name="AlkaconOptimizedJsResources" type="OpenCmsAlkaconOptimizedJsResources"/>
@@ -15,6 +16,7 @@
<xsd:sequence>
<xsd:element name="Path" type="OpenCmsVfsFile" minOccurs="1" maxOccurs="1" />
<xsd:element name="Options" type="OpenCmsAlkaconOptimizedJsOption" minOccurs="0" maxOccurs="1" />
+ <xsd:element name="Behaviour" type="OpenCmsAlkaconOptimizedBehaviour" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="language" type="OpenCmsLocale" use="optional"/>
</xsd:complexType>
View
2  .../resources/system/modules/com.alkacon.opencms.weboptimization/schemas/sprite-resource.xsd
@@ -2,6 +2,7 @@
<xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>
<xsd:include schemaLocation="opencms://system/modules/com.alkacon.opencms.weboptimization/schemas/sprite-position.xsd"/>
+ <xsd:include schemaLocation="opencms://system/modules/com.alkacon.opencms.weboptimization/schemas/optimized-behaviour.xsd"/>
<xsd:element name="AlkaconSpriteResources" type="OpenCmsAlkaconSpriteResources"/>
@@ -16,6 +17,7 @@
<xsd:element name="Path" type="OpenCmsVfsFile" minOccurs="1" maxOccurs="1" />
<xsd:element name="Position" type="OpenCmsAlkaconSpritePosition" minOccurs="1" maxOccurs="1" />
<xsd:element name="Selector" type="OpenCmsString" minOccurs="1" maxOccurs="1" />
+ <xsd:element name="Behaviour" type="OpenCmsAlkaconOptimizedBehaviour" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="language" type="OpenCmsLocale" use="optional"/>
</xsd:complexType>
View
280 ....opencms.weboptimization/src/com/alkacon/opencms/weboptimization/CmsOptimizationBean.java
@@ -1,7 +1,7 @@
/*
* File : $Source: /alkacon/cvs/alkacon/com.alkacon.opencms.weboptimization/src/com/alkacon/opencms/weboptimization/CmsOptimizationBean.java,v $
- * Date : $Date: 2009/09/11 07:39:52 $
- * Version: $Revision: 1.2 $
+ * Date : $Date: 2010/01/08 09:46:05 $
+ * Version: $Revision: 1.3 $
*
* This file is part of the Alkacon OpenCms Add-On Module Package
*
@@ -32,6 +32,7 @@
package com.alkacon.opencms.weboptimization;
+import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
@@ -44,7 +45,10 @@
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
+import org.opencms.xml.CmsXmlUtils;
import org.opencms.xml.content.CmsXmlContent;
+import org.opencms.xml.content.CmsXmlContentFactory;
+import org.opencms.xml.types.I_CmsXmlContentValue;
import java.util.ArrayList;
import java.util.Iterator;
@@ -63,11 +67,89 @@
*
* @author Michael Moossen
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*
* @since 7.0.6
*/
-public class CmsOptimizationBean extends CmsJspActionElement {
+public abstract class CmsOptimizationBean extends CmsJspActionElement {
+
+ /**
+ * The inclusion mode.<p>
+ */
+ protected enum IncludeMode {
+ /** Optimized mode. */
+ OPTIMIZED,
+ /** Original mode.*/
+ ORIGINAL,
+ /** Automatic mode. */
+ AUTO;
+ }
+
+ /**
+ * The parsing results.<p>
+ */
+ protected static class Resolution {
+
+ /** List of original resources. */
+ private List<CmsResource> m_resources = new ArrayList<CmsResource>();
+
+ /** Are there any optimized resource left?. */
+ private boolean m_hasOptimizedLeft;
+
+ /**
+ * Adds the given resource to the list.<p>
+ *
+ * @param resource the resource to add
+ */
+ public void addResource(CmsResource resource) {
+
+ if (!m_resources.contains(resource)) {
+ m_resources.add(resource);
+ }
+ }
+
+ /**
+ * Returns the list of resources.<p>
+ *
+ * @return the list of resources
+ */
+ public List<CmsResource> getResources() {
+
+ return m_resources;
+ }
+
+ /**
+ * Checks if there is at least one optimized resource left.<p>
+ *
+ * @return <code>true</code> if there is at least one optimized resource left
+ */
+ public boolean hasOptimizedLeft() {
+
+ return m_hasOptimizedLeft;
+ }
+
+ /**
+ * Merges the data with the given resolution.<p>
+ *
+ * @param resolution the resolution to merge with
+ */
+ public void merge(Resolution resolution) {
+
+ if(resolution.hasOptimizedLeft()) {
+ setOptimizedLeft();
+ }
+ m_resources.addAll(resolution.getResources());
+ }
+
+ /**
+ * Sets the flag indicating that there is at least one optimized
+ * resource left.<p>
+ */
+ public void setOptimizedLeft() {
+
+ m_hasOptimizedLeft = true;
+ }
+ }
/** type attribute constant. */
protected static final String ATTR_TYPE = "type";
@@ -81,9 +163,21 @@
/** Node name constant. */
protected static final String N_PATH = "Path";
- /** Node resource constant. */
+ /** Node name constant. */
protected static final String N_RESOURCE = "Resource";
+ /** Node name constant. */
+ protected static final String N_BEHAVIOUR = "Behaviour";
+
+ /** Behaviour value constant. */
+ protected static final String BEHAVIOUR_OPTIMIZED = "optimized";
+
+ /** Node name constant. */
+ protected static final String N_ONLINE = "Online";
+
+ /** Node name constant. */
+ protected static final String N_OFFLINE = "Offline";
+
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsOptimizationBean.class);
@@ -98,7 +192,7 @@ public CmsOptimizationBean(PageContext context, HttpServletRequest req, HttpServ
super(context, req, res);
}
-
+
/**
* Creates a new HTML tag with the given name and attributes.<p>
*
@@ -108,15 +202,15 @@ public CmsOptimizationBean(PageContext context, HttpServletRequest req, HttpServ
*
* @return the HTML code
*/
- protected String createTag(String tag, Map attr, boolean xmlStyle) {
+ protected String createTag(String tag, Map<String,String> attr, boolean xmlStyle) {
StringBuffer sb = new StringBuffer();
sb.append("<");
sb.append(tag);
if (attr != null) {
- Iterator it = attr.entrySet().iterator();
+ Iterator<Map.Entry<String,String>> it = attr.entrySet().iterator();
while (it.hasNext()) {
- Map.Entry entry = (Map.Entry)it.next();
+ Map.Entry<String,String> entry = it.next();
sb.append(" ");
sb.append(entry.getKey());
sb.append("=\"");
@@ -136,7 +230,7 @@ protected String createTag(String tag, Map attr, boolean xmlStyle) {
}
return sb.toString();
}
-
+
/**
* Returns the content of all files of the given path with the 'right' extension.<p>
*
@@ -153,17 +247,17 @@ protected String getAllContent(CmsObject cms, String path) throws Exception {
String ext = cms.getRequestContext().getUri().substring(cms.getRequestContext().getUri().lastIndexOf('.'));
// retrieve the actual files to process
- List resorces = resolveResource(cms, path, ext);
- if (resorces.isEmpty()) {
+ List<CmsResource> resources = resolveResource(cms, path, ext);
+ if (resources.isEmpty()) {
LOG.warn(Messages.get().getBundle().key(Messages.LOG_WARN_NOTHING_TO_PROCESS_1, path));
return "";
}
// merge file contents
StringBuffer sb = new StringBuffer();
- Iterator itRes = resorces.iterator();
+ Iterator<CmsResource> itRes = resources.iterator();
while (itRes.hasNext()) {
- CmsResource res = (CmsResource)itRes.next();
+ CmsResource res = itRes.next();
byte[] data = getBinaryContent(cms, res);
sb.append(new String(data, getRequestContext().getEncoding()));
}
@@ -205,6 +299,154 @@ protected String getAllContent(CmsObject cms, String path) throws Exception {
}
/**
+ * Creates code for the given optimized resource,
+ * by default it will use the original code in the
+ * offline project for debugging purposes, and
+ * optimized code in the online project for optimal
+ * performance.<p>
+ *
+ * @param path the uri of the file to be included
+ *
+ * @throws Exception if something goes wrong
+ */
+ public void includeDefault(String path) throws Exception {
+
+ includeDefault(path, IncludeMode.AUTO);
+ }
+
+ /**
+ * Creates optimized code for the optimized resource, depending on the mode.<p>
+ *
+ * @param path the optimized resource uri
+ * @param mode the mode to use
+ *
+ * @throws Exception if something goes wrong
+ */
+ protected abstract void includeDefault(String path, IncludeMode mode) throws Exception;
+
+ /**
+ * Creates optimized code for the optimized resource.<p>
+ *
+ * @param path the optimized resource uri
+ *
+ * @throws Exception if something goes wrong
+ */
+ public void includeOptimized(String path) throws Exception {
+
+ includeDefault(path, IncludeMode.OPTIMIZED);
+ }
+
+ /**
+ * Creates original code for the optimized resource.<p>
+ *
+ * @param path the optimized resource uri
+ *
+ * @throws Exception if something goes wrong
+ */
+ public void includeOriginal(String path) throws Exception {
+
+ includeDefault(path, IncludeMode.ORIGINAL);
+ }
+
+ /**
+ * Checks if the given resource node has to be optimized.<p>
+ *
+ * @param cms the current cms context
+ * @param xml the xml content to use
+ * @param value the resource xml node
+ * @param locale the locale to use
+ * @param online if online or offline
+ *
+ * @return <code>true</code> if the given resource node has to be optimized
+ */
+ protected boolean isOptimized(CmsObject cms, CmsXmlContent xml, I_CmsXmlContentValue value, Locale locale, boolean online) {
+
+ boolean optimized = false;
+ String xpath = CmsXmlUtils.concatXpath(value.getPath(), N_BEHAVIOUR);
+ I_CmsXmlContentValue behaviour = xml.getValue(xpath, locale);
+ if (behaviour == null) {
+ if (online) {
+ optimized = true;
+ }
+ } else {
+ if (online) {
+ xpath = CmsXmlUtils.concatXpath(behaviour.getPath(), N_ONLINE);
+ } else {
+ xpath = CmsXmlUtils.concatXpath(behaviour.getPath(), N_OFFLINE);
+ }
+ I_CmsXmlContentValue p = xml.getValue(xpath, locale);
+ optimized = p.getStringValue(cms).equals(BEHAVIOUR_OPTIMIZED);
+ }
+ return optimized;
+ }
+
+ /**
+ * Resolves the given file.<p>
+ *
+ * @param cms the current context
+ * @param file the file to resolve
+ * @param mode the mode to use
+ * @param extension the file extension to restrict the inclusion
+ * @param type the resource type id for recursion
+ *
+ * @return the resolution
+ *
+ * @throws CmsException if something goes wrong
+ */
+ protected Resolution resolveInclude(CmsObject cms, CmsFile file, IncludeMode mode, String extension, int type) throws CmsException {
+
+ Resolution resolution = new Resolution();
+ // read the XML content
+ CmsXmlContent xml = CmsXmlContentFactory.unmarshal(cms, file);
+
+ // resolve the locale
+ Locale locale = resolveLocale(cms, xml);
+
+ // cache the current project
+ boolean online = cms.getRequestContext().currentProject().isOnlineProject();
+
+ // iterate the resources
+ Iterator<I_CmsXmlContentValue> itPath = xml.getValues(N_RESOURCE, locale).iterator();
+ while (itPath.hasNext()) {
+ I_CmsXmlContentValue value = itPath.next();
+ // get the uri
+ String xpath = CmsXmlUtils.concatXpath(value.getPath(), N_PATH);
+ String uri = xml.getValue(xpath, locale).getStringValue(cms);
+
+ // retrieve the actual files to process
+ List<CmsResource> resorces = resolveResource(cms, uri, extension);
+ if (resorces.isEmpty()) {
+ LOG.warn(Messages.get().getBundle().key(
+ Messages.LOG_WARN_NOTHING_TO_PROCESS_1, uri));
+ continue;
+ }
+
+ if (mode == IncludeMode.AUTO) {
+ // compute the mode to use
+ boolean optimized = isOptimized(cms, xml, value, locale, online);
+ if (optimized) {
+ resolution.setOptimizedLeft();
+ // if optimized it will be handled while rendering
+ continue;
+ }
+ }
+
+ Iterator<CmsResource> itRes = resorces.iterator();
+ while (itRes.hasNext()) {
+ CmsResource res = itRes.next();
+ if (res.getTypeId() == type) {
+ // recurse in case of nested optimized resources
+ resolution.merge(resolveInclude(cms, cms.readFile(res), mode,extension, type));
+ } else {
+ // handle this resource
+ resolution.addResource(res);
+ }
+ }
+ }
+ return resolution;
+ }
+
+ /**
* Resolves the right locale to use.<p>
*
* @param cms the cms context
@@ -239,17 +481,17 @@ protected Locale resolveLocale(CmsObject cms, CmsXmlContent xml) {
*
* @throws CmsException if something goes wrong
*/
- protected List resolveResource(CmsObject cms, String path, String ext) throws CmsException {
+ protected List<CmsResource> resolveResource(CmsObject cms, String path, String ext) throws CmsException {
CmsResource res = cms.readResource(path);
- List resorces = new ArrayList();
+ List<CmsResource> resorces = new ArrayList<CmsResource>();
if (res.isFolder()) {
// if folder, get all files with the given extension in the folder
- List files = cms.readResources(path, CmsResourceFilter.DEFAULT_FILES);
- Iterator itFiles = files.iterator();
+ List<CmsResource> files = cms.readResources(path, CmsResourceFilter.DEFAULT_FILES);
+ Iterator<CmsResource> itFiles = files.iterator();
while (itFiles.hasNext()) {
- CmsResource file = (CmsResource)itFiles.next();
+ CmsResource file = itFiles.next();
if (file.getRootPath().endsWith(ext)) {
resorces.add(file);
}
View
152 ...n.opencms.weboptimization/src/com/alkacon/opencms/weboptimization/CmsOptimizationCss.java
@@ -1,7 +1,7 @@
/*
* File : $Source: /alkacon/cvs/alkacon/com.alkacon.opencms.weboptimization/src/com/alkacon/opencms/weboptimization/CmsOptimizationCss.java,v $
- * Date : $Date: 2009/09/11 07:39:52 $
- * Version: $Revision: 1.2 $
+ * Date : $Date: 2010/01/08 09:46:05 $
+ * Version: $Revision: 1.3 $
*
* This file is part of the Alkacon OpenCms Add-On Module Package
*
@@ -36,7 +36,6 @@
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.main.CmsIllegalArgumentException;
-import org.opencms.main.CmsLog;
import org.opencms.xml.CmsXmlUtils;
import org.opencms.xml.content.CmsXmlContent;
import org.opencms.xml.content.CmsXmlContentFactory;
@@ -48,7 +47,6 @@
import java.io.StringReader;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -56,8 +54,6 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
-import org.apache.commons.logging.Log;
-
import com.yahoo.platform.yui.compressor.CssCompressor;
/**
@@ -65,7 +61,7 @@
*
* @author Michael Moossen
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*
* @since 7.0.6
*/
@@ -98,9 +94,6 @@
/** text/css type constant. */
protected static final String TYPE_TEXT_CSS = "text/css";
- /** The log object for this class. */
- private static final Log LOG = CmsLog.getLog(CmsOptimizationCss.class);
-
/**
* Default constructor.
*
@@ -113,99 +106,41 @@ public CmsOptimizationCss(PageContext context, HttpServletRequest req, HttpServl
super(context, req, res);
}
- /**
- * Include the given optimized file, will include the original
- * files in the offline project for debugging purposes.<p>
- *
- * @param path the uri of the file to be included
- *
- * @throws Exception if something goes wrong
- */
- public void includeDefault(String path) throws Exception {
-
- if (getCmsObject().getRequestContext().currentProject().isOnlineProject()) {
- includeOptimized(path);
- } else {
- includeOriginal(path);
- }
- }
-
- /**
- * Will include the optimized file.<p>
- *
- * @param path the optimized file uri
- *
- * @throws Exception if something goes wrong
- */
- public void includeOptimized(String path) throws Exception {
-
- CmsObject cms = getCmsObject();
- // check the resource type
- CmsResource res = cms.readResource(path);
- if (res.getTypeId() != RESOURCE_TYPE_CSS) {
- throw new CmsIllegalArgumentException(Messages.get().container(
- Messages.ERR_NOT_SUPPORTED_RESOURCE_TYPE_2,
- path,
- new Integer(res.getTypeId())));
- }
- writeCssInclude(cms, path);
- }
-
- /**
- * Will include the original files.<p>
- *
- * @param path the optimized file uri
- *
- * @throws Exception if something goes wrong
- */
- public void includeOriginal(String path) throws Exception {
-
- CmsObject cms = getCmsObject();
- CmsFile file = cms.readFile(path);
-
- // check the resource type
- if (file.getTypeId() != RESOURCE_TYPE_CSS) {
- throw new CmsIllegalArgumentException(Messages.get().container(
- Messages.ERR_NOT_SUPPORTED_RESOURCE_TYPE_2,
- path,
- new Integer(file.getTypeId())));
- }
-
- // read the XML content
- CmsXmlContent xml = CmsXmlContentFactory.unmarshal(cms, file);
-
- // resolve the locale
- Locale locale = resolveLocale(cms, xml);
-
- // iterate the resources
- Iterator itPath = xml.getValues(N_RESOURCE, locale).iterator();
- while (itPath.hasNext()) {
- I_CmsXmlContentValue value = (I_CmsXmlContentValue)itPath.next();
- // get the uri
- String xpath = CmsXmlUtils.concatXpath(value.getPath(), N_PATH);
- String uri = xml.getValue(xpath, locale).getStringValue(cms);
-
- // retrieve the actual files to process
- List resorces = resolveResource(cms, uri, EXT_CSS);
- if (resorces.isEmpty()) {
- LOG.warn(Messages.get().getBundle().key(Messages.LOG_WARN_NOTHING_TO_PROCESS_1, uri));
- continue;
- }
-
- Iterator itRes = resorces.iterator();
- while (itRes.hasNext()) {
- CmsResource res = (CmsResource)itRes.next();
- String resPath = cms.getSitePath(res);
- if (res.getTypeId() == RESOURCE_TYPE_CSS) {
- // recurse in case of nested optimized resources
- includeOriginal(resPath);
- } else {
- // handle this resource
- writeCssInclude(cms, resPath);
- }
- }
- }
- }
+ /**
+ * @see com.alkacon.opencms.weboptimization.CmsOptimizationBean#includeDefault(java.lang.String,
+ * com.alkacon.opencms.weboptimization.CmsOptimizationBean.IncludeMode)
+ */
+ @Override
+ public void includeDefault(String path, IncludeMode mode) throws Exception {
+
+ CmsObject cms = getCmsObject();
+ // check the resource type
+ CmsFile file = cms.readFile(path);
+ if (file.getTypeId() != RESOURCE_TYPE_CSS) {
+ throw new CmsIllegalArgumentException(Messages.get().container(
+ Messages.ERR_NOT_SUPPORTED_RESOURCE_TYPE_2, path,
+ new Integer(file.getTypeId())));
+ }
+ if (mode == IncludeMode.OPTIMIZED) {
+ // if we are forcing optimization
+ // handle this resource
+ writeCssInclude(cms, path);
+ return;
+ }
+
+ Resolution resolution = resolveInclude(cms, file, mode, EXT_CSS, RESOURCE_TYPE_CSS);
+ if (resolution.hasOptimizedLeft()) {
+ // handle this resource
+ writeCssInclude(cms, path);
+ }
+ Iterator<CmsResource> itRes = resolution.getResources().iterator();
+ while (itRes.hasNext()) {
+ CmsResource res = itRes.next();
+ String resPath = cms.getSitePath(res);
+ // handle this resource
+ writeCssInclude(cms, resPath);
+ }
+ }
/**
* Will optimize the resources taken from the underlying XML content.<p>
@@ -230,11 +165,16 @@ public void optimize() throws Exception {
// resolve the locale
Locale locale = resolveLocale(cms, xml);
+ // cache the current project
+ boolean online = cms.getRequestContext().currentProject().isOnlineProject();
// iterate the resources
- Iterator itRes = xml.getValues(N_RESOURCE, locale).iterator();
+ Iterator<I_CmsXmlContentValue> itRes = xml.getValues(N_RESOURCE, locale).iterator();
while (itRes.hasNext()) {
- I_CmsXmlContentValue value = (I_CmsXmlContentValue)itRes.next();
+ I_CmsXmlContentValue value = itRes.next();
+ if (!isOptimized(cms, xml, value, locale, online)) {
+ continue;
+ }
// get the path
String xpath = CmsXmlUtils.concatXpath(value.getPath(), N_PATH);
String path = xml.getValue(xpath, locale).getStringValue(cms);
@@ -285,7 +225,7 @@ public void optimizeCss(String cssCode, CmsOptimizationCssOptions options) throw
*/
public void writeCssInclude(CmsObject cms, String uri) throws IOException {
- Map attrs = new HashMap();
+ Map<String,String> attrs = new HashMap<String,String>();
attrs.put(ATTR_HREF, link(uri));
attrs.put(ATTR_TYPE, TYPE_TEXT_CSS);
attrs.put(ATTR_REL, REL_STYLESHEET);
View
158 ...on.opencms.weboptimization/src/com/alkacon/opencms/weboptimization/CmsOptimizationJs.java
@@ -1,7 +1,7 @@
/*
* File : $Source: /alkacon/cvs/alkacon/com.alkacon.opencms.weboptimization/src/com/alkacon/opencms/weboptimization/CmsOptimizationJs.java,v $
- * Date : $Date: 2009/09/11 07:39:52 $
- * Version: $Revision: 1.2 $
+ * Date : $Date: 2010/01/08 09:46:05 $
+ * Version: $Revision: 1.3 $
*
* This file is part of the Alkacon OpenCms Add-On Module Package
*
@@ -36,7 +36,6 @@
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.main.CmsIllegalArgumentException;
-import org.opencms.main.CmsLog;
import org.opencms.xml.CmsXmlUtils;
import org.opencms.xml.content.CmsXmlContent;
import org.opencms.xml.content.CmsXmlContentFactory;
@@ -48,7 +47,6 @@
import java.io.StringReader;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -56,8 +54,6 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
-import org.apache.commons.logging.Log;
-
import com.yahoo.platform.yui.compressor.JavaScriptCompressor;
/**
@@ -65,14 +61,14 @@
*
* @author Michael Moossen
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*
* @since 7.0.6
*/
public class CmsOptimizationJs extends CmsOptimizationBean {
- /** src attribute constant. */
- protected static final String ATTR_SRC = "src";
+ /** src attribute constant. */
+ protected static final String ATTR_SRC = "src";
/** type attribute constant. */
protected static final String ATTR_TYPE = "type";
@@ -98,11 +94,8 @@
/** text/javascript type constant. */
protected static final String TYPE_TEXT_JS = "text/javascript";
- /** The log object for this class. */
- private static final Log LOG = CmsLog.getLog(CmsOptimizationJs.class);
-
/**
- * Default constructor.
+ * Default constructor.<p>
*
* @param context the JSP page context object
* @param req the JSP request
@@ -113,99 +106,41 @@ public CmsOptimizationJs(PageContext context, HttpServletRequest req, HttpServle
super(context, req, res);
}
- /**
- * Include the given optimized file, will include the original
- * files in the offline project for debugging purposes.<p>
- *
- * @param path the uri of the file to be included
- *
- * @throws Exception if something goes wrong
- */
- public void includeDefault(String path) throws Exception {
-
- if (getCmsObject().getRequestContext().currentProject().isOnlineProject()) {
- includeOptimized(path);
- } else {
- includeOriginal(path);
- }
- }
-
- /**
- * Will include the optimized file.<p>
- *
- * @param path the optimized file uri
- *
- * @throws Exception if something goes wrong
- */
- public void includeOptimized(String path) throws Exception {
-
- CmsObject cms = getCmsObject();
- // check the resource type
- CmsResource res = cms.readResource(path);
- if (res.getTypeId() != RESOURCE_TYPE_JS) {
- throw new CmsIllegalArgumentException(Messages.get().container(
- Messages.ERR_NOT_SUPPORTED_RESOURCE_TYPE_2,
- path,
- new Integer(res.getTypeId())));
- }
- writeScriptInclude(cms, path);
- }
-
- /**
- * Will include the original files.<p>
- *
- * @param path the optimized file uri
- *
- * @throws Exception if something goes wrong
- */
- public void includeOriginal(String path) throws Exception {
-
- CmsObject cms = getCmsObject();
- CmsFile file = cms.readFile(path);
-
- // check the resource type
- if (file.getTypeId() != RESOURCE_TYPE_JS) {
- throw new CmsIllegalArgumentException(Messages.get().container(
- Messages.ERR_NOT_SUPPORTED_RESOURCE_TYPE_2,
- path,
- new Integer(file.getTypeId())));
- }
-
- // read the XML content
- CmsXmlContent xml = CmsXmlContentFactory.unmarshal(cms, file);
-
- // resolve the locale
- Locale locale = resolveLocale(cms, xml);
-
- // iterate the resources
- Iterator itPath = xml.getValues(N_RESOURCE, locale).iterator();
- while (itPath.hasNext()) {
- I_CmsXmlContentValue value = (I_CmsXmlContentValue)itPath.next();
- // get the uri
- String xpath = CmsXmlUtils.concatXpath(value.getPath(), N_PATH);
- String uri = xml.getValue(xpath, locale).getStringValue(cms);
-
- // retrieve the actual files to process
- List resorces = resolveResource(cms, uri, EXT_JS);
- if (resorces.isEmpty()) {
- LOG.warn(Messages.get().getBundle().key(Messages.LOG_WARN_NOTHING_TO_PROCESS_1, uri));
- continue;
- }
-
- Iterator itRes = resorces.iterator();
- while (itRes.hasNext()) {
- CmsResource res = (CmsResource)itRes.next();
- String resPath = cms.getSitePath(res);
- if (res.getTypeId() == RESOURCE_TYPE_JS) {
- // recurse in case of nested optimized resources
- includeOriginal(resPath);
- } else {
- // handle this resource
- writeScriptInclude(cms, resPath);
- }
- }
- }
- }
+ /**
+ * @see com.alkacon.opencms.weboptimization.CmsOptimizationBean#includeDefault(java.lang.String,
+ * com.alkacon.opencms.weboptimization.CmsOptimizationBean.IncludeMode)
+ */
+ @Override
+ public void includeDefault(String path, IncludeMode mode) throws Exception {
+
+ CmsObject cms = getCmsObject();
+ // check the resource type
+ CmsFile file = cms.readFile(path);
+ if (file.getTypeId() != RESOURCE_TYPE_JS) {
+ throw new CmsIllegalArgumentException(Messages.get().container(
+ Messages.ERR_NOT_SUPPORTED_RESOURCE_TYPE_2, path,
+ new Integer(file.getTypeId())));
+ }
+ if (mode == IncludeMode.OPTIMIZED) {
+ // if we are forcing optimization
+ // handle this resource
+ writeScriptInclude(cms, path);
+ return;
+ }
+
+ Resolution resolution = resolveInclude(cms, file, mode, EXT_JS, RESOURCE_TYPE_JS);
+ if (resolution.hasOptimizedLeft()) {
+ // handle this resource
+ writeScriptInclude(cms, path);
+ }
+ Iterator<CmsResource> itRes = resolution.getResources().iterator();
+ while (itRes.hasNext()) {
+ CmsResource res = itRes.next();
+ String resPath = cms.getSitePath(res);
+ // handle this resource
+ writeScriptInclude(cms, resPath);
+ }
+ }
/**
* Will optimize the resources taken from the underlying XML content.<p>
@@ -230,11 +165,16 @@ public void optimize() throws Exception {
// resolve the locale
Locale locale = resolveLocale(cms, xml);
+ // cache the current project
+ boolean online = cms.getRequestContext().currentProject().isOnlineProject();
// iterate the resources
- Iterator itRes = xml.getValues(N_RESOURCE, locale).iterator();
+ Iterator<I_CmsXmlContentValue> itRes = xml.getValues(N_RESOURCE, locale).iterator();
while (itRes.hasNext()) {
- I_CmsXmlContentValue value = (I_CmsXmlContentValue)itRes.next();
+ I_CmsXmlContentValue value = itRes.next();
+ if (!isOptimized(cms, xml, value, locale, online)) {
+ continue;
+ }
// get the path
String xpath = CmsXmlUtils.concatXpath(value.getPath(), N_PATH);
String path = xml.getValue(xpath, locale).getStringValue(cms);
@@ -300,7 +240,7 @@ public void optimizeJs(String jsCode, CmsOptimizationJsOptions options) throws E
*/
public void writeScriptInclude(CmsObject cms, String uri) throws IOException {
- Map attrs = new HashMap();
+ Map<String,String> attrs = new HashMap<String, String>();
attrs.put(ATTR_SRC, link(uri));
attrs.put(ATTR_TYPE, TYPE_TEXT_JS);
getJspContext().getOut().println(createTag(TAG_SCRIPT, attrs, false));
View
160 ...pencms.weboptimization/src/com/alkacon/opencms/weboptimization/CmsOptimizationSprite.java
@@ -1,7 +1,7 @@
/*
* File : $Source: /alkacon/cvs/alkacon/com.alkacon.opencms.weboptimization/src/com/alkacon/opencms/weboptimization/CmsOptimizationSprite.java,v $
- * Date : $Date: 2009/09/11 07:39:52 $
- * Version: $Revision: 1.2 $
+ * Date : $Date: 2010/01/08 09:46:05 $
+ * Version: $Revision: 1.3 $
*
* This file is part of the Alkacon OpenCms Add-On Module Package
*
@@ -64,7 +64,7 @@
*
* @author Michael Moossen
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*
* @since 7.0.6
*/
@@ -141,46 +141,23 @@ public BufferedImage addImage(BufferedImage sprite, BufferedImage image, CmsOpti
}
/**
- * Create css rules for the given optimized sprite,
- * will create css rules for the original images
- * in the offline project for debugging purposes.<p>
- *
- * @param path the uri of the file to be included
- *
- * @throws Exception if something goes wrong
- */
- public void includeDefault(String path) throws Exception {
-
- if (getCmsObject().getRequestContext().currentProject().isOnlineProject()) {
- includeOptimized(path);
- } else {
- includeOriginal(path);
- }
- }
-
- /**
- * Will create css rules for the optimized sprite.<p>
- *
- * @param path the optimized sprite uri
- *
- * @throws Exception if something goes wrong
- */
- public void includeOptimized(String path) throws Exception {
-
- includeSprite(path, true, null);
- }
-
- /**
- * Will create css rules for the original images.<p>
- *
- * @param path the optimized sprite uri
- *
- * @throws Exception if something goes wrong
- */
- public void includeOriginal(String path) throws Exception {
-
- includeSprite(path, false, null);
- }
+ * @see com.alkacon.opencms.weboptimization.CmsOptimizationBean#includeDefault(java.lang.String,
+ * com.alkacon.opencms.weboptimization.CmsOptimizationBean.IncludeMode)
+ */
+ @Override
+ public void includeDefault(String path, IncludeMode mode) throws Exception {
+
+ CmsObject cms = getCmsObject();
+ // check the resource type
+ CmsFile file = cms.readFile(path);
+ if (file.getTypeId() != RESOURCE_TYPE_SPRITE) {
+ throw new CmsIllegalArgumentException(Messages.get().container(
+ Messages.ERR_NOT_SUPPORTED_RESOURCE_TYPE_2, path,
+ new Integer(file.getTypeId())));
+ }
+
+ resolveSpriteInclude(cms, file, mode, null);
+ }
/**
* Will optimize the resources taken from the underlying XML content.<p>
@@ -206,12 +183,17 @@ public void optimize() throws Exception {
// resolve the locale
Locale locale = resolveLocale(cms, xml);
+ // cache the current project
+ boolean online = cms.getRequestContext().currentProject().isOnlineProject();
BufferedImage sprite = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
// iterate the resources
- Iterator itPath = xml.getValues(N_RESOURCE, locale).iterator();
+ Iterator<I_CmsXmlContentValue> itPath = xml.getValues(N_RESOURCE, locale).iterator();
while (itPath.hasNext()) {
- I_CmsXmlContentValue value = (I_CmsXmlContentValue)itPath.next();
+ I_CmsXmlContentValue value = itPath.next();
+ if (!isOptimized(cms, xml, value, locale, online)) {
+ continue;
+ }
// get the path
String xpath = CmsXmlUtils.concatXpath(value.getPath(), N_PATH);
String path = xml.getValue(xpath, locale).getStringValue(cms);
@@ -242,55 +224,18 @@ public void optimize() throws Exception {
writeImage(sprite, type);
}
- /**
- * Writes a new css sprite rule for the given resource.<p>
- *
- * @param uri the resource to use
- * @param opts the options to use
- *
- * @throws IOException if something goes wrong
- */
- public void writeSpriteInclude(String uri, CmsOptimizationSpriteOptions opts) throws IOException {
-
- StringBuffer sb = new StringBuffer();
-
- sb.append(opts.getSelector());
- sb.append(" { background-image: url(");
- sb.append(link(uri));
- sb.append(");");
- if ((opts.getX() != 0) || (opts.getY() != 0)) {
- sb.append(" background-position: ");
- sb.append(-opts.getX());
- sb.append("px ");
- sb.append(-opts.getY());
- sb.append("px;");
- }
- sb.append(" }");
-
- getJspContext().getOut().println(sb.toString());
- }
-
- /**
+ /**
* Will create css rules for the given optimized sprite.<p>
*
* @param path the optimized file uri
- * @param optimized if to write the rules for the optimized image or the originals
+ * @param mode the inclusion mode
* @param offset optional position offset, used when called recursively
*
* @throws Exception if something goes wrong
*/
- protected void includeSprite(String path, boolean optimized, CmsOptimizationSpriteOptions offset) throws Exception {
+ protected void resolveSpriteInclude(CmsObject cms, CmsFile file, IncludeMode mode, CmsOptimizationSpriteOptions offset) throws Exception {
- CmsObject cms = getCmsObject();
- CmsFile file = cms.readFile(path);
-
- // check the resource type
- if (file.getTypeId() != RESOURCE_TYPE_SPRITE) {
- throw new CmsIllegalArgumentException(Messages.get().container(
- Messages.ERR_NOT_SUPPORTED_RESOURCE_TYPE_2,
- path,
- new Integer(file.getTypeId())));
- }
+ String path = cms.getSitePath(file);
// read the XML content
CmsXmlContent xml = CmsXmlContentFactory.unmarshal(cms, file);
@@ -298,10 +243,13 @@ protected void includeSprite(String path, boolean optimized, CmsOptimizationSpri
// resolve the locale
Locale locale = resolveLocale(cms, xml);
+ // cache the current project
+ boolean online = cms.getRequestContext().currentProject().isOnlineProject();
+
// iterate the resources
- Iterator itRes = xml.getValues(N_RESOURCE, locale).iterator();
+ Iterator<I_CmsXmlContentValue> itRes = xml.getValues(N_RESOURCE, locale).iterator();
while (itRes.hasNext()) {
- I_CmsXmlContentValue value = (I_CmsXmlContentValue)itRes.next();
+ I_CmsXmlContentValue value = itRes.next();
// get the uri
String xpath = CmsXmlUtils.concatXpath(value.getPath(), N_PATH);
String uri = xml.getValue(xpath, locale).getStringValue(cms);
@@ -313,6 +261,12 @@ protected void includeSprite(String path, boolean optimized, CmsOptimizationSpri
continue;
}
+ boolean optimized = (mode == IncludeMode.OPTIMIZED);
+ if (mode == IncludeMode.AUTO) {
+ // compute the mode to use
+ optimized = isOptimized(cms, xml, value, locale, online);
+ }
+
// get the options
CmsOptimizationSpriteOptions opts = new CmsOptimizationSpriteOptions();
xpath = CmsXmlUtils.concatXpath(value.getPath(), N_POSITION);
@@ -333,7 +287,7 @@ protected void includeSprite(String path, boolean optimized, CmsOptimizationSpri
}
if (res.getTypeId() == RESOURCE_TYPE_SPRITE) {
// recurse in case of nested sprites
- includeSprite(uri, optimized, opts);
+ resolveSpriteInclude(cms, cms.readFile(res), mode, opts);
} else {
// handle this resource
if (optimized) {
@@ -367,4 +321,32 @@ protected void writeImage(BufferedImage image, String type) throws IOException {
stream.close();
writer.dispose();
}
+
+ /**
+ * Writes a new css sprite rule for the given resource.<p>
+ *
+ * @param uri the resource to use
+ * @param opts the options to use
+ *
+ * @throws IOException if something goes wrong
+ */
+ public void writeSpriteInclude(String uri, CmsOptimizationSpriteOptions opts) throws IOException {
+
+ StringBuffer sb = new StringBuffer();
+
+ sb.append(opts.getSelector());
+ sb.append(" { background-image: url(");
+ sb.append(link(uri));
+ sb.append(");");
+ if ((opts.getX() != 0) || (opts.getY() != 0)) {
+ sb.append(" background-position: ");
+ sb.append(-opts.getX());
+ sb.append("px ");
+ sb.append(-opts.getY());
+ sb.append("px;");
+ }
+ sb.append(" }");
+
+ getJspContext().getOut().println(sb.toString());
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.