use of org.eclipse.xsd.util.XSDResourceFactoryImpl in project tmdm-studio-se by Talend.
the class XSDParser method main.
/**
* Print a particle with markup for the document.
*
* @param xsdParticle a particle.
* @param rootElementDeclarationMarkup the markup.
*/
/*
* public void printParticle(XSDParticle xsdParticle, String rootElementDeclarationMarkup) { int minOccurs =
* xsdParticle.getMinOccurs(); int maxOccurs = xsdParticle.getMaxOccurs(); XSDTerm xsdTerm = xsdParticle.getTerm();
* if (xsdTerm instanceof XSDElementDeclaration) { XSDElementDeclaration xsdElementDeclaration =
* (XSDElementDeclaration) xsdTerm; String elementDeclarationName = xsdElementDeclaration.getName(); String
* elementDeclarationMarkup = null; if (rootElementDeclarationMarkup == null) { elementDeclarationMarkup =
* getElementDeclarationMarkup(elementDeclarationName); } if (elementDeclarationMarkup != null) {
* System.out.print("<span class='"); System.out.print(elementDeclarationMarkup); System.out.print("'>"); }
* System.out.print("<a href='#" + getLocalAnchor(xsdElementDeclaration) + "'>");
* System.out.print(elementDeclarationName.charAt(0)); System.out.print("</a>");
* System.out.print(elementDeclarationName.substring(1)); if (elementDeclarationMarkup != null) {
* System.out.print("</span>"); } if (minOccurs == 0) { if (maxOccurs == 1) { System.out.print("?"); } else {
* System.out.print("*"); } } else if (maxOccurs == -1) { System.out.print("+"); } } else if (xsdTerm instanceof
* XSDModelGroup) { XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdTerm; List particles =
* xsdModelGroup.getParticles(); boolean isRedundant = particles.size() == 1 && minOccurs == 1 && maxOccurs == 1 &&
* ((XSDParticle) particles.get(0)).getTerm() instanceof XSDModelGroup; if (!isRedundant) { System.out.print("(");
* // ) }
*
* String separator = XSDCompositor.CHOICE_LITERAL == xsdModelGroup .getCompositor() ? " | " :
* XSDCompositor.SEQUENCE_LITERAL == xsdModelGroup .getCompositor() ? ", " : " & ";
*
* for (Iterator i = xsdModelGroup.getParticles().iterator(); i .hasNext();) { XSDParticle childParticle =
* (XSDParticle) i.next(); printParticle(childParticle, rootElementDeclarationMarkup); if (i.hasNext()) {
* System.out.print(separator); } }
*
* if (!isRedundant) { // ( System.out.print(")"); if (minOccurs == 0) { if (maxOccurs == 1) {
* System.out.print("?"); } else { System.out.print("*"); } } else if (maxOccurs == -1) { System.out.print("+"); } }
* } else if (xsdTerm instanceof XSDWildcard) { System.out.print("<em>{any}</em>"); } }
*/
/**
* Print a simple type definition for the document.
*
* @param xsdSimpleTypeDefinition a simple type definition in the schema for schema.
*/
/*
* public void printSimpleTypeDefinition( XSDSimpleTypeDefinition xsdSimpleTypeDefinition) { if
* (xsdSimpleTypeDefinition == null) { } else if (xsdSimpleTypeDefinition.getEffectiveEnumerationFacet() != null) {
* List value = xsdSimpleTypeDefinition.getEffectiveEnumerationFacet() .getValue(); if (value.size() > 1) {
* System.out.print("("); } for (Iterator enumerators = value.iterator(); enumerators.hasNext();) { String
* enumerator = enumerators.next().toString(); System.out.print("<em>"); System.out.print(enumerator);
* System.out.print("</em>"); if (enumerators.hasNext()) { System.out.print(" | "); } } if (value.size() >
* 1) { System.out.print(")"); } } else if (xsdSimpleTypeDefinition.getElement() != null &&
* xsdSimpleTypeDefinition.getElement().hasAttribute( XSDConstants.ID_ATTRIBUTE)) { System.out.print("<a href='#" +
* xsdSimpleTypeDefinition.getName() + "-simple-type'>"); System.out.print(xsdSimpleTypeDefinition.getName());
* System.out.print("</a>"); } else if (XSDVariety.UNION_LITERAL == xsdSimpleTypeDefinition .getVariety()) {
* System.out.print("("); for (Iterator members = xsdSimpleTypeDefinition .getMemberTypeDefinitions().iterator();
* members.hasNext();) { XSDSimpleTypeDefinition memberTypeDefinition = (XSDSimpleTypeDefinition) members .next();
* printSimpleTypeDefinition(memberTypeDefinition); if (members.hasNext()) { System.out.print(" | "); } }
* System.out.print(")"); } else if (XSDVariety.UNION_LITERAL == xsdSimpleTypeDefinition .getVariety()) {
* System.out.print("List of "); printSimpleTypeDefinition(xsdSimpleTypeDefinition
* .getItemTypeDefinition()); } else if (xsdSimpleTypeDefinition.getName() != null) { if
* ("public".equals(xsdSimpleTypeDefinition.getName())) { System.out.print("<a target='Part2' href='" +
* XSDConstants.PART2 + "#anyURI'>anyURI</a> "); System.out.print("<a target='Errata' href='" + errata +
* "#pfipublic'><em>public</em></a>"); } else { System.out.print("<b><em>");
* System.out.print(xsdSimpleTypeDefinition.getName()); System.out.print("</em></b>"); } } else if
* (xsdSimpleTypeDefinition.getEffectivePatternFacet() != null) { //
* System.out.print(xsdSimpleTypeDefinition.getEffectivePatternFacet().getLexicalValue());
*
* System.out.print("<em>"); System.out.print("<a target='Part1' href='" + XSDConstants.PART1 +
* "#coss-identity-constraint'>"); System.out.print("a restricted xpath expression"); System.out.print("</a>");
* System.out.print("</em>"); } else { System.out.print("***"); } }
*/
public static void main(String[] args) {
try {
/*
* String xsd = ""; FileInputStream fis = new FileInputStream(
* "/home/bgrieder/workspace/XCBL35/XCBL35.xsd"); BufferedReader br = new BufferedReader(new
* InputStreamReader(fis, "utf-8")); String line; while ((line = br.readLine()) != null) xsd += line + "\n";
*
* XSDParser parser = new XSDParser(); parser.loadAndPrint(xsd);
*/
// $NON-NLS-1$
FileWriter fw = new FileWriter("/tmp/xcb35sr.xsd");
// $NON-NLS-1$
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xsd", new XSDResourceFactoryImpl());
// $NON-NLS-1$
String xsdFile = "/home/bgrieder/workspace/XCBL35/XCBL35.xsd";
ResourceSet resourceSet = new ResourceSetImpl();
XSDResourceImpl xsdResource = (XSDResourceImpl) resourceSet.getResource(URI.createFileURI(xsdFile), true);
/*
* XSDResourceImpl res = new XSDResourceImpl(URI.createFileURI(xsdFile));
*/
XSDSchema xsdSchema = xsdResource.getSchema();
String header = // $NON-NLS-1$ //$NON-NLS-2$
"<xsd:schema " + "elementFormDefault=\"qualified\" " + // $NON-NLS-1$
"targetNamespace=\"rrn:org.xcbl:schemas/xcbl/v3_5/xcbl35.xsd\" " + "xmlns=\"rrn:org.xcbl:schemas/xcbl/v3_5/xcbl35.xsd\" " + // $NON-NLS-1$ //$NON-NLS-2$
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
fw.write(header);
Iterator it = xsdSchema.getElementDeclarations().iterator();
for (; it.hasNext(); ) {
XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) it.next();
// if ("Order".equals(elementDeclaration.getName())) {
fw.write(Util.nodeToString(elementDeclaration.getElement()).replaceAll("xmlns:xsd=\"http:\\/\\/www\\.w3\\.org\\/2001\\/XMLSchema\"", // $NON-NLS-1$ //$NON-NLS-2$
""));
// }
}
it = xsdSchema.getTypeDefinitions().iterator();
for (; it.hasNext(); ) {
XSDTypeDefinition typedef = (XSDTypeDefinition) it.next();
fw.write(Util.nodeToString(typedef.getElement()));
}
// $NON-NLS-1$
String footer = "</xsd:schema>";
fw.write(footer);
fw.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
Aggregations