Java Code Examples for org.apache.xmlbeans.XmlCursor#getTextValue()

The following examples show how to use org.apache.xmlbeans.XmlCursor#getTextValue() . 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: XML.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 * @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;
}
 
Example 2
Source File: XML.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param cursor
 * @param opts
 * @return
 */
private static String dumpNode(XmlCursor cursor, XmlOptions opts)
{
    if (cursor.isText())
        return cursor.getChars();

    if (cursor.isFinish())
        return "";

    cursor.push();
    boolean wanRawText = cursor.isStartdoc() && !cursor.toFirstChild();
    cursor.pop();

    return wanRawText ? cursor.getTextValue() : cursor.xmlText( opts );
}
 
Example 3
Source File: XmlPath.java    From mdw with Apache License 2.0 4 votes vote down vote up
public static String getRootNodeValue(XmlObject xmlbean) {
    XmlCursor cursor = xmlbean.newCursor();
    cursor.toFirstChild();
    return cursor.getTextValue();
}
 
Example 4
Source File: XML.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @return
 */
String toXMLString(int indent)
{
    // XXX indent is ignored

    String result;

    XmlCursor curs = newCursor();

    if (curs.isStartdoc())
    {
        curs.toFirstContentToken();
    }

    try
    {
        if (curs.isText())
        {
            result = curs.getChars();
        }
        else if (curs.isAttr())
        {
            result = curs.getTextValue();
        }
        else if (curs.isComment() || curs.isProcinst())
        {
            result = XML.dumpNode(curs, getOptions());

            // todo: XBeans-dependent hack here
            // If it's a comment or PI, take off the xml-frament stuff
            String start = "<xml-fragment>";
            String end = "</xml-fragment>";

            if (result.startsWith(start))
            {
                result = result.substring(start.length());
            }

            if (result.endsWith(end))
            {
                result = result.substring(0, result.length() - end.length());
            }
        }
        else
        {
            result = XML.dumpNode(curs, getOptions());
        }
    }
    finally
    {
        curs.dispose();
    }

    return result;
}
 
Example 5
Source File: DescribeSensorParser.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
public static SensorMLDocument unwrapSensorMLFrom(XmlObject xmlObject) throws XmlException, XMLHandlingException, IOException {
    if (SoapUtil.isSoapEnvelope(xmlObject)) {
        xmlObject = SoapUtil.stripSoapEnvelope(xmlObject);
    }
    if (xmlObject instanceof SensorMLDocument) {
        return (SensorMLDocument) xmlObject;
    }
    if (xmlObject instanceof DescribeSensorResponseDocument) {
        DescribeSensorResponseDocument responseDoc = (DescribeSensorResponseDocument) xmlObject;
        DescribeSensorResponseType response = responseDoc.getDescribeSensorResponse();
        DescribeSensorResponseType.Description[] descriptionArray = response.getDescriptionArray();
        if (descriptionArray.length == 0) {
            LOGGER.warn("No SensorDescription available in response!");
        }
        else {
            for (DescribeSensorResponseType.Description description : descriptionArray) {
                SensorDescriptionType.Data dataDescription = description.getSensorDescription().getData();
                String namespace = "declare namespace gml='http://www.opengis.net/gml'; ";
                for (XmlObject xml : dataDescription.selectPath(namespace + "$this//*/@gml:id")) {
                    XmlCursor cursor = xml.newCursor();
                    String gmlId = cursor.getTextValue();
                    if ( !NcNameResolver.isNCName(gmlId)) {
                        cursor.setTextValue(NcNameResolver.fixNcName(gmlId));
                    }
                }
                XmlObject object = XmlObject.Factory.parse(dataDescription.xmlText());
                if (object instanceof SystemDocumentImpl) {
                    SensorMLDocument smlDoc = SensorMLDocument.Factory.newInstance();
                    SensorMLDocument.SensorML.Member member = smlDoc.addNewSensorML().addNewMember();
                    member.set(XMLBeansParser.parse(object.newInputStream()));
                    return smlDoc;
                }

                return SensorMLDocument.Factory.parse(dataDescription.newInputStream());
            }
        }
    }

    LOGGER.warn("Failed to unwrap SensorML from '{}'. Return an empty description.", xmlObject.xmlText());
    return SensorMLDocument.Factory.newInstance();
}
 
Example 6
Source File: PdfGenerator.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
private MetadataType buildUpMetadata(String sosURL, String procedureID) throws Exception {

        SOSMetadata metadata = ConfigurationContext.getSOSMetadata(sosURL);
        String sosVersion = metadata.getSosVersion();
        String smlVersion = metadata.getSensorMLVersion();
        ParameterContainer paramCon = new ParameterContainer();
        paramCon.addParameterShell(ISOSRequestBuilder.DESCRIBE_SENSOR_SERVICE_PARAMETER, "SOS");
        paramCon.addParameterShell(ISOSRequestBuilder.DESCRIBE_SENSOR_VERSION_PARAMETER, sosVersion);
        paramCon.addParameterShell(ISOSRequestBuilder.DESCRIBE_SENSOR_PROCEDURE_PARAMETER, procedureID);
        if (SosUtil.isVersion100(sosVersion)) {
            paramCon.addParameterShell(ISOSRequestBuilder.DESCRIBE_SENSOR_OUTPUT_FORMAT, smlVersion);
        } else if (SosUtil.isVersion200(sosVersion)) {
            paramCon.addParameterShell(ISOSRequestBuilder.DESCRIBE_SENSOR_PROCEDURE_DESCRIPTION_FORMAT, smlVersion);
        } else {
            throw new IllegalStateException("SOS Version (" + sosVersion + ") is not supported!");
        }

        Operation descSensorOperation = new Operation(SOSAdapter.DESCRIBE_SENSOR, sosURL, sosURL);
        SOSAdapter adapter = SosAdapterFactory.createSosAdapter(metadata);
		
        OperationResult opResult = adapter.doOperation(descSensorOperation, paramCon);

        // parse resulting SensorML doc and store information in the
        // MetadataType object:
        XmlOptions xmlOpts = new XmlOptions();
        xmlOpts.setCharacterEncoding(ENCODING);

        XmlObject xmlObject =
                XmlObject.Factory.parse(opResult.getIncomingResultAsStream(), xmlOpts);
        MetadataType metadataType = MetadataType.Factory.newInstance();

        String namespaceDecl = "declare namespace sml='http://www.opengis.net/sensorML/1.0'; "; //$NON-NLS-1$

        for (XmlObject termObj : xmlObject.selectPath(namespaceDecl + "$this//sml:Term")) { //$NON-NLS-1$
            String attributeVal = termObj.selectAttribute(new QName("definition")).newCursor() //$NON-NLS-1$
                    .getTextValue();

            String name = null;
            String value;

            if (attributeVal.equals("urn:ogc:identifier:stationName")) {
                name = "Station"; //$NON-NLS-1$
            }

            if (attributeVal.equals("urn:ogc:identifier:operator")) {
                name = "Operator"; //$NON-NLS-1$
            }

            if (attributeVal.equals("urn:ogc:identifier:stationID")) {
                name = "ID"; //$NON-NLS-1$
            }

            if (attributeVal.equals("urn:ogc:identifier:sensorType")) {
                name = "Sensor"; //$NON-NLS-1$
            }

            XmlCursor cursor = termObj.newCursor();
            cursor.toChild("value"); //$NON-NLS-1$
            value = cursor.getTextValue();

            if (name != null) {
                GenericMetadataPair genMetaPair = metadataType.addNewGenericMetadataPair();
                genMetaPair.setName(name);
                genMetaPair.setValue(value);
            }
        }

        return metadataType;
    }