Java Code Examples for org.apache.xmlbeans.XmlCursor#setName()
The following examples show how to use
org.apache.xmlbeans.XmlCursor#setName() .
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: SweCommonEncoderv101.java From arctic-sea with Apache License 2.0 | 6 votes |
private XmlObject createTimeGeometricPrimitivePropertyType(TimePeriod timePeriod) throws EncodingException { TimeGeometricPrimitivePropertyType xbTimeGeometricPrimitiveProperty = TimeGeometricPrimitivePropertyType.Factory.newInstance(getXmlOptions()); if (timePeriod.isSetStart() && timePeriod.isSetEnd()) { xbTimeGeometricPrimitiveProperty.addNewTimeGeometricPrimitive() .set(encodeObjectToXml(GmlConstants.NS_GML, timePeriod)); } // TODO check GML 311 rename nodename of geometric primitive to // gml:timePeriod XmlCursor timeCursor = xbTimeGeometricPrimitiveProperty.newCursor(); boolean hasTimePrimitive = timeCursor.toChild(new QName(GmlConstants.NS_GML, GmlConstants.EN_ABSTRACT_TIME_GEOM_PRIM)); if (hasTimePrimitive) { timeCursor.setName(new QName(GmlConstants.NS_GML, GmlConstants.EN_TIME_PERIOD)); } timeCursor.dispose(); return xbTimeGeometricPrimitiveProperty; }
Example 2
Source File: EbicsXmlFactory.java From ebics-java-client with GNU Lesser General Public License v2.1 | 6 votes |
/** * Qualifies a valid member of a substitution group. This method tries to use the * built-in {@link XmlObject#substitute(QName, SchemaType)} and if succesful returns * a valid substitution which is usable (not disconnected). If it fails, it uses * low-level {@link XmlCursor} manipulation to qualify the substitution group. Note * that if the latter is the case the resulting document is disconnected and should * no longer be manipulated. Thus, use it as a final step after all markup is included. * * If newType is null, this method will skip {@link XmlObject#substitute(QName, SchemaType)} * and directly use {@link XmlCursor}. This can be used, if you are sure that the substitute * is not in the list of (pre-compiled) valid substitutions (this is the case if a schema * uses another schema's type as a base for elements. E.g. om:Observation uses gml:_Feature * as the base type). * * @param xobj * the abstract element * @param newInstance * the new {@link QName} of the instance * @param newType the new schemaType. if null, cursors will be used and the resulting object * will be disconnected. * @return if successful applied {@link XmlObject#substitute(QName, SchemaType)} a living object with a * type == newType is returned. Otherwise null is returned as you can no longer manipulate the object. */ public static XmlObject qualifySubstitutionGroup(XmlObject xobj, QName newInstance, SchemaType newType) { XmlObject substitute = null; if (newType != null) { substitute = xobj.substitute(newInstance, newType); if (substitute != null && substitute.schemaType() == newType && substitute.getDomNode().getLocalName().equals(newInstance.getLocalPart())) { return substitute; } } XmlCursor cursor = xobj.newCursor(); cursor.setName(newInstance); QName qName = new QName("http://www.w3.org/2001/XMLSchema-instance", "type"); cursor.removeAttribute(qName); cursor.toNextToken(); if (cursor.isNamespace()) { cursor.removeXml(); } cursor.dispose(); return null; }
Example 3
Source File: XML.java From astor with GNU General Public License v2.0 | 6 votes |
/** * * @param name */ void setLocalName(String localName) { XmlCursor cursor = newCursor(); try { if(cursor.isStartdoc()) cursor.toFirstContentToken(); if(cursor.isText() || cursor.isComment()) return; javax.xml.namespace.QName qname = cursor.getName(); cursor.setName(new javax.xml.namespace.QName( qname.getNamespaceURI(), localName, qname.getPrefix())); } finally { cursor.dispose(); } }
Example 4
Source File: XML.java From astor with GNU General Public License v2.0 | 6 votes |
/** * * @param ns */ void setNamespace(Namespace ns) { XmlCursor cursor = newCursor(); try { if(cursor.isStartdoc()) cursor.toFirstContentToken(); if(cursor.isText() || cursor.isComment() || cursor.isProcinst()) return; String prefix = ns.prefix(); if (prefix == null) { prefix = ""; } cursor.setName(new javax.xml.namespace.QName( ns.uri(), localName(), prefix)); } finally { cursor.dispose(); } }
Example 5
Source File: GetCapabilitiesResponseEncoder.java From arctic-sea with Apache License 2.0 | 5 votes |
private void renameContentsElementNames(final Contents xbContents) { for (final Offering offering : xbContents.getContents().getOfferingArray()) { final XmlCursor cursor = offering.getAbstractOffering().newCursor(); cursor.setName(Sos2Constants.QN_OBSERVATION_OFFERING); cursor.removeAttribute(W3CConstants.QN_XSI_TYPE); if (cursor.toChild(Sos2Constants.QN_SOS_OBSERVED_AREA)) { cursor.setName(Sos2Constants.QN_SOS_OBSERVED_AREA); cursor.toParent(); } if (cursor.toChild(Sos2Constants.QN_SOS_PHENOMENON_TIME)) { cursor.setName(Sos2Constants.QN_SOS_PHENOMENON_TIME); cursor.toParent(); } if (cursor.toChild(Sos2Constants.QN_SOS_RESULT_TIME)) { cursor.setName(Sos2Constants.QN_SOS_RESULT_TIME); cursor.toParent(); } if (cursor.toChild(Sos2Constants.QN_SOS_RESPONSE_FORMAT)) { cursor.setName(Sos2Constants.QN_SOS_RESPONSE_FORMAT); while (cursor.toNextSibling(Sos2Constants.QN_SOS_RESPONSE_FORMAT)) { cursor.setName(Sos2Constants.QN_SOS_RESPONSE_FORMAT); } cursor.toParent(); } if (cursor.toChild(Sos2Constants.QN_SOS_OBSERVATION_TYPE)) { cursor.setName(Sos2Constants.QN_SOS_OBSERVATION_TYPE); while (cursor.toNextSibling(Sos2Constants.QN_SOS_OBSERVATION_TYPE)) { cursor.setName(Sos2Constants.QN_SOS_OBSERVATION_TYPE); } cursor.toParent(); } if (cursor.toChild(Sos2Constants.QN_SOS_FEATURE_OF_INTEREST_TYPE)) { cursor.setName(Sos2Constants.QN_SOS_FEATURE_OF_INTEREST_TYPE); while (cursor.toNextSibling(Sos2Constants.QN_SOS_FEATURE_OF_INTEREST_TYPE)) { cursor.setName(Sos2Constants.QN_SOS_FEATURE_OF_INTEREST_TYPE); } } cursor.dispose(); } }
Example 6
Source File: EbicsXmlFactory.java From axelor-open-suite with GNU Affero General Public License v3.0 | 5 votes |
/** * Qualifies a valid member of a substitution group. This method tries to use the built-in {@link * XmlObject#substitute(QName, SchemaType)} and if succesful returns a valid substitution which is * usable (not disconnected). If it fails, it uses low-level {@link XmlCursor} manipulation to * qualify the substitution group. Note that if the latter is the case the resulting document is * disconnected and should no longer be manipulated. Thus, use it as a final step after all markup * is included. * * <p>If newType is null, this method will skip {@link XmlObject#substitute(QName, SchemaType)} * and directly use {@link XmlCursor}. This can be used, if you are sure that the substitute is * not in the list of (pre-compiled) valid substitutions (this is the case if a schema uses * another schema's type as a base for elements. E.g. om:Observation uses gml:_Feature as the base * type). * * @param xobj the abstract element * @param newInstance the new {@link QName} of the instance * @param newType the new schemaType. if null, cursors will be used and the resulting object will * be disconnected. * @return if successful applied {@link XmlObject#substitute(QName, SchemaType)} a living object * with a type == newType is returned. Otherwise null is returned as you can no longer * manipulate the object. */ public static XmlObject qualifySubstitutionGroup( XmlObject xobj, QName newInstance, SchemaType newType) { XmlObject substitute = null; if (newType != null) { substitute = xobj.substitute(newInstance, newType); if (substitute != null && substitute.schemaType() == newType && substitute.getDomNode().getLocalName().equals(newInstance.getLocalPart())) { return substitute; } } XmlCursor cursor = xobj.newCursor(); cursor.setName(newInstance); QName qName = new QName("http://www.w3.org/2001/XMLSchema-instance", "type"); cursor.removeAttribute(qName); cursor.toNextToken(); if (cursor.isNamespace()) { cursor.removeXml(); } cursor.dispose(); return null; }
Example 7
Source File: XML.java From astor with GNU General Public License v2.0 | 5 votes |
protected void changeNS (String oldURI, String newURI) { XmlCursor curs = newCursor(); while (curs.toParent()) { /* Goto the top of the document */ } TokenType tt = curs.currentTokenType(); if (tt.isStartdoc()) { tt = curs.toFirstContentToken(); } if (tt.isStart()) { do { if (tt.isStart() || tt.isAttr() || tt.isNamespace()) { javax.xml.namespace.QName currQName = curs.getName(); if (oldURI.equals(currQName.getNamespaceURI())) { curs.setName(new javax.xml.namespace.QName(newURI, currQName.getLocalPart())); } } tt = curs.toNextToken(); } while (!tt.isEnddoc() && !tt.isNone()); } curs.dispose(); }
Example 8
Source File: XML.java From astor with GNU General Public License v2.0 | 5 votes |
/** * * @param name */ void setName(QName qname) { XmlCursor cursor = newCursor(); try { if(cursor.isStartdoc()) cursor.toFirstContentToken(); if(cursor.isText() || cursor.isComment()) return; if(cursor.isProcinst()) { String localName = qname.localName(); cursor.setName(new javax.xml.namespace.QName(localName)); } else { String prefix = qname.prefix(); if (prefix == null) { prefix = ""; } cursor.setName(new javax.xml.namespace.QName( qname.uri(), qname.localName(), prefix)); } } finally { cursor.dispose(); } }
Example 9
Source File: GmlEncoderv321.java From arctic-sea with Apache License 2.0 | 4 votes |
/** * Creates a XML Polygon from a SOS Polygon. * * @param jtsPolygon * SOS Polygon * @param xbPolType * XML Polygon */ private void createPolygonFromJtsGeometry(Polygon jtsPolygon, PolygonType xbPolType) { List<?> jtsPolygons = PolygonExtracter.getPolygons(jtsPolygon); String srsName = getSrsName(jtsPolygon); for (int i = 0; i < jtsPolygons.size(); i++) { Polygon pol = (Polygon) jtsPolygons.get(i); AbstractRingPropertyType xbArpt = xbPolType.addNewExterior(); AbstractRingType xbArt = xbArpt.addNewAbstractRing(); LinearRingType xbLrt = LinearRingType.Factory.newInstance(); // Exterior ring LineString ring = pol.getExteriorRing(); DirectPositionListType xbPosList = xbLrt.addNewPosList(); xbPosList.setSrsName(srsName); xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring)); xbArt.set(xbLrt); // Rename element name for output XmlCursor cursor = xbArpt.newCursor(); if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) { cursor.setName(GmlConstants.QN_LINEAR_RING_32); } cursor.dispose(); // Interior ring int numberOfInteriorRings = pol.getNumInteriorRing(); for (int ringNumber = 0; ringNumber < numberOfInteriorRings; ringNumber++) { xbArpt = xbPolType.addNewInterior(); xbArt = xbArpt.addNewAbstractRing(); xbLrt = LinearRingType.Factory.newInstance(); ring = pol.getInteriorRingN(ringNumber); xbPosList = xbLrt.addNewPosList(); xbPosList.setSrsName(srsName); xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring)); xbArt.set(xbLrt); // Rename element name for output cursor = xbArpt.newCursor(); if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) { cursor.setName(GmlConstants.QN_LINEAR_RING_32); } cursor.dispose(); } } }
Example 10
Source File: GmlEncoderv311.java From arctic-sea with Apache License 2.0 | 4 votes |
/** * Creates a XML Polygon from a SOS Polygon. * * @param jtsPolygon * SOS Polygon * @param xbPolType * XML Polygon */ private void createPolygonFromJtsGeometry(Polygon jtsPolygon, PolygonType xbPolType) { List<?> jtsPolygons = PolygonExtracter.getPolygons(jtsPolygon); for (int i = 0; i < jtsPolygons.size(); i++) { Polygon pol = (Polygon) jtsPolygons.get(i); AbstractRingPropertyType xbArpt = xbPolType.addNewExterior(); AbstractRingType xbArt = xbArpt.addNewRing(); LinearRingType xbLrt = LinearRingType.Factory.newInstance(getXmlOptions()); // Exterior ring LineString ring = pol.getExteriorRing(); String coords = JTSHelper.getCoordinatesString(ring); DirectPositionListType xbPosList = xbLrt.addNewPosList(); xbPosList.setSrsName(getSrsName(jtsPolygon)); // switch coordinates xbPosList.setStringValue(coords); xbArt.set(xbLrt); // Rename element name for output XmlCursor cursor = xbArpt.newCursor(); if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING)) { cursor.setName(GmlConstants.QN_LINEAR_RING); } cursor.dispose(); // Interior ring int numberOfInteriorRings = pol.getNumInteriorRing(); for (int ringNumber = 0; ringNumber < numberOfInteriorRings; ringNumber++) { xbArpt = xbPolType.addNewInterior(); xbArt = xbArpt.addNewRing(); xbLrt = LinearRingType.Factory.newInstance(getXmlOptions()); ring = pol.getInteriorRingN(ringNumber); xbPosList = xbLrt.addNewPosList(); xbPosList.setSrsName(getSrsName(jtsPolygon)); xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring)); xbArt.set(xbLrt); // Rename element name for output cursor = xbArpt.newCursor(); if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING)) { cursor.setName(GmlConstants.QN_LINEAR_RING); } cursor.dispose(); } } }