sitemesh
  1. sitemesh
  2. SITEMESH-3

Resolve DTDs from inside the Sitemesh JAR

    Details

    • Type: Task Task
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      3

      Description

      If you include the DOCTYPE header in the decorators.xml on a server without an
      outbound internet connection, the startup will fail as the XML parser will try
      to load the DTD from the Internet.

      The patch includes an entity resolver, modifies files that are required to use
      it, puts the DTDs in the source path for inclusion in the JAR, and modifies the
      build file to include the DTDs in the JAR. A basic test included to demonstrate
      the functionality (but is not clean or robust enough for inclusion in the Unit
      tests).

      PS - Sitemesh is great. Is it very active still?

      Index: build.xml
      ===================================================================
      RCS file: /cvs/sitemesh/build.xml,v
      retrieving revision 1.43
      diff -u -r1.43 build.xml
      — build.xml 2 Aug 2005 23:50:48 -0000 1.43
      +++ build.xml 3 Jun 2006 03:56:32 -0000
      @@ -44,12 +44,22 @@
      <src path="src/java"/>
      <src path="build/java"/>
      </javac>
      + <copy todir="build/classes">
      + <fileset dir="src/java">
      + <include name="*/.dtd"/>
      + </fileset>
      + </copy>
      </target>

      <target name="test" depends="compile" description="Run all unit tests">
      <mkdir dir="build/test-classes"/>
      <mkdir dir="build/test-results"/>
      <javac srcdir="src/test" destdir="build/test-classes" classpathref="cp"
      classpath="build/classes"/>
      + <copy todir="build/test-classes">
      + <fileset dir="src/test">
      + <include name="*/.xml"/>
      + </fileset>
      + </copy>
      <taskdef name="junit"
      classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
      classpathref="cp"/>
      <echo message="Running unit tests..."/>
      <junit printsummary="no" haltonfailure="yes" fork="yes" forkmode="once"
      dir=".">
      Index: src/java/com/opensymphony/module/sitemesh/SitemeshEntityResolver.java
      ===================================================================
      RCS file: src/java/com/opensymphony/module/sitemesh/SitemeshEntityResolver.java
      diff -N src/java/com/opensymphony/module/sitemesh/SitemeshEntityResolver.java
      — /dev/null 1 Jan 1970 00:00:00 -0000
      +++ src/java/com/opensymphony/module/sitemesh/SitemeshEntityResolver.java 1 Jan
      1970 00:00:00 -0000
      @@ -0,0 +1,28 @@
      +package com.opensymphony.module.sitemesh;
      +
      +import java.io.InputStream;
      +
      +import org.xml.sax.EntityResolver;
      +import org.xml.sax.InputSource;
      +
      +public class SitemeshEntityResolver implements EntityResolver {
      + private static final String DOCTYPE_URL =
      "http://www.opensymphony.com/sitemesh/dtd/";
      + private static final String DTD_CLASSPATH_ROOT =
      "/com/opensymphony/module/sitemesh/";
      +
      + public InputSource resolveEntity(String publicId, String systemId) {
      + if (systemId != null && systemId.startsWith(DOCTYPE_URL)) {
      + String dtdFile = systemId.substring(DOCTYPE_URL.length());
      + // Search for DTD
      + String resource = DTD_CLASSPATH_ROOT + dtdFile;
      + InputStream is = getClass().getResourceAsStream(resource);
      + if (is != null)

      { + InputSource source = new InputSource(is); + source.setPublicId(publicId); + source.setSystemId(systemId); + return source; + }

      + }
      + //Use default behavior
      + return null;
      + }
      +}
      Index: src/java/com/opensymphony/module/sitemesh/sitemesh_1_0_decorators.dtd
      ===================================================================
      RCS file: src/java/com/opensymphony/module/sitemesh/sitemesh_1_0_decorators.dtd
      diff -N src/java/com/opensymphony/module/sitemesh/sitemesh_1_0_decorators.dtd
      — /dev/null 1 Jan 1970 00:00:00 -0000
      +++ src/java/com/opensymphony/module/sitemesh/sitemesh_1_0_decorators.dtd 1 Jan
      1970 00:00:00 -0000
      @@ -0,0 +1,53 @@
      +<?xml version="1.0" encoding="UTF-8"?>
      +<!--
      +DTD Version: 1.0
      +
      +This is the DTD for the SiteMesh 1.0 decorator.xml file.
      +
      +It's style and order are based on the web.xml DTD file
      +listed in the Servlet 2.3 specification. This means that
      +the declaration of decorators and mappings follows the same
      +format as servlets / servlet mappings or filters / filter
      +mappings.
      +
      +Valid decorator.xml files must contain the following DOCTYPE
      +declaration
      +
      +<!DOCTYPE decorators PUBLIC "-//OpenSymphony//SiteMesh 1.0 Decorators//EN"
      "http://www.opensymphony.com/sitemesh/dtd/sitemesh_1_0_decorators.dtd">
      +-->
      +
      +<!--
      +The decorators element is the root element of the file.
      +It contains decorator and decorator mapping elements.
      +-->
      +<!ELEMENT decorators (decorator*, decorator-mapping*)>
      +
      +<!--
      +The decorator element contains the declarative data of a
      +decorator.
      +-->
      +<!ELEMENT decorator (decorator-name, jsp-file)>
      +
      +<!--
      +The decorator-name element contains the canonical name
      +of the decorator
      +-->
      +<!ELEMENT decorator-name (#PCDATA)>
      +
      +<!--
      +The jsp-file element contains the full path to a JSP file
      +within the web application.
      +-->
      +<!ELEMENT jsp-file (#PCDATA)>
      +
      +<!--
      +The decorator-mapping element defines a mapping between a
      +decorator and a url pattern
      +-->
      +<!ELEMENT decorator-mapping (decorator-name, url-pattern*)>
      +
      +<!--
      +The url-pattern element contains the url pattern of the
      +mapping.
      +-->
      +<!ELEMENT url-pattern (#PCDATA)>
      Index: src/java/com/opensymphony/module/sitemesh/sitemesh_1_5_decorators.dtd
      ===================================================================
      RCS file: src/java/com/opensymphony/module/sitemesh/sitemesh_1_5_decorators.dtd
      diff -N src/java/com/opensymphony/module/sitemesh/sitemesh_1_5_decorators.dtd
      — /dev/null 1 Jan 1970 00:00:00 -0000
      +++ src/java/com/opensymphony/module/sitemesh/sitemesh_1_5_decorators.dtd 1 Jan
      1970 00:00:00 -0000
      @@ -0,0 +1,48 @@
      +<?xml version="1.0" encoding="UTF-8"?>
      +<!--
      +DTD Version: 1.5
      +
      +This is the DTD for the SiteMesh 1.5 decorator.xml file.
      +
      +It's style and order are based on the web.xml DTD file
      +listed in the Servlet 2.3 specification. This means that
      +the declaration of decorators and mappings follows the same
      +format as servlets / servlet mappings or filters / filter
      +mappings.
      +
      +Valid decorator.xml files must contain the following DOCTYPE
      +declaration
      +
      +<!DOCTYPE decorators PUBLIC "-//OpenSymphony//SiteMesh 1.5 Decorators//EN"
      "http://www.opensymphony.com/sitemesh/dtd/sitemesh_1_5_decorators.dtd">
      +-->
      +
      +<!--
      +The decorators element is the root element of the file.
      +It contains decorator and decorator mapping elements.
      +-->
      <!ELEMENT decorators (excludes?, decorator)>
      +<!ATTLIST decorators
      + defaultdir CDATA #IMPLIED
      +>
      +
      +<!--
      +A list of patterns to exclude
      +-->
      +<!ELEMENT excludes (pattern*)>
      +
      +<!--
      +The decorator element contains the declarative data of a
      +decorator.
      +-->
      +<!ELEMENT decorator (pattern*)>
      +<!ATTLIST decorator
      + name CDATA #REQUIRED
      + page CDATA #IMPLIED
      + webapp CDATA #IMPLIED
      +>
      +
      +<!--
      +The url-pattern element contains the url pattern of the
      +mapping.
      +-->
      +<!ELEMENT pattern (#PCDATA)>
      Index: src/test/com/opensymphony/module/sitemesh/SitemeshEntityResolverTest.java
      ===================================================================
      RCS file: src/test/com/opensymphony/module/sitemesh/SitemeshEntityResolverTest.java
      diff -N src/test/com/opensymphony/module/sitemesh/SitemeshEntityResolverTest.java
      — /dev/null 1 Jan 1970 00:00:00 -0000
      +++ src/test/com/opensymphony/module/sitemesh/SitemeshEntityResolverTest.java 1
      Jan 1970 00:00:00 -0000
      @@ -0,0 +1,26 @@
      +package com.opensymphony.module.sitemesh;
      +
      +import java.io.InputStream;
      +import java.net.URL;
      +
      +import javax.xml.parsers.DocumentBuilder;
      +import javax.xml.parsers.DocumentBuilderFactory;
      +
      +import junit.framework.TestCase;
      +
      +import org.w3c.dom.Document;
      +
      +public class SitemeshEntityResolverTest extends TestCase {
      + public void testParse() throws Exception

      { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setEntityResolver(new SitemeshEntityResolver()); + + URL url = this.getClass().getClassLoader().getResource("com/opensymphony/module/sitemesh/decorators-1.5.xml"); + InputStream is = url.openStream(); + assertNotNull(is); + Document document = builder.parse(is); + assertNotNull(document); + is.close(); + }

      +}
      Index: src/test/com/opensymphony/module/sitemesh/decorators-1.0.xml
      ===================================================================
      RCS file: src/test/com/opensymphony/module/sitemesh/decorators-1.0.xml
      diff -N src/test/com/opensymphony/module/sitemesh/decorators-1.0.xml
      — /dev/null 1 Jan 1970 00:00:00 -0000
      +++ src/test/com/opensymphony/module/sitemesh/decorators-1.0.xml 1 Jan 1970
      00:00:00 -0000
      @@ -0,0 +1,15 @@
      +<?xml version="1.0" encoding="ISO-8859-1"?>
      +<!DOCTYPE decorators PUBLIC "-//OpenSymphony//SiteMesh 1.0 Decorators//EN"
      "http://www.opensymphony.com/sitemesh/dtd/sitemesh_1_0_decorators.dtd">
      +
      +<decorators>
      + <decorator>
      + <decorator-name>decorator-name</decorator-name>
      + <jsp-file>jsp-file</jsp-file>
      +
      + </decorator>
      +
      + <decorator-mapping>
      + <decorator-name>decorator-name</decorator-name>
      + <url-pattern>url-pattern</url-pattern>
      + </decorator-mapping>
      +</decorators>
      Index: src/test/com/opensymphony/module/sitemesh/decorators-1.5.xml
      ===================================================================
      RCS file: src/test/com/opensymphony/module/sitemesh/decorators-1.5.xml
      diff -N src/test/com/opensymphony/module/sitemesh/decorators-1.5.xml
      — /dev/null 1 Jan 1970 00:00:00 -0000
      +++ src/test/com/opensymphony/module/sitemesh/decorators-1.5.xml 1 Jan 1970
      00:00:00 -0000
      @@ -0,0 +1,32 @@
      +<?xml version="1.0" encoding="ISO-8859-1"?>
      +<!DOCTYPE decorators PUBLIC "-//OpenSymphony//SiteMesh 1.5 Decorators//EN"
      "http://www.opensymphony.com/sitemesh/dtd/sitemesh_1_5_decorators.dtd">
      +
      +<decorators defaultdir="/decorators">
      + <!-- Any urls that are excluded will never be decorated by Sitemesh -->
      + <excludes>
      + <pattern>/exclude.jsp</pattern>
      + <pattern>/exclude/*</pattern>
      + </excludes>
      +
      + <decorator name="main" page="main.jsp">
      + <pattern>/*</pattern>
      + </decorator>
      +
      + <decorator name="panel" page="panel.jsp"/>
      + <decorator name="printable" page="printable.jsp"/>
      + <decorator name="black" page="black.jsp"/>
      + <decorator name="nopanelsource" page="nopanelsource.jsp"/>
      + <decorator name="badpanelsource" page="badpanelsource.jsp"/>
      +
      + <decorator name="velocity" page="velocity.vm">
      + <pattern>/velocity.html</pattern>
      + </decorator>
      +
      + <decorator name="freemarker" page="freemarker.ftl">
      + <pattern>/freemarker.html</pattern>
      + </decorator>
      +
      + <decorator name="test" page="test.jsp">
      + <pattern>/agent.jsp</pattern>
      + </decorator>
      +</decorators>

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            sitemesh-issues
            Reporter:
            katentim
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: