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

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

本文整理了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

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

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

/**
 * Creates a new {@link Marshaller} with the given writer.
 * 
 * @param out the {@link Writer} to serialise to.
 * @throws IllegalArgumentException if the given {@link Writer} is null
 * @throws IOException If the given {@link Writer} instance cannot be opened.
 * @deprecate Please use {@link XMLContext#createMarshaller()} and
 *            {@link Marshaller#setWriter(Writer)} instead
 * 
 * @see {@link XMLContext#createMarshaller()}
 * @see {@link Marshaller#setWriter(Writer)}
 * @see XMLContext
 * 
 **/
public Marshaller(final Writer out) throws IOException {
 super(null);
 setWriter(out);
}

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

/**
 * Creates a new Marshaller with the given writer.
 * @param out the Writer to serialize to
**/
public Marshaller( Writer out )
  throws IOException
{
  initialize();
  setWriter(out);
} //-- Marshaller

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

/**
 * {@inheritDoc}
 *
 * @see marshalsec.MarshallerBase#marshal(java.lang.Object)
 */
@Override
public String marshal ( Object o ) throws Exception {
  XMLContext context = new XMLContext();
  Marshaller m = context.createMarshaller();
  StringWriter sw = new StringWriter();
  m.setWriter(sw);
  return sw.toString();
}

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

public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
  Writer writer = new OutputStreamWriter(outputStream, encoding);
  Marshaller marshaller = createMarshaller(exchange);
  marshaller.setWriter(writer);
  marshaller.marshal(body);
  if (contentTypeHeader) {
    if (exchange.hasOut()) {
      exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/xml");
    } else {
      exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/xml");
    }
  }
}

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

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

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

setWriter(streamResult.getWriter());
 return;
} else if (streamResult.getOutputStream() != null) {
 setWriter(new PrintWriter(streamResult.getOutputStream()));
 return;

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

/**
 * Writes the specified object as an XML stream to an output writer.
 * @param o the object to serialize.
 * @param out the writer.
 * @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.
 * @throws MappingException an exception indicating an invalid mapping error.
 * @throws org.exolab.castor.xml.MarshalException a marshalling exception.
 * @throws org.exolab.castor.xml.ValidationException an XML validation error occurred.
 * @throws NullPointerException if <code>o</code> is <code>null</code>.
 * @throws NullPointerException if <code>out</code> is <code>null</code>.
 * @see Mapping
 */
public void marshal(final Object o, final Writer out, final boolean asDocument) throws Exception
{
  synchronized(_marshaller)
  {
    _marshaller.setWriter(out); // May throw IOException.
    _marshaller.setMarshalAsDocument(asDocument);
    _marshaller.setEncoding("ISO-8859-1");
    // Do not use marshal(Object object, Writer out): IT DOESN'T WORK !!!
    _marshaller.marshal(o); // May throw MarshalException, ValidationException.
  }
}

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

public static void main(String[] args) {
 // TODO: add CommandLineOptions
 // options needed
 // 1. filename/path of CHANGELOG
 // 2. mapping file for customization
 // 3. output file name
 XMLContext xmlContext = new XMLContext();
 ChangeLog2XML parser = xmlContext.createChangeLog2XML();
 try {
  File file = new File(DEFAULT_FILE);
  Changelog changelog = parser.parse(file);
  file = new File(DEFAULT_OUTPUT);
  FileWriter writer = new FileWriter(file);
  xmlContext.setProperty(XMLProperties.USE_INDENTATION, true);
  Marshaller marshaller = xmlContext.createMarshaller();
  marshaller.setWriter(writer);
  marshaller.setRootElement("changelog");
  marshaller.setSuppressXSIType(true);
  marshaller.marshal(changelog);
 } catch (Exception ex) {
  ex.printStackTrace();
 }
}

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

public static void main(String[] args) {
  //TODO: add CommandLineOptions
  // options needed
  // 1. filename/path of CHANGELOG
  // 2. mapping file for customization
  // 3. output file name
  
  XMLContext xmlContext = new XMLContext();
  ChangeLog2XML parser = xmlContext.createChangeLog2XML();
  
  try {
    File file = new File(DEFAULT_FILE);
    Changelog changelog = parser.parse(file);
    
    file = new File(DEFAULT_OUTPUT);
    FileWriter writer = new FileWriter(file);
    xmlContext.setProperty(XMLConfiguration.USE_INDENTATION, true);
    Marshaller marshaller = xmlContext.createMarshaller();
    marshaller.setWriter(writer);
    
    marshaller.setRootElement("changelog");
    marshaller.setSuppressXSIType(true);
    marshaller.marshal(changelog);
    
  }
  catch(Exception ex) {
    ex.printStackTrace();
  }
}

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

marshaller.setWriter(writer);

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

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

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

private Marshaller createMarshaler(final File marshalOutput) throws Exception {
 getXMLContext().getInternalContext().getXMLClassDescriptorResolver().cleanDescriptorCache();
 Marshaller marshaller = getXMLContext().createMarshaller();
 marshaller.setWriter(new FileWriter(marshalOutput));
 // -- Configuration for marshaler? Use config from unit test case if available
 Configuration config = _unitTest.getConfiguration();
 if (config == null) {
  config = _configuration;
 }
 if (config != null) {
  ConfigurationType marshal = config.getMarshal();
  List returnValues = invokeEnumeratedMethods(marshaller, marshal);
  returnValues.clear(); // We don't care about the return values
 } // -- config != null
 if (_mapping != null) {
  marshaller.setMapping(_mapping);
 }
 if (_listener != null && _listener instanceof MarshalListener
   && _listenerType != TypeType.UNMARSHAL) {
  marshaller.setMarshalListener((MarshalListener) _listener);
 }
 return marshaller;
}

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

public String marshall(Html html) throws Exception {
  StringWriter writer = new StringWriter();
  xmlContext = new XMLContext();
  Mapping mapping = xmlContext.createMapping();
  mapping.loadMapping(coreResources.getURL("xformMapping.xml"));
  xmlContext.addMapping(mapping);
  Marshaller marshaller = xmlContext.createMarshaller();
  marshaller.setNamespaceMapping("h", "http://www.w3.org/1999/xhtml");
  marshaller.setNamespaceMapping("jr", "http://openrosa.org/javarosa");
  marshaller.setNamespaceMapping("xsd", "http://www.w3.org/2001/XMLSchema");
  marshaller.setNamespaceMapping("ev", "http://www.w3.org/2001/xml-events");
  marshaller.setNamespaceMapping("", "http://www.w3.org/2002/xforms");
  marshaller.setNamespaceMapping("enk", "http://enketo.org/xforms");
  marshaller.setNamespaceMapping("oc", "http://openclinica.org/xforms");
  marshaller.setWriter(writer);
  marshaller.marshal(html);
  String xform = writer.toString();
  return xform;
}

相关文章