Author: alessio.soldano(a)jboss.com
Date: 2013-03-21 09:55:16 -0400 (Thu, 21 Mar 2013)
New Revision: 544
Added:
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/JBossEntityResolver.java
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/StringPropertyReplacer.java
Modified:
core/trunk/core/pom.xml
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/WiseEntityResolver.java
core/trunk/pom.xml
Log:
[WISE-200] Include JBossEntityResolver from jboss-common and drop the dependency
Modified: core/trunk/core/pom.xml
===================================================================
--- core/trunk/core/pom.xml 2013-03-20 15:30:02 UTC (rev 543)
+++ core/trunk/core/pom.xml 2013-03-21 13:55:16 UTC (rev 544)
@@ -55,11 +55,6 @@
</dependency>
<dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
Added:
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/JBossEntityResolver.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/JBossEntityResolver.java
(rev 0)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/JBossEntityResolver.java 2013-03-21
13:55:16 UTC (rev 544)
@@ -0,0 +1,593 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat, Inc., 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.wise.core.client.impl.wsdlResolver;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * A copy of org.jboss.util.xml.JBossEntityResolver from jboss-common to avoid
+ * depending on it just for the resolver needs.
+ *
+ * Local entity resolver to handle standard J2EE DTDs and Schemas as well as
+ * JBoss specific DTDs.
+ * <p/>
+ * Function boolean isEntityResolved() is here to avoid validation errors in
+ * descriptors that do not have a DOCTYPE declaration.
+ *
+ * @author Scott.Stark(a)jboss.org
+ * @author Thomas.Diesler(a)jboss.org
+ * @author Dimitris.Andreadis(a)jboss.org
+ * @version $Revision$
+ */
+@SuppressWarnings("unchecked")
+public class JBossEntityResolver implements EntityResolver {
+ private static final Logger log = Logger.getLogger(JBossEntityResolver.class);
+
+ /** A class wide Map<String, String> of publicId/systemId to dtd/xsd file */
+ private static Map entities = new ConcurrentHashMap();
+
+ /**
+ * A class flag indicating whether an attempt to resolve a systemID as a
+ * non-file URL should produce a warning rather than a trace level log msg.
+ */
+ 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;
+
+ static {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ warnOnNonFileURLs = new
Boolean(System.getProperty("org.jboss.resolver.warning",
"false")).booleanValue();
+ return null;
+ }
+ });
+
+ // xml
+ registerEntity("-//W3C//DTD/XMLSCHEMA 200102//EN",
"XMLSchema.dtd");
+
registerEntity("http://www.w3.org/2001/XMLSchema.dtd",
"XMLSchema.dtd");
+ registerEntity("datatypes", "datatypes.dtd"); // This dtd
doesn't have a
+ // publicId - see
+ // XMLSchema.dtd
+
registerEntity("http://www.w3.org/XML/1998/namespace", "xml.xsd");
+
registerEntity("http://www.w3.org/2001/xml.xsd", "xml.xsd");
+
registerEntity("http://www.w3.org/2005/05/xmlmime",
"xml-media-types.xsd");
+
+ // Java EE common
+
registerEntity("http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd",
"j2ee_1_4.xsd");
+
registerEntity("http://java.sun.com/xml/ns/javaee/javaee_5.xsd",
"javaee_5.xsd");
+ // JBoss common
+
registerEntity("http://www.jboss.org/j2ee/schema/jboss-common_5_1.xs...;,
"jboss-common_5_1.xsd");
+
+ // Java EE WS
+
registerEntity("http://schemas.xmlsoap.org/soap/encoding/",
"soap-encoding_1_1.xsd");
+
registerEntity("http://www.ibm.com/webservices/xsd/j2ee_web_services...;,
"j2ee_web_services_client_1_1.xsd");
+
registerEntity("http://www.ibm.com/webservices/xsd/j2ee_web_services...;,
"j2ee_web_services_1_1.xsd");
+
registerEntity("http://www.ibm.com/webservices/xsd/j2ee_jaxrpc_mappi...;,
"j2ee_jaxrpc_mapping_1_1.xsd");
+
registerEntity("http://java.sun.com/xml/ns/javaee/javaee_web_service...;,
"javaee_web_services_client_1_2.xsd");
+
+ // ejb
+ registerEntity("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN",
"ejb-jar_1_1.dtd");
+ registerEntity("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN",
"ejb-jar_2_0.dtd");
+
registerEntity("http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd",
"ejb-jar_2_1.xsd");
+ // ejb3
+
registerEntity("http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd",
"ejb-jar_3_0.xsd");
+ // jboss ejb2
+ registerEntity("-//JBoss//DTD JBOSS//EN", "jboss.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 2.4//EN", "jboss_2_4.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 3.0//EN", "jboss_3_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 3.2//EN", "jboss_3_2.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 4.0//EN", "jboss_4_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 4.2//EN", "jboss_4_2.dtd");
+ registerEntity("-//JBoss//DTD JBOSS 5.0//EN", "jboss_5_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN",
"jbosscmp-jdbc_3_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN",
"jbosscmp-jdbc_3_2.dtd");
+ registerEntity("-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN",
"jbosscmp-jdbc_4_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSSCMP-JDBC 4.2//EN",
"jbosscmp-jdbc_4_2.dtd");
+ // jboss ejb3
+
registerEntity("http://www.jboss.org/j2ee/schema/jboss_5_0.xsd",
"jboss_5_0.xsd");
+
registerEntity("http://www.jboss.org/j2ee/schema/jboss_5_1.xsd",
"jboss_5_1.xsd");
+
+ // ear stuff
+ registerEntity("-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN",
"application_1_2.dtd");
+ registerEntity("-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN",
"application_1_3.dtd");
+ registerEntity("-//Sun Microsystems, Inc.//DTD J2EE Application Client
1.3//EN", "application-client_1_3.dtd");
+
registerEntity("http://java.sun.com/xml/ns/j2ee/application_1_4.xsd&...;,
"application_1_4.xsd");
+
registerEntity("http://java.sun.com/xml/ns/javaee/application_5.xsd&...;,
"application_5.xsd");
+ // jboss-app
+ registerEntity("-//JBoss//DTD J2EE Application 1.3//EN",
"jboss-app_3_0.dtd");
+ registerEntity("-//JBoss//DTD J2EE Application 1.3V2//EN",
"jboss-app_3_2.dtd");
+ registerEntity("-//JBoss//DTD J2EE Application 1.4//EN",
"jboss-app_4_0.dtd");
+ registerEntity("-//JBoss//DTD J2EE Application 4.2//EN",
"jboss-app_4_2.dtd");
+ registerEntity("-//JBoss//DTD Java EE Application 5.0//EN",
"jboss-app_5_0.dtd");
+
+ // connector descriptors
+ registerEntity("-//Sun Microsystems, Inc.//DTD Connector 1.0//EN",
"connector_1_0.dtd");
+
registerEntity("http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd",
"connector_1_5.xsd");
+
registerEntity("http://java.sun.com/xml/ns/j2ee/connector_1_6.xsd",
"connector_1_6.xsd");
+ // jboss-ds
+ registerEntity("-//JBoss//DTD JBOSS JCA Config 1.0//EN",
"jboss-ds_1_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSS JCA Config 1.5//EN",
"jboss-ds_1_5.dtd");
+
registerEntity("http://www.jboss.org/j2ee/schema/jboss-ds_5_0.xsd",
"jboss-ds_5_0.xsd");
+ // jboss-ra
+
registerEntity("http://www.jboss.org/j2ee/schema/jboss-ra_1_0.xsd",
"jboss-ra_1_0.xsd");
+
+ // war meta-data
+ registerEntity("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
"web-app_2_2.dtd");
+ registerEntity("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
"web-app_2_3.dtd");
+
registerEntity("http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd",
"web-app_2_4.xsd");
+
registerEntity("http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd",
"web-app_2_5.xsd");
+ // jboss-web
+ registerEntity("-//JBoss//DTD Web Application 2.2//EN",
"jboss-web.dtd");
+ registerEntity("-//JBoss//DTD Web Application 2.3//EN",
"jboss-web_3_0.dtd");
+ registerEntity("-//JBoss//DTD Web Application 2.3V2//EN",
"jboss-web_3_2.dtd");
+ registerEntity("-//JBoss//DTD Web Application 2.4//EN",
"jboss-web_4_0.dtd");
+ registerEntity("-//JBoss//DTD Web Application 4.2//EN",
"jboss-web_4_2.dtd");
+ registerEntity("-//JBoss//DTD Web Application 5.0//EN",
"jboss-web_5_0.dtd");
+
registerEntity("http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd",
"jboss-web_5_1.xsd");
+
+ // application client
+
registerEntity("http://java.sun.com/xml/ns/j2ee/application-client_1...;,
"application-client_1_4.xsd");
+
registerEntity("http://java.sun.com/xml/ns/javaee/application-client...;,
"application-client_5.xsd");
+ // jboss-client
+ registerEntity("-//JBoss//DTD Application Client 3.2//EN",
"jboss-client_3_2.dtd");
+ registerEntity("-//JBoss//DTD Application Client 4.0//EN",
"jboss-client_4_0.dtd");
+ registerEntity("-//JBoss//DTD Application Client 4.2//EN",
"jboss-client_4_2.dtd");
+ registerEntity("-//JBoss//DTD Application Client 5.0//EN",
"jboss-client_5_0.dtd");
+
registerEntity("http://www.jboss.org/j2ee/schema/jboss-client_5_1.xs...;,
"jboss-client_5_1.xsd");
+
+ // jboss-specific
+ registerEntity("-//JBoss//DTD Web Service Reference 4.0//EN",
"service-ref_4_0.dtd");
+ registerEntity("-//JBoss//DTD Web Service Reference 4.2//EN",
"service-ref_4_2.dtd");
+ registerEntity("-//JBoss//DTD Web Service Reference 5.0//EN",
"service-ref_5_0.dtd");
+ registerEntity("-//JBoss//DTD MBean Service 3.2//EN",
"jboss-service_3_2.dtd");
+ registerEntity("-//JBoss//DTD MBean Service 4.0//EN",
"jboss-service_4_0.dtd");
+ registerEntity("-//JBoss//DTD MBean Service 4.2//EN",
"jboss-service_4_2.dtd");
+ registerEntity("-//JBoss//DTD MBean Service 5.0//EN",
"jboss-service_5_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSS XMBEAN 1.0//EN",
"jboss_xmbean_1_0.dtd");
+ registerEntity("-//JBoss//DTD JBOSS XMBEAN 1.1//EN",
"jboss_xmbean_1_1.dtd");
+ registerEntity("-//JBoss//DTD JBOSS XMBEAN 1.2//EN",
"jboss_xmbean_1_2.dtd");
+ registerEntity("-//JBoss//DTD JBOSS Security Config 3.0//EN",
"security_config.dtd");
+
registerEntity("http://www.jboss.org/j2ee/schema/security-config_4_0...;,
"security-config_4_0.xsd");
+ registerEntity("urn:jboss:aop-deployer", "aop-deployer_1_1.xsd");
+ registerEntity("urn:jboss:aop-beans:1.0", "aop-beans_1_0.xsd");
+ registerEntity("urn:jboss:bean-deployer", "bean-deployer_1_0.xsd");
+ registerEntity("urn:jboss:bean-deployer:2.0",
"bean-deployer_2_0.xsd");
+ registerEntity("urn:jboss:javabean:1.0", "javabean_1_0.xsd");
+ registerEntity("urn:jboss:javabean:2.0", "javabean_2_0.xsd");
+ registerEntity("urn:jboss:spring-beans:2.0",
"mc-spring-beans_2_0.xsd");
+ registerEntity("urn:jboss:policy:1.0", "policy_1_0.xsd");
+ registerEntity("urn:jboss:osgi-beans:1.0", "osgi-beans_1_0.xsd");
+ registerEntity("urn:jboss:seam-components:1.0",
"seam-components_1_0.xsd");
+ registerEntity("urn:jboss:security-config:4.1",
"security-config_4_1.xsd");
+ registerEntity("urn:jboss:security-config:5.0",
"security-config_5_0.xsd");
+ registerEntity("urn:jboss:jndi-binding-service:1.0",
"jndi-binding-service_1_0.xsd");
+ registerEntity("urn:jboss:user-roles:1.0", "user-roles_1_0.xsd");
+ }
+
+ /**
+ * Obtain a read-only view of the current entity map.
+ *
+ * @return Map<String, String> of the publicID/systemID to dtd/schema file
+ * name
+ */
+ public static Map getEntityMap() {
+ return Collections.unmodifiableMap(entities);
+ }
+
+ public static boolean isWarnOnNonFileURLs() {
+ return warnOnNonFileURLs;
+ }
+
+ public static void setWarnOnNonFileURLs(boolean warnOnNonFileURLs) {
+ JBossEntityResolver.warnOnNonFileURLs = warnOnNonFileURLs;
+ }
+
+ /**
+ * Register the mapping from the public id/system id to the dtd/xsd file
+ * name. This overwrites any existing mapping.
+ *
+ * @param id
+ * the DOCTYPE public id or system id such as
+ * "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans
1.1//EN"
+ * @param dtdFileName
+ * the simple dtd/xsd file name, "ejb-jar.dtd"
+ */
+ public static void registerEntity(String id, String dtdFileName) {
+ 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.
+ *
+ * @param id
+ * the DOCTYPE public id or system id such as
+ * "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans
1.1//EN"
+ * @param dtdOrSchema
+ * the simple dtd/xsd file name, "ejb-jar.dtd"
+ */
+ public synchronized void registerLocalEntity(String id, String dtdOrSchema) {
+ if (localEntities == null)
+ localEntities = new ConcurrentHashMap();
+ localEntities.put(id, dtdOrSchema);
+ }
+
+ /**
+ * Returns DTD/Schema inputSource. The resolution logic is:
+ *
+ * 1. Check the publicId against the current registered values in the class
+ * mapping of entity name to dtd/schema file name. If found, the resulting
+ * file name is passed to the loadClasspathResource to locate the file as a
+ * classpath resource.
+ *
+ * 2. Check the systemId against the current registered values in the class
+ * mapping of entity name to dtd/schema file name. If found, the resulting
+ * file name is passed to the loadClasspathResource to locate the file as a
+ * classpath resource.
+ *
+ * 3. Strip the systemId name down to the simple file name by removing an
+ * URL style path elements (myschemas/x.dtd becomes x.dtd), and call
+ * loadClasspathResource to locate the simple file name as a classpath
+ * resource.
+ *
+ * 4. Attempt to resolve the systemId as a URL from which the schema can be
+ * read. If the URL input stream can be opened this returned as the resolved
+ * input.
+ *
+ * @param publicId
+ * - Public ID of DTD, or null if it is a schema
+ * @param systemId
+ * - the system ID of DTD or Schema
+ * @return InputSource of entity
+ */
+ public InputSource resolveEntity(String publicId, String systemId) throws
SAXException, IOException {
+ entityResolved = false;
+
+ // nothing to resolve
+ if (publicId == null && systemId == null)
+ return null;
+
+ boolean trace = log.isTraceEnabled();
+
+ boolean resolvePublicIdFirst = true;
+ if (publicId != null && systemId != null) {
+ String registeredSystemId = null;
+ if (localEntities != null)
+ 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
+ inputSource = resolveSystemID(systemId, trace);
+ }
+
+ if (inputSource == null) {
+ // Try to resolve the systemID as a classpath reference under dtd or
+ // schema
+ inputSource = resolveClasspathName(systemId, trace);
+ }
+
+ if (inputSource == null) {
+ // Try to resolve the systemID as a absolute URL
+ inputSource = resolveSystemIDasURL(systemId, trace);
+ }
+
+ entityResolved = (inputSource != null);
+
+ if (entityResolved == false)
+ log.debug("Cannot resolve [publicID=" + publicId + ",systemID="
+ systemId + "]");
+
+ return inputSource;
+ }
+
+ /**
+ * Returns the boolean value to inform id DTD was found in the XML file or
+ * not
+ *
+ * @todo this is not thread safe and should be removed?
+ *
+ * @return boolean - true if DTD was found in XML
+ */
+ public boolean isEntityResolved() {
+ return entityResolved;
+ }
+
+ /**
+ * Load the schema from the class entity to schema file mapping.
+ *
+ * @see #registerEntity(String, String)
+ * @param publicId
+ * - the public entity name of the schema
+ * @param trace
+ * - trace level logging flag
+ * @return the InputSource for the schema file found on the classpath, null
+ * if the publicId is not registered or found.
+ */
+ protected InputSource resolvePublicID(String publicId, boolean trace) {
+ if (publicId == null)
+ return null;
+
+ if (trace)
+ log.trace("resolvePublicID, publicId=" + publicId);
+
+ InputSource inputSource = null;
+
+ String filename = null;
+ if (localEntities != null)
+ filename = (String) localEntities.get(publicId);
+ if (filename == null)
+ filename = (String) entities.get(publicId);
+
+ if (filename != null) {
+ if (trace)
+ log.trace("Found entity from publicId=" + publicId + " fileName=" +
filename);
+
+ InputStream ins = loadClasspathResource(filename, trace);
+ if (ins != null) {
+ inputSource = new InputSource(ins);
+ inputSource.setPublicId(publicId);
+ } else {
+ log.trace("Cannot load publicId from classpath resource: " + filename);
+
+ // Try the file name as a URI
+ inputSource = resolveSystemIDasURL(filename, trace);
+
+ if (inputSource == null)
+ log.warn("Cannot load publicId from resource: " + filename);
+ }
+ }
+
+ return inputSource;
+ }
+
+ /**
+ * Attempt to use the systemId as a URL from which the schema can be read.
+ * This checks to see whether the systemId is a key to an entry in the class
+ * entity map.
+ *
+ * @param systemId
+ * - the systemId
+ * @param trace
+ * - trace level logging flag
+ * @return the URL InputSource if the URL input stream can be opened, null
+ * if the systemId is not a URL or could not be opened.
+ */
+ protected InputSource resolveSystemID(String systemId, boolean trace) {
+ if (systemId == null)
+ return null;
+
+ if (trace)
+ log.trace("resolveSystemID, systemId=" + systemId);
+
+ InputSource inputSource = null;
+
+ // Try to resolve the systemId as an entity key
+ String filename = null;
+ if (localEntities != null)
+ filename = (String) localEntities.get(systemId);
+ if (filename == null)
+ filename = (String) entities.get(systemId);
+
+ if (filename != null) {
+ if (trace)
+ log.trace("Found entity systemId=" + systemId + " fileName=" +
filename);
+
+ InputStream ins = loadClasspathResource(filename, trace);
+ if (ins != null) {
+ inputSource = new InputSource(ins);
+ inputSource.setSystemId(systemId);
+ } else {
+ log.warn("Cannot load systemId from resource: " + filename);
+ }
+ }
+
+ return inputSource;
+ }
+
+ /**
+ * Attempt to use the systemId as a URL from which the schema can be read.
+ * This uses the systemID as a URL.
+ *
+ * @param systemId
+ * - the systemId
+ * @param trace
+ * - trace level logging flag
+ * @return the URL InputSource if the URL input stream can be opened, null
+ * if the systemId is not a URL or could not be opened.
+ */
+ protected InputSource resolveSystemIDasURL(String systemId, boolean trace) {
+ if (systemId == null)
+ return null;
+
+ if (trace)
+ log.trace("resolveSystemIDasURL, systemId=" + systemId);
+
+ InputSource inputSource = null;
+
+ // Try to use the systemId as a URL to the schema
+ try {
+ 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) {
+ log.warn("Trying to resolve systemId as a non-file URL: " + systemId);
+ }
+
+ InputStream ins = url.openStream();
+ if (ins != null) {
+ inputSource = new InputSource(ins);
+ inputSource.setSystemId(systemId);
+ } else {
+ log.warn("Cannot load systemId as URL: " + systemId);
+ }
+
+ if (trace)
+ log.trace("Resolved systemId as a URL");
+ } catch (MalformedURLException ignored) {
+ if (trace)
+ log.trace("SystemId is not a url: " + systemId, ignored);
+ } catch (IOException e) {
+ if (trace)
+ log.trace("Failed to obtain URL.InputStream from systemId: " + systemId, e);
+ }
+ return inputSource;
+ }
+
+ /**
+ * Resolve the systemId as a classpath resource. If not found, the systemId
+ * is simply used as a classpath resource name.
+ *
+ * @param systemId
+ * - the system ID of DTD or Schema
+ * @param trace
+ * - trace level logging flag
+ * @return the InputSource for the schema file found on the classpath, null
+ * if the systemId is not registered or found.
+ */
+ protected InputSource resolveClasspathName(String systemId, boolean trace) {
+ if (systemId == null)
+ return null;
+
+ if (trace)
+ log.trace("resolveClasspathName, systemId=" + systemId);
+ String filename = systemId;
+ // Parse the systemId as a uri to get the final path component
+ try {
+ URI url = new URI(systemId);
+ String path = url.getPath();
+ if (path == null)
+ path = url.getSchemeSpecificPart();
+ int slash = path.lastIndexOf('/');
+ if (slash >= 0)
+ filename = path.substring(slash + 1);
+ else
+ filename = path;
+
+ if (path.length() == 0)
+ return null;
+
+ if (trace)
+ log.trace("Mapped systemId to filename: " + filename);
+ } catch (URISyntaxException e) {
+ if (trace)
+ log.trace("systemId: is not a URI, using systemId as resource", e);
+ }
+
+ // Resolve the filename as a classpath resource
+ InputStream is = loadClasspathResource(filename, trace);
+ InputSource inputSource = null;
+ if (is != null) {
+ inputSource = new InputSource(is);
+ inputSource.setSystemId(systemId);
+ }
+ return inputSource;
+ }
+
+ /**
+ * Look for the resource name on the thread context loader resource path.
+ * This first simply tries the resource name as is, and if not found, the
+ * resource is prepended with either "dtd/" or "schema/"
depending on
+ * whether the resource ends in ".dtd" or ".xsd".
+ *
+ * @param resource
+ * - the classpath resource name of the schema
+ * @param trace
+ * - trace level logging flag
+ * @return the resource InputStream if found, null if not found.
+ */
+ protected InputStream loadClasspathResource(String resource, boolean trace) {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ URL url = loader.getResource(resource);
+ if (url == null) {
+ /*
+ * Prefix the simple filename with the schema type patch as this is
+ * the naming convention for the jboss bundled schemas.
+ */
+ if (resource.endsWith(".dtd"))
+ resource = "dtd/" + resource;
+ else if (resource.endsWith(".xsd"))
+ resource = "schema/" + resource;
+ url = loader.getResource(resource);
+ }
+
+ InputStream inputStream = null;
+ if (url != null) {
+ if (trace)
+ log.trace(resource + " maps to URL: " + url);
+ try {
+ inputStream = url.openStream();
+ } catch (IOException e) {
+ log.debug("Failed to open url stream", e);
+ }
+ }
+ return inputStream;
+ }
+
+}
Added:
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/StringPropertyReplacer.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/StringPropertyReplacer.java
(rev 0)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/StringPropertyReplacer.java 2013-03-21
13:55:16 UTC (rev 544)
@@ -0,0 +1,247 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat, Inc., 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.wise.core.client.impl.wsdlResolver;
+
+import java.util.Properties;
+import java.io.File;
+
+/**
+ * A utility class for replacing properties in strings.
+ *
+ * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
+ * @author <a href="Scott.Stark(a)jboss.org">Scott Stark</a>
+ * @author <a href="claudio.vesco(a)previnet.it">Claudio Vesco</a>
+ * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:dimitris@jboss.org">Dimitris
Andreadis</a>
+ * @version <tt>$Revision$</tt>
+ */
+public final class StringPropertyReplacer {
+ /** File separator value */
+ private static final String FILE_SEPARATOR = File.separator;
+
+ /** Path separator value */
+ private static final String PATH_SEPARATOR = File.pathSeparator;
+
+ /** File separator alias */
+ private static final String FILE_SEPARATOR_ALIAS = "/";
+
+ /** Path separator alias */
+ private static final String PATH_SEPARATOR_ALIAS = ":";
+
+ // States used in property parsing
+ private static final int NORMAL = 0;
+
+ private static final int SEEN_DOLLAR = 1;
+
+ private static final int IN_BRACKET = 2;
+
+ /**
+ * Go through the input string and replace any occurance of ${p} with the
+ * System.getProperty(p) value. If there is no such property p defined, then
+ * the ${p} reference will remain unchanged.
+ *
+ * If the property reference is of the form ${p:v} and there is no such
+ * property p, then the default value v will be returned.
+ *
+ * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then the
+ * primary and the secondary properties will be tried in turn, before
+ * returning either the unchanged input, or the default value.
+ *
+ * The property ${/} is replaced with System.getProperty("file.separator")
+ * value and the property ${:} is replaced with
+ * System.getProperty("path.separator").
+ *
+ * @param string
+ * - the string with possible ${} references
+ * @return the input string with all property references replaced if any. If
+ * there are no valid references the input string will be returned.
+ */
+ public static String replaceProperties(final String string) {
+ return replaceProperties(string, null);
+ }
+
+ /**
+ * Go through the input string and replace any occurance of ${p} with the
+ * props.getProperty(p) value. If there is no such property p defined, then
+ * the ${p} reference will remain unchanged.
+ *
+ * If the property reference is of the form ${p:v} and there is no such
+ * property p, then the default value v will be returned.
+ *
+ * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then the
+ * primary and the secondary properties will be tried in turn, before
+ * returning either the unchanged input, or the default value.
+ *
+ * The property ${/} is replaced with System.getProperty("file.separator")
+ * value and the property ${:} is replaced with
+ * System.getProperty("path.separator").
+ *
+ * @param string
+ * - the string with possible ${} references
+ * @param props
+ * - the source for ${x} property ref values, null means use
+ * System.getProperty()
+ * @return the input string with all property references replaced if any. If
+ * there are no valid references the input string will be returned.
+ */
+ public static String replaceProperties(final String string, final Properties props)
{
+ final char[] chars = string.toCharArray();
+ StringBuffer buffer = new StringBuffer();
+ boolean properties = false;
+ int state = NORMAL;
+ int start = 0;
+ for (int i = 0; i < chars.length; ++i) {
+ char c = chars[i];
+
+ // Dollar sign outside brackets
+ if (c == '$' && state != IN_BRACKET)
+ state = SEEN_DOLLAR;
+
+ // Open bracket immediatley after dollar
+ else if (c == '{' && state == SEEN_DOLLAR) {
+ buffer.append(string.substring(start, i - 1));
+ state = IN_BRACKET;
+ start = i - 1;
+ }
+
+ // No open bracket after dollar
+ else if (state == SEEN_DOLLAR)
+ state = NORMAL;
+
+ // Closed bracket after open bracket
+ else if (c == '}' && state == IN_BRACKET) {
+ // No content
+ if (start + 2 == i) {
+ buffer.append("${}"); // REVIEW: Correct?
+ } else // Collect the system property
+ {
+ String value = null;
+
+ String key = string.substring(start + 2, i);
+
+ // check for alias
+ if (FILE_SEPARATOR_ALIAS.equals(key)) {
+ value = FILE_SEPARATOR;
+ } else if (PATH_SEPARATOR_ALIAS.equals(key)) {
+ value = PATH_SEPARATOR;
+ } else {
+ // check from the properties
+ if (props != null)
+ value = props.getProperty(key);
+ else
+ value = System.getProperty(key);
+
+ if (value == null) {
+ // Check for a default value ${key:default}
+ int colon = key.indexOf(':');
+ if (colon > 0) {
+ String realKey = key.substring(0, colon);
+ if (props != null)
+ value = props.getProperty(realKey);
+ else
+ value = System.getProperty(realKey);
+
+ if (value == null) {
+ // Check for a composite key, "key1,key2"
+ value = resolveCompositeKey(realKey, props);
+
+ // Not a composite key either, use the
+ // specified default
+ if (value == null)
+ value = key.substring(colon + 1);
+ }
+ } else {
+ // No default, check for a composite key,
+ // "key1,key2"
+ value = resolveCompositeKey(key, props);
+ }
+ }
+ }
+
+ if (value != null) {
+ properties = true;
+ buffer.append(value);
+ } else {
+ buffer.append("${");
+ buffer.append(key);
+ buffer.append('}');
+ }
+
+ }
+ start = i + 1;
+ state = NORMAL;
+ }
+ }
+
+ // No properties
+ if (properties == false)
+ return string;
+
+ // Collect the trailing characters
+ if (start != chars.length)
+ buffer.append(string.substring(start, chars.length));
+
+ // Done
+ return buffer.toString();
+ }
+
+ /**
+ * Try to resolve a "key" from the provided properties by checking if it
is
+ * actually a "key1,key2", in which case try first "key1", then
"key2". If
+ * all fails, return null.
+ *
+ * It also accepts "key1," and ",key2".
+ *
+ * @param key
+ * the key to resolve
+ * @param props
+ * the properties to use
+ * @return the resolved key or null
+ */
+ private static String resolveCompositeKey(String key, Properties props) {
+ String value = null;
+
+ // Look for the comma
+ int comma = key.indexOf(',');
+ if (comma > -1) {
+ // If we have a first part, try resolve it
+ if (comma > 0) {
+ // Check the first part
+ String key1 = key.substring(0, comma);
+ if (props != null)
+ value = props.getProperty(key1);
+ else
+ value = System.getProperty(key1);
+ }
+ // Check the second part, if there is one and first lookup failed
+ if (value == null && comma < key.length() - 1) {
+ String key2 = key.substring(comma + 1);
+ if (props != null)
+ value = props.getProperty(key2);
+ else
+ value = System.getProperty(key2);
+ }
+ }
+ // Return whatever we've found or null
+ return value;
+ }
+}
Modified:
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/WiseEntityResolver.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/WiseEntityResolver.java 2013-03-20
15:30:02 UTC (rev 543)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/WiseEntityResolver.java 2013-03-21
13:55:16 UTC (rev 544)
@@ -27,7 +27,6 @@
import java.net.URL;
import org.apache.log4j.Logger;
-import org.jboss.util.xml.JBossEntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2013-03-20 15:30:02 UTC (rev 543)
+++ core/trunk/pom.xml 2013-03-21 13:55:16 UTC (rev 544)
@@ -154,19 +154,6 @@
</dependency>
<dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- <version>2.2.17.GA</version>
- <exclusions>
- <exclusion>
- <groupId>org.jboss.logging</groupId>
- <artifactId>jboss-logging-spi</artifactId>
- </exclusion>
- </exclusions>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.1.2.GA</version>