use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.
the class N52XmlHelper method setSchemaLocationToDocument.
/**
* Sets the schema location to a XmlObject
*
* @param document
* XML document
* @param schemaLocations
* schema location
*/
public static void setSchemaLocationToDocument(XmlObject document, String schemaLocations) {
XmlCursor cursor = document.newCursor();
if (cursor.toFirstChild()) {
cursor.setAttributeText(getSchemaLocationQName(), schemaLocations);
}
cursor.dispose();
}
use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.
the class XmlHelper method getPrefixForNamespace.
public static String getPrefixForNamespace(XmlObject element, String namespace) {
final XmlCursor cursor = element.newCursor();
final String prefix = cursor.prefixForNamespace(namespace);
cursor.dispose();
return prefix;
}
use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.
the class XmlHelper method getNamespaces.
public static Map<?, ?> getNamespaces(XmlObject xmlObject) {
XmlCursor cursor = xmlObject.newCursor();
Map<?, ?> nsMap = Maps.newHashMap();
cursor.getAllNamespaces(nsMap);
cursor.dispose();
return nsMap;
}
use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.
the class XmlHelper method removeElement.
/**
* Remove the element from XML document
*
* @param element
* Element to remove
* @return <code>true</code>, if element is removed
*/
public static boolean removeElement(XmlObject element) {
XmlCursor cursor = element.newCursor();
boolean removed = cursor.removeXml();
cursor.dispose();
return removed;
}
use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.
the class SosDecoderv20 method parseInsertObservation.
private OwsServiceRequest parseInsertObservation(final InsertObservationDocument insertObservationDoc) throws DecodingException {
// set namespace for default XML type (e.g. xs:string, xs:integer,
// xs:boolean, ...)
// Fix for problem with XmlBeans: namespace is not set in child elements
// when defined in root of request (SOAP)
final XmlCursor cursor = insertObservationDoc.newCursor();
if (cursor.toFirstChild() && cursor.namespaceForPrefix(W3CConstants.NS_XS_PREFIX) == null) {
cursor.prefixForNamespace(W3CConstants.NS_XS);
}
cursor.dispose();
final InsertObservationRequest insertObservationRequest = new InsertObservationRequest();
final InsertObservationType insertObservationType = insertObservationDoc.getInsertObservation();
insertObservationRequest.setService(insertObservationType.getService());
insertObservationRequest.setVersion(insertObservationType.getVersion());
if (insertObservationDoc.getInsertObservation().getOfferingArray() != null) {
insertObservationRequest.setOfferings(Arrays.asList(insertObservationType.getOfferingArray()));
}
insertObservationRequest.setExtensions(parseExtensibleRequest(insertObservationType));
if (insertObservationType.getObservationArray() != null) {
final int length = insertObservationType.getObservationArray().length;
final Map<String, Time> phenomenonTimes = new HashMap<>(length);
final Map<String, TimeInstant> resultTimes = new HashMap<>(length);
final Map<String, AbstractFeature> features = new HashMap<>(length);
CompositeException exceptions = new CompositeException();
for (final Observation observation : insertObservationType.getObservationArray()) {
final Object decodedObject = decodeXmlElement(observation.getOMObservation());
if (decodedObject instanceof OmObservation) {
final OmObservation sosObservation = (OmObservation) decodedObject;
checkAndAddPhenomenonTime(sosObservation.getPhenomenonTime(), phenomenonTimes);
checkAndAddResultTime(sosObservation.getResultTime(), resultTimes);
checkAndAddFeatures(sosObservation.getObservationConstellation().getFeatureOfInterest(), features);
insertObservationRequest.addObservation(sosObservation);
} else {
exceptions.add(new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested observation type (%s) is not supported by this server!", observation.getOMObservation().getDomNode().getNodeName()));
}
}
checkReferencedElements(insertObservationRequest.getObservations(), phenomenonTimes, resultTimes, features);
try {
exceptions.throwIfNotEmpty();
} catch (CompositeException ex) {
throw new DecodingException(ex, Sos2Constants.InsertObservationParams.observation);
}
} else {
// TODO MissingMandatoryParameterException?
throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The request does not contain an observation");
}
return insertObservationRequest;
}
Aggregations