• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JsonXMLConfigBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中de.odysseus.staxon.json.JsonXMLConfigBuilder的典型用法代码示例。如果您正苦于以下问题:Java JsonXMLConfigBuilder类的具体用法?Java JsonXMLConfigBuilder怎么用?Java JsonXMLConfigBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JsonXMLConfigBuilder类属于de.odysseus.staxon.json包,在下文中一共展示了JsonXMLConfigBuilder类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: xmlToJson

import de.odysseus.staxon.json.JsonXMLConfigBuilder; //导入依赖的package包/类
void xmlToJson(InputStream xmlInput, OutputStream jsonOutput) throws XMLStreamException
{
   JsonXMLConfig config = new JsonXMLConfigBuilder()
         .autoArray(true)
         .autoPrimitive(false)
         .fieldPrefix("")
         .contentField("content")
         .build();
   
   XMLEventReader reader = XMLInputFactory.newInstance().createXMLEventReader(xmlInput);
   XMLEventWriter writer = new JsonXMLOutputFactory(config).createXMLEventWriter(jsonOutput);
   
   writer.add(reader);
   
   reader.close();
   writer.close();
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:18,代码来源:SearchController.java


示例2: getDestination

import de.odysseus.staxon.json.JsonXMLConfigBuilder; //导入依赖的package包/类
@Override
public Destination getDestination(WebApp webApp, HttpServletRequest req, 
    HttpServletResponse resp, OutputStream os, Properties outputProperties) throws XMLStreamException {
  JsonXMLConfig config = new JsonXMLConfigBuilder()
      .autoArray(autoArray)
      .autoPrimitive(autoPrimitive)
      .multiplePI(multiplePI)
      .namespaceDeclarations(namespaceDeclarations)
      .namespaceSeparator(namespaceSeparator)
      .prettyPrint(prettyPrint)
      .virtualRoot(virtualRoot)
      .repairingNamespaces(repairingNamespaces)
      .namespaceMappings(namespaceMappings)
      .build();
  XMLOutputFactory factory = new JsonXMLOutputFactory(config);
  return new XMLStreamWriterDestination(factory.createXMLStreamWriter(os, outputProperties.getProperty("encoding", "UTF-8")));            
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:18,代码来源:JSONSerializerStep.java


示例3: call

import de.odysseus.staxon.json.JsonXMLConfigBuilder; //导入依赖的package包/类
@Override
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {                            
  StringWriter sw = new StringWriter();      
  JsonXMLConfig config = new JsonXMLConfigBuilder().        
      prettyPrint(true).
      build();    
  XMLOutputFactory jFactory = new JsonXMLOutputFactory(config);                  
  TransformerFactory tFactory = new TransformerFactoryImpl();      
  try {
    SequenceIterator iter = arguments[0].iterate(); 
    Item item;
    while ((item = iter.next()) != null) {
      if (item instanceof NodeInfo) {
        Transformer transformer = tFactory.newTransformer();            
        XMLStreamWriter xsw = jFactory.createXMLStreamWriter(sw);            
        transformer.transform((NodeInfo) item, new StAXResult(xsw));                                   
      } else {
        sw.append(item.getStringValue());
      }
    }
  } catch (Exception e) {
    throw new XPathException("Error serializing sequence to JSON", e);
  }
  return StringValue.makeStringValue(sw.toString());              
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:26,代码来源:SerializeJSON.java


示例4: convertXmlToJson

import de.odysseus.staxon.json.JsonXMLConfigBuilder; //导入依赖的package包/类
/**
 * Converts xml to json.
 *
 * @param xml xml as byte array.
 * @return json as byte array.
 */
public byte[] convertXmlToJson(byte[] xml) {
    JsonXMLConfig config = new JsonXMLConfigBuilder()
            .prettyPrint(true)
            .autoArray(true)
            .autoPrimitive(true)
            .build();
    XMLInputFactory reader = XMLInputFactory.newInstance();
    JsonXMLOutputFactory writer = new JsonXMLOutputFactory(config);
    return convert(reader, writer, xml);
}
 
开发者ID:eea,项目名称:eionet.webq,代码行数:17,代码来源:JsonXMLBidirectionalConverter.java


示例5: convertJsonToXml

import de.odysseus.staxon.json.JsonXMLConfigBuilder; //导入依赖的package包/类
/**
 * Converts json to xml.
 *
 * @param json json as byte array.
 * @return xml as byte array.
 */
public byte[] convertJsonToXml(byte[] json) {
    JsonXMLConfig config = new JsonXMLConfigBuilder()
        .prettyPrint(true)
        .multiplePI(false)
        .build();
    XMLInputFactory reader = new JsonXMLInputFactory(config);
    XMLOutputFactory writer = XMLOutputFactory.newInstance();
    return convert(reader, writer, json);
}
 
开发者ID:eea,项目名称:eionet.webq,代码行数:16,代码来源:JsonXMLBidirectionalConverter.java


示例6: xmlQuizzToJson

import de.odysseus.staxon.json.JsonXMLConfigBuilder; //导入依赖的package包/类
/**
 * . Lit le fichier de quizz XML xmlInput, ecrit le test convertit en JSON
 * dans le fichier jsonOutput
 *
 * @param xmlInput
 *            Ficher de Quizz XML
 * @param jsonOutput
 *            Fichier de sortie JSON
 * @throws IOException
 *             exception entrée/sortie
 * @throws FactoryConfigurationError
 *             Erreur de configurations
 * @throws XMLStreamException
 *             exception de flux XML
 */
public static void xmlQuizzToJson(final File xmlInput, final File jsonOutput)
        throws IOException, XMLStreamException, FactoryConfigurationError {

    InputStream is = new FileInputStream(xmlInput);
    OutputStream os = new FileOutputStream(jsonOutput);

    Reader r = new InputStreamReader(is, "UTF-8");
    Writer w = new OutputStreamWriter(os, "UTF-8");

    JsonXMLConfig config = new JsonXMLConfigBuilder().autoArray(true)
            .autoPrimitive(true).prettyPrint(true).build();
    try {
        /*
         * Create reader (XML).
         */
        XMLEventReader reader = XMLInputFactory.newInstance()
                .createXMLEventReader(r);

        /*
         * Create writer (JSON).
         */
        XMLEventWriter writer = new JsonXMLOutputFactory(config)
                .createXMLEventWriter(w);

        /*
         * Copy events from reader to writer.
         */
        writer.add(reader);

        /*
         * Close reader/writer.
         */
        reader.close();
        writer.close();
    } finally {
        /*
         * As per StAX specification, XMLEventReader/Writer.close() doesn't
         * close the underlying stream.
         */
        r.close();
        w.close();
        os.close();
        is.close();
    }
}
 
开发者ID:loclamor,项目名称:morphoQuizz,代码行数:61,代码来源:QuizzConverter.java


示例7: save

import de.odysseus.staxon.json.JsonXMLConfigBuilder; //导入依赖的package包/类
public void save(OutputStream output) throws IOException, XMLStreamException {
	JsonXMLOutputFactory factory = new JsonXMLOutputFactory(new JsonXMLConfigBuilder().prettyPrint(false).virtualRoot("assetStore").build());
	JsonXMLStreamWriter writer = factory.createXMLStreamWriter(output);
	try {
		writer.writeStartDocument();
		writer.writeStartElement("assetStore");
		writeStringProperty(writer, "version", version);
		writeNumberProperty(writer, "timestamp", timestamp);
		if (retina != null) {
			writeBooleanProperty(writer, "retina", retina);
		}
		writer.writeProcessingInstruction(JsonXMLStreamConstants.MULTIPLE_PI_TARGET);
		for (AssetEntity entity : entities.values()) {
			String assetPath;
			try {
				assetPath = musicFolder.getPath().relativize(entity.asset.getResource().getPath()).toString();
			} catch (IllegalArgumentException e) {
				LOGGER.warning("Could not determine path for asset resource: " + entity.asset.getResource());
				continue;
			}
			writer.writeStartElement("asset");
			writeNumberProperty(writer, "albumId", entity.albumId);
			writeStringProperty(writer, "album", entity.asset.getAlbum());
			writeStringProperty(writer, "albumArtist", entity.asset.getAlbumArtist());
			writeStringProperty(writer, "artist", entity.asset.getArtist());
			writeBooleanProperty(writer, "artworkAvailable", entity.asset.isArtworkAvailable());
			writeStringProperty(writer, "assetPath", assetPath);
			writeBooleanProperty(writer, "compilation", entity.asset.isCompilation());
			writeStringProperty(writer, "composer", entity.asset.getComposer());
			writeNumberProperty(writer, "discNumber", entity.asset.getDiscNumber());
			writeNumberProperty(writer, "duration", entity.asset.getDuration());
			writeStringProperty(writer, "genre", entity.asset.getGenre());
			writeStringProperty(writer, "grouping", entity.asset.getGrouping());
			writeStringProperty(writer, "name", entity.asset.getName());
			writeNumberProperty(writer, "trackNumber", entity.asset.getTrackNumber());
			writeNumberProperty(writer, "year", entity.asset.getYear());
			writer.writeEndElement();
		}
		writer.writeEndElement();
		writer.writeEndDocument();
	} finally {
		writer.close();
	}
}
 
开发者ID:beckchr,项目名称:musicmount,代码行数:45,代码来源:AssetStore.java


示例8: load

import de.odysseus.staxon.json.JsonXMLConfigBuilder; //导入依赖的package包/类
public void load(InputStream input) throws IOException, XMLStreamException {
	XMLInputFactory factory = new JsonXMLInputFactory(new JsonXMLConfigBuilder().virtualRoot("assetStore").build());
	XMLStreamReader reader = factory.createXMLStreamReader(input);
	try {
		if (reader.getEventType() == XMLStreamConstants.START_DOCUMENT) {
			reader.nextTag();
		}
		reader.require(XMLStreamConstants.START_ELEMENT, null, "assetStore");
		reader.nextTag();
		while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
			switch (reader.getLocalName()) {
			case "version":
				String version = reader.getElementText();
				if (!this.version.equals(version)) {
					throw new IOException("incompatible store version");
				}
				break;
			case "timestamp":
				timestamp = Long.valueOf(reader.getElementText());
				break;
			case "asset":
				AssetEntity entity = loadEntity(reader);
				if (entity != null) {
					entities.put(entity.asset.getResource(), entity);
					if (LOGGER.isLoggable(Level.FINEST)) {
						LOGGER.finest("Asset has been loaded: " + entity.asset.getResource().getPath().toAbsolutePath());
					}
				}
				break;
			case "retina":
				retina = Boolean.valueOf(reader.getElementText());
				break;
			default:
				throw new XMLStreamException("unexpected store property: " + reader.getLocalName());
			}
			reader.require(XMLStreamConstants.END_ELEMENT, null, null);
			reader.nextTag();
		}
		reader.require(XMLStreamConstants.END_ELEMENT, null, "assetStore");
	} finally {
		reader.close();
	}
}
 
开发者ID:beckchr,项目名称:musicmount,代码行数:44,代码来源:AssetStore.java


示例9: JSON

import de.odysseus.staxon.json.JsonXMLConfigBuilder; //导入依赖的package包/类
public JSON(String apiVersion, LocalStrings localStrings, boolean directoryIndex, boolean includeUnknownGenre, boolean useGrouping, boolean prettyPrint) {
	super(apiVersion, localStrings, directoryIndex ? "index.json" : null, includeUnknownGenre, useGrouping);
	factory = new JsonXMLOutputFactory(new JsonXMLConfigBuilder().prettyPrint(prettyPrint).virtualRoot("response").build());
}
 
开发者ID:beckchr,项目名称:musicmount,代码行数:5,代码来源:ResponseFormatter.java



注:本文中的de.odysseus.staxon.json.JsonXMLConfigBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OAuth2Credentials类代码示例发布时间:2022-05-23
下一篇:
Java IVideoPictureEvent类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap