Java Code Examples for org.apache.xmlbeans.XmlCursor#hasNextToken()
The following examples show how to use
org.apache.xmlbeans.XmlCursor#hasNextToken() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: N52XmlHelper.java From arctic-sea with Apache License 2.0 | 6 votes |
public static Set<String> getNamespaces(XmlObject xmlObject) { Set<String> namespaces = Sets.newHashSet(); XmlCursor newCursor = xmlObject.newCursor(); while (newCursor.hasNextToken()) { TokenType evt = newCursor.toNextToken(); if (evt == TokenType.START) { QName qn = newCursor.getName(); if (qn != null) { namespaces.add(qn.getNamespaceURI()); } } else if (evt == TokenType.NAMESPACE) { namespaces.add(newCursor.getName().getNamespaceURI()); } } return namespaces; }
Example 2
Source File: XmlHelper.java From arctic-sea with Apache License 2.0 | 6 votes |
public static void fixNamespaceForXsiType(final XmlObject object, final QName value) { final XmlCursor cursor = object.newCursor(); while (cursor.hasNextToken()) { if (cursor.toNextToken().isStart()) { final String xsiType = cursor.getAttributeText(W3CConstants.QN_XSI_TYPE); if (xsiType != null) { final String[] toks = xsiType.split(":"); String localName; if (toks.length > 1) { localName = toks[1]; } else { localName = toks[0]; } if (localName.equals(value.getLocalPart())) { cursor.setAttributeText(W3CConstants.QN_XSI_TYPE, Joiner.on(":").join(XmlHelper.getPrefixForNamespace(object, value.getNamespaceURI()), value.getLocalPart())); } } } } cursor.dispose(); }
Example 3
Source File: XmlHelper.java From arctic-sea with Apache License 2.0 | 6 votes |
public static void fixNamespaceForXsiType(XmlObject content, Map<?, ?> namespaces) { final XmlCursor cursor = content.newCursor(); while (cursor.hasNextToken()) { if (cursor.toNextToken().isStart()) { final String xsiType = cursor.getAttributeText(W3CConstants.QN_XSI_TYPE); if (xsiType != null) { final String[] toks = xsiType.split(":"); if (toks.length > 1) { String prefix = toks[0]; String localName = toks[1]; if (namespaces.containsKey(prefix)) { cursor.setAttributeText( W3CConstants.QN_XSI_TYPE, Joiner.on(":").join( XmlHelper.getPrefixForNamespace(content, (String) namespaces.get(prefix)), localName)); } } } } } cursor.dispose(); }
Example 4
Source File: DefaultEbicsRootElement.java From ebics-java-client with GNU Lesser General Public License v2.1 | 6 votes |
/** * Inserts a schema location to the current ebics root element. * @param namespaceURI the name space URI * @param localPart the local part * @param prefix the prefix * @param value the value */ public void insertSchemaLocation(String namespaceURI, String localPart, String prefix, String value) { XmlCursor cursor; cursor = document.newCursor(); while (cursor.hasNextToken()) { if (cursor.isStart()) { cursor.toNextToken(); cursor.insertAttributeWithValue(new QName(namespaceURI, localPart, prefix), value); break; } else { cursor.toNextToken(); } } }
Example 5
Source File: DefaultEbicsRootElement.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
/** * Inserts a schema location to the current ebics root element. * * @param namespaceURI the name space URI * @param localPart the local part * @param prefix the prefix * @param value the value */ public void insertSchemaLocation( String namespaceURI, String localPart, String prefix, String value) { XmlCursor cursor; cursor = document.newCursor(); while (cursor.hasNextToken()) { if (cursor.isStart()) { cursor.toNextToken(); cursor.insertAttributeWithValue(new QName(namespaceURI, localPart, prefix), value); break; } else { cursor.toNextToken(); } } }
Example 6
Source File: Soap12Decoder.java From arctic-sea with Apache License 2.0 | 5 votes |
private void fixNamespaceForXsiType(XmlObject content, Map<?, ?> namespaces) { final XmlCursor cursor = content.newCursor(); while (cursor.hasNextToken()) { if (cursor.toNextToken().isStart()) { final String xsiType = cursor.getAttributeText(W3CConstants.QN_XSI_TYPE); if (xsiType != null) { final String[] toks = xsiType.split(":"); if (toks.length > 1) { String prefix = toks[0]; String localName = toks[1]; String namespace = (String) namespaces.get(prefix); if (Strings.isNullOrEmpty(namespace)) { namespace = schemaRepository.getNamespaceFor(prefix); } if (!Strings.isNullOrEmpty(namespace)) { cursor.setAttributeText(W3CConstants.QN_XSI_TYPE, Joiner.on(":").join( XmlHelper.getPrefixForNamespace(content, (String) namespaces.get(prefix)), localName)); } } } } } cursor.dispose(); }
Example 7
Source File: XmlHelper.java From arctic-sea with Apache License 2.0 | 5 votes |
/** * Remove namespace declarations from an xml fragment (useful for moving all * declarations to a document root * * @param x * The fragment to localize */ public static void removeNamespaces(final XmlObject x) { final XmlCursor c = x.newCursor(); while (c.hasNextToken()) { if (c.isNamespace()) { c.removeXml(); } else { c.toNextToken(); } } c.dispose(); }
Example 8
Source File: DefaultEbicsRootElement.java From ebics-java-client with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void addNamespaceDecl(String prefix, String uri) { XmlCursor cursor; cursor = document.newCursor(); while (cursor.hasNextToken()) { if (cursor.isStart()) { cursor.toNextToken(); cursor.insertNamespace(prefix, uri); break; } else { cursor.toNextToken(); } } }
Example 9
Source File: NiceXWPFDocument.java From poi-tl with Apache License 2.0 | 5 votes |
private boolean toStartCursor(XmlCursor newCursor) { do { if (newCursor.currentTokenType().isStart()) { return true; } else if (newCursor.hasNextToken()) { newCursor.toNextToken(); } else return false; } while (true); }
Example 10
Source File: DefaultEbicsRootElement.java From axelor-open-suite with GNU Affero General Public License v3.0 | 5 votes |
@Override public void addNamespaceDecl(String prefix, String uri) { XmlCursor cursor; cursor = document.newCursor(); while (cursor.hasNextToken()) { if (cursor.isStart()) { cursor.toNextToken(); cursor.insertNamespace(prefix, uri); break; } else { cursor.toNextToken(); } } }