[jboss-svn-commits] JBoss Common SVN: r2743 - in common-core/trunk/src: test and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Mar 17 09:11:43 EDT 2008
Author: alex.loubyansky at jboss.com
Date: 2008-03-17 09:11:43 -0400 (Mon, 17 Mar 2008)
New Revision: 2743
Added:
common-core/trunk/src/test/java/org/jboss/test/util/test/xml/
common-core/trunk/src/test/java/org/jboss/test/util/test/xml/resolver/
common-core/trunk/src/test/java/org/jboss/test/util/test/xml/resolver/JBossEntityResolverUnitTestCase.java
common-core/trunk/src/test/resources/
common-core/trunk/src/test/resources/JBossEntityResolverUnitTestCase_testResolveRedefine_redefined.xsd
common-core/trunk/src/test/resources/JBossEntityResolverUnitTestCase_testResolveRedefine_redefining.xsd
Modified:
common-core/trunk/src/main/java/org/jboss/util/xml/JBossEntityResolver.java
Log:
JBCOMMON-43
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-03-14 12:39:54 UTC (rev 2742)
+++ common-core/trunk/src/main/java/org/jboss/util/xml/JBossEntityResolver.java 2008-03-17 13:11:43 UTC (rev 2743)
@@ -255,9 +255,31 @@
boolean trace = log.isTraceEnabled();
- // Look for a registered publicID
- InputSource inputSource = resolvePublicID(publicId, trace);
-
+ boolean resolvePublicIdFirst = true;
+ if(publicId != null && systemId != null)
+ {
+ String registeredSystemId = (String) localEntities.get(publicId);
+ if(registeredSystemId == null)
+ registeredSystemId = (String) entities.get(publicId);
+
+ if(registeredSystemId != null && !registeredSystemId.equals(systemId))
+ {
+ resolvePublicIdFirst = false;
+ if(trace)
+ log.trace("systemId argument '" + systemId + "' for publicId '" +
+ publicId + "' is different from the registered systemId '" +
+ registeredSystemId + "', resolution will be based on the argument");
+ }
+ }
+
+ InputSource inputSource = null;
+
+ if(resolvePublicIdFirst)
+ {
+ // Look for a registered publicID
+ inputSource = resolvePublicID(publicId, trace);
+ }
+
if( inputSource == null )
{
// Try to resolve the systemID from the registry
Added: 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 (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/xml/resolver/JBossEntityResolverUnitTestCase.java 2008-03-17 13:11:43 UTC (rev 2743)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.test.util.test.xml.resolver;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.jboss.util.xml.JBossEntityResolver;
+import org.xml.sax.InputSource;
+
+import junit.framework.TestCase;
+
+
+/**
+ * A JBossEntityResolverUnitTestCase.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossEntityResolverUnitTestCase
+ extends TestCase
+{
+ public JBossEntityResolverUnitTestCase(String arg0)
+ {
+ super(arg0);
+ }
+
+ /**
+ * The spcial thing about the resolution of xsd:redefine is that
+ * the parser passes the namespace of the redefining schema as publicId
+ * and the schema location of the redefined schema as systemId. Now, if
+ * the redefining schema's namespace has already been mapped
+ * to a schema location of the redefining schema then schema location
+ * argument is ignored and the redefining schema is returned instead of the
+ * redefined schema.
+ *
+ * @throws Exception
+ */
+ public void testResolveRedefine() throws Exception
+ {
+ String baseName = getRootName() + "_" + getName() + "_";
+ String redefiningName = baseName + "redefining.xsd";
+ InputStream redefiningStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(redefiningName);
+ assertNotNull("Expected to find " + redefiningName + " in the classpath", redefiningStream);
+ int redefiningSize = bytesTotal(redefiningStream);
+
+ String redefinedName = baseName + "redefined.xsd";
+ InputStream redefinedStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(redefinedName);
+ assertNotNull("Expected to find " + redefinedName + " in the classpath", redefinedStream);
+ int redefinedSize = bytesTotal(redefinedStream);
+
+ assertTrue(redefiningSize != redefinedSize);
+
+ JBossEntityResolver resolver = new JBossEntityResolver();
+ resolver.registerLocalEntity("urn:jboss:xml:test", redefiningName);
+ InputSource resolvedSource = resolver.resolveEntity("urn:jboss:xml:test", redefinedName);
+ assertNotNull(resolvedSource);
+ InputStream resolvedStream = resolvedSource.getByteStream();
+ assertNotNull(resolvedStream);
+ int resolvedSize = bytesTotal(resolvedStream);
+ assertEquals("Schema sizes: redefined=" + redefinedSize + ", redefining=" + redefiningSize, redefinedSize, resolvedSize);
+ }
+
+ private int bytesTotal(InputStream redefinedStream) throws IOException
+ {
+ byte[] bytes = new byte[1024];
+ int redefinedSize = 0;
+ try
+ {
+ for(int i = 0; (i = redefinedStream.read(bytes)) > 0; redefinedSize += i);
+ }
+ finally
+ {
+ redefinedStream.close();
+ }
+ return redefinedSize;
+ }
+
+ protected String getRootName()
+ {
+ String longName = getClass().getName();
+ int dot = longName.lastIndexOf('.');
+ if (dot != -1)
+ return longName.substring(dot + 1);
+ return longName;
+ }
+}
Added: common-core/trunk/src/test/resources/JBossEntityResolverUnitTestCase_testResolveRedefine_redefined.xsd
===================================================================
--- common-core/trunk/src/test/resources/JBossEntityResolverUnitTestCase_testResolveRedefine_redefined.xsd (rev 0)
+++ common-core/trunk/src/test/resources/JBossEntityResolverUnitTestCase_testResolveRedefine_redefined.xsd 2008-03-17 13:11:43 UTC (rev 2743)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ version="1.0">
+
+ <xsd:simpleType name="classNameType">
+ <xsd:annotation>
+ <xsd:documentation> The elements that use this type designate the name
+ of a Java class or interface. The name is in the form of a "binary
+ name", as defined in the JLS and as used in Class.forName().
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:restriction base="xsd:string">
+ <xsd:whiteSpace value="collapse"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+</xsd:schema>
Added: common-core/trunk/src/test/resources/JBossEntityResolverUnitTestCase_testResolveRedefine_redefining.xsd
===================================================================
--- common-core/trunk/src/test/resources/JBossEntityResolverUnitTestCase_testResolveRedefine_redefining.xsd (rev 0)
+++ common-core/trunk/src/test/resources/JBossEntityResolverUnitTestCase_testResolveRedefine_redefining.xsd 2008-03-17 13:11:43 UTC (rev 2743)
@@ -0,0 +1,19 @@
+<?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:redefine schemaLocation="JBossEntityResolverUnitTestCase_testResolveRedefine_redefined.xsd">
+ <xsd:simpleType name="classNameType">
+ <xsd:restriction base="classNameType">
+ <xsd:maxLength value="40"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:redefine>
+
+</xsd:schema>
More information about the jboss-svn-commits
mailing list