use of org.geotoolkit.wps.xml.ReferenceProxy in project geotoolkit by Geomatys.
the class GMLAdaptor method toWPS2Input.
@Override
public DataInput toWPS2Input(Object candidate) throws UnconvertibleObjectException {
if (candidate instanceof ReferenceProxy)
return super.toWPS2Input(candidate);
final ComplexData cdt = new ComplexData();
cdt.getContent().add(new org.geotoolkit.wps.xml.v200.Format(encoding, mimeType, schema, null));
final JAXPStreamFeatureWriter writer = new JAXPStreamFeatureWriter(gmlVersion, null, null);
try {
if (ENC_BASE64.equalsIgnoreCase(encoding)) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
writer.write(candidate, out);
out.flush();
String base64 = Base64.getEncoder().encodeToString(out.toByteArray());
cdt.getContent().add(base64);
} else if (ENC_UTF8.equalsIgnoreCase(encoding)) {
final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
final DocumentBuilder constructeur = fabrique.newDocumentBuilder();
final Document document = constructeur.newDocument();
final DOMResult domResult = new DOMResult(document);
writer.write(candidate, domResult);
cdt.getContent().add(document.getDocumentElement());
}
} catch (IOException | XMLStreamException | DataStoreException | ParserConfigurationException ex) {
throw new UnconvertibleObjectException(ex.getMessage(), ex);
}
final Data data = new Data();
data.getContent().add(cdt);
final DataInput dit = new DataInput();
dit.setData(data);
return dit;
}
use of org.geotoolkit.wps.xml.ReferenceProxy in project geotoolkit by Geomatys.
the class OctetStreamAdaptor method toWPS2Input.
@Override
public DataInput toWPS2Input(Path candidate) throws UnconvertibleObjectException {
if (candidate instanceof ReferenceProxy)
return super.toWPS2Input(candidate);
final byte[] bytes;
try {
bytes = Files.readAllBytes(candidate);
} catch (IOException ex) {
throw new UnconvertibleObjectException(ex.getMessage(), ex);
}
final String base64 = Base64.getEncoder().encodeToString(bytes);
final DataInput dit = new DataInput();
final Data data = new Data();
data.setEncoding("base64");
data.getContent().add(base64);
dit.setData(data);
return dit;
}
use of org.geotoolkit.wps.xml.ReferenceProxy in project geotoolkit by Geomatys.
the class WKTAdaptor method toWPS2Input.
@Override
public DataInput toWPS2Input(Object candidate) throws UnconvertibleObjectException {
if (candidate instanceof ReferenceProxy)
return super.toWPS2Input(candidate);
final ComplexData cdt = new ComplexData();
cdt.getContent().add(new org.geotoolkit.wps.xml.v200.Format(encoding, mimeType, null, null));
Geometry geom = (Geometry) candidate;
int srid = 0;
int dimension = 2;
try {
CoordinateReferenceSystem crs = Geometries.wrap(geom).get().getCoordinateReferenceSystem();
if (crs != null) {
dimension = crs.getCoordinateSystem().getDimension();
final IdentifiedObjectFinder finder = IdentifiedObjects.newFinder("EPSG");
// TODO: Ensure no project strongly rely on that, then remove. It's pure non-sense/madness.
// Note: If you read this after march 2020: do not ask : delete.
finder.setIgnoringAxes(true);
final CoordinateReferenceSystem epsgcrs = (CoordinateReferenceSystem) finder.findSingleton(crs);
if (epsgcrs != null) {
srid = IdentifiedObjects.lookupEPSG(epsgcrs);
// force geometry in longitude first
final CoordinateReferenceSystem crs2 = ((AbstractCRS) crs).forConvention(AxesConvention.RIGHT_HANDED);
if (crs2 != crs) {
geom = org.apache.sis.internal.feature.jts.JTS.transform(geom, crs2);
}
if (crs2 != null)
dimension = crs2.getCoordinateSystem().getDimension();
}
}
} catch (FactoryException | MismatchedDimensionException | TransformException ex) {
throw new UnconvertibleObjectException(ex.getMessage(), ex);
}
// String wkt = geom.toText();
WKTWriter writer = new WKTWriter(dimension);
String wkt = writer.write(geom);
if (srid > 0) {
wkt = "SRID=" + srid + ";" + wkt;
}
cdt.getContent().add(wkt);
final Data data = new Data();
data.getContent().add(cdt);
final DataInput dit = new DataInput();
dit.setData(data);
return dit;
}
use of org.geotoolkit.wps.xml.ReferenceProxy in project geotoolkit by Geomatys.
the class XMLAdaptor method toWPS2Input.
@Override
public DataInput toWPS2Input(Node candidate) throws UnconvertibleObjectException {
if (candidate instanceof ReferenceProxy) {
return super.toWPS2Input(candidate);
}
final ComplexData cdt = new ComplexData();
cdt.getContent().add(new org.geotoolkit.wps.xml.v200.Format(encoding, mimeType, schema, null));
if (candidate instanceof Document) {
candidate = ((Document) candidate).getDocumentElement();
}
cdt.getContent().add(candidate);
final Data data = new Data();
data.getContent().add(cdt);
final DataInput dit = new DataInput();
dit.setData(data);
return dit;
}
use of org.geotoolkit.wps.xml.ReferenceProxy in project geotoolkit by Geomatys.
the class ComplexAdaptor method toWPS2Input.
/**
* Convert java object to WPS-2 input.
*
* <p>
* Default implementation of this method only support objects of type Reference.
* </p>
*
* @param candidate
* @return
*/
@Override
public DataInput toWPS2Input(T candidate) throws UnconvertibleObjectException {
if (candidate instanceof ReferenceProxy) {
final Reference reference = ((ReferenceProxy) candidate).getReference();
final Reference ref;
if (reference instanceof Reference) {
ref = (Reference) reference;
} else {
ref = new Reference();
ref.setHref(reference.getHref());
ref.setEncoding(reference.getEncoding());
ref.setMimeType(reference.getMimeType());
ref.setSchema(reference.getSchema());
ref.setBody(reference.getBody());
}
final DataInput dit = new DataInput();
dit.setReference(ref);
return dit;
}
throw new UnconvertibleObjectException("Unsupported value.");
}
Aggregations