com.thoughtworks.xstream.io.HierarchicalStreamWriter Java Examples
The following examples show how to use
com.thoughtworks.xstream.io.HierarchicalStreamWriter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphModelConverter.java From depan with Apache License 2.0 | 6 votes |
/** * No need to start a node, since the caller ensures we are wrapped correctly. */ @Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { GraphModel graph = (GraphModel) source; // Save all nodes. for (GraphNode node : graph.getNodes()) { marshalObject(node, writer, context); } // Save all edges. for (GraphEdge edge : graph.getEdges()) { marshalObject(edge, writer, context); } }
Example #2
Source File: StringKeyMapConverter.java From brooklyn-server with Apache License 2.0 | 6 votes |
protected void marshalStringKey(HierarchicalStreamWriter writer, MarshallingContext context, Entry entry) { String key = (String)entry.getKey(); String entryNodeName = getEntryNodeName(); boolean useKeyAsNodeName = (!key.equals(entryNodeName) && isKeyValidForNodeName(key)); if (useKeyAsNodeName) entryNodeName = key; ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryNodeName, Map.Entry.class); if (!useKeyAsNodeName) writer.addAttribute("key", key); Object value = entry.getValue(); if (entry.getValue()!=null && isInlineableType(value.getClass())) { if (!(value instanceof String)) writer.addAttribute("type", mapper().serializedClass(entry.getValue().getClass())); if (entry.getValue().getClass().isEnum()) writer.setValue(((Enum)entry.getValue()).name()); else writer.setValue(""+entry.getValue()); } else { writeItem(entry.getValue(), context, writer); } writer.endNode(); }
Example #3
Source File: GlossaryItemManager.java From olat with Apache License 2.0 | 6 votes |
/** * writes glossary to xml-file prepend doc-book dtd: <!DOCTYPE glossary PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" * "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> * * @param glossaryFile * @param glossaryItemArr */ private void saveToFile(VFSLeaf glossaryFile, ArrayList<GlossaryItem> glossaryItemArr) { // cdata-tags should be used instead of strings, overwrite writer. XStream xstream = new XStream(new XppDriver() { @Override public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out) { @Override protected void writeText(QuickWriter writer, String text) { if (text.contains("<") || text.contains(">") || text.contains("&")) { writer.write("<![CDATA["); writer.write(text); writer.write("]]>"); } else { writer.write(text); } } }; } }); xstream.alias(XML_GLOSSARY_ITEM_NAME, GlossaryItem.class); glossaryItemArr = removeEmptyGlossaryItems(glossaryItemArr); XStreamHelper.writeObject(xstream, glossaryFile, glossaryItemArr); }
Example #4
Source File: MessageUtil.java From jeewx with Apache License 2.0 | 6 votes |
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); } } }; }
Example #5
Source File: WxPayOrderNotifyResultConverter.java From weixin-java-tools with Apache License 2.0 | 6 votes |
@Override public void marshal(Object original, HierarchicalStreamWriter writer, MarshallingContext context) { super.marshal(original, writer, context); WxPayOrderNotifyResult obj = (WxPayOrderNotifyResult) original; List<WxPayOrderNotifyCoupon> list = obj.getCouponList(); if (list == null || list.size() == 0) { return; } for (int i = 0; i < list.size(); i++) { WxPayOrderNotifyCoupon coupon = list.get(i); writer.startNode("coupon_id_" + i); writer.setValue(coupon.getCouponId()); writer.endNode(); writer.startNode("coupon_type_" + i); writer.setValue(coupon.getCouponType()); writer.endNode(); writer.startNode("coupon_fee_" + i); writer.setValue(coupon.getCouponFee() + ""); writer.endNode(); } }
Example #6
Source File: BeanDefinitionWriterServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { BeanDefinitionHolder holder = (BeanDefinitionHolder) source; BeanDefinition definition = holder.getBeanDefinition(); writer.addAttribute("class", definition.getBeanClassName()); writer.addAttribute("name", holder.getBeanName()); for (PropertyValue property : definition.getPropertyValues().getPropertyValueList()) { writer.startNode("property"); writer.addAttribute("name", property.getName()); if (property.getValue().getClass().equals(TypedStringValue.class)) { context.convertAnother(property.getValue()); } else { writeItem(property.getValue(), context, writer); } writer.endNode(); } }
Example #7
Source File: LocaleConverter.java From weblaf with GNU General Public License v3.0 | 6 votes |
@Override public void marshal ( final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context ) { final Locale locale = ( Locale ) source; // Adding language writer.addAttribute ( "language", locale.getLanguage () ); // Adding country final String country = locale.getCountry (); if ( TextUtils.notEmpty ( country ) ) { writer.addAttribute ( "country", country ); } // Adding country final String variant = locale.getVariant (); if ( TextUtils.notEmpty ( variant ) ) { writer.addAttribute ( "variant", variant ); } }
Example #8
Source File: DateTimeConverterImpl.java From yes-cart with Apache License 2.0 | 6 votes |
@Override public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { if (source == null) { writer.setValue(""); } else if (source instanceof LocalDate) { writer.setValue(((LocalDate) source).atStartOfDay().format(DateTimeFormatter.ISO_DATE_TIME)); } else if (source instanceof LocalDateTime) { writer.setValue(((LocalDateTime) source).format(DateTimeFormatter.ISO_DATE_TIME)); } else if (source instanceof ZonedDateTime) { writer.setValue(((ZonedDateTime) source).format(DateTimeFormatter.ISO_DATE_TIME)); } else if (source instanceof Instant) { writer.setValue(ZonedDateTime.ofInstant((Instant) source, DateUtils.zone()).format(DateTimeFormatter.ISO_DATE_TIME)); } else { writer.setValue(source.toString()); } }
Example #9
Source File: PropertiesConverter.java From lams with GNU General Public License v2.0 | 6 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { final Properties properties = (Properties) source; Map map = sort ? (Map)new TreeMap(properties) : (Map)properties; for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); writer.startNode("property"); writer.addAttribute("name", entry.getKey().toString()); writer.addAttribute("value", entry.getValue().toString()); writer.endNode(); } if (defaultsField != null) { Properties defaults = (Properties)Fields.read(defaultsField, properties); if (defaults != null) { writer.startNode("defaults"); marshal(defaults, writer, context); writer.endNode(); } } }
Example #10
Source File: BeanDefinitionWriterServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { ManagedMap<?, ?> map = (ManagedMap<?, ?>) source; for (Map.Entry<?, ?> entry : map.entrySet()) { writer.startNode("entry"); writer.startNode("key"); if (entry.getKey().getClass().equals(TypedStringValue.class)) { writer.startNode("value"); writer.setValue(((TypedStringValue) entry.getKey()).getValue()); writer.endNode(); } else { writeItem(entry.getKey(), context, writer); } writer.endNode(); if (entry.getValue().getClass().equals(TypedStringValue.class)) { writer.startNode("value"); writer.setValue(((TypedStringValue) entry.getValue()).getValue()); writer.endNode(); } else { writeItem(entry.getValue(), context, writer); } writer.endNode(); } }
Example #11
Source File: AttributeConverter.java From pentaho-aggdesigner with GNU General Public License v2.0 | 5 votes |
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) { Attribute attribute = (Attribute)object; writer.startNode("label"); writer.setValue(attribute.getLabel()); writer.endNode(); writer.startNode("table"); writer.setValue(attribute.getTable().getLabel()); writer.endNode(); }
Example #12
Source File: AbstractXStreamConverter.java From kogito-runtimes with Apache License 2.0 | 5 votes |
protected void writeString(HierarchicalStreamWriter writer, String name, String value) { if (value != null) { writer.startNode(name); writer.setValue(value); writer.endNode(); } }
Example #13
Source File: NamedMapConverter.java From lams with GNU General Public License v2.0 | 5 votes |
protected void writeItem(String name, Class type, Object item, MarshallingContext context, HierarchicalStreamWriter writer) { Class itemType = item == null ? Mapper.Null.class : item.getClass(); ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType); if (!itemType.equals(type)) { String attributeName = mapper().aliasForSystemAttribute("class"); if (attributeName != null) { writer.addAttribute(attributeName, mapper().serializedClass(itemType)); } } if (item != null) { context.convertAnother(item); } writer.endNode(); }
Example #14
Source File: JsonHierarchicalStreamDriver.java From lams with GNU General Public License v2.0 | 5 votes |
public HierarchicalStreamWriter createWriter(OutputStream out) { try { // JSON spec requires UTF-8 return createWriter(new OutputStreamWriter(out, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new StreamException(e); } }
Example #15
Source File: MapConverter.java From lams with GNU General Public License v2.0 | 5 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Map map = (Map) source; String entryName = mapper().serializedClass(Map.Entry.class); for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryName, entry.getClass()); writeCompleteItem(entry.getKey(), context, writer); writeCompleteItem(entry.getValue(), context, writer); writer.endNode(); } }
Example #16
Source File: GamaListConverter.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext arg2) { final IList list = (IList) arg0; // System.out.println("ConvertAnother : GamaList " + list.getClass()+ " "+list.getGamlType().getContentType()); DEBUG.OUT("ConvertAnother : IList " + list.getClass() + " " + list.getGamlType().getContentType()); arg2.convertAnother(new GamaListReducer(list)); // System.out.println("END --- ConvertAnother : GamaList "); DEBUG.OUT("END --- ConvertAnother : GamaList "); }
Example #17
Source File: ReferenceByIdMarshaller.java From lams with GNU General Public License v2.0 | 5 votes |
public ReferenceByIdMarshaller(HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper, IDGenerator idGenerator) { super(writer, converterLookup, mapper); this.idGenerator = idGenerator; }
Example #18
Source File: Dom4JDriver.java From lams with GNU General Public License v2.0 | 5 votes |
public HierarchicalStreamWriter createWriter(final Writer out) { final HierarchicalStreamWriter[] writer = new HierarchicalStreamWriter[1]; final FilterWriter filter = new FilterWriter(out){ public void close() { writer[0].close(); } }; writer[0] = new Dom4JXmlWriter(new XMLWriter(filter, outputFormat), getNameCoder()); return writer[0]; }
Example #19
Source File: DynamicProxyConverter.java From lams with GNU General Public License v2.0 | 5 votes |
private void addInterfacesToXml(Object source, HierarchicalStreamWriter writer) { Class[] interfaces = source.getClass().getInterfaces(); for (int i = 0; i < interfaces.length; i++) { Class currentInterface = interfaces[i]; writer.startNode("interface"); writer.setValue(mapper.serializedClass(currentInterface)); writer.endNode(); } }
Example #20
Source File: XStreamFactory.java From engage-api-client with Apache License 2.0 | 5 votes |
public XStream createXStream() { return new XStream( new XppDriver() { @Override public HierarchicalStreamWriter createWriter(Writer out) { return new XmlApiPrintWriter(out, new XmlFriendlyNameCoder("__", "_")); } }); }
Example #21
Source File: GamaSpeciesConverter.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext context) { // System.out.println("ConvertAnother : ConvertGamaSpecies " + arg0.getClass()); DEBUG.OUT("ConvertAnother : ConvertGamaSpecies " + arg0.getClass()); final AbstractSpecies spec = (AbstractSpecies) arg0; final GamaPopulation<? extends IAgent> pop = (GamaPopulation<? extends IAgent>) spec.getPopulation(convertScope.getScope()); writer.startNode("agentSetFromPopulation"); context.convertAnother(pop.getAgents(convertScope.getScope())); writer.endNode(); // System.out.println("===========END ConvertAnother : ConvertGamaSpecies"); DEBUG.OUT("===========END ConvertAnother : ConvertGamaSpecies"); }
Example #22
Source File: ArrayConverter.java From lams with GNU General Public License v2.0 | 5 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { int length = Array.getLength(source); for (int i = 0; i < length; i++) { final Object item = Array.get(source, i); writeCompleteItem(item, context, writer); } }
Example #23
Source File: MapConverter.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings({ "rawtypes" }) public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Map map = (Map) source; try { for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); marshalEntry(writer, context, entry); } } catch (ConcurrentModificationException e) { log.debug("Map " // seems there is no non-deprecated way to get the path... + (context instanceof ReferencingMarshallingContext ? "at "+((ReferencingMarshallingContext)context).currentPath() : "") + "["+source+"] modified while serializing; will fail, and retry may be attempted"); throw e; // would be nice to attempt to re-serialize being slightly more defensive, as code below; // but the code above may have written partial data so that is dangerous, we could have corrupted output. // if we could mark and restore in the output stream then we could do this below (but we don't have that in our stream), // or we could try this copying code in the first instance (but that's slow); // error is rare most of the time (e.g. attribute being updated) so we bail on this whole attempt // and simply try serializing the map-owner (e.g. an entity) again. // ImmutableList entries = ImmutableList.copyOf(map.entrySet()); // for (Iterator iterator = entries.iterator(); iterator.hasNext();) { // Map.Entry entry = (Map.Entry) iterator.next(); // marshalEntry(writer, context, entry); // } } }
Example #24
Source File: GamaPopulationConverter.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext context) { System.out.println("ConvertAnother : GamaPopulationConverter " + arg0.getClass()); final GamaPopulation pop = (GamaPopulation) arg0; writer.startNode("agentSetFromPopulation"); context.convertAnother(pop.getAgents(convertScope.getScope())); writer.endNode(); // System.out.println("===========END ConvertAnother : GamaSavedAgentConverter"); DEBUG.OUT("===========END ConvertAnother : GamaSavedAgentConverter"); }
Example #25
Source File: ResourceTransportWrapperConverter.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) { ResourceTransportWrapper<?> wrapper = (ResourceTransportWrapper<?>) value; IResource resource = wrapper.getResource(); String i = session.getReferencePointId(resource.getReferencePoint()); if (i == null) { log.error( "Could not retrieve reference point id for reference point '" + resource.getReferencePoint().getName() + "' of resource " + resource + ". Make sure you don't create activities for non-shared resources"); return; } // TODO use IPath.toPortableString() instead? String p = URLCodec.encode(pathFactory.fromPath(resource.getReferencePointRelativePath())); Type type = resource.getType(); if (type != Type.FILE && type != Type.FOLDER) { throw new IllegalStateException( "Illegal resource type " + type + " for resource " + resource); } String t = type.name(); writer.addAttribute(REFERENCE_POINT_ID, i); writer.addAttribute(PATH, p); writer.addAttribute(TYPE, t); }
Example #26
Source File: MapKeyValueCustomXstreamConverter.java From gatf with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void marshal(final Object value, final HierarchicalStreamWriter writer, final MarshallingContext context) { final AbstractMap<String, String> map = (AbstractMap<String, String>) value; for (final Entry<String, String> entry : map.entrySet()) { writer.startNode(entry.getKey().toString()); writer.setValue(entry.getValue().toString()); writer.endNode(); } }
Example #27
Source File: SystemClockConverter.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final Clock clock = (Clock)source; ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(Clock.class, "zone"), null); context.convertAnother(clock.getZone()); writer.endNode(); }
Example #28
Source File: XmlXstreamTest.java From amforeas with GNU General Public License v3.0 | 5 votes |
@Override public void marshal (Object o, HierarchicalStreamWriter writer, MarshallingContext mc) { Map<String, Object> map = (Map<String, Object>) o; for (String key : map.keySet()) { Object val = map.get(key); writer.startNode(key.toLowerCase()); if (val != null) { writer.setValue(val.toString()); } else { writer.setValue(""); } writer.endNode(); } }
Example #29
Source File: XmlUtilsTest.java From onetwo with Apache License 2.0 | 5 votes |
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { TestPersonAnnotation p = (TestPersonAnnotation) source; writer.startNode("name"); writer.setValue(p.getUserName()); writer.endNode(); writer.startNode("age"); writer.setValue(""+p.getAge()); writer.endNode(); writer.startNode("parent"); writer.setValue(""); writer.endNode(); }
Example #30
Source File: FileDocumentReferenceConverter.java From depan with Apache License 2.0 | 5 votes |
/** * Simply output the workspace relative name for the referenced GraphModel. */ @Override public void marshal( Object source, HierarchicalStreamWriter writer, MarshallingContext context) { FileDocumentReference<?> docRef = (FileDocumentReference<?>) source; String location = PlatformTools.fromPath(docRef.getLocation().getFullPath()); writer.startNode(FILE_DOC_REF_TAG); writer.addAttribute(DOC_PATH_ATTR, location); writer.endNode(); }