当前位置: 首页>>代码示例>>Java>>正文


Java Marshaller.setProperty方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:wooui,项目名称:springboot-training,代码行数:26,代码来源:XMLUtil.java

示例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());
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:19,代码来源:HelloWorldXml.java

示例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();
    }
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:17,代码来源:TraMLParser.java

示例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();
    }
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:18,代码来源:TraMLCreator.java

示例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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:JAXBMessage.java

示例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();
}
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:13,代码来源:JAXB.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:MarshallerBridge.java

示例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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:JAXBDispatchMessage.java

示例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();
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:11,代码来源:PartnersTest.java

示例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();
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:11,代码来源:DistributionTest.java

示例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 );
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:ExceptionBean.java

示例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));
  }
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:9,代码来源:JAXBContextFactory.java

示例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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:MarshallerBridge.java

示例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;
	}
 
开发者ID:geodir,项目名称:Layer-Query,代码行数:28,代码来源:GeodirQuery.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:MarshallerBridge.java


注:本文中的javax.xml.bind.Marshaller.setProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。