xsddoc/src/net/sf/xframe/xsddoc Processor.java,1.30,1.31
Kurt Riede <[email protected]> Mon, 13 Dec 2004 13:23:02 +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-serv10321/src/net/sf/xframe/xsddoc
Modified Files:
Processor.java
Log Message:
avoid Stack Overflow with circular includes
Index: Processor.java
===================================================================
RCS file: /cvsroot/xframe/xsddoc/src/net/sf/xframe/xsddoc/Processor.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** Processor.java 9 Dec 2004 12:42:17 -0000 1.30
--- Processor.java 13 Dec 2004 13:23:00 -0000 1.31
***************
*** 207,210 ****
--- 207,213 ----
private boolean initialized = false;
+ /** Map of all already processed schema locations. */
+ private Map schemaLocationProcessedMap = new HashMap();
+
////////////////////////////////////////////////
// instantiation
***************
*** 571,574 ****
--- 574,578 ----
transform(source, tOverviewNamespace, subfolder, "overview-namespace");
transform(source, tSchemaIndex, subfolder, "index");
+ schemaLocationProcessedMap.clear();
processComponents(schema, schemaLocation);
}
***************
*** 646,678 ****
name = parentName + "." + localName;
}
if (verbose) {
final String targetNamespace = DomUtil.getAttributeValue(schema.getDocumentElement(), TARGETNAMESPACE);
! System.out.println("process " + "{" + targetNamespace + "}" + name + " from file " + schemaLocation);
}
! if (name == null) {
! System.out.println("Ignoring unnamed component " + componentType);
} else {
! new File(subfolder).mkdir();
! new File(subfolder + FILE_SEP + componentType).mkdir();
! final Source source = getSource(schema, getSystemId(schemaLocation));
! if (!"".equals(parentName)) {
! ((Element) component).setAttributeNS(NAMESPACE_NAMESPACE, "xmlns:" + XSDDOC_PREFIX, XSDDOC_NAMESPACE);
! ((Element) component).setAttributeNS(XSDDOC_NAMESPACE, XSDDOC_PREFIX + ":" + XSDDOCID_ATTR, "a");
! }
! if (xml) {
! transform(source, tComponent, component,
! subfolder + FILE_SEP + componentType + FILE_SEP + name + getExtension(),
! namespaceURI, componentType, name);
! } else {
! final Node result = transform(source, tComponent, component, namespaceURI, componentType, name);
! transform(new DOMSource(result, DOM_PROTOCOL), tHtml,
! subfolder + FILE_SEP + componentType + FILE_SEP + name + getExtension());
! }
! if (!"".equals(parentName)) {
! ((Element) component).removeAttributeNS(XSDDOC_NAMESPACE, XSDDOCID_ATTR);
! }
! if ("element".equals(componentType) || "complexType".equals(componentType) || "group".equals(componentType)) {
! searchLocalElementDeclarations(schema, schemaLocation, rootComponent, component, name);
! }
}
}
--- 650,682 ----
name = parentName + "." + localName;
}
+ if (name == null) {
+ System.out.println("Ignoring unnamed component " + componentType);
+ return;
+ }
if (verbose) {
final String targetNamespace = DomUtil.getAttributeValue(schema.getDocumentElement(), TARGETNAMESPACE);
! System.out.println("process " + componentType + " {" + targetNamespace + "}" + name);
}
! new File(subfolder).mkdir();
! new File(subfolder + FILE_SEP + componentType).mkdir();
! final Source source = getSource(schema, getSystemId(schemaLocation));
! if (!"".equals(parentName)) {
! ((Element) component).setAttributeNS(NAMESPACE_NAMESPACE, "xmlns:" + XSDDOC_PREFIX, XSDDOC_NAMESPACE);
! ((Element) component).setAttributeNS(XSDDOC_NAMESPACE, XSDDOC_PREFIX + ":" + XSDDOCID_ATTR, "a");
! }
! if (xml) {
! transform(source, tComponent, component,
! subfolder + FILE_SEP + componentType + FILE_SEP + name + getExtension(),
! namespaceURI, componentType, name);
} else {
! final Node result = transform(source, tComponent, component, namespaceURI, componentType, name);
! transform(new DOMSource(result, DOM_PROTOCOL), tHtml,
! subfolder + FILE_SEP + componentType + FILE_SEP + name + getExtension());
! }
! if (!"".equals(parentName)) {
! ((Element) component).removeAttributeNS(XSDDOC_NAMESPACE, XSDDOCID_ATTR);
! }
! if ("element".equals(componentType) || "complexType".equals(componentType) || "group".equals(componentType)) {
! searchLocalElementDeclarations(schema, schemaLocation, rootComponent, component, name);
}
}
***************
*** 746,749 ****
--- 750,757 ----
return;
}
+ if (schemaLocationProcessedMap.containsKey(rawSchemaLocation)) {
+ return;
+ }
+ schemaLocationProcessedMap.put(rawSchemaLocation, Boolean.TRUE);
final String includedSchemaLocation = FileUtil.getLocation(schemaLocation, rawSchemaLocation);
if (debug) {
***************
*** 791,794 ****
--- 799,806 ----
return;
}
+ if (schemaLocationProcessedMap.containsKey(rawSchemaLocation)) {
+ return;
+ }
+ schemaLocationProcessedMap.put(rawSchemaLocation, Boolean.TRUE);
final String importedSchemaLocation = FileUtil.getLocation(schemaLocation, rawSchemaLocation);
if (debug) {
***************
*** 982,986 ****
* targetNamespace defined or empty
*/
! private String getTargetNamespace(final Document schema) {
final String targetNameSpace = DomUtil.getAttributeValue(schema.getDocumentElement(), TARGETNAMESPACE);
return targetNameSpace == null ? "" : targetNameSpace;
--- 994,998 ----
* targetNamespace defined or empty
*/
! String getTargetNamespace(final Document schema) {
final String targetNameSpace = DomUtil.getAttributeValue(schema.getDocumentElement(), TARGETNAMESPACE);
return targetNameSpace == null ? "" : targetNameSpace;
***************
*** 998,1002 ****
* @param namespace identifier
*/
! private void setTargetNamespace(final Document schema, final String namespace) {
final Element schemaElement = (Element) DomUtil.getFirstElementChild(schema);
schemaElement.setAttributeNS(NAMESPACE_NAMESPACE, "xmlns", namespace);
--- 1010,1014 ----
* @param namespace identifier
*/
! void setTargetNamespace(final Document schema, final String namespace) {
final Element schemaElement = (Element) DomUtil.getFirstElementChild(schema);
schemaElement.setAttributeNS(NAMESPACE_NAMESPACE, "xmlns", namespace);
***************
*** 1053,1057 ****
* @deprecated use getSource instead
*/
! private Document getDocument(final String systemId) throws SAXException, IOException {
Document doc = (Document) schemaCache.get(systemId);
if (doc == null) {
--- 1065,1069 ----
* @deprecated use getSource instead
*/
! Document getDocument(final String systemId) throws SAXException, IOException {
Document doc = (Document) schemaCache.get(systemId);
if (doc == null) {
***************
*** 1061,1068 ****
schemaCache.put(systemId, doc);
}
- return doc;
- } else {
- return doc;
}
}
--- 1073,1078 ----
schemaCache.put(systemId, doc);
}
}
+ return doc;
}
***************
*** 1077,1081 ****
* @throws IOException If any IO errors occur.
*/
! private Source getSource(final Document doc, final String systemId) throws SAXException, IOException {
Source source = null; // XXX (Source) sourceCache.get(systemId);
if (source == null) {
--- 1087,1091 ----
* @throws IOException If any IO errors occur.
*/
! Source getSource(final Document doc, final String systemId) throws SAXException, IOException {
Source source = null; // XXX (Source) sourceCache.get(systemId);
if (source == null) {
***************
*** 1131,1136 ****
final String resourceName = href.substring(base.indexOf(":") + 1);
return getResourceSource(resourceName, href);
- } else {
- return schemaResolver.resolve(href, base);
}
} else if (base != null) {
--- 1141,1144 ----
***************
*** 1139,1148 ****
final String resourceName = baseName.substring(0, baseName.lastIndexOf("/") + 1) + href;
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);
--- 1147,1153 ----
final String resourceName = baseName.substring(0, baseName.lastIndexOf("/") + 1) + href;
return getResourceSource(resourceName, RESOURCE_PROTOCOL + resourceName);
}
}
+ return schemaResolver.resolve(href, base);
} catch (IOException e) {
throw new TransformerException("Cannot resolve URI " + href + " for base URI " + base, e);
***************
*** 1179,1185 ****
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);
--- 1184,1189 ----
setTargetNamespace(schema, targetNamespace);
return getSource(schema, XMLUtil.getAbsoluteURI(href, base));
}
+ return getSource(null, XMLUtil.getAbsoluteURI(href, base));
} catch (SAXException e) {
throw new TransformerException("Cannot resolve schema URI " + href + " for base URI " + base, e);
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/