xsddoc/src/net/sf/xframe/xsddoc Processor.java,1.26,1.27
Kurt Riede <[email protected]> Thu, 07 Oct 2004 22:53:05 +0000
| Newsgroups | gmane.text.xml.xframe.xsddoc.devel |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/xframe/xsddoc/src/net/sf/xframe/xsddoc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24337/src/net/sf/xframe/xsddoc
Modified Files:
Processor.java
Log Message:
fixes for cameleon schema and nested element declarations in groups
Index: Processor.java
===================================================================
RCS file: /cvsroot/xframe/xsddoc/src/net/sf/xframe/xsddoc/Processor.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** Processor.java 3 Sep 2004 08:04:24 -0000 1.26
--- Processor.java 7 Oct 2004 22:53:02 -0000 1.27
***************
*** 69,73 ****
////////////////////////////////////////////////
! /** Name of xsddoc-id attribute to indicate a nested component. */
private static final String XSDDOCID_ATTR = "xsddocid";
--- 69,73 ----
////////////////////////////////////////////////
! /** Name of xsddoc-id attribute to mark a nested component for processing. */
private static final String XSDDOCID_ATTR = "xsddocid";
***************
*** 78,81 ****
--- 78,84 ----
public static final String NAMESPACE_NAMESPACE = "http://www.w3.org/2000/xmlns/";
+ /** Namespace-URI of namespace of W3C-XML-Schema. */
+ public static final String XMLSCHEMA_NAMESPACE = "http://www.w3.org/2001/XMLSchema";
+
/** Namespace-URI of namespace of xsddoc. */
public static final String XSDDOC_NAMESPACE = "http://xframe.sf.net/xsddoc/doc";
***************
*** 90,103 ****
public static final String RESOURCE_PROTOCOL = "resource:";
! /** file extension of HTML files. */
private static final String HTML_EXT = ".html";
! /** file extension of XML files. */
private static final String XML_EXT = ".xml";
! /** file separator from <code>File.separator</code>. */
private static final String FILE_SEP = File.separator;
! /** protocol prefix for internal temporary DOM sources. */
private static final String DOM_PROTOCOL = "temp:";
--- 93,106 ----
public static final String RESOURCE_PROTOCOL = "resource:";
! /** File extension of HTML files. */
private static final String HTML_EXT = ".html";
! /** File extension of XML files. */
private static final String XML_EXT = ".xml";
! /** File separator from <code>File.separator</code>. */
private static final String FILE_SEP = File.separator;
! /** Protocol prefix for internal temporary DOM sources. */
private static final String DOM_PROTOCOL = "temp:";
***************
*** 379,390 ****
*/
public void execute() throws ProcessorException {
try {
- final File outFile = new File(this.out);
- if (!outFile.exists()) {
- throw new ProcessorException("output folder doesn't exist: " + outFile);
- }
- if (debug) {
- status(System.out);
- }
initBuilder();
initTransformers();
--- 382,393 ----
*/
public void execute() throws ProcessorException {
+ final File outFile = new File(this.out);
+ if (!outFile.exists()) {
+ throw new ProcessorException("output folder doesn't exist: " + outFile);
+ }
+ if (debug) {
+ status(System.out);
+ }
try {
initBuilder();
initTransformers();
***************
*** 492,496 ****
final Document schema;
if (this.mainSchema == null) {
! schema = getDocument(systemId);
} else {
schema = mainSchema;
--- 495,500 ----
final Document schema;
if (this.mainSchema == null) {
! mainSchema = getDocument(systemId);
! schema = mainSchema;
} else {
schema = mainSchema;
***************
*** 562,566 ****
/**
! * Process all nested components of current component.
*
* @param schema root Node of DOM tree of current schema
--- 566,570 ----
/**
! * Process top level components and nested element components.
*
* @param schema root Node of DOM tree of current schema
***************
*** 629,633 ****
((Element) component).removeAttributeNS(XSDDOC_NAMESPACE, XSDDOCID_ATTR);
}
! if ("element".equals(componentType) || "complexType".equals(componentType)) {
searchLocalElementDeclarations(schema, schemaLocation, rootComponent, component, name);
}
--- 633,637 ----
((Element) component).removeAttributeNS(XSDDOC_NAMESPACE, XSDDOCID_ATTR);
}
! if ("element".equals(componentType) || "complexType".equals(componentType) || "group".equals(componentType)) {
searchLocalElementDeclarations(schema, schemaLocation, rootComponent, component, name);
}
***************
*** 905,908 ****
--- 909,915 ----
transformer.setParameter("hideAttributes", this.hideAttributes ? "true" : "false");
transformer.setParameter("hideGroups", this.hideGroups ? "true" : "false");
+ //DomUtil.getFirstElementChild(mainSchema);
+ NodeList nl = mainSchema.getChildNodes();
+ transformer.setParameter("mainSchema", nl);
}
***************
*** 945,949 ****
* <p>Setting the target namespace of schema means
* <ul>
! * <li>settings the attribute <code>targetNamespace</code> to the value
* of the target namespace and</li>
* <li>setting the default namespace to the target namespace</li>
--- 952,956 ----
* <p>Setting the target namespace of schema means
* <ul>
! * <li>setting the attribute <code>targetNamespace</code> to the value
* of the target namespace and</li>
* <li>setting the default namespace to the target namespace</li>
***************
*** 956,959 ****
--- 963,967 ----
schemaElement.setAttributeNS(NAMESPACE_NAMESPACE, "xmlns", namespace);
schemaElement.setAttribute(TARGETNAMESPACE, namespace == null ? "noNamespace" : namespace);
+ //schemaElement.setAttributeNS(XMLSCHEMA_NAMESPACE, TARGETNAMESPACE, namespace == null ? "noNamespace" : namespace);
}
***************
*** 994,997 ****
--- 1002,1010 ----
* Cache handler for schema document cache.
* <p>Creates, caches and returns cached DOM documents for given system-IDs.</p>
+ * <p>Only schema with a valid target namespace are cached
+ * This implies that cameleon schema are not cached.
+ * This is important because a cameleon schema changes the
+ * target namspace depending on the refering schema's target
+ * namespace.</p>
*
* @param systemId system-ID of schema
***************
*** 1005,1009 ****
if (doc == null) {
doc = builder.parse(systemId);
! schemaCache.put(systemId, doc);
return doc;
} else {
--- 1018,1025 ----
if (doc == null) {
doc = builder.parse(systemId);
! final String targetNamespace = getTargetNamespace(doc);
! if (targetNamespace != null && !"".equals(targetNamespace)) {
! schemaCache.put(systemId, doc);
! }
return doc;
} else {
***************
*** 1023,1027 ****
*/
private Source getSource(final Document doc, final String systemId) throws SAXException, IOException {
! Source source = (Source) sourceCache.get(systemId);
if (source == null) {
if (doc == null) {
--- 1039,1043 ----
*/
private Source getSource(final Document doc, final String systemId) throws SAXException, IOException {
! Source source = null; // XXX (Source) sourceCache.get(systemId);
if (source == null) {
if (doc == null) {
***************
*** 1052,1055 ****
--- 1068,1074 ----
private final class ResourceResolver implements URIResolver {
+ /** Reference to schema resolver. */
+ private final URIResolver schemaResolver = new SchemaResolver();
+
/**
* URI resolver for XSLT files stored as resources in the xsddoc.jar file.
***************
*** 1060,1067 ****
* @param base The base URI in effect when the href attribute was
* encountered.
- * @throws TransformerException if an error occurs when trying to
- * resolve the URI.
* @return A Source object, or null if the href cannot be resolved, and the
* processor should try to resolve the URI itself.
*/
public Source resolve(final String href, final String base) throws TransformerException {
--- 1079,1086 ----
* @param base The base URI in effect when the href attribute was
* encountered.
* @return A Source object, or null if the href cannot be resolved, and the
* processor should try to resolve the URI itself.
+ * @throws TransformerException if an error occurs when trying to
+ * resolve the URI.
*/
public Source resolve(final String href, final String base) throws TransformerException {
***************
*** 1074,1078 ****
return getResourceSource(resourceName, href);
} else {
! return getSource(null, XMLUtil.getAbsoluteURI(href, base));
}
} else if (base != null) {
--- 1093,1097 ----
return getResourceSource(resourceName, href);
} else {
! return schemaResolver.resolve(href, base);
}
} else if (base != null) {
***************
*** 1082,1094 ****
return getResourceSource(resourceName, RESOURCE_PROTOCOL + resourceName);
} else {
! return getSource(null, XMLUtil.getAbsoluteURI(href, base));
}
} else {
return getSource(null, XMLUtil.getAbsoluteURI(href, base));
}
} catch (SAXException e) {
! throw new TransformerException("Cannot resolve URI " + href + " for base URI " + base, e);
} catch (IOException e) {
! throw new TransformerException("Cannot resolve URI " + href + " for base URI " + base, e);
}
}
--- 1101,1150 ----
return getResourceSource(resourceName, RESOURCE_PROTOCOL + resourceName);
} else {
! return schemaResolver.resolve(href, base);
}
} else {
+ return schemaResolver.resolve(href, base);
+ }
+ } catch (IOException e) {
+ throw new TransformerException("Cannot resolve URI " + href + " for base URI " + base, e);
+ }
+ }
+ }
+
+ /**
+ * URIResolver for included, imported or redefined schema files.
+ */
+ private final class SchemaResolver implements URIResolver {
+
+ /**
+ * Resolves a schema reference from <code>xs:include</code>,
+ * <code>xs:import</code> or <code>xs:redefine</code> tags.
+ *
+ * <p>XSL-scripts that use the <code>document()</code> function can optionaly
+ * add a <code>targetNamespace</code> CGI parameter to allow resolving
+ * cameleon schema.</p>
+ *
+ * @param href An href attribute, which may be relative or absolute
+ * @param base The base URI in effect when the href attribute was
+ * @return A Source object, or null if the href cannot be resolved, and the
+ * processor should try to resolve the URI itself.
+ * @throws TransformerException if an error occurs when trying to
+ * resolve the URI.
+ */
+ public Source resolve(final String href, final String base) throws TransformerException {
+ try {
+ final Document schema = getDocument(XMLUtil.getAbsoluteURI(href, base));
+ if ("".equals(getTargetNamespace(schema))) {
+ final Document baseSchema = getDocument(base);
+ final String targetNamespace = getTargetNamespace(baseSchema);
+ setTargetNamespace(schema, targetNamespace);
+ return getSource(schema, XMLUtil.getAbsoluteURI(href, base));
+ } else {
return getSource(null, XMLUtil.getAbsoluteURI(href, base));
}
} catch (SAXException e) {
! throw new TransformerException("Cannot resolve schema URI " + href + " for base URI " + base, e);
} catch (IOException e) {
! throw new TransformerException("Cannot resolve schema URI " + href + " for base URI " + base, e);
}
}
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl