Search in sources :

Example 36 with EncodingContext

use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.

the class Iso19139GcoEncoder method encode.

@Override
public XmlObject encode(Object element, EncodingContext additionalValues) throws EncodingException, UnsupportedEncoderInputException {
    XmlObject encodedObject = null;
    if (element instanceof AbstractRole) {
        encodedObject = encodeRole((AbstractRole) element);
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlObject(org.apache.xmlbeans.XmlObject) AbstractRole(org.n52.shetland.iso.gco.AbstractRole) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 37 with EncodingContext

use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.

the class Iso19139GmdEncoder method encodeMDMetadata.

private XmlObject encodeMDMetadata(MDMetadata mdMetadata, EncodingContext context) throws EncodingException {
    if (mdMetadata.isSetSimpleAttrs()) {
        MDMetadataPropertyType mdmpt = MDMetadataPropertyType.Factory.newInstance(getXmlOptions());
        mdmpt.setHref(mdMetadata.getSimpleAttrs().getHref());
        if (mdMetadata.getSimpleAttrs().isSetTitle()) {
            mdmpt.setTitle(mdMetadata.getSimpleAttrs().getTitle());
        }
        if (mdMetadata.getSimpleAttrs().isSetRole()) {
            mdmpt.setRole(mdMetadata.getSimpleAttrs().getRole());
        }
        return mdmpt;
    }
    MDMetadataType mdmt = MDMetadataType.Factory.newInstance(getXmlOptions());
    encodeAbstractObject(mdmt, mdMetadata);
    // add contacts
    for (CiResponsibleParty contact : mdMetadata.getContact()) {
        mdmt.addNewContact().set(encodeResponsibleParty(contact, EncodingContext.of(XmlBeansEncodingFlags.PROPERTY_TYPE, true)));
    }
    // add dateStamp
    mdmt.addNewDateStamp().setDateTime(mdMetadata.getDateStamp().toCalendar(Locale.ROOT));
    // add identificationInfo
    for (AbstractMDIdentification identificationInfo : mdMetadata.getIdentificationInfo()) {
        if (identificationInfo.isSetSimpleAttrs()) {
            MDIdentificationPropertyType mdipt = mdmt.addNewIdentificationInfo();
            mdipt.setHref(identificationInfo.getSimpleAttrs().getHref());
            if (identificationInfo.getSimpleAttrs().isSetTitle()) {
                mdipt.setTitle(identificationInfo.getSimpleAttrs().getTitle());
            }
            if (identificationInfo.getSimpleAttrs().isSetRole()) {
                mdipt.setRole(identificationInfo.getSimpleAttrs().getRole());
            }
        } else {
            mdmt.addNewIdentificationInfo().set(encode(identificationInfo, EncodingContext.of(XmlBeansEncodingFlags.PROPERTY_TYPE)));
        // TODO substitution???
        }
    }
    // TODO all other optional elements if required
    if (context.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
        MDMetadataPropertyType mdmpt = MDMetadataPropertyType.Factory.newInstance(getXmlOptions());
        mdmpt.setMDMetadata(mdmt);
        return mdmpt;
    } else if (context.has(XmlBeansEncodingFlags.DOCUMENT)) {
        MDMetadataDocument mdmd = MDMetadataDocument.Factory.newInstance(getXmlOptions());
        mdmd.setMDMetadata(mdmt);
        return mdmd;
    }
    return mdmt;
}
Also used : CiResponsibleParty(org.n52.shetland.iso.gmd.CiResponsibleParty) AbstractMDIdentification(org.n52.shetland.iso.gmd.AbstractMDIdentification) MDMetadataType(org.isotc211.x2005.gmd.MDMetadataType) MDMetadataPropertyType(org.isotc211.x2005.gmd.MDMetadataPropertyType) MDIdentificationPropertyType(org.isotc211.x2005.gmd.MDIdentificationPropertyType) MDMetadataDocument(org.isotc211.x2005.gmd.MDMetadataDocument)

Example 38 with EncodingContext

use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.

the class Soap12Encoder method createSOAP12Envelope.

private XmlObject createSOAP12Envelope(SoapResponse response, EncodingContext additionalValues) throws EncodingException {
    String action = null;
    final EnvelopeDocument envelopeDoc = EnvelopeDocument.Factory.newInstance();
    final Envelope envelope = envelopeDoc.addNewEnvelope();
    final Body body = envelope.addNewBody();
    if (response.getSoapFault() != null) {
        body.set(createSOAP12Fault(response.getSoapFault()));
    } else {
        if (response.getException() != null) {
            if (!response.getException().getExceptions().isEmpty()) {
                final CodedException firstException = response.getException().getExceptions().get(0);
                action = getExceptionActionURI(firstException.getCode());
            }
            body.set(createSOAP12FaultFromExceptionResponse(response.getException()));
            N52XmlHelper.setSchemaLocationsToDocument(envelopeDoc, Sets.newHashSet(N52XmlHelper.getSchemaLocationForSOAP12(), N52XmlHelper.getSchemaLocationForOWS110Exception()));
        } else {
            action = response.getSoapAction();
            final XmlObject bodyContent = getBodyContent(response);
            String value = null;
            Node nodeToRemove = null;
            final NamedNodeMap attributeMap = bodyContent.getDomNode().getFirstChild().getAttributes();
            for (int i = 0; i < attributeMap.getLength(); i++) {
                final Node node = attributeMap.item(i);
                if (node.getLocalName().equals(W3CConstants.AN_SCHEMA_LOCATION)) {
                    value = node.getNodeValue();
                    nodeToRemove = node;
                }
            }
            if (nodeToRemove != null) {
                attributeMap.removeNamedItem(nodeToRemove.getNodeName());
            }
            final Set<SchemaLocation> schemaLocations = Sets.newHashSet();
            schemaLocations.add(N52XmlHelper.getSchemaLocationForSOAP12());
            if (value != null && !value.isEmpty()) {
                String[] split = value.split(" ");
                for (int i = 0; i < split.length; i += 2) {
                    schemaLocations.add(new SchemaLocation(split[i], split[i + 1]));
                }
            }
            N52XmlHelper.setSchemaLocationsToDocument(envelopeDoc, schemaLocations);
            body.set(bodyContent);
        }
    }
    if (response.getHeader() != null) {
        createSOAP12Header(envelope, response.getHeader(), action);
    } else {
        envelope.addNewHeader();
    }
    // checkAndValidateSoapMessage(envelopeDoc);
    return envelopeDoc;
}
Also used : SchemaLocation(org.n52.shetland.w3c.SchemaLocation) EnvelopeDocument(org.w3.x2003.x05.soapEnvelope.EnvelopeDocument) NamedNodeMap(org.w3c.dom.NamedNodeMap) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) Node(org.w3c.dom.Node) XmlObject(org.apache.xmlbeans.XmlObject) XmlString(org.apache.xmlbeans.XmlString) Envelope(org.w3.x2003.x05.soapEnvelope.Envelope) Body(org.w3.x2003.x05.soapEnvelope.Body)

Example 39 with EncodingContext

use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.

the class SosRequestEncoderv20 method encode.

@Override
public XmlObject encode(OwsServiceRequest request, EncodingContext additionalValues) throws EncodingException {
    XmlObject encodedObject = encodeRequests(request);
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlObject(org.apache.xmlbeans.XmlObject)

Example 40 with EncodingContext

use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.

the class GmlEncoderv321 method createAbstractGeometry.

private AbstractGeometryType createAbstractGeometry(AbstractGeometry element, EncodingContext ctx) throws EncodingException {
    XmlObject xbGeometry = createPosition(element.getGeometry(), ctx);
    AbstractGeometryType abstractGeometryType = null;
    if (xbGeometry instanceof AbstractGeometryType) {
        abstractGeometryType = (AbstractGeometryType) xbGeometry;
    } else if (xbGeometry instanceof GeometryPropertyType) {
        abstractGeometryType = ((GeometryPropertyType) xbGeometry).getAbstractGeometry();
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    if (element.isSetIdentifier()) {
        abstractGeometryType.setIdentifier(createCodeWithAuthorityType(element.getIdentifierCodeWithAuthority()));
    }
    if (element.isSetName()) {
        for (org.n52.shetland.ogc.gml.CodeType codeType : element.getName()) {
            abstractGeometryType.addNewName().set(createCodeType(codeType));
        }
    }
    if (element.isSetDescription()) {
        abstractGeometryType.addNewDescription().setStringValue(element.getDescription());
    }
    return abstractGeometryType;
}
Also used : AbstractGeometryType(net.opengis.gml.x32.AbstractGeometryType) XmlObject(org.apache.xmlbeans.XmlObject) GeometryPropertyType(net.opengis.gml.x32.GeometryPropertyType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Aggregations

EncodingException (org.n52.svalbard.encode.exception.EncodingException)26 XmlObject (org.apache.xmlbeans.XmlObject)24 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)15 XmlException (org.apache.xmlbeans.XmlException)9 XMLStreamException (javax.xml.stream.XMLStreamException)6 OmObservation (org.n52.shetland.ogc.om.OmObservation)6 Supplier (java.util.function.Supplier)5 Time (org.n52.shetland.ogc.gml.time.Time)5 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 AbstractCRSType (net.opengis.gml.x32.AbstractCRSType)4 CodeType (net.opengis.gml.x32.CodeType)4 FeaturePropertyType (net.opengis.gml.x32.FeaturePropertyType)4 DateTime (org.joda.time.DateTime)4 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)4 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 AbstractGeometryType (net.opengis.gml.x32.AbstractGeometryType)3 GeometryPropertyType (net.opengis.gml.x32.GeometryPropertyType)3