當前位置: 首頁>>代碼示例>>Java>>正文


Java HierarchicalStreamWriter類代碼示例

本文整理匯總了Java中com.thoughtworks.xstream.io.HierarchicalStreamWriter的典型用法代碼示例。如果您正苦於以下問題:Java HierarchicalStreamWriter類的具體用法?Java HierarchicalStreamWriter怎麽用?Java HierarchicalStreamWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HierarchicalStreamWriter類屬於com.thoughtworks.xstream.io包,在下文中一共展示了HierarchicalStreamWriter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: marshal

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
/**
 * writes the argument <code>value</code> to the XML file specified through
 * <code>writer</code>
 *
 * @pre     <code>value</code> is a valid <code>ShrimpSpeciesNode</code>, <code>
 *          writer</code> is a valid <code>HierarchicalStreamWriter</code>, and
 * <code>context</code> is a valid <code>MarshallingContext</code>
 * @post    <code>value</code> is written to the XML file specified via
 * <code>writer</code>
 * @param value   <code>ShrimpSpeciesNode</code> that you wish to write to a
 * file
 * @param writer stream to write through
 * @param context <code>MarshallingContext</code> used to store generic data
 */
@Override
public void marshal(Object value, HierarchicalStreamWriter writer,
        MarshallingContext context) {

    ShrimpSpeciesNode shrimpSpeciesNode = (ShrimpSpeciesNode) value;
    
    writer.startNode("isotopeName");
    writer.setValue(shrimpSpeciesNode.getName());
    writer.endNode();

    writer.startNode("squidSpeciesModel");
    context.convertAnother(shrimpSpeciesNode.getSquidSpeciesModel());
    writer.endNode();
    
    writer.startNode("methodNameForShrimpFraction");
    writer.setValue(shrimpSpeciesNode.getMethodNameForShrimpFraction());
    writer.endNode();

}
 
開發者ID:CIRDLES,項目名稱:Squid,代碼行數:34,代碼來源:ShrimpSpeciesNodeXMLConverter.java

示例2: marshal

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
/**
 * writes the argument <code>value</code> to the XML file specified through
 * <code>writer</code>
 *
 * @pre     <code>value</code> is a valid <code>SpotFieldNode</code>, <code>
 *          writer</code> is a valid <code>HierarchicalStreamWriter</code>, and
 * <code>context</code> is a valid <code>MarshallingContext</code>
 * @post    <code>value</code> is written to the XML file specified via
 * <code>writer</code>
 * @param value   <code>SpotFieldNode</code> that you wish to write to a
 * file
 * @param writer stream to write through
 * @param context <code>MarshallingContext</code> used to store generic data
 */
@Override
public void marshal(Object value, HierarchicalStreamWriter writer,
        MarshallingContext context) {

    SpotFieldNode spotFieldNode = (SpotFieldNode) value;
    
    writer.startNode("isotopeName");
    writer.setValue(spotFieldNode.getName());
    writer.endNode();
    
    writer.startNode("methodNameForShrimpFraction");
    writer.setValue(spotFieldNode.getMethodNameForShrimpFraction());
    writer.endNode();

}
 
開發者ID:CIRDLES,項目名稱:Squid,代碼行數:30,代碼來源:SpotFieldNodeNodeXMLConverter.java

示例3: createWriter

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
public HierarchicalStreamWriter createWriter(Writer out) {
	return new PrettyPrintWriter(out) {
		boolean CDATA = true;
		
		@SuppressWarnings("rawtypes")
		public void startNode(String name, Class clazz) {
			super.startNode(name, clazz);
		}
		protected void writeText(QuickWriter writer, String text) {
			if (CDATA) {
				writer.write("<![CDATA[");
				writer.write(text);
				writer.write("]]>");
			} else {
				writer.write(text);
			}
		}
	};
}
 
開發者ID:Leibnizhu,項目名稱:AlipayWechatPlatform,代碼行數:20,代碼來源:MsgXmlUtil.java

示例4: createWriter

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
public HierarchicalStreamWriter createWriter(Writer out) {
    return new PrettyPrintWriter(out) {
        // 對所有xml節點的轉換都增加CDATA標記
        boolean cdata = true;

        @SuppressWarnings("unchecked")
        public void startNode(String name, Class clazz) {
            super.startNode(name, clazz);
        }

        protected void writeText(QuickWriter writer, String text) {
            if (cdata) {
                writer.write("<![CDATA[");
                writer.write(text);
                writer.write("]]>");
            } else {
                writer.write(text);
            }
        }
    };
}
 
開發者ID:Evan1120,項目名稱:wechat-api-java,代碼行數:22,代碼來源:MessageUtil.java

示例5: copy

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
public void copy(HierarchicalStreamReader source, HierarchicalStreamWriter destination) {
    destination.startNode(source.getNodeName());
    int attributeCount = source.getAttributeCount();
    for (int i = 0; i < attributeCount; i++) {
        destination.addAttribute(source.getAttributeName(i), source.getAttribute(i));
    }
    String value = source.getValue();
    if (value != null && value.length() > 0) {
        destination.setValue(value);
    }
    while (source.hasMoreChildren()) {
        source.moveDown();
        copy(source, destination);
        source.moveUp();
    }
    destination.endNode();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:HierarchicalStreamCopier.java

示例6: marshal

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
@Override
public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext arg2)
{
	writer.addAttribute("xmlns:oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
	writer.addAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
	writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
	writer.addAttribute("xsi:schemaLocation",
		"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd");

	DublinCore metadata = (DublinCore) arg0;

	startNode(writer, "dc:title", metadata.getTitle());
	startNode(writer, "dc:creator", metadata.getCreator());
	startNode(writer, "dc:creator", metadata.getTitle());
	startNode(writer, "dc:date", metadata.getDate());
	startNode(writer, "dc:description", metadata.getDescription());
	startNode(writer, "dc:identifier", metadata.getIdentifier());
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:19,代碼來源:OAIDublinCoreConverter.java

示例7: marshal

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
@Override
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext arg2)
{
	Request rep = (Request) object;
	Map map = rep.getAttributes();
	Iterator i = map.keySet().iterator();
	while( i.hasNext() )
	{
		String key = i.next().toString();
		String[] value = (String[]) map.get(key);
		for( int j = 0; j < value.length; j++ )
		{
			writer.addAttribute(key, value[j]);
		}
	}

	writer.setValue(rep.getNode());
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:19,代碼來源:OAIRequestConverter.java

示例8: marshal

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
@Override
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext arg2)
{
	Header header = (Header) object;

	addAttribute(writer, "status", header.getStatus());

	writer.startNode("identifier");
	writer.setValue(header.getIdentifier());
	writer.endNode();
	writer.startNode("datestamp");
	writer.setValue(header.getDatestamp());
	writer.endNode();
	Iterator i = header.getSpecs().iterator();
	while( i.hasNext() )
	{
		writer.startNode("setSpec");
		writer.setValue(i.next().toString());
		writer.endNode();
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:22,代碼來源:OAIHeaderConverter.java

示例9: marshal

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
@Override
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext arg2)
{
	Response rep = (Response) object;
	writer.addAttribute("xmlns", "http://www.openarchives.org/OAI/2.0/");
	writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
	writer.addAttribute("xsi:schemaLocation",
		"http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd");

	startNode(writer, "responseDate", rep.getResponseDate());
	marshal(rep.getRequest(), writer);

	Object message = rep.getMessage();
	if( message instanceof List )
	{
		List col = (List) message;
		startNode(writer, rep.getMessageNodeName(), col, true);
	}
	else
	{
		marshal(rep.getMessage(), writer);
	}
	marshal(rep.getError(), writer);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:25,代碼來源:OAIResponseConverter.java

示例10: marshal

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
@Override
public void marshal(final Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) {
    final Object source = serializationMethodInvoker.callWriteReplace(original);

    if (source != original && context instanceof ReferencingMarshallingContext) {
        ((ReferencingMarshallingContext<?>)context).replace(original, source);
    }
    if (source.getClass() != original.getClass()) {
        final String attributeName = mapper.aliasForSystemAttribute("resolves-to");
        if (attributeName != null) {
            writer.addAttribute(attributeName, mapper.serializedClass(source.getClass()));
        }
        context.convertAnother(source);
    } else {
        doMarshal(source, writer, context);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:AbstractReflectionConverter.java

示例11: marshal

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
    final BitSet bitSet = (BitSet)source;
    final StringBuilder buffer = new StringBuilder();
    boolean seenFirst = false;
    for (int i = 0; i < bitSet.length(); i++) {
        if (bitSet.get(i)) {
            if (seenFirst) {
                buffer.append(',');
            } else {
                seenFirst = true;
            }
            buffer.append(i);
        }
    }
    writer.setValue(buffer.toString());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:BitSetConverter.java

示例12: marshal

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
    final Properties properties = (Properties)source;
    final Map<Object, Object> map = sort ? new TreeMap<Object, Object>(properties) : properties;
    for (final Map.Entry<Object, Object> entry : map.entrySet()) {
        writer.startNode("property");
        writer.addAttribute("name", entry.getKey().toString());
        writer.addAttribute("value", entry.getValue().toString());
        writer.endNode();
    }
    if (defaultsField != null) {
        final Properties defaults = (Properties)Fields.read(defaultsField, properties);
        if (defaults != null) {
            writer.startNode("defaults");
            marshal(defaults, writer, context);
            writer.endNode();
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:PropertiesConverter.java

示例13: createXMLXStream

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
/**
 * 功能描述:創建xml轉換器
 * 
 * @return xstream 轉換信息
 */
@SuppressWarnings("all")
public static XStream createXMLXStream() {
	return new XStream(new DomDriver(Constant.DEFAULT_ENCODING) {
		@Override
		public HierarchicalStreamWriter createWriter(Writer out) {
			return new PrettyPrintWriter(out) {
				boolean cdata = false;
				Class<?> targetClass = null;

				@Override
				public void startNode(String name, Class clazz) {
					super.startNode(name, clazz);
					// 業務處理,對於用XStream2Field標記的Field,需要加上CDATA標簽
					XStream2Type xStream2Type = (XStream2Type) clazz
							.getAnnotation(XStream2Type.class);
					if (null == xStream2Type) {
						// if(!name.equals("xml"))
						cdata = needCDATA(targetClass, name);
					} else {
						targetClass = clazz;
					}
				}

				@Override
				protected void writeText(QuickWriter writer, String text) {
					if (cdata) {
						writer.write(addCDATA(text));
					} else {
						writer.write(text);
					}
				}
			};
		}
	});
}
 
開發者ID:jiangzongyao,項目名稱:kettle_support_kettle8.0,代碼行數:41,代碼來源:XStreamFacade.java

示例14: marshal

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
    final Pattern pattern = (Pattern)source;
    writer.startNode("pattern");
    writer.setValue(pattern.pattern());
    writer.endNode();
    writer.startNode("flags");
    writer.setValue(String.valueOf(pattern.flags()));
    writer.endNode();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:11,代碼來源:RegexPatternConverter.java

示例15: marshal

import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入依賴的package包/類
/**
 * writes the argument <code>value</code> to the XML file specified through
 * <code>writer</code>
 *
 * @pre     <code>value</code> is a valid <code>SquidSpeciesModel</code>, <code>
 *          writer</code> is a valid <code>HierarchicalStreamWriter</code>, and
 * <code>context</code> is a valid <code>MarshallingContext</code>
 * @post    <code>value</code> is written to the XML file specified via
 * <code>writer</code>
 * @param value   <code>SquidSpeciesModel</code> that you wish to write to a
 * file
 * @param writer stream to write through
 * @param context <code>MarshallingContext</code> used to store generic data
 */
@Override
public void marshal(Object value, HierarchicalStreamWriter writer,
        MarshallingContext context) {

    SquidSpeciesModel squidSpeciesModel = (SquidSpeciesModel) value;

    writer.startNode("massStationIndex");
    writer.setValue(String.valueOf(squidSpeciesModel.getMassStationIndex()));
    writer.endNode();

    writer.startNode("massStationSpeciesName");
    writer.setValue(squidSpeciesModel.getMassStationSpeciesName());
    writer.endNode();

    writer.startNode("isotopeName");
    writer.setValue(squidSpeciesModel.getIsotopeName());
    writer.endNode();

    writer.startNode("elementName");
    writer.setValue(squidSpeciesModel.getElementName());
    writer.endNode();

    writer.startNode("isBackground");
    writer.setValue(String.valueOf(squidSpeciesModel.getIsBackground()));
    writer.endNode();

}
 
開發者ID:CIRDLES,項目名稱:Squid,代碼行數:42,代碼來源:SquidSpeciesModelXMLConverter.java


注:本文中的com.thoughtworks.xstream.io.HierarchicalStreamWriter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。