Commits

Anonymous committed 30500c3

Added: appfuse:wro tag for resource fingerprinting

Comments (0)

Files changed (5)

                 <filtering>true</filtering>
             </resource>
             <resource>
+                <directory>src/main/wro-target</directory>
+                <includes>
+                    <include>wromapping.properties</include>
+                </includes>
+            </resource>
+            <resource>
                 <directory>target/resources</directory>
                 <filtering>true</filtering>
             </resource>

src/main/java/es/jogaco/webapp/taglib/WroResourceTag.java

+package es.jogaco.webapp.taglib;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+
+
+/**
+ * Tag for customized internal links.
+ */
+public class WroResourceTag extends TagSupport {
+    private static Properties wroMapping;
+    private String resource;
+    private String path;
+
+    public void setResource(String resource) {
+        this.resource = resource;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    /**
+     * Process the start of this tag.
+     *
+     * @return int status
+     * @exception JspException if a JSP exception has occurred
+     * @see javax.servlet.jsp.tagext.Tag#doStartTag()
+     */
+    @Override
+    public int doStartTag() throws JspException {
+        String ctx = pageContext.getServletContext().getContextPath();
+        StringBuilder sb = new StringBuilder(ctx);
+        sb.append(path);
+        if (!path.endsWith("/")) {
+            sb.append('/');
+        }
+        try {
+            sb.append(getWroMapping().getProperty(resource, resource));
+            pageContext.getOut().write(sb.toString());
+        } catch (IOException io) {
+            throw new JspException(io);
+        }
+        return super.doStartTag();
+    }
+
+    private Properties getWroMapping() throws IOException {
+        if (wroMapping == null) {
+            wroMapping = new Properties();
+            String wroMappingFile = "wromapping.properties";
+            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(wroMappingFile);
+            if (inputStream == null) {
+                throw new FileNotFoundException("property file '" + wroMappingFile
+                        + "' not found in the classpath");
+            }
+            wroMapping.load(inputStream);
+        }
+        return wroMapping;
+    }
+}

src/main/webapp/WEB-INF/appfuse.tld

             <rtexprvalue>true</rtexprvalue>
         </attribute>
     </tag>
+    <tag>
+        <name>wro</name>
+        <tag-class>es.jogaco.webapp.taglib.WroResourceTag</tag-class>
+        <attribute>
+            <name>path</name>
+            <required>true</required>
+            <rtexprvalue>true</rtexprvalue>
+        </attribute>
+        <attribute>
+            <name>resource</name>
+            <required>true</required>
+            <rtexprvalue>true</rtexprvalue>
+        </attribute>
+    </tag>
 </taglib>

src/main/webapp/decorators/default.jsp

         <link rel="icon" href="<c:url value="/images/favicon.ico"/>"/>
         <title><decorator:title/> | <fmt:message key="webapp.name"/></title>
 
-        <link rel="stylesheet" type="text/css" media="all" href="<c:url value='/styles/all.css'/>" />
+        <link rel="stylesheet" type="text/css" media="all" href="<appfuse:wro path='/styles' resource='all.css'/>" />
         <decorator:head/>
     </head>
-<script type="text/javascript" src="<c:url value='/scripts/all.js'/>"></script>
-
+<script type="text/javascript" src="<appfuse:wro path='/scripts' resource='all.js'/>"></script>
 
 <body<decorator:getProperty property="body.id" writeEntireProperty="true"/><decorator:getProperty property="body.class" writeEntireProperty="true"/>>
     <c:set var="currentMenu" scope="request"><decorator:getProperty property="meta.menu"/></c:set>
             <div class="container-fluid">
                 <a class="brand" href="<c:url value='/'/>"><fmt:message key="webapp.name"/></a>
                 <%@ include file="/common/menu.jsp"%>
-
                 <c:if test="${pageContext.request.locale.language ne 'en'}">
                     <div id="switchLocale"><a href="<c:url value='/?locale=en'/>">
                         <fmt:message key="webapp.name"/> in English</a>

src/main/wro.properties

 postProcessors=cssVariables,jsMin
 uriLocators=servletContext,uri,classpath
 # Configurable options available since 1.4.7 (not mandatory)
-#hashStrategy=MD5
-#namingStrategy=hashEncoder-CRC32
+hashStrategy=MD5
+namingStrategy=hashEncoder-CRC32