@Override public void write(OutputNode node, String raw) throws Exception { if (encryptedFields.contains(node.getName())) { node.setValue(TransferSettings.encrypt(raw)); node.setAttribute("encrypted", Boolean.TRUE.toString()); } else { node.setValue(raw); } }
@Override public void write(OutputNode node, FileContent.FileChecksum value) throws Exception { node.setValue(value.toString()); } }
public void write(OutputNode node, Map<String, String> value) throws Exception final OutputNode parent = node.getParent(); node.setName(e.getKey()); node.setValue(e.getValue()); node.getAttributes().remove("class"); first = false; parent.getChild(e.getKey()).setValue(e.getValue());
/** * This <code>write</code> method will write the specified object * to the given XML element as as list entries. Each entry within * the given list must be assignable to the given primitive type. * This will deserialize each entry type as a primitive value. In * order to do this the parent string provided forms the element. * * @param source this is the source collection to be serialized * @param node this is the XML element container to be populated */ public void write(OutputNode node, Object source) throws Exception { OutputNode parent = node.getParent(); Mode mode = node.getMode(); if(!node.isCommitted()) { node.remove(); } write(parent, source, mode); }
public static void write(OutputNode parent, Element domElement) throws Exception { OutputNode child = parent.getChild(domElement.getNodeName()); child.getNamespaces().setReference(domElement.getNamespaceURI(), domElement.getPrefix()); child.setValue(domElement.getTextContent()); child.commit(); } }
public void write(OutputNode node, SaltedSecretKey saltedSecretKey) { node.setAttribute("salt", StringUtil.toHex(saltedSecretKey.getSalt())); node.setAttribute("key", StringUtil.toHex(saltedSecretKey.getEncoded())); } }
@Override public void write(OutputNode node, T entity) throws Exception { for(org.w3c.dom.Element domElement : entity.getAny()) { ElementConverter.write(node, domElement); } Map<String, Field> entityFields = getEntityFields(); for (String fieldName : entityFields.keySet()) { Field field = entityFields.get(fieldName); Object value = getGetterForField(field).invoke(entity); if (value == null) { continue; } if (value instanceof String) { OutputNode childNode = node.getChild(fieldName); childNode.setReference(SardineUtil.DEFAULT_NAMESPACE_URI); childNode.setValue((String)value); } else { serializer.write(value, node); } } } }
/** * This <code>write</code> method will write the specified object * to the given XML element as as array entries. Each entry within * the given array must be assignable to the array component type. * This will deserialize each entry type as a primitive value. In * order to do this the parent string provided forms the element. * * @param source this is the source object array to be serialized * @param node this is the XML element container to be populated */ public void write(OutputNode node, Object source) throws Exception { int size = Array.getLength(source); for(int i = 0; i < size; i++) { OutputNode child = node.getChild(parent); if(child == null) { break; } write(child, source, i); } }
/** * This <code>write</code> method is used to convert the provided * object to an XML element. This creates a child node from the * given <code>OutputNode</code> object. Once this child element * is created it is populated with the fields of the source object * in accordance with the XML schema class. * * @param source this is the object to be serialized to XML * @param expect this is the class that is expected to be written * @param name this is the name of the root annotation used * * @throws Exception thrown if there is a problem serializing */ public void write(OutputNode node, Object source, Class expect, String name) throws Exception { OutputNode child = node.getChild(name); Type type = getType(expect); if(source != null) { Class actual = source.getClass(); Decorator decorator = getDecorator(actual); if(decorator != null) { decorator.decorate(child); } if(!context.setOverride(type, source, child)) { getComposite(actual).write(child, source); } } child.commit(); }
/** * This is used to write the attributes of the specified node to * the output. This will iterate over each node entered on to * the node. Once written the node is considered inactive. * * @param node this is the node to have is attributes written */ private void writeAttributes(OutputNode node) throws Exception { NodeMap<OutputNode> map = node.getAttributes(); for(String name : map) { OutputNode entry = map.get(name); String value = entry.getValue(); String prefix = entry.getPrefix(verbose); writer.writeAttribute(name, value, prefix); } active.remove(node); }
/** * This is used to write a new end element to the resulting XML * document. This will acquire the name and value of the given * node, if the node has a value that is written. Finally a new * end tag is written to the document and the output is flushed. * * @param node this is the node that is to have an end tag */ private void writeEnd(OutputNode node) throws Exception { String name = node.getName(); String prefix = node.getPrefix(verbose); String value = node.getValue(); if(value != null) { writeValue(node); } if(name != null) { writer.writeEnd(name, prefix); writer.flush(); } }
/** * The <code>write</code> method uses the name of the XML element to * select a converter to be used to write the instance. Selection of * the converter is done by looking up the associated label from * the union group using the instance type. Once the converter has * been selected it is used to write the instance. * * @param node this is the XML element used to write the instance * @param item this is the individual list entry to be serialized * @param label this is the label to used to acquire the converter */ private void write(OutputNode node, Object item, Label label) throws Exception { Converter converter = label.getConverter(context); Collection list = Collections.singleton(item); if(!label.isInline()) { String name = label.getName(); String root = style.getElement(name); if(!node.isCommitted()) { node.setName(root); } } converter.write(node, list); } }
/** * This <code>write</code> method will write the specified object * to the given XML element as as list entries. Each entry within * the given collection must be assignable from the annotated * type specified within the <code>ElementList</code> annotation. * Each entry is serialized as a root element, that is, its * <code>Root</code> annotation is used to extract the name. * * @param source this is the source collection to be serialized * @param node this is the XML element container to be populated */ public void write(OutputNode node, Object source) throws Exception { Collection list = (Collection) source; OutputNode parent = node.getParent(); if(!node.isCommitted()) { node.remove(); } write(parent, list); }
/** * This <code>writeSection</code> method is used to perform serialization * of the given source object. Serialization is performed by appending * elements and attributes from the source object to the provided XML * element object. How the objects contacts are serialized is * determined by the XML schema class that the source object is an * instance of. If a required contact is null an exception is thrown. * * @param source this is the source object to be serialized * @param node the XML element the object is to be serialized to * @param section this is the section that defines the XML structure */ private void writeSection(OutputNode node, Object source, Section section) throws Exception { NamespaceMap scope = node.getNamespaces(); String prefix = section.getPrefix(); if(prefix != null) { String reference = scope.getReference(prefix); if(reference == null) { throw new ElementException("Namespace prefix '%s' in %s is not in scope", prefix, type); } else { node.setReference(reference); } } writeAttributes(node, source, section); writeElements(node, source, section); writeText(node, source, section); }
_logger.Verbose("Old name was " + element.getName()); element.setName(javaType.getSimpleName()); _logger.Verbose("Changing name to " + javaType.getSimpleName()); String className = element.getAttributes().get("class").getValue(); Class localClass = Class.forName(className); boolean shouldShortenName = ObjectBase.class.isAssignableFrom(localClass); if (shouldShortenName) element.getAttributes().remove("class"); element.setName(localClass.getSimpleName()); element.setName(type.getType().getSimpleName());
/** * This is used to write a new start element to the resulting XML * document. This will create an output node of the specified * name before writing the start tag. Once the tag is written * the node is pushed on to the head of the output node stack. * * @param node this is the node that is to have its name written */ private void writeName(OutputNode node) throws Exception { String prefix = node.getPrefix(verbose); String name = node.getName(); if(name != null) { writer.writeStart(name, prefix); } }
/** * Constructor for the <code>OutputAttribute</code> object. This * is used to create a simple name value pair attribute holder. * * @param name this is the name that is used for the node * @param value this is the value used for the node */ public OutputAttribute(OutputNode source, String name, String value) { this.scope = source.getNamespaces(); this.source = source; this.value = value; this.name = name; }
/** * This <code>write</code> method will write the specified object * to the given XML element as as array entries. Each entry within * the given array must be assignable to the array component type. * Each array entry is serialized as a root element, that is, its * <code>Root</code> annotation is used to extract the name. * * @param source this is the source object array to be serialized * @param node this is the XML element container to be populated */ public void write(OutputNode node, Object source) throws Exception { int size = Array.getLength(source); for(int i = 0; i < size; i++) { Object item = Array.get(source, i); Class type = entry.getType(); root.write(node, item, type, parent); } node.commit(); } }
@Override public OutputNode writeElement(OutputNode output, String namespace, String element, Object source) { OutputNode node = null; if (!skip(null, source)) { try { node = output.getChild(element); } catch (Exception exception) { throw new XmlPersisterException(exception); } node.setReference(namespace == null ? EMPTY : namespace); write(node, source); } return node; }