org.exolab.castor.xml.Marshaller.setWriter()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(216)

本文整理了Java中org.exolab.castor.xml.Marshaller.setWriter()方法的一些代码示例,展示了Marshaller.setWriter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Marshaller.setWriter()方法的具体详情如下:
包路径:org.exolab.castor.xml.Marshaller
类名称:Marshaller
方法名:setWriter

Marshaller.setWriter介绍

[英]Sets the java.io.Writer to be used during marshalling.
[中]设置java。伊奥。编组时使用的书写器。

代码示例

代码示例来源:origin: apache/servicemix-bundles

  1. @Override
  2. protected void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
  3. Assert.state(this.xmlContext != null, "CastorMarshaller not initialized");
  4. Marshaller marshaller = this.xmlContext.createMarshaller();
  5. marshaller.setWriter(writer);
  6. doMarshal(graph, marshaller);
  7. }

代码示例来源:origin: org.codehaus.castor/castor-xml

  1. /**
  2. * Creates a new {@link Marshaller} with the given writer.
  3. *
  4. * @param out the {@link Writer} to serialise to.
  5. * @throws IllegalArgumentException if the given {@link Writer} is null
  6. * @throws IOException If the given {@link Writer} instance cannot be opened.
  7. * @deprecate Please use {@link XMLContext#createMarshaller()} and
  8. * {@link Marshaller#setWriter(Writer)} instead
  9. *
  10. * @see {@link XMLContext#createMarshaller()}
  11. * @see {@link Marshaller#setWriter(Writer)}
  12. * @see XMLContext
  13. *
  14. **/
  15. public Marshaller(final Writer out) throws IOException {
  16. super(null);
  17. setWriter(out);
  18. }

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

  1. /**
  2. * Creates a new Marshaller with the given writer.
  3. * @param out the Writer to serialize to
  4. **/
  5. public Marshaller( Writer out )
  6. throws IOException
  7. {
  8. initialize();
  9. setWriter(out);
  10. } //-- Marshaller

代码示例来源:origin: mbechler/marshalsec

  1. /**
  2. * {@inheritDoc}
  3. *
  4. * @see marshalsec.MarshallerBase#marshal(java.lang.Object)
  5. */
  6. @Override
  7. public String marshal ( Object o ) throws Exception {
  8. XMLContext context = new XMLContext();
  9. Marshaller m = context.createMarshaller();
  10. StringWriter sw = new StringWriter();
  11. m.setWriter(sw);
  12. return sw.toString();
  13. }

代码示例来源:origin: org.apache.camel/camel-castor

  1. public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
  2. Writer writer = new OutputStreamWriter(outputStream, encoding);
  3. Marshaller marshaller = createMarshaller(exchange);
  4. marshaller.setWriter(writer);
  5. marshaller.marshal(body);
  6. if (contentTypeHeader) {
  7. if (exchange.hasOut()) {
  8. exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/xml");
  9. } else {
  10. exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/xml");
  11. }
  12. }
  13. }

代码示例来源:origin: org.springframework.ws/spring-oxm

  1. protected final void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
  2. Marshaller marshaller = xmlContext.createMarshaller();
  3. marshaller.setWriter(writer);
  4. marshal(graph, marshaller);
  5. }

代码示例来源:origin: org.codehaus.castor/castor-xml

  1. setWriter(streamResult.getWriter());
  2. return;
  3. } else if (streamResult.getOutputStream() != null) {
  4. setWriter(new PrintWriter(streamResult.getOutputStream()));
  5. return;

代码示例来源:origin: com.github.muff1nman.chameleon/core

  1. /**
  2. * Writes the specified object as an XML stream to an output writer.
  3. * @param o the object to serialize.
  4. * @param out the writer.
  5. * @param asDocument if <code>true</code>, indicates to marshal as a complete XML document, which includes the XML declaration, and if necessary the DOCTYPE declaration.
  6. * @throws MappingException an exception indicating an invalid mapping error.
  7. * @throws org.exolab.castor.xml.MarshalException a marshalling exception.
  8. * @throws org.exolab.castor.xml.ValidationException an XML validation error occurred.
  9. * @throws NullPointerException if <code>o</code> is <code>null</code>.
  10. * @throws NullPointerException if <code>out</code> is <code>null</code>.
  11. * @see Mapping
  12. */
  13. public void marshal(final Object o, final Writer out, final boolean asDocument) throws Exception
  14. {
  15. synchronized(_marshaller)
  16. {
  17. _marshaller.setWriter(out); // May throw IOException.
  18. _marshaller.setMarshalAsDocument(asDocument);
  19. _marshaller.setEncoding("ISO-8859-1");
  20. // Do not use marshal(Object object, Writer out): IT DOESN'T WORK !!!
  21. _marshaller.marshal(o); // May throw MarshalException, ValidationException.
  22. }
  23. }

代码示例来源:origin: org.codehaus.castor/castor-xml

  1. public static void main(String[] args) {
  2. // TODO: add CommandLineOptions
  3. // options needed
  4. // 1. filename/path of CHANGELOG
  5. // 2. mapping file for customization
  6. // 3. output file name
  7. XMLContext xmlContext = new XMLContext();
  8. ChangeLog2XML parser = xmlContext.createChangeLog2XML();
  9. try {
  10. File file = new File(DEFAULT_FILE);
  11. Changelog changelog = parser.parse(file);
  12. file = new File(DEFAULT_OUTPUT);
  13. FileWriter writer = new FileWriter(file);
  14. xmlContext.setProperty(XMLProperties.USE_INDENTATION, true);
  15. Marshaller marshaller = xmlContext.createMarshaller();
  16. marshaller.setWriter(writer);
  17. marshaller.setRootElement("changelog");
  18. marshaller.setSuppressXSIType(true);
  19. marshaller.marshal(changelog);
  20. } catch (Exception ex) {
  21. ex.printStackTrace();
  22. }
  23. }

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

  1. public static void main(String[] args) {
  2. //TODO: add CommandLineOptions
  3. // options needed
  4. // 1. filename/path of CHANGELOG
  5. // 2. mapping file for customization
  6. // 3. output file name
  7. XMLContext xmlContext = new XMLContext();
  8. ChangeLog2XML parser = xmlContext.createChangeLog2XML();
  9. try {
  10. File file = new File(DEFAULT_FILE);
  11. Changelog changelog = parser.parse(file);
  12. file = new File(DEFAULT_OUTPUT);
  13. FileWriter writer = new FileWriter(file);
  14. xmlContext.setProperty(XMLConfiguration.USE_INDENTATION, true);
  15. Marshaller marshaller = xmlContext.createMarshaller();
  16. marshaller.setWriter(writer);
  17. marshaller.setRootElement("changelog");
  18. marshaller.setSuppressXSIType(true);
  19. marshaller.marshal(changelog);
  20. }
  21. catch(Exception ex) {
  22. ex.printStackTrace();
  23. }
  24. }

代码示例来源:origin: hmkcode/Java

  1. marshaller.setWriter(writer);

代码示例来源:origin: OpenClinica/OpenClinica

  1. Marshaller marshaller = xmlContext.createMarshaller();
  2. marshaller.setWriter(writer);
  3. marshaller.marshal(rpic);
  4. String result = writer.toString();

代码示例来源:origin: org.codehaus.castor/castor-testsuite-xml-framework

  1. private Marshaller createMarshaler(final File marshalOutput) throws Exception {
  2. getXMLContext().getInternalContext().getXMLClassDescriptorResolver().cleanDescriptorCache();
  3. Marshaller marshaller = getXMLContext().createMarshaller();
  4. marshaller.setWriter(new FileWriter(marshalOutput));
  5. // -- Configuration for marshaler? Use config from unit test case if available
  6. Configuration config = _unitTest.getConfiguration();
  7. if (config == null) {
  8. config = _configuration;
  9. }
  10. if (config != null) {
  11. ConfigurationType marshal = config.getMarshal();
  12. List returnValues = invokeEnumeratedMethods(marshaller, marshal);
  13. returnValues.clear(); // We don't care about the return values
  14. } // -- config != null
  15. if (_mapping != null) {
  16. marshaller.setMapping(_mapping);
  17. }
  18. if (_listener != null && _listener instanceof MarshalListener
  19. && _listenerType != TypeType.UNMARSHAL) {
  20. marshaller.setMarshalListener((MarshalListener) _listener);
  21. }
  22. return marshaller;
  23. }

代码示例来源:origin: OpenClinica/OpenClinica

  1. public String marshall(Html html) throws Exception {
  2. StringWriter writer = new StringWriter();
  3. xmlContext = new XMLContext();
  4. Mapping mapping = xmlContext.createMapping();
  5. mapping.loadMapping(coreResources.getURL("xformMapping.xml"));
  6. xmlContext.addMapping(mapping);
  7. Marshaller marshaller = xmlContext.createMarshaller();
  8. marshaller.setNamespaceMapping("h", "http://www.w3.org/1999/xhtml");
  9. marshaller.setNamespaceMapping("jr", "http://openrosa.org/javarosa");
  10. marshaller.setNamespaceMapping("xsd", "http://www.w3.org/2001/XMLSchema");
  11. marshaller.setNamespaceMapping("ev", "http://www.w3.org/2001/xml-events");
  12. marshaller.setNamespaceMapping("", "http://www.w3.org/2002/xforms");
  13. marshaller.setNamespaceMapping("enk", "http://enketo.org/xforms");
  14. marshaller.setNamespaceMapping("oc", "http://openclinica.org/xforms");
  15. marshaller.setWriter(writer);
  16. marshaller.marshal(html);
  17. String xform = writer.toString();
  18. return xform;
  19. }

相关文章