protected void marshallEncryptionDocument(EncryptionDocument ed, LittleEndianByteArrayOutputStream os) { XmlOptions xo = new XmlOptions(); xo.setCharacterEncoding("UTF-8"); Map<String,String> nsMap = new HashMap<>(); nsMap.put(passwordUri.toString(),"p"); nsMap.put(certificateUri.toString(), "c"); xo.setUseDefaultNamespace(); xo.setSaveSuggestedPrefixes(nsMap); xo.setSaveNamespacesFirst(); xo.setSaveAggressiveNamespaces(); // setting standalone doesn't work with xmlbeans-2.3 & 2.6 // ed.documentProperties().setStandalone(true); xo.setSaveNoXmlDecl(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { bos.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n".getBytes("UTF-8")); ed.save(bos, xo); bos.writeTo(os); } catch (IOException e) { throw new EncryptedDocumentException("error marshalling encryption info document", e); } }
public void setSaveNoXmlDecl(boolean b) { if (b) super.setSaveNoXmlDecl(); else remove( SAVE_NO_XML_DECL ); }
public void setSaveNoXmlDecl(boolean b) { if (b) super.setSaveNoXmlDecl(); else remove( SAVE_NO_XML_DECL ); }
public void setSaveNoXmlDecl(boolean b) { if (b) super.setSaveNoXmlDecl(); else remove( SAVE_NO_XML_DECL ); }
request.save(writer, new XmlOptions().setCharacterEncoding("UTF-8").setSaveNoXmlDecl());
protected void marshallEncryptionDocument(EncryptionDocument ed, LittleEndianByteArrayOutputStream os) { XmlOptions xo = new XmlOptions(); xo.setCharacterEncoding("UTF-8"); Map<String,String> nsMap = new HashMap<>(); nsMap.put(passwordUri.toString(),"p"); nsMap.put(certificateUri.toString(), "c"); xo.setUseDefaultNamespace(); xo.setSaveSuggestedPrefixes(nsMap); xo.setSaveNamespacesFirst(); xo.setSaveAggressiveNamespaces(); // setting standalone doesn't work with xmlbeans-2.3 & 2.6 // ed.documentProperties().setStandalone(true); xo.setSaveNoXmlDecl(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { bos.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n".getBytes("UTF-8")); ed.save(bos, xo); bos.writeTo(os); } catch (IOException e) { throw new EncryptedDocumentException("error marshalling encryption info document", e); } }
@Override public InputStream generateStream(IData data, String mimeType, String schema) throws IOException { if(data instanceof GenericXMLDataBinding){ XmlObject xmlData = ((GenericXMLDataBinding)data).getPayload(); XmlOptions xmlOptions = new XmlOptions(); xmlOptions.setSaveNoXmlDecl(); return xmlData.newInputStream(xmlOptions); } return XmlObject.Factory.newInstance().newInputStream(); }
xmlSaveOptions = xmlSaveOptions.setSaveNoXmlDecl();
@SuppressWarnings("unchecked") private void writeObservationData(EncodingContext ctx, OmObservation observation, ObservationEncoder<XmlObject, OmObservation> encoder) throws XMLStreamException, EncodingException { start(Sos2StreamingConstants.OBSERVATION_DATA); if (encoder instanceof StreamingEncoder) { ((StreamingEncoder<XmlObject, OmObservation>) encoder).encode(observation, getOutputStream(), ctx); } else { rawText(encoder.encode(observation, ctx).xmlText(getXmlOptions().setSaveNoXmlDecl())); } end(Sos2StreamingConstants.OBSERVATION_DATA); }
@SuppressWarnings("unchecked") private void writeObservationData(EncodingContext ctx, OmObservation observation, ObservationEncoder<XmlObject, OmObservation> encoder) throws XMLStreamException, EncodingException { start(Sos2StreamingConstants.OBSERVATION_DATA); if (encoder instanceof StreamingEncoder) { ((StreamingEncoder<XmlObject, OmObservation>) encoder).encode(observation, getOutputStream(), ctx); } else { rawText(encoder.encode(observation, ctx).xmlText(getXmlOptions().setSaveNoXmlDecl())); } end(Sos2StreamingConstants.OBSERVATION_DATA); }
public static InputStream createInputStream(XmlObject xmlObject, boolean writeXMLDeclaration) throws GenericException, ValidationException { // Create an XmlOptions instance and set the error listener. XmlOptions validateOptions = new XmlOptions(); List<XmlValidationError> errorList = new ArrayList<>(); validateOptions.setErrorListener(errorList); // Validate the XML. boolean isValid = xmlObject.validate(validateOptions); if (isValid) { XmlOptions xmlSaveOptions = new XmlOptions().setUseDefaultNamespace().setSavePrettyPrint() .setSaveAggressiveNamespaces(); if (!writeXMLDeclaration) { xmlSaveOptions = xmlSaveOptions.setSaveNoXmlDecl(); } return xmlObject.newInputStream(xmlSaveOptions); } else { throw new ValidationException(xmlValidationErrorsToValidationReport(errorList)); } }
@Override public void encode(Object objectToEncode, OutputStream outputStream, EncodingContext ctx) throws EncodingException { try { XmlOptions xmlOptions = getXmlOptions(); if (ctx.has(StreamingEncoderFlags.EMBEDDED)) { xmlOptions.setSaveNoXmlDecl(); } encode(objectToEncode, ctx.with(StreamingEncoderFlags.ENCODER, this)) .save(outputStream, xmlOptions); } catch (IOException ioe) { throw new EncodingException("Error while writing element to stream!", ioe); } finally { if (ctx.has(StreamingEncoderFlags.EMBEDDED)) { getXmlOptions().remove(XmlOptions.SAVE_NO_XML_DECL); } } }
/** * Override this method in concrete response encoder if streaming is supported for this operations. * * @param response Implementation of {@link OwsServiceResponse} * @param outputStream {@link OutputStream} to write * @param encodingValues {@link EncodingValues} with additional indicators for encoding * * @throws EncodingException If an error occurs during encoding/writing to stream */ protected void create(T response, OutputStream outputStream, EncodingContext encodingValues) throws EncodingException { try { XmlOptions xmlOptions; if (encodingValues.has(StreamingEncoderFlags.EMBEDDED)) { xmlOptions = new XmlOptions(getXmlOptions()); xmlOptions.setSaveNoXmlDecl(); } else { xmlOptions = getXmlOptions(); } XmlObject xmlObject = create(response); setSchemaLocations(xmlObject); xmlObject.save(outputStream, xmlOptions); } catch (IOException ioe) { throw new EncodingException("Error while writing element to stream!", ioe); } }
@Override public void encode(Object element, OutputStream outputStream, EncodingValues encodingValues) throws OwsExceptionReport { try { if (element instanceof OmObservation && InspireOMSOConstants.OBS_TYPE_POINT_TIME_SERIES_OBSERVATION .equals(((OmObservation) element).getObservationConstellation().getObservationType())) { new PointTimeSeriesObservationXmlStreamWriter().write((OmObservation)element, outputStream, encodingValues); } else { XmlOptions xmlOptions = getXmlOptions(); if (encodingValues.isEmbedded()) { xmlOptions.setSaveNoXmlDecl(); } // writeIndent(encodingValues.getIndent(), outputStream); encode(element, encodingValues.getAdditionalValues()).save(outputStream, xmlOptions); } } catch (IOException ioe) { throw new NoApplicableCodeException().causedBy(ioe).withMessage("Error while writing element to stream!"); } catch (XMLStreamException xmlse) { throw new NoApplicableCodeException().causedBy(xmlse) .withMessage("Error while writing element to stream!"); } finally { if (encodingValues.isEmbedded()) { getXmlOptions().remove(XmlOptions.SAVE_NO_XML_DECL); } } }