Search in sources :

Example 76 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.

the class GetCapabilitiesResponseEncoder method renameContentsElementNames.

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();
    }
}
Also used : SosOffering(org.n52.shetland.ogc.sos.SosOffering) Offering(net.opengis.swes.x20.AbstractContentsType.Offering) SosObservationOffering(org.n52.shetland.ogc.sos.SosObservationOffering) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 77 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.

the class SensorMLEncoderv101 method addAbstractProcessValues.

// TODO refactor/rename
private void addAbstractProcessValues(final AbstractProcessType abstractProcess, final AbstractProcess sosAbstractProcess) throws EncodingException {
    if (sosAbstractProcess.isSetGmlID()) {
        abstractProcess.setId(sosAbstractProcess.getGmlId());
    }
    if (sosAbstractProcess.isSetCapabilities()) {
        final Capabilities[] existing = abstractProcess.getCapabilitiesArray();
        final Set<String> names = Sets.newHashSetWithExpectedSize(existing.length);
        for (final Capabilities element : existing) {
            if (element.getName() != null) {
                names.add(element.getName());
            }
        }
        for (final SmlCapabilities sosCapability : sosAbstractProcess.getCapabilities()) {
            final Capabilities c = createCapability(sosCapability);
            // replace existing capability with the same name
            if (names.contains(c.getName())) {
                removeCapability(abstractProcess, c);
            }
            abstractProcess.addNewCapabilities().set(c);
        }
    }
    // set description
    if (sosAbstractProcess.isSetDescription() && !abstractProcess.isSetDescription()) {
        abstractProcess.addNewDescription().setStringValue(sosAbstractProcess.getDescription());
    }
    if (sosAbstractProcess.isSetName() && CollectionHelper.isNullOrEmpty(abstractProcess.getNameArray())) {
        // TODO check if override existing names
        addNamesToAbstractProcess(abstractProcess, sosAbstractProcess.getNames());
    }
    // set identification
    if (sosAbstractProcess.isSetIdentifications()) {
        abstractProcess.setIdentificationArray(createIdentification(sosAbstractProcess.getIdentifications()));
    }
    // set classification
    if (sosAbstractProcess.isSetClassifications()) {
        abstractProcess.setClassificationArray(createClassification(sosAbstractProcess.getClassifications()));
    }
    // set characteristics
    if (sosAbstractProcess.isSetCharacteristics()) {
        abstractProcess.setCharacteristicsArray(createCharacteristics(sosAbstractProcess.getCharacteristics()));
    }
    // set documentation
    if (sosAbstractProcess.isSetDocumentation() && CollectionHelper.isNullOrEmpty(abstractProcess.getDocumentationArray())) {
        abstractProcess.setDocumentationArray(createDocumentationArray(sosAbstractProcess.getDocumentation()));
    }
    // process
    if (sosAbstractProcess.isSetContact() && CollectionHelper.isNullOrEmpty(abstractProcess.getContactArray())) {
        ContactList contactList = createContactList(sosAbstractProcess.getContact());
        if (contactList != null && contactList.getMemberArray().length > 0) {
            abstractProcess.addNewContact().setContactList(contactList);
        }
    }
    // set keywords
    if (sosAbstractProcess.isSetKeywords()) {
        final List<String> keywords = sosAbstractProcess.getKeywords();
        final int length = abstractProcess.getKeywordsArray().length;
        for (int i = 0; i < length; ++i) {
            abstractProcess.removeKeywords(i);
        }
        abstractProcess.addNewKeywords().addNewKeywordList().setKeywordArray(keywords.toArray(new String[keywords.size()]));
    }
    if (sosAbstractProcess.isSetValidTime()) {
        if (abstractProcess.isSetValidTime()) {
            // remove existing validTime element
            final XmlCursor newCursor = abstractProcess.getValidTime().newCursor();
            newCursor.removeXml();
            newCursor.dispose();
        }
        final Time time = sosAbstractProcess.getMergedValidTime();
        final XmlObject xbtime = encodeObjectToXml(GmlConstants.NS_GML, time);
        if (time instanceof TimeInstant) {
            abstractProcess.addNewValidTime().addNewTimeInstant().set(xbtime);
        } else if (time instanceof TimePeriod) {
            abstractProcess.addNewValidTime().addNewTimePeriod().set(xbtime);
        }
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Time(org.n52.shetland.ogc.gml.time.Time) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) ContactList(net.opengis.sensorML.x101.ContactListDocument.ContactList) SmlContactList(org.n52.shetland.ogc.sensorML.SmlContactList) XmlCursor(org.apache.xmlbeans.XmlCursor) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) Capabilities(net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) XmlObject(org.apache.xmlbeans.XmlObject) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 78 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.

the class SweCommonEncoderv101 method createTimeGeometricPrimitivePropertyType.

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;
}
Also used : QName(javax.xml.namespace.QName) TimeGeometricPrimitivePropertyType(net.opengis.swe.x101.TimeGeometricPrimitivePropertyType) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 79 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.

the class AbstractOmV20XmlStreamWriter method writeResult.

/**
 * write om:result to stream
 *
 * @throws XMLStreamException
 *             If an error occurs when writing to stream
 * @throws EncodingException
 *             If an error occurs when creating elements to be written
 */
protected void writeResult() throws XMLStreamException, EncodingException {
    OmObservation observation = getElement();
    if (observation.getValue() instanceof AbstractObservationValue<?>) {
        ((AbstractObservationValue<?>) observation.getValue()).setValuesForResultEncoding(observation);
    }
    XmlObject createResult = (XmlObject) getEncoder(getEncodeNamespace().orElse(OmConstants.NS_OM_2), observation.getValue()).encode(observation.getValue());
    if (createResult != null) {
        if (createResult.xmlText().contains(XML_FRAGMENT)) {
            XmlObject set = OMObservationType.Factory.newInstance(getXmlOptions()).addNewResult().set(createResult);
            writeXmlObject(set, OmConstants.QN_OM_20_RESULT);
        } else {
            if (checkResult(createResult)) {
                QName name = createResult.schemaType().getName();
                String prefix = name.getPrefix();
                if (Strings.isNullOrEmpty(prefix)) {
                    XmlCursor newCursor = createResult.newCursor();
                    prefix = newCursor.prefixForNamespace(name.getNamespaceURI());
                    newCursor.setAttributeText(W3CConstants.QN_XSI_TYPE, prefix + ":" + name.getLocalPart());
                    newCursor.dispose();
                }
                writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT);
            } else {
                start(OmConstants.QN_OM_20_RESULT);
                writeXmlObject(createResult, OmConstants.QN_OM_20_RESULT);
                end(OmConstants.QN_OM_20_RESULT);
            }
        }
    } else {
        empty(OmConstants.QN_OM_20_RESULT);
    }
}
Also used : AbstractObservationValue(org.n52.shetland.ogc.om.AbstractObservationValue) QName(javax.xml.namespace.QName) OmObservation(org.n52.shetland.ogc.om.OmObservation) XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 80 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.

the class XML method insertChild.

/**
     *
     * @param curs
     * @param xmlToInsert
     */
private void insertChild(XmlCursor curs, Object xmlToInsert) {
    if (xmlToInsert == null || xmlToInsert instanceof Undefined) {
    // Do nothing
    } else if (xmlToInsert instanceof XmlCursor) {
        moveSrcToDest((XmlCursor) xmlToInsert, curs, true);
    } else if (xmlToInsert instanceof XML) {
        XML xmlValue = (XML) xmlToInsert;
        // If it's an attribute, then change to text node
        if (xmlValue.tokenType() == XmlCursor.TokenType.ATTR) {
            insertChild(curs, xmlValue.toString());
        } else {
            XmlCursor cursToInsert = ((XML) xmlToInsert).newCursor();
            moveSrcToDest(cursToInsert, curs, true);
            cursToInsert.dispose();
        }
    } else if (xmlToInsert instanceof XMLList) {
        XMLList list = (XMLList) xmlToInsert;
        for (int i = 0; i < list.length(); i++) {
            insertChild(curs, list.item(i));
        }
    } else {
        // Convert to string and make XML out of it
        String xmlStr = ScriptRuntime.toString(xmlToInsert);
        // Create an empty document.
        XmlObject xo = XmlObject.Factory.newInstance();
        XmlCursor sourceCurs = xo.newCursor();
        sourceCurs.toNextToken();
        // To hold the text.
        sourceCurs.insertChars(xmlStr);
        sourceCurs.toPrevToken();
        // Call us again with the cursor.
        moveSrcToDest(sourceCurs, curs, true);
    }
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Aggregations

XmlCursor (org.apache.xmlbeans.XmlCursor)160 XmlObject (org.apache.xmlbeans.XmlObject)68 QName (javax.xml.namespace.QName)21 XmlException (org.apache.xmlbeans.XmlException)16 TokenType (org.apache.xmlbeans.XmlCursor.TokenType)14 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)14 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)10 ArrayList (java.util.ArrayList)9 POSIXApplicationType (org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.POSIXApplicationType)8 HPCProfileApplicationType (org.ggf.schemas.jsdl.x2006.x07.jsdlHpcpa.HPCProfileApplicationType)8 SPMDApplicationType (org.ogf.schemas.jsdl.x2007.x02.jsdlSpmd.SPMDApplicationType)8 IOException (java.io.IOException)5 POIXMLException (org.apache.poi.POIXMLException)5 InputStream (java.io.InputStream)4 DrawPaint (org.apache.poi.sl.draw.DrawPaint)3 ArrayType (org.dmg.pmml.ArrayType)3 ApplicationType (org.ggf.schemas.jsdl.x2005.x11.jsdl.ApplicationType)3 LineString (org.locationtech.jts.geom.LineString)3 CTRow (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow)3 CTSdtBlock (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)3