本文整理匯總了Java中javax.xml.bind.Marshaller.setProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java Marshaller.setProperty方法的具體用法?Java Marshaller.setProperty怎麽用?Java Marshaller.setProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.bind.Marshaller
的用法示例。
在下文中一共展示了Marshaller.setProperty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: obj2xml
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
/**
* 對象轉為xml字符串
*
* @param obj
* @param isFormat
* true即按標簽自動換行,false即是一行的xml
* @param includeHead
* true則包含xm頭聲明信息,false則不包含
* @return
*/
public String obj2xml(Object obj, boolean isFormat, boolean includeHead) {
try (StringWriter writer = new StringWriter()) {
Marshaller m = MARSHALLERS.get(obj.getClass());
if (m == null) {
m = JAXBContext.newInstance(obj.getClass()).createMarshaller();
m.setProperty(Marshaller.JAXB_ENCODING, I18NConstants.DEFAULT_CHARSET);
}
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, isFormat);
m.setProperty(Marshaller.JAXB_FRAGMENT, !includeHead);// 是否省略xm頭聲明信息
m.marshal(obj, writer);
return writer.toString();
} catch (Exception e) {
throw new ZhhrException(e.getMessage(), e);
}
}
示例2: main
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
public static void main(String[] args) throws JAXBException{
//create instance of JAXBContext with the class we want to serialize into XML
JAXBContext jaxb = JAXBContext.newInstance(Messages.class);
//create a marshaller which will do the task of generating xml
Marshaller marshaller = jaxb.createMarshaller();
//setting the property of marshaller to not add the <? xml> tag
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
StringWriter writer = new StringWriter();
//serialze the Messages instance and send the string to the writer
marshaller.marshal(new Messages(), writer);
//get the XML from the writer
System.out.println(writer.toString());
}
示例3: getTransitionListXML
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
public String getTransitionListXML(Logger logger) throws Exception {
JAXBContext ctx = JAXBContext.newInstance("ExternalPackages.org.hupo.psi.ms.traml");
Marshaller m = ctx.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, JTRAML_URL.TRAML_XSD_LOCATION);
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
JAXBElement<TraMLType> tramlWrap =
new JAXBElement<TraMLType>(new QName(JTRAML_URL.TRAML_URI, "TraML"), TraMLType.class, traML);
StringWriter sw = new StringWriter();
m.marshal(tramlWrap, sw);
return sw.toString();
}
示例4: asString
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
public String asString() throws JAXBException {
java.io.StringWriter sw = new StringWriter();
JAXBContext ctx = JAXBContext.newInstance("org.hupo.psi.ms.traml");
Marshaller m = ctx.createMarshaller();
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, JTRAML_URL.TRAML_XSD_LOCATION);
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
JAXBElement<TraMLType> tramlWrap =
new JAXBElement<TraMLType>(new QName(JTRAML_URL.TRAML_URI, "TraML"), TraMLType.class, traML);
m.marshal(tramlWrap, sw);
return sw.toString();
}
示例5: sniff
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
/**
* Obtains the tag name of the root element.
*/
private void sniff() {
RootElementSniffer sniffer = new RootElementSniffer(false);
try {
if (rawContext != null) {
Marshaller m = rawContext.createMarshaller();
m.setProperty("jaxb.fragment", Boolean.TRUE);
m.marshal(jaxbObject,sniffer);
} else
bridge.marshal(jaxbObject,sniffer,null);
} catch (JAXBException e) {
// if it's due to us aborting the processing after the first element,
// we can safely ignore this exception.
//
// if it's due to error in the object, the same error will be reported
// when the readHeader() method is used, so we don't have to report
// an error right now.
nsUri = sniffer.getNsUri();
localName = sniffer.getLocalName();
}
}
示例6: convertToXml
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
private static String convertToXml(Object obj, String encoding, boolean formattedOutput)
throws JAXBException {
JAXBContext context = getJAXBContext(obj.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formattedOutput);
marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
StringWriter writer = new StringWriter();
marshaller.marshal(obj, writer);
return writer.toString();
}
示例7: marshal
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
public void marshal(Marshaller m, Object object, OutputStream output, NamespaceContext nsContext) throws JAXBException {
m.setProperty(Marshaller.JAXB_FRAGMENT,true);
try {
((MarshallerImpl)m).marshal(object,output,nsContext);
} finally {
m.setProperty(Marshaller.JAXB_FRAGMENT,false);
}
}
示例8: writeTo
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public void writeTo(XMLStreamWriter sw) throws XMLStreamException {
try {
// MtomCodec sets its own AttachmentMarshaller
AttachmentMarshaller am = (sw instanceof MtomStreamWriter)
? ((MtomStreamWriter) sw).getAttachmentMarshaller()
: new AttachmentMarshallerImpl(attachmentSet);
// Get the encoding of the writer
String encoding = XMLStreamWriterUtil.getEncoding(sw);
// Get output stream and use JAXB UTF-8 writer
OutputStream os = bridge.supportOutputStream() ? XMLStreamWriterUtil.getOutputStream(sw) : null;
if (rawContext != null) {
Marshaller m = rawContext.createMarshaller();
m.setProperty("jaxb.fragment", Boolean.FALSE);
m.setAttachmentMarshaller(am);
if (os != null) {
m.marshal(jaxbObject, os);
} else {
m.marshal(jaxbObject, sw);
}
} else {
if (os != null && encoding != null && encoding.equalsIgnoreCase(SOAPBindingCodec.UTF8_ENCODING)) {
bridge.marshal(jaxbObject, os, sw.getNamespaceContext(), am);
} else {
bridge.marshal(jaxbObject, sw, am);
}
}
//cleanup() is not needed since JAXB doesn't keep ref to AttachmentMarshaller
} catch (JAXBException e) {
// bug 6449684, spec 4.3.4
throw new WebServiceException(e);
}
}
示例9: serializeIt
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
private String serializeIt(Partners partner, Boolean format) throws Exception {
JAXBContext context = JAXBContext.newInstance(Partners.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, format);
StringWriter result = new StringWriter();
marshaller.marshal(partner, result);
return result.toString();
}
示例10: serializeIt
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
private String serializeIt(Distribution dist, Boolean format) throws Exception {
JAXBContext context = JAXBContext.newInstance(Distribution.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, format);
StringWriter result = new StringWriter();
marshaller.marshal(dist, result);
return result.toString();
}
示例11: marshal
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
/**
* Converts the given {@link Throwable} into an XML representation
* and put that as a DOM tree under the given node.
*/
public static void marshal( Throwable t, Node parent ) throws JAXBException {
Marshaller m = JAXB_CONTEXT.createMarshaller();
try {
m.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper",nsp);
} catch (PropertyException pe) {}
m.marshal(new ExceptionBean(t), parent );
}
示例12: setMarshallerProperties
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
private void setMarshallerProperties(Marshaller marshaller) throws PropertyException {
Iterator<String> keys = properties.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
marshaller.setProperty(key, properties.get(key));
}
}
示例13: marshal
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
public void marshal(Marshaller m, Object object, ContentHandler contentHandler) throws JAXBException {
m.setProperty(Marshaller.JAXB_FRAGMENT,true);
try {
m.marshal(object,contentHandler);
} finally {
m.setProperty(Marshaller.JAXB_FRAGMENT,false);
}
}
示例14: saveLayerQuery
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
public String saveLayerQuery(QueryConfiguration queryConfiguration) {
final String finalQuery = queryConfiguration
.generateSQL(this.geodirLayerManager.getLayerConfiguration().getDafaultConditions());
if (this.geodirLayerManager.getLayerConfiguration().getLayer() == null) {
log.info(queryConfiguration.toString());
return finalQuery;
}
this.geodirLayerManager.getLayerConfiguration().getLayer().setQuery(finalQuery);
this.geodirLayerManager.saveConfiguration();
File parent_file = new File(
this.geodirLayerManager.getLayerConfiguration().getLayer().getPath() + "/" + this.queryDirectory + "/");
if (!parent_file.exists()) {
parent_file.mkdirs();
}
File file = new File(parent_file, "/" + this.queryFileConf + ".xml");
try {
JAXBContext jaxbContext = JAXBContext.newInstance(QueryConfiguration.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(queryConfiguration, file);
log.info("done..");
} catch (JAXBException e) {
log.error("fail creating file..", e);
}
return finalQuery;
}
示例15: marshal
import javax.xml.bind.Marshaller; //導入方法依賴的package包/類
public void marshal(Marshaller m, Object object, XMLStreamWriter output) throws JAXBException {
m.setProperty(Marshaller.JAXB_FRAGMENT,true);
try {
m.marshal(object,output);
} finally {
m.setProperty(Marshaller.JAXB_FRAGMENT,false);
}
}