Search in sources :

Example 41 with XmlException

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

the class GetDataAvailabilityXmlEncoder method create.

@Override
protected XmlObject create(GetDataAvailabilityResponse response) throws EncodingException {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        EncodingContext ctx = EncodingContext.empty().with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
        if (GetDataAvailabilityConstants.NS_GDA.equals(response.getResponseFormat())) {
            new GetDataAvailabilityStreamWriter(ctx, baos, response.getDataAvailabilities()).write();
        } else if (GetDataAvailabilityConstants.NS_GDA_20.equals(response.getResponseFormat())) {
            new GetDataAvailabilityV20StreamWriter(ctx, baos, response.getDataAvailabilities()).write();
        }
        XmlObject encodedObject = XmlObject.Factory.parse(baos.toString("UTF8"));
        XmlHelper.validateDocument(encodedObject, EncodingException::new);
        return encodedObject;
    } catch (XMLStreamException | XmlException | UnsupportedEncodingException ex) {
        throw new EncodingException("Error encoding response", ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) GetDataAvailabilityV20StreamWriter(org.n52.svalbard.write.GetDataAvailabilityV20StreamWriter) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) XmlObject(org.apache.xmlbeans.XmlObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GetDataAvailabilityStreamWriter(org.n52.svalbard.write.GetDataAvailabilityStreamWriter)

Example 42 with XmlException

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

the class AqdEncoder method encodeEReportingHeader.

private XmlObject encodeEReportingHeader(EReportingHeader element, EncodingContext ctx) throws EncodingException {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
        new EReportingHeaderEncoder(context, baos, element).write();
        if (context.has(XmlStreamEncoderFlags.XML_WRITER)) {
            return null;
        }
        return XmlObject.Factory.parse(baos.toString("UTF8"));
    } catch (XMLStreamException | XmlException | UnsupportedEncodingException xmlse) {
        throw new EncodingException("Error encoding response", xmlse);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EReportingHeaderEncoder(org.n52.svalbard.write.EReportingHeaderEncoder)

Example 43 with XmlException

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

the class InspireXmlEncoder method encodeObject.

private XmlObject encodeObject(InspireObject objectToEncode, EncodingContext ctx) throws EncodingException {
    try {
        checkIfSupported(objectToEncode);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
        new InspireXmlStreamWriter(context, out, objectToEncode).write();
        String s = out.toString("UTF8");
        return XmlObject.Factory.parse(s);
    } catch (XMLStreamException | DateTimeFormatException | XmlException | UnsupportedEncodingException ex) {
        throw new EncodingException("Error encoding Inspire extended capabilities!", ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) InspireXmlStreamWriter(org.n52.svalbard.write.InspireXmlStreamWriter) DateTimeFormatException(org.n52.shetland.util.DateTimeFormatException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 44 with XmlException

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

the class SamplingEncoderv20 method createFeature.

@Override
protected XmlObject createFeature(FeaturePropertyType featurePropertyType, AbstractFeature abstractFeature, EncodingContext context) throws EncodingException {
    if (abstractFeature instanceof AbstractSamplingFeature) {
        final AbstractSamplingFeature samplingFeature = (AbstractSamplingFeature) abstractFeature;
        String namespace;
        if (context.has(XmlEncoderFlags.ENCODE_NAMESPACE) && context.get(XmlEncoderFlags.ENCODE_NAMESPACE).isPresent() && context.get(XmlEncoderFlags.ENCODE_NAMESPACE).get() instanceof String) {
            namespace = (String) context.get(XmlEncoderFlags.ENCODE_NAMESPACE).get();
        } else {
            namespace = OMHelper.getNamespaceForFeatureType(samplingFeature.getFeatureType());
        }
        final XmlObject encodedXmlObject = encodeObjectToXml(namespace, samplingFeature);
        if (encodedXmlObject != null) {
            return encodedXmlObject;
        } else {
            if (samplingFeature.isSetXml()) {
                try {
                    // XmlDescription? <-- XmlCursor
                    return XmlObject.Factory.parse(samplingFeature.getXml());
                } catch (final XmlException xmle) {
                    throw new EncodingException("Error while encoding featurePropertyType!", xmle);
                }
            } else {
                featurePropertyType.setHref(samplingFeature.getIdentifierCodeWithAuthority().getValue());
                if (samplingFeature.isSetName()) {
                    featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
                }
                return featurePropertyType;
            }
        }
    }
    return featurePropertyType;
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 45 with XmlException

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

the class SpecimenEncoderv20 method createSpecimen.

private XmlObject createSpecimen(SfSpecimen specimen) throws EncodingException {
    SFSpecimenDocument sfsd = SFSpecimenDocument.Factory.newInstance(getXmlOptions());
    if (specimen.isSetXml()) {
        try {
            final XmlObject feature = XmlObject.Factory.parse(specimen.getXml(), getXmlOptions());
            XmlHelper.updateGmlIDs(feature.getDomNode().getFirstChild(), specimen.getGmlId(), null);
            if (XmlHelper.getNamespace(feature).equals(SfConstants.NS_SPEC) && feature instanceof SFSpecimenType) {
                sfsd.setSFSpecimen((SFSpecimenType) feature);
                addName(sfsd.getSFSpecimen(), specimen);
                addDescription(sfsd.getSFSpecimen(), specimen);
                return sfsd;
            }
            addName(((SFSpecimenDocument) feature).getSFSpecimen(), specimen);
            addDescription(((SFSpecimenDocument) feature).getSFSpecimen(), specimen);
            return feature;
        } catch (final XmlException xmle) {
            throw new EncodingException("Error while encoding GetFeatureOfInterest response, invalid specimen description!", xmle);
        }
    }
    final SFSpecimenType sfst = sfsd.addNewSFSpecimen();
    // TODO: CHECK for all fields set gml:id
    addId(sfst, specimen);
    addIdentifier(sfst, specimen);
    // set type
    addFeatureType(sfst, specimen);
    addName(sfst, specimen);
    addDescription(sfst, specimen);
    // set sampledFeatures
    addSampledFeatures(sfst, specimen);
    addParameter(sfst, specimen);
    // set specimen specific data
    addMaterialClass(sfst, specimen);
    addSamplingTime(sfst, specimen);
    addSamplingMethod(sfst, specimen);
    addSamplingLocation(sfst, specimen);
    addProcessingDetails(sfst, specimen);
    addSize(sfst, specimen);
    addCurrentLocation(sfst, specimen);
    addSpecimenType(sfst, specimen);
    specimen.wasEncoded();
    return sfsd;
}
Also used : SFSpecimenType(net.opengis.samplingSpecimen.x20.SFSpecimenType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) SFSpecimenDocument(net.opengis.samplingSpecimen.x20.SFSpecimenDocument)

Aggregations

XmlException (org.apache.xmlbeans.XmlException)112 XmlObject (org.apache.xmlbeans.XmlObject)45 IOException (java.io.IOException)35 DecodingException (org.n52.svalbard.decode.exception.DecodingException)19 EncodingException (org.n52.svalbard.encode.exception.EncodingException)17 POIXMLException (org.apache.poi.POIXMLException)15 InputStream (java.io.InputStream)11 ArrayList (java.util.ArrayList)10 XmlCursor (org.apache.xmlbeans.XmlCursor)10 XmlOptions (org.apache.xmlbeans.XmlOptions)10 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)8 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)7 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)7 Geometry (org.locationtech.jts.geom.Geometry)6 Document (org.w3c.dom.Document)6 Node (org.w3c.dom.Node)6 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 File (java.io.File)5