public static void fixNamespaceForXsiType(XmlObject content, Map<?, ?> namespaces) { final XmlCursor cursor = content.newCursor(); while (cursor.hasNextToken()) { if (cursor.toNextToken().isStart()) { final String xsiType = cursor.getAttributeText(W3CConstants.QN_XSI_TYPE); if (xsiType != null) { final String[] toks = xsiType.split(":"); if (toks.length > 1) { String prefix = toks[0]; String localName = toks[1]; String namespace = (String) namespaces.get(prefix); if (Strings.isNullOrEmpty(namespace)) { namespace = CodingRepository.getInstance().getNamespaceFor(prefix); } if (StringHelper.isNotEmpty(namespace)) { cursor.setAttributeText( W3CConstants.QN_XSI_TYPE, Joiner.on(Constants.COLON_CHAR) .join( XmlHelper.getPrefixForNamespace(content, (String) namespaces.get(prefix)), localName)); } } } } } cursor.dispose(); }
/** * Get the content for the SOAPBody as {@link XmlObject} * * @param response SOAP response * @return SOAPBody content as {@link XmlObject} * @throws OwsExceptionReport If no encoder is available, the object to encode is not supported or * an error occurs during the encoding */ protected XmlObject getBodyContent(SoapResponse response) throws OwsExceptionReport { if (response.isSetXmlBodyContent()) { return response.getSoapBodyContent(); } OperationEncoderKey key = new OperationEncoderKey( response.getBodyContent().getOperationKey(), MediaTypes.APPLICATION_XML); Encoder<Object, AbstractServiceResponse> encoder = CodingRepository.getInstance().getEncoder(key); if (encoder == null) { throw new NoEncoderForKeyException(key); } return (XmlObject) encoder.encode(response.getBodyContent()); }
/** * Finds a O&Mv2 compatible {@link ObservationEncoder} * * @param responseFormat the response format * @return the encoder or {@code null} if none is found * @throws OwsExceptionReport if the found encoder is not a {@linkplain ObservationEncoder} */ private ObservationEncoder<XmlObject, OmObservation> findObservationEncoder(String responseFormat) throws OwsExceptionReport { Encoder<XmlObject, OmObservation> encoder = CodingRepository.getInstance() .getEncoder(new XmlEncoderKey(responseFormat, OmObservation.class)); if (encoder == null) { return null; } else if (encoder instanceof ObservationEncoder) { ObservationEncoder<XmlObject, OmObservation> oe = (ObservationEncoder<XmlObject, OmObservation>) encoder; return oe.isObservationAndMeasurmentV20Type() ? oe : null; } else { throw new NoApplicableCodeException() .withMessage("Error while encoding response, encoder is not of type ObservationEncoder!"); } }
/** * Finds a compatible response encoder to delegate to. * * @param responseFormat the response format * @return the encoder or {@code null} if no encoder was found */ private Encoder<XmlObject, T> findResponseEncoder(String responseFormat) { return CodingRepository.getInstance() .getEncoder(new XmlEncoderKey(responseFormat, getResponseType())); }