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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations