private boolean isStartToken(XmlCursor cursor, String string) { if (!cursor.isStart()) { return false; } QName qName = cursor.getName(); if (qName != null && qName.getLocalPart() != null && qName.getLocalPart().equals(string)) { return true; } return false; }
private static String generateInternal(XmlCursor node, XmlCursor context, NamespaceContext nsctx) throws XPathGenerationException { if (node.isStartdoc()) return ""; if (context != null && node.isAtSamePositionAs(context)) return "."; assert node.isStart(); QName name = node.getName(); XmlCursor d = node.newCursor(); if (!node.toParent()) return "/" + name; int elemIndex = 0, i = 1; node.push(); if (!node.toChild(name)) throw new IllegalStateException("Must have at least one child with name: " + name); do { if (node.isAtSamePositionAs(d)) elemIndex = i; else i++; } while (node.toNextSibling(name)); node.pop(); d.dispose(); String pathToParent = generateInternal(node, context, nsctx); return i == 1 ? pathToParent + '/' + qnameToString(name, nsctx) : pathToParent + '/' + qnameToString(name, nsctx) + '[' + elemIndex + ']'; }
if (cursor.isStart()) { depth++; } else if (cursor.isEnd()) {
/** * * @param xml * @return */ XML appendChild(Object xml) { XmlCursor curs = newCursor(); if (curs.isStartdoc()) { curs.toFirstContentToken(); } // Move the cursor to the end of this element if (curs.isStart()) { curs.toEndToken(); } insertChild(curs, xml); curs.dispose(); return this; }
public void processDoc(XmlObject[] instances, Inst2XsdOptions options, TypeSystemHolder typeSystemHolder) { for (int i = 0; i < instances.length; i++) { XmlObject instance = instances[i]; XmlCursor xc = instance.newCursor(); // xc on start doc StringBuffer comment = new StringBuffer(); while( !xc.isStart() ) { xc.toNextToken(); if( xc.isComment() ) comment.append(xc.getTextValue()); else if (xc.isEnddoc()) return; } // xc now on the root element Element withElem = processElement(xc, comment.toString(), options, typeSystemHolder); withElem.setGlobal(true); addGlobalElement(withElem, typeSystemHolder, options); } }
/** * * @return */ String localName() { XmlCursor cursor = newCursor(); if (cursor.isStartdoc()) cursor.toFirstContentToken(); String name = null; if(cursor.isStart() || cursor.isAttr() || cursor.isProcinst()) { javax.xml.namespace.QName qname = cursor.getName(); name = qname.getLocalPart(); } cursor.dispose(); return name; }
protected Element processElement(XmlCursor xc, String comment, Inst2XsdOptions options, TypeSystemHolder typeSystemHolder) assert xc.isStart(); Element element = new Element(); element.setName(xc.getName());
/** * The name method returns the qualified name associated with this XML object. * * @return The qualified name associated with this XML object. */ QName name() { XmlCursor cursor = newCursor(); if (cursor.isStartdoc()) cursor.toFirstContentToken(); QName name = null; if(cursor.isStart() || cursor.isAttr() || cursor.isProcinst()) { javax.xml.namespace.QName qname = cursor.getName(); if(cursor.isProcinst()) { name = new QName(lib, "", qname.getLocalPart(), ""); } else { String uri = qname.getNamespaceURI(); String prefix = qname.getPrefix(); name = new QName(lib, uri, qname.getLocalPart(), prefix); } } cursor.dispose(); return name; }
private boolean isStartToken(XmlCursor cursor, String string) { if (!cursor.isStart()) { return false; } QName qName = cursor.getName(); if (qName != null && qName.getLocalPart() != null && qName.getLocalPart().equals(string)) { return true; } return false; }
/** * * @return */ public String toString() { String result; XmlCursor curs = newCursor(); if (curs.isStartdoc()) { curs.toFirstContentToken(); } if (curs.isText()) { result = curs.getChars(); } else if (curs.isStart() && hasSimpleContent()) { result = curs.getTextValue(); } else { result = toXMLString(0); } return result; }
public boolean toNextStartToken(XmlCursor cursor) { while (!cursor.isStart()) { if (!cursor.hasNextToken()) { return false; } cursor.toNextToken(); } return true; }
protected ColumnReferenceType[] getColumnReferences(SelectDocument doc) throws QueryException { ArrayList colRefs = new ArrayList() ; // // Loop through the whole of the query looking for // ColumnReferenceType(s).... XmlCursor cursor = doc.newCursor() ; try { while( !cursor.toNextToken().isNone() ) { if( cursor.isStart() && (cursor.getObject().schemaType() == ColumnReferenceType.type )){ colRefs.add( cursor.getObject() ) ; } } // end while } catch( Exception ex ) { log.error("Warning: Failed to get all column references from SelectDocument; error was " + ex.toString()); throw new QueryException("Failed to get column references from SelectDocument", ex); } finally { cursor.dispose() ; } return (ColumnReferenceType[])colRefs.toArray( new ColumnReferenceType[ colRefs.size() ] ) ; }
protected void convertToNamingNS(XmlCursor cursor, XmlCursor end) { end.toCursor(cursor); end.toEndToken(); while (cursor.hasNextToken() && cursor.isLeftOf(end)) { if (cursor.isStart()) { String localPart = cursor.getName().getLocalPart(); cursor.setName(new QName(NAMING_NS, localPart)); } cursor.toNextToken(); } }
public void convertElement(XmlCursor cursor, XmlCursor end) { end.toCursor(cursor); end.toEndToken(); while (cursor.hasNextToken() && cursor.isLeftOf(end)) { if (cursor.isStart()) { String localPart = cursor.getName().getLocalPart(); cursor.setName(new QName(CLUSTERING_WADI_NS, localPart)); if (localPart.equals(CLUSTER_ELEMENT_NAME) || localPart.equals(BACKING_STRATEGY_FACTORY_ELEMENT_NAME)) { convertChildrenToNamingNS(cursor); cursor.toEndToken(); } } cursor.toNextToken(); } }
if( cursor.getName().getLocalPart().equals( name ) ) { // Found it... content = cursor.getTextValue().replaceAll( ">_;", ">" ).replaceAll( "<_;", "<" ) ; break ; } } else if( cursor.isStart() && cursor.getObject().schemaType() == SelectionListType.type ) { break ; } } // end while return content ; } finally { cursor.dispose(); } } // end of readProcessingInstruction }
public void processDoc(XmlObject[] instances, Inst2XsdOptions options, TypeSystemHolder typeSystemHolder) { for (int i = 0; i < instances.length; i++) { XmlObject instance = instances[i]; XmlCursor xc = instance.newCursor(); // xc on start doc StringBuffer comment = new StringBuffer(); while( !xc.isStart() ) { xc.toNextToken(); if( xc.isComment() ) comment.append(xc.getTextValue()); else if (xc.isEnddoc()) return; } // xc now on the root element Element withElem = processElement(xc, comment.toString(), options, typeSystemHolder); withElem.setGlobal(true); addGlobalElement(withElem, typeSystemHolder, options); } }
public void processDoc(XmlObject[] instances, Inst2XsdOptions options, TypeSystemHolder typeSystemHolder) { for (int i = 0; i < instances.length; i++) { XmlObject instance = instances[i]; XmlCursor xc = instance.newCursor(); // xc on start doc StringBuffer comment = new StringBuffer(); while( !xc.isStart() ) { xc.toNextToken(); if( xc.isComment() ) comment.append(xc.getTextValue()); else if (xc.isEnddoc()) return; } // xc now on the root element Element withElem = processElement(xc, comment.toString(), options, typeSystemHolder); withElem.setGlobal(true); addGlobalElement(withElem, typeSystemHolder, options); } }
private String getNamespaceFromPlan(Object plan) throws DeploymentException { XmlObject xmlObject; if (plan instanceof File) { try { xmlObject = XmlBeansUtil.parse(((File) plan).toURI().toURL(), getClass().getClassLoader()); } catch (IOException e) { throw new DeploymentException("Could not read plan file", e); } catch (XmlException e) { throw new DeploymentException("Plan file does not contain well formed xml", e); } } else if (plan instanceof XmlObject) { xmlObject = (XmlObject) plan; } else { return defaultNamespace; } XmlCursor cursor = xmlObject.newCursor(); try { while (cursor.hasNextToken()){ if (cursor.isStart()) { return cursor.getName().getNamespaceURI(); } cursor.toNextToken(); } } finally { cursor.dispose(); } throw new DeploymentException("Cannot find namespace in xmlObject: " + xmlObject.xmlText()); }
cursor.push() ; } // // But we search for existing ones down to the SelectionList... else if( type == SelectionListType.type ) { break ; } } } // end while cursor.pop() ; cursor.insertProcInst( name, mangledContent ) ; } finally { cursor.dispose(); if( log.isTraceEnabled() ) log.trace( "exit: WriteProcessingInstruction()" ) ; } } // end of writeProcessingInstruction public static String ReadProcessingInstruction( SelectDocument doc, String name ) { String content = null ; XmlCursor cursor = doc.newCursor() ; try { while( !cursor.toNextToken().isNone() ) { if( cursor.isProcinst() ) {
XmlCursor cursor = doc.newCursor() ; try { while( !cursor.toNextToken().isNone() ) { if( cursor.isProcinst() ) { if( cursor.getName().getLocalPart().equals( name ) ) {