public ElementInstance element(String text, QName original, String name) { try { File temp = File.createTempFile("name", "xsd"); FileWriter file = new FileWriter(temp); BufferedWriter buff = new BufferedWriter(file); PrintWriter print = new PrintWriter(buff); print.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + " <xsd:schema xmlns:my=\"http://mails/refractions/net\"" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " targetNamespace=\"http://localhost//test\">" + " <xsd:element name=\"" + name + "\" type=\"xsd:" + original.getLocalPart() + "\"/>" + "</xsd:schema>"); URL url = temp.toURL(); XSDParser parser = new XSDParser(); parser.parse(url.toString()); XSDSchema schema = parser.getSchema(); Map map = schema.getSimpleTypeIdMap(); return (ElementInstance) map.get(name); } catch (Throwable t) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", t); return null; } }
/** * Returns the column at which the given node starts. * @param node the node to query. * @return the column at which the given node starts. */ public static int getStartColumn(Node node) { Integer result = (Integer)getUserData(node).get("startColumn"); return result == null ? 1 : result.intValue(); }
@Override public void startDocument() { saveLocation(); document = createDocument(); xsdSchema = null; stack.clear(); getEncoding(); }
@Override public void endElement(String uri, String localName, String qName) throws SAXException { saveLocation(); Map<Object, Object> extendedAttributes = getUserData(element); extendedAttributes.put("endLine", new Integer(line)); extendedAttributes.put("endColumn", new Integer(column)); element = stack.pop(); }
protected void createUserInfo(XSDAnnotation xsdAnnotation, String documentation) { Element userInformation = xsdAnnotation.createUserInformation(null); // Try to parse the documentation and use the parsed version if it's successful. // XSDParser xsdParser = new XSDParser(null); xsdParser.parseString("<documentation>" + documentation + "</documentation>"); Document document = xsdParser.getDocument(); if (xsdParser.getDiagnostics().isEmpty() && document.getDocumentElement().getFirstChild() != null) { Document xsdDocument = xsdAnnotation.getSchema().getDocument(); for (Node node = document.getDocumentElement().getFirstChild(); node != null; node = node.getNextSibling()) { userInformation.appendChild(xsdDocument.importNode(node, true)); } } else { userInformation.appendChild(xsdAnnotation.getSchema().getDocument().createTextNode(documentation)); } xsdAnnotation.getElement().appendChild(userInformation); }
XSDParser xsdParser = new XSDParser(options); xsdParser.parse(inputSource); document = xsdParser.getDocument(); if (xsdParser.getEncoding() != null) getDefaultSaveOptions().put(XSD_ENCODING, xsdParser.getEncoding()); errors = xsdParser.getDiagnostics();
public int getColumn() { Node theNode = getNode(); if (theNode != null && theNode.getNodeType() == Node.ATTRIBUTE_NODE) { theNode = ((Attr)theNode).getOwnerElement(); } if (theNode != null && XSDParser.getUserData(theNode) != null) { return XSDParser.getStartColumn(theNode); } return getColumnGen(); }
public int getLine() { Node theNode = getNode(); if (theNode != null && theNode.getNodeType() == Node.ATTRIBUTE_NODE) { theNode = ((Attr)theNode).getOwnerElement(); } if (theNode != null && XSDParser.getUserData(theNode) != null) { return XSDParser.getStartLine(theNode); } return getLineGen(); }
public void parse(InputSource inputSource) { try { saxParser.parse(inputSource, this); } catch (IOException exception) { fatalError(exception); } catch (SAXException exception) { if (xsdDiagnostics.isEmpty()) { fatalError(exception); } } finally { if (jaxpPool != null) { jaxpPool.releaseSAXParser(saxParser); } } }
public void parseString(String input) { parse(new InputSource(new StringReader(input))); }
public Document updateDocument() { document = XSDParser.createDocument(); return document; }
public void setSchema(XSDSchema xsdSchema) { if (document != null) { this.xsdSchema = xsdSchema; Element element = document.getDocumentElement(); if (element != null) { xsdSchema.setElement(element); } xsdSchema.clearDiagnostics(); XSDResourceImpl.assignDiagnostics(xsdSchema, xsdDiagnostics); XSDResourceImpl resource = (XSDResourceImpl)xsdSchema.eResource(); if (resource != null && getEncoding() != null) { resource.getDefaultSaveOptions().put(XSDResourceImpl.XSD_ENCODING, getEncoding()); } } }
protected void createUserInfo(XSDAnnotation xsdAnnotation, String documentation) { Element userInformation = xsdAnnotation.createUserInformation(null); // Try to parse the documentation and use the parsed version if it's successful. // XSDParser xsdParser = new XSDParser(null); xsdParser.parseString("<documentation>" + documentation + "</documentation>"); Document document = xsdParser.getDocument(); if (xsdParser.getDiagnostics().isEmpty() && document.getDocumentElement().getFirstChild() != null) { Document xsdDocument = xsdAnnotation.getSchema().getDocument(); for (Node node = document.getDocumentElement().getFirstChild(); node != null; node = node.getNextSibling()) { userInformation.appendChild(xsdDocument.importNode(node, true)); } } else { userInformation.appendChild(xsdAnnotation.getSchema().getDocument().createTextNode(documentation)); } xsdAnnotation.getElement().appendChild(userInformation); }
XSDParser xsdParser = new XSDParser(options); xsdParser.parse(inputSource); document = xsdParser.getDocument(); if (xsdParser.getEncoding() != null) getDefaultSaveOptions().put(XSD_ENCODING, xsdParser.getEncoding()); errors = xsdParser.getDiagnostics();
public int getColumn() { Node theNode = getNode(); if (theNode != null && theNode.getNodeType() == Node.ATTRIBUTE_NODE) { theNode = ((Attr)theNode).getOwnerElement(); } if (theNode != null && XSDParser.getUserData(theNode) != null) { return XSDParser.getStartColumn(theNode); } return getColumnGen(); }
element = newElement; Map<Object, Object> extendedAttributes = getUserData(element); extendedAttributes.put("startLine", new Integer(line)); extendedAttributes.put("startColumn", new Integer(column)); saveLocation();
public int getLine() { Node theNode = getNode(); if (theNode != null && theNode.getNodeType() == Node.ATTRIBUTE_NODE) { theNode = ((Attr)theNode).getOwnerElement(); } if (theNode != null && XSDParser.getUserData(theNode) != null) { return XSDParser.getStartLine(theNode); } return getLineGen(); }
public void parse(InputSource inputSource) { try { saxParser.parse(inputSource, this); } catch (IOException exception) { fatalError(exception); } catch (SAXException exception) { if (xsdDiagnostics.isEmpty()) { fatalError(exception); } } finally { if (jaxpPool != null) { jaxpPool.releaseSAXParser(saxParser); } } }
public void parseString(String input) { parse(new InputSource(new StringReader(input))); }
public Document updateDocument() { document = XSDParser.createDocument(); return document; }