Java Code Examples for org.apache.xmlbeans.XmlOptions#setCharacterEncoding()

The following examples show how to use org.apache.xmlbeans.XmlOptions#setCharacterEncoding() . 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: DhlXTeeServiceImpl.java    From j-road with Apache License 2.0 6 votes vote down vote up
/**
 * Writes the document into given stream. Removes namespace usage from SignedDoc element (Digidoc container) Amphora test
 * environment is not capable of receiving such xml
 */
private void writeXmlObject(XmlObject xmlObject, OutputStream outputStream) {
    XmlOptions options = new XmlOptions();
    options.setCharacterEncoding(DVK_MESSAGE_CHARSET);
    { // fix DigiDoc client bug (also present with PostiPoiss doc-management-system)
      // they don't accept that SignedDoc have nameSpace alias set
        options.setSavePrettyPrint();
        HashMap<String, String> suggestedPrefixes = new HashMap<String, String>(2);
        suggestedPrefixes.put("http://www.sk.ee/DigiDoc/v1.3.0#", "");
        // suggestedPrefixes.put("http://www.sk.ee/DigiDoc/v1.4.0#", "");
        options.setSaveSuggestedPrefixes(suggestedPrefixes);
    }
    try {
        xmlObject.save(outputStream, options);
        writeXmlObjectToSentDocumentsFolder(xmlObject, options);
    } catch (IOException e) {
        log.error("Writing document failed", e);
        throw new java.lang.RuntimeException(e);
    }
}
 
Example 2
Source File: DhlXTeeServiceImpl.java    From j-road with Apache License 2.0 6 votes vote down vote up
private byte[] createMarkDocumentsReceivedV2AttachmentBody(Collection<TagasisideType> receivedDocsInfos) {
    TagasisideArrayType receivedDocs = TagasisideArrayType.Factory.newInstance();
    receivedDocs.setItemArray(receivedDocsInfos.toArray(new TagasisideType[receivedDocsInfos.size()]));
    if (log.isTraceEnabled()) {
        log.trace("created markDocumentsReceivedV2 attachmentBody: " + receivedDocs);
    }
    XmlOptions options = new XmlOptions();
    options.setCharacterEncoding(DVK_MESSAGE_CHARSET);
    { // When marking documents received, with version 2
      // they don't accept that item children, such as dhl_id and fault have nameSpace prefixes set
        HashMap<String, String> suggestedPrefixes = new HashMap<String, String>(2);
        suggestedPrefixes.put("http://www.riik.ee/schemas/dhl", "");
        options.setSaveSuggestedPrefixes(suggestedPrefixes);
        options.setSaveNoXmlDecl();
    }
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        receivedDocs.save(bos, options);
        String s = new String(bos.toByteArray(), DVK_MESSAGE_CHARSET);
        return gzipAndEncodeString(s);
    } catch (IOException e) {
        throw new RuntimeException("Failed to create markDocumentsReceivedV2 request attachmentBody", e);
    }
}
 
Example 3
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;
    }