[jboss-svn-commits] JBoss Common SVN: r2799 - in common-core/trunk: src/main/java/org/jboss/util/xml and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Apr 6 01:06:29 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-04-06 01:06:28 -0400 (Sun, 06 Apr 2008)
New Revision: 2799
Added:
common-core/trunk/src/test/resources/tst-config_5.xsd
Modified:
common-core/trunk/.classpath
common-core/trunk/pom.xml
common-core/trunk/src/main/java/org/jboss/util/xml/JBossEntityResolver.java
common-core/trunk/src/test/java/org/jboss/test/util/test/xml/resolver/JBossEntityResolverUnitTestCase.java
Log:
JBCOMMON-48, add support for system property replacement in systemIds resolved as URLs.
Modified: common-core/trunk/.classpath
===================================================================
--- common-core/trunk/.classpath 2008-04-05 23:18:31 UTC (rev 2798)
+++ common-core/trunk/.classpath 2008-04-06 05:06:28 UTC (rev 2799)
@@ -3,10 +3,10 @@
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
- <classpathentry kind="src" path="/common-logging-spi"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="M2_REPO/apache-httpclient/commons-httpclient/2.0.2/commons-httpclient-2.0.2.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar" sourcepath="M2_REPO/junit/junit/4.4/junit-4.4-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/apache-slide/webdavlib/2.0/webdavlib-2.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-logging-spi/2.0.5.GA/jboss-common-logging-spi-2.0.5.GA.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Modified: common-core/trunk/pom.xml
===================================================================
--- common-core/trunk/pom.xml 2008-04-05 23:18:31 UTC (rev 2798)
+++ common-core/trunk/pom.xml 2008-04-06 05:06:28 UTC (rev 2799)
@@ -75,7 +75,7 @@
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-common-logging-spi</artifactId>
- <version>2.0.5-SNAPSHOT</version>
+ <version>2.0.5.GA</version>
<scope>compile</scope>
</dependency>
@@ -88,4 +88,4 @@
</dependencies>
-</project>
\ No newline at end of file
+</project>
Modified: common-core/trunk/src/main/java/org/jboss/util/xml/JBossEntityResolver.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/xml/JBossEntityResolver.java 2008-04-05 23:18:31 UTC (rev 2798)
+++ common-core/trunk/src/main/java/org/jboss/util/xml/JBossEntityResolver.java 2008-04-06 05:06:28 UTC (rev 2799)
@@ -34,6 +34,7 @@
import java.util.concurrent.ConcurrentHashMap;
import org.jboss.logging.Logger;
+import org.jboss.util.StringPropertyReplacer;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -63,6 +64,9 @@
private static boolean warnOnNonFileURLs;
private boolean entityResolved = false;
+ /** Should system property refs in system ids be replaced */
+ private boolean replaceSystemProperties = true;
+
/** A local entities map that overrides the class level entities */
private Map localEntities;
@@ -206,6 +210,16 @@
entities.put(id, dtdFileName);
}
+
+ public boolean isReplaceSystemProperties()
+ {
+ return replaceSystemProperties;
+ }
+ public void setReplaceSystemProperties(boolean replaceSystemProperties)
+ {
+ this.replaceSystemProperties = replaceSystemProperties;
+ }
+
/**
* Register the mapping from the public id/system id to the dtd/xsd file
* name. This overwrites any existing mapping.
@@ -443,7 +457,9 @@
{
if (trace)
log.trace("Trying to resolve systemId as a URL");
-
+ // Replace any system property refs if isReplaceSystemProperties is true
+ if(isReplaceSystemProperties())
+ systemId = StringPropertyReplacer.replaceProperties(systemId);
URL url = new URL(systemId);
if (warnOnNonFileURLs && url.getProtocol().equalsIgnoreCase("file") == false)
{
Modified: common-core/trunk/src/test/java/org/jboss/test/util/test/xml/resolver/JBossEntityResolverUnitTestCase.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/xml/resolver/JBossEntityResolverUnitTestCase.java 2008-04-05 23:18:31 UTC (rev 2798)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/xml/resolver/JBossEntityResolverUnitTestCase.java 2008-04-06 05:06:28 UTC (rev 2799)
@@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import org.jboss.util.xml.JBossEntityResolver;
import org.xml.sax.InputSource;
@@ -80,6 +81,22 @@
assertEquals("Schema sizes: redefined=" + redefinedSize + ", redefining=" + redefiningSize, redefinedSize, resolvedSize);
}
+ public void testSystemPropertyInSystemID()
+ throws Exception
+ {
+ JBossEntityResolver resolver = new JBossEntityResolver();
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ URL tstConfig = loader.getResource("tst-config_5.xsd");
+ assertNotNull(tstConfig);
+ System.setProperty("tst.config_5.xsd", tstConfig.toExternalForm());
+ InputSource resolvedSource = resolver.resolveEntity("urn:jboss:xml:test", "${tst.config_5.xsd}");
+ assertNotNull(resolvedSource);
+ InputStream resolvedStream = resolvedSource.getByteStream();
+ assertNotNull(resolvedStream);
+ int resolvedSize = bytesTotal(resolvedStream);
+ assertEquals(280, resolvedSize);
+ }
+
private int bytesTotal(InputStream redefinedStream) throws IOException
{
byte[] bytes = new byte[1024];
Added: common-core/trunk/src/test/resources/tst-config_5.xsd
===================================================================
--- common-core/trunk/src/test/resources/tst-config_5.xsd (rev 0)
+++ common-core/trunk/src/test/resources/tst-config_5.xsd 2008-04-06 05:06:28 UTC (rev 2799)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="urn:jboss:xml:test"
+ xmlns="urn:jboss:xml:test"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ version="1.0"
+ >
+</xsd:schema>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list