本文整理汇总了Java中com.thoughtworks.xstream.io.xml.CompactWriter类的典型用法代码示例。如果您正苦于以下问题:Java CompactWriter类的具体用法?Java CompactWriter怎么用?Java CompactWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompactWriter类属于com.thoughtworks.xstream.io.xml包,在下文中一共展示了CompactWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
@Override
public void write(final GenericEntity entity, final MediaType contentType, final HttpOutputMessage outputMessage)
throws IOException {
final HierarchicalStreamWriter writer = new CompactWriter(new OutputStreamWriter(outputMessage.getBody()));
writer.startNode("Entity");
writer.addAttribute("Type", entity.getType());
writer.startNode("Fields");
for (final Field field : entity.getFields()) {
writer.startNode("Field");
writer.addAttribute("Name", field.getName());
if (field.getValues().size() == 0) {
writer.startNode("Value");
writer.endNode();
} else {
for (final String value : field.getValues()) {
writer.startNode("Value");
writer.setValue(value);
writer.endNode();
}
}
writer.endNode();
}
writer.endNode();
writer.endNode();
}
示例2: createEntityFieldCollectionXml
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
public static final String createEntityFieldCollectionXml(final EntityFieldCollection fieldCollection) {
final StringWriter stringWriter = new StringWriter();
final HierarchicalStreamWriter writer = new CompactWriter(stringWriter);
writer.startNode("Fields");
for (final EntityField field : fieldCollection) {
writer.startNode("Field");
writer.addAttribute("Name", field.getName());
writer.addAttribute("Label", field.getLabel());
addFieldNode(writer, "Required", String.valueOf(field.isRequired()));
addFieldNode(writer, "System", String.valueOf(field.isSystem()));
addFieldNode(writer, "Editable", String.valueOf(field.isEditable()));
addFieldNode(writer, "Size", "1");
addFieldNode(writer, "History", "false");
addFieldNode(writer, "Type", "String");
addFieldNode(writer, "Verify", "false");
addFieldNode(writer, "Virtual", "true");
addFieldNode(writer, "Active", "false");
addFieldNode(writer, "Filterable", "true");
addFieldNode(writer, "Groupable", "false");
addFieldNode(writer, "SupportsMultivalue", "false");
writer.endNode();
}
writer.endNode();
return stringWriter.toString();
}
示例3: createSiteXml
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
public static final String createSiteXml(final Site site) {
final StringWriter stringWriter = new StringWriter();
final HierarchicalStreamWriter writer = new CompactWriter(stringWriter);
writer.startNode("Domains");
for (final Domain domain : site) {
writer.startNode("Domain");
writer.addAttribute("Name", domain.getName());
writer.startNode("Projects");
for (final Project project : domain.getProjects()) {
writer.startNode("Project");
writer.addAttribute("Name", project.getProjectName());
writer.endNode();
}
writer.endNode();
writer.endNode();
}
writer.endNode();
return stringWriter.toString();
}
示例4: appendEvents
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void appendEvents(String type, EventStream eventsToStore) {
OutputStream out = null;
try {
File eventFile = getBaseDirForType(type).createRelative(eventsToStore.getAggregateIdentifier() + ".events")
.getFile();
out = new FileOutputStream(eventFile, true);
CompactWriter writer = new CompactWriter(new OutputStreamWriter(out, "UTF-8"));
while (eventsToStore.hasNext()) {
DomainEvent event = eventsToStore.next();
xStream.marshal(event, writer);
IOUtils.write("\n", out);
}
} catch (IOException e) {
throw new EventStorageException("Unable to store given entity due to a IOException", e);
} finally {
IOUtils.closeQuietly(out);
}
}
示例5: testWithValueInConvertedClass
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
/**
* Tests conversion with field defined in converted class.
*/
public void testWithValueInConvertedClass() {
converterLookup.registerConverter(new ToAttributedValueConverter(
Software.class, mapper, reflectionProvider, converterLookup, "name"), 0);
final Software name = new Software(null, "XStream");
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
new TreeMarshaller(compactWriter, converterLookup, mapper).start(name, null);
compactWriter.flush();
assertEquals("<software>XStream</software>", writer.toString());
final HierarchicalStreamReader reader = driver.createReader(new StringReader(
writer.toString()));
assertEquals(
name, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
}
示例6: testWithValueInSuperclass
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
/**
* Tests conversion with field defined in superclass.
*/
public void testWithValueInSuperclass() {
converterLookup.registerConverter(new ToAttributedValueConverter(
OpenSourceSoftware.class, mapper, reflectionProvider, converterLookup, "name",
Software.class), 0);
final Software software = new OpenSourceSoftware("Codehaus", "XStream", "BSD");
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
new TreeMarshaller(compactWriter, converterLookup, mapper).start(software, null);
compactWriter.flush();
assertEquals(
"<open-source vendor=\"Codehaus\" license=\"BSD\">XStream</open-source>",
writer.toString());
final HierarchicalStreamReader reader = driver.createReader(new StringReader(
writer.toString()));
assertEquals(
software, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
}
示例7: testWithNullValueDeserializedAsEmptyString
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
/**
* Tests conversion with null in field value.
*/
public void testWithNullValueDeserializedAsEmptyString() {
converterLookup.registerConverter(new ToAttributedValueConverter(
Software.class, mapper, reflectionProvider, converterLookup, "name"), 0);
final Software software = new Software(null, null);
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
new TreeMarshaller(compactWriter, converterLookup, mapper).start(software, null);
compactWriter.flush();
assertEquals("<software/>", writer.toString());
final HierarchicalStreamReader reader = driver.createReader(new StringReader(
writer.toString()));
assertEquals(
"",
((Software)new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null)).name);
}
示例8: testWithoutValueField
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
/**
* Tests conversion with null in field value.
*/
public void testWithoutValueField() {
converterLookup.registerConverter(new ToAttributedValueConverter(
Software.class, mapper, reflectionProvider, converterLookup, null), 0);
final Software software = new Software("Codehaus", "XStream");
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
new TreeMarshaller(compactWriter, converterLookup, mapper).start(software, null);
compactWriter.flush();
assertEquals("<software vendor=\"Codehaus\" name=\"XStream\"/>", writer.toString());
final HierarchicalStreamReader reader = driver.createReader(new StringReader(
writer.toString()));
assertEquals(
software, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
}
示例9: testWithComplexValueField
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
/**
* Tests conversion with complex value field.
*/
public void testWithComplexValueField() {
converterLookup.registerConverter(new ToAttributedValueConverter(
X.class, mapper, reflectionProvider, converterLookup, "innerObj"), 0);
final X x = new X(42);
x.aStr = "xXx";
x.innerObj = new Y();
x.innerObj.yField = "inner";
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
new TreeMarshaller(compactWriter, converterLookup, mapper).start(x, null);
compactWriter.flush();
assertEquals(
"<x aStr=\"xXx\" anInt=\"42\"><yField>inner</yField></x>", writer.toString());
final HierarchicalStreamReader reader = driver.createReader(new StringReader(
writer.toString()));
assertEquals(x, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
}
示例10: testFailsWhenFieldCannotBeWrittenAsAttribute
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
public void testFailsWhenFieldCannotBeWrittenAsAttribute() {
converterLookup.registerConverter(new ToAttributedValueConverter(
X.class, mapper, reflectionProvider, converterLookup, "aStr"), 0);
final X x = new X(42);
x.aStr = "xXx";
x.innerObj = new Y();
x.innerObj.yField = "inner";
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
try {
new TreeMarshaller(compactWriter, converterLookup, mapper).start(x, null);
fail("Thrown " + ConversionException.class.getName() + " expected");
} catch (final ConversionException e) {
assertTrue(e.getMessage().indexOf("innerObj") >= 0);
}
}
示例11: write
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
/**
* Writes a list of {@link IModel} to the given output stream.
*
* IF YOU WANT TO WRITE IVML THEN CALL {@link #isIvmlFile()} TO DISABLE CERTAIN
* CONVERTERS!
*
* @param list
* the list to be written
* @param target
* the target where to write the list to
* @param isIvmlFile switch to enable specific converter
* @throws IOException
*/
public static final void write(List<IModel> list, File target, boolean isIvmlFile) throws IOException {
XStream xStream = createStream();
if (!isIvmlFile) {
xStream.registerConverter(new ProjectConverter());
}
// PRODUCTION
Writer writer = null;
FileOutputStream out = null;
try {
out = new FileOutputStream(target);
writer = new OutputStreamWriter(out, "UTF-8");
xStream.marshal(list, new CompactWriter(writer));
printMap(CLASSES, target);
} catch (UnsupportedEncodingException e) {
logger.exception(e);
} finally {
if (null != out) {
out.close();
writer.close();
}
}
// FOR DEBUGGING ONLY: This will print the xml with pretty printing.
// xStream.toXML(list, out);
}
示例12: XStreamSerializer
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
public XStreamSerializer(String name, boolean withSpecialConverter, final XMLInputFactory inf, final XMLOutputFactory outf) throws Exception
{
super(name);
if (inf != null && outf != null) {
xstream = new XStream(new StaxDriver() {
public XMLInputFactory getInputFactory() {
return inf;
}
public XMLOutputFactory getOutputFactory() {
return outf;
}
});
} else {
xstream = new XStream(new XppDriver(){
public HierarchicalStreamWriter createWriter(Writer out) {
//return new PrettyPrintWriter(out, xmlFriendlyReplacer());
return new CompactWriter(out, xmlFriendlyReplacer());
}
});
}
if (withSpecialConverter) {
registerConverters();
}
}
示例13: marshalWriter
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
public void marshalWriter(Object graph, Writer writer, DataHolder dataHolder)
throws XmlMappingException, IOException {
if (this.streamDriver != null) {
doMarshal(graph, this.streamDriver.createWriter(writer), dataHolder);
}
else {
doMarshal(graph, new CompactWriter(writer), dataHolder);
}
}
示例14: createEntityCollectionXml
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
public static final String createEntityCollectionXml(final GenericEntityCollection entities) {
final StringWriter stringWriter = new StringWriter();
final HierarchicalStreamWriter writer = new CompactWriter(stringWriter);
writer.startNode("Entities");
writer.addAttribute("TotalResults", String.valueOf(entities.getTotalResults()));
for (final GenericEntity entity : entities) {
createXml(writer, entity);
}
writer.endNode();
return stringWriter.toString();
}
示例15: toString
import com.thoughtworks.xstream.io.xml.CompactWriter; //导入依赖的package包/类
@Override
public String toString() {
StringWriter sw = new StringWriter();
xstream.marshal(LoginTicketRequest.this, new CompactWriter(sw));
return sw.toString();
}