當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。