Search in sources :

Example 1 with JAXBFeatureTypeWriter

use of org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter in project geotoolkit by Geomatys.

the class XmlFeatureTypeTest method testWriteComplexFeatureType.

@Test
public void testWriteComplexFeatureType() throws JAXBException, IOException, ParserConfigurationException, SAXException {
    final StringWriter sw = new StringWriter();
    final JAXBFeatureTypeWriter writer = new JAXBFeatureTypeWriter();
    writer.write(complexType, sw);
    DomCompare.compare(XmlFeatureTypeTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/ComplexType.xsd"), sw.toString());
}
Also used : StringWriter(java.io.StringWriter) JAXBFeatureTypeWriter(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter)

Example 2 with JAXBFeatureTypeWriter

use of org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter in project geotoolkit by Geomatys.

the class XmlFeatureTypeTest method testWriteSimpleGeomFeatureType.

@Test
public void testWriteSimpleGeomFeatureType() throws JAXBException, IOException, ParserConfigurationException, SAXException {
    final StringWriter sw = new StringWriter();
    final JAXBFeatureTypeWriter writer = new JAXBFeatureTypeWriter();
    writer.write(simpleTypeGeom, sw);
    DomCompare.compare(XmlFeatureTypeTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleGeomType.xsd"), sw.toString());
}
Also used : StringWriter(java.io.StringWriter) JAXBFeatureTypeWriter(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter)

Example 3 with JAXBFeatureTypeWriter

use of org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter in project geotoolkit by Geomatys.

the class XmlFeatureTypeTest method testWriteMultiGeomFeatureType.

@Test
public void testWriteMultiGeomFeatureType() throws JAXBException, IOException, ParserConfigurationException, SAXException {
    final StringWriter sw = new StringWriter();
    final JAXBFeatureTypeWriter writer = new JAXBFeatureTypeWriter();
    writer.write(multiGeomType, sw);
    DomCompare.compare(XmlFeatureTypeTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/MultiGeomType.xsd"), sw.toString());
}
Also used : StringWriter(java.io.StringWriter) JAXBFeatureTypeWriter(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter)

Example 4 with JAXBFeatureTypeWriter

use of org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter in project geotoolkit by Geomatys.

the class FeatureTypeToReferenceConverter method convert.

/**
 * {@inheritDoc}
 */
@Override
public Reference convert(final FeatureType source, final Map<String, Object> params) throws UnconvertibleObjectException {
    if (params.get(TMP_DIR_PATH) == null) {
        throw new UnconvertibleObjectException("The output directory should be defined.");
    }
    if (source == null) {
        throw new UnconvertibleObjectException("The output directory should be defined.");
    }
    Reference reference = new Reference();
    reference.setMimeType((String) params.get(MIME));
    reference.setEncoding((String) params.get(ENCODING));
    reference.setSchema((String) params.get(SCHEMA));
    reference.setMimeType((String) params.get(MIME));
    reference.setEncoding((String) params.get(ENCODING));
    final String randomFileName = UUID.randomUUID().toString();
    // Write FeatureType
    try {
        final String schemaFileName = randomFileName + "_schema" + ".xsd";
        // create file
        final Path schemaFile = buildPath(params, schemaFileName);
        final OutputStream schemaStream = Files.newOutputStream(schemaFile);
        // write featureType xsd on file
        final JAXBFeatureTypeWriter xmlFTWriter = new JAXBFeatureTypeWriter();
        xmlFTWriter.write(source, schemaStream);
        final String relLoc = getRelativeLocation(schemaFile, params);
        reference.setHref((String) params.get(TMP_DIR_URL) + "/" + relLoc);
    } catch (JAXBException ex) {
        throw new UnconvertibleObjectException("Can't write FeatureType into xsd schema.", ex);
    } catch (IOException ex) {
        throw new UnconvertibleObjectException("Can't create xsd schema file.", ex);
    }
    return reference;
}
Also used : Path(java.nio.file.Path) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Reference(org.geotoolkit.wps.xml.v200.Reference) JAXBException(javax.xml.bind.JAXBException) JAXBFeatureTypeWriter(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter)

Example 5 with JAXBFeatureTypeWriter

use of org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter in project geotoolkit by Geomatys.

the class FeatureTypeToComplexConverter method convert.

/**
 * {@inheritDoc}
 */
@Override
public Data convert(final FeatureType source, final Map<String, Object> params) throws UnconvertibleObjectException {
    if (source == null) {
        throw new UnconvertibleObjectException("The output data should be defined.");
    }
    final Data complex = new Data();
    final Object tmpEncoding = params == null ? null : params.get(ENCODING);
    if (tmpEncoding instanceof String) {
        complex.setEncoding((String) tmpEncoding);
    }
    complex.setMimeType(WPSMimeType.TEXT_GML.val());
    try {
        final JAXBFeatureTypeWriter xmlWriter = new JAXBFeatureTypeWriter();
        complex.getContent().add(xmlWriter.writeToElement(source));
    } catch (JAXBException | ParserConfigurationException ex) {
        throw new UnconvertibleObjectException("Can't write FeatureType into ResponseDocument.", ex);
    }
    return complex;
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) JAXBException(javax.xml.bind.JAXBException) Data(org.geotoolkit.wps.xml.v200.Data) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) JAXBFeatureTypeWriter(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter)

Aggregations

JAXBFeatureTypeWriter (org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter)7 StringWriter (java.io.StringWriter)4 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)3 Path (java.nio.file.Path)2 JAXBException (javax.xml.bind.JAXBException)2 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 GeoJSONObject (org.geotoolkit.internal.geojson.binding.GeoJSONObject)1 Data (org.geotoolkit.wps.xml.v200.Data)1 Reference (org.geotoolkit.wps.xml.v200.Reference)1