/** * Convert to an XML element. */ public Element toElement(Branch parent) { Element root = parent.addElement("FindBugsSummary"); DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); Date date = new Date(); root.addAttribute("timestamp", df.format(date)); root.addAttribute("total_classes", String.valueOf(totalClasses)); root.addAttribute("total_bugs", String.valueOf(totalErrors)); root.addAttribute("num_packages", String.valueOf(packageStatsMap.size())); Iterator<PackageStats> i = packageStatsMap.values().iterator(); while (i.hasNext()) { PackageStats stats = i.next(); stats.toElement(root); } return root; }
@Override protected Object createNode(final String name) { final Element element = documentFactory.createElement(encodeNode(name)); final Branch top = top(); if (top != null) { top().add(element); } return element; }
private void unmarshallElement(HierarchicalStreamReader reader, Branch branch) { Element element = branch.addElement(reader.getNodeName()); for (int i=0; i<reader.getAttributeCount(); i++) { String attributeName = reader.getAttributeName(i); String attributeValue = reader.getAttribute(i); element.addAttribute(attributeName, attributeValue); } if (StringUtils.isNotBlank(reader.getValue())) element.setText(reader.getValue().trim()); while (reader.hasMoreChildren()) { reader.moveDown(); unmarshallElement(reader, element); reader.moveUp(); } }
public void openTag(String tagName, XMLAttributeList attributeList) { Branch top = stack.getLast(); Element element = top.addElement(tagName); stack.addLast(element); for (Iterator<XMLAttributeList.NameValuePair> i= attributeList.iterator(); i.hasNext(); ) { XMLAttributeList.NameValuePair pair = i.next(); element.addAttribute(pair.getName(), pair.getValue()); } }
public Object evaluate(TaskRequest req, TaskResponse res) { Branch rslt = new DocumentFactory().createDocument(); if (name != null) { rslt = rslt.addElement((String) name.evaluate(req, res)); } return rslt; }
public Iterator getChildAxisIterator(Object contextNode) { Iterator result = null; if ( contextNode instanceof Branch ) { Branch node = (Branch) contextNode; result = node.nodeIterator(); } if (result != null) { return result; } return JaxenConstants.EMPTY_ITERATOR; }
public void openTag(String tagName, XMLAttributeList attributeList) { Branch top = stack.getLast(); Element element = top.addElement(tagName); stack.addLast(element); for (Iterator<XMLAttributeList.NameValuePair> i = attributeList.iterator(); i.hasNext();) { XMLAttributeList.NameValuePair pair = i.next(); element.addAttribute(pair.getName(), pair.getValue()); } }
private void writeValue(final Branch branch, final Object obj, final String key, final String sValue, final boolean asAttribute, final boolean asCDATA) { if (sValue == null) { return; } if (asAttribute == true) { addAttribute((Element) branch, obj, key, sValue); } else if (asCDATA == true) { branch.addElement(key).add(new DefaultCDATA(sValue)); } else { branch.addElement(key).setText(sValue); } }
/** * entry method * * @param obj * @param name */ public void visit(_Object obj, String name) { Field field = new Field(name, false); field.setTarget(obj); Branch branch = document; VisitorContext childCtx = new VisitorContext(); childCtx.setField(field); childCtx.setBranch(branch); push(childCtx); obj.accept(this); }
/** * Updates a collection record Document. * * @param collectionRecordDoc A collection record Document (may be from the template) * @param title Title (must not be null) * @param description Description (can be null) * @param additionalMetadata Additional metadata (String, XML, or null) * @param xmlFormat Format specifier or "DDS_UNCHANGED" to leave unchanged * @param key Collection key or "DDS_UNCHANGED" to leave unchanged * @param id Record ID or "DDS_UNCHANGED" to leave unchanged * @param accessionDate Accession date or null to leave unchanged * @return An updated Document * @exception Exception If error */ private org.dom4j.Document updateCollectionRecord( org.dom4j.Document collectionRecordDoc, String title, String description, String additionalMetadata, String xmlFormat, String key, String id, Date accessionDate) throws Exception { if (!key.equals("DDS_UNCHANGED")) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='access']/*[local-name()='key']").setText(key); if (!xmlFormat.equals("DDS_UNCHANGED")) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='access']/*[local-name()='key']/@libraryFormat").setText(xmlFormat); if (!id.equals("DDS_UNCHANGED")) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='metaMetadata']/*[local-name()='catalogEntries']/*[local-name()='catalog']/@entry").setText(id); if (accessionDate != null) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='approval']/*[local-name()='collectionStatuses']/*[local-name()='collectionStatus']/@date").setText(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(accessionDate)); // Update the short title: Node shortTitleNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']/*[local-name()='shortTitle']"); if (shortTitleNode != null) shortTitleNode.setText(title); // For previous repositories that are upgraded, remove the fullTitle (legacy) Node fullTitleNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']/*[local-name()='fullTitle']"); if (fullTitleNode != null) fullTitleNode.detach(); Node descriptionNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']/*[local-name()='description']"); if (descriptionNode == null) descriptionNode = ((Branch) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']")).addElement("description"); if (description == null || description.trim().length() == 0) description = title; descriptionNode.setText(description); // Delete and then re-create the additionalMetadata node: Node additionalMetadataNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='additionalMetadata']"); if (additionalMetadataNode != null) additionalMetadataNode.detach(); if (additionalMetadata != null && additionalMetadata.trim().length() > 0) { org.dom4j.Document additionalMetadataDocument; try { additionalMetadataDocument = Dom4jUtils.getXmlDocument("<additionalMetadata>" + additionalMetadata + "</additionalMetadata>"); } catch (Throwable t) { throw new PutCollectionException("Error processing additionalMetadata argument: " + t.getMessage(), PutCollectionException.ERROR_CODE_BAD_ADDITIONAL_METADATA); } ((Branch) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']")).add(additionalMetadataDocument.getRootElement()); } return collectionRecordDoc; }
/** * @since 1.4 */ public Dom4JWriter(final Branch root, final DocumentFactory factory, final NameCoder nameCoder) { super(root, nameCoder); documentFactory = factory; }
/** * @since 1.4 */ public Dom4JWriter(final Branch root, final NameCoder nameCoder) { this(root, new DocumentFactory(), nameCoder); }
/** * @since 1.2.1 * @deprecated As of 1.4 use {@link Dom4JWriter#Dom4JWriter(Branch, DocumentFactory, NameCoder)} instead. */ @Deprecated public Dom4JWriter(final Branch root, final DocumentFactory factory, final XmlFriendlyReplacer replacer) { this(root, factory, (NameCoder)replacer); }
/** * @since 1.2.1 * @deprecated As of 1.4 use {@link Dom4JWriter#Dom4JWriter(Branch, NameCoder)} instead */ @Deprecated public Dom4JWriter(final Branch root, final XmlFriendlyReplacer replacer) { this(root, new DocumentFactory(), (NameCoder)replacer); }
public Dom4JWriter(final Branch root) { this(root, new DocumentFactory(), new XmlFriendlyNameCoder()); }
private Branch top() { return (Branch)getCurrent(); }
public void appendContent(Branch branch) { element.appendContent( branch ); }
public void appendContent(Branch branch) { getWrapped().appendContent(branch); }
private void toElement(XMLWriteable obj, Branch parent) { Dom4JXMLOutput treeBuilder = new Dom4JXMLOutput(parent); treeBuilder.write(obj); }
public void openTag(String tagName) { Branch top = stack.getLast(); Element element = top.addElement(tagName); stack.addLast(element); }
/** * Updates a collection record Document. * * @param collectionRecordDoc A collection record Document (may be from the template) * @param title Title (must not be null) * @param description Description (can be null) * @param additionalMetadata Additional metadata (String, XML, or null) * @param xmlFormat Format specifier or "DDS_UNCHANGED" to leave unchanged * @param key Collection key or "DDS_UNCHANGED" to leave unchanged * @param id Record ID or "DDS_UNCHANGED" to leave unchanged * @param accessionDate Accession date or null to leave unchanged * @return An updated Document * @throws Exception If error */ private org.dom4j.Document updateCollectionRecord( org.dom4j.Document collectionRecordDoc, String title, String description, String additionalMetadata, String xmlFormat, String key, String id, Date accessionDate) throws Exception { if (!key.equals("DDS_UNCHANGED")) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='access']/*[local-name()='key']").setText(key); if (!xmlFormat.equals("DDS_UNCHANGED")) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='access']/*[local-name()='key']/@libraryFormat").setText(xmlFormat); if (!id.equals("DDS_UNCHANGED")) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='metaMetadata']/*[local-name()='catalogEntries']/*[local-name()='catalog']/@entry").setText(id); if (accessionDate != null) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='approval']/*[local-name()='collectionStatuses']/*[local-name()='collectionStatus']/@date").setText(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(accessionDate)); // Update the full title, if present: Node fullTitleNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']/*[local-name()='fullTitle']"); if (fullTitleNode != null) fullTitleNode.setText(title); // Update the short title too, if present: Node shortTitleNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']/*[local-name()='shortTitle']"); if (shortTitleNode != null) shortTitleNode.setText(title); Node descriptionNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']/*[local-name()='description']"); if (descriptionNode == null) descriptionNode = ((Branch) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']")).addElement("description"); if (description == null || description.trim().length() == 0) description = title; descriptionNode.setText(description); // Delete and then re-create the additionalMetadata node: Node additionalMetadataNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='additionalMetadata']"); if (additionalMetadataNode != null) additionalMetadataNode.detach(); if (additionalMetadata != null && additionalMetadata.trim().length() > 0) { org.dom4j.Document additionalMetadataDocument; try { additionalMetadataDocument = Dom4jUtils.getXmlDocument("<additionalMetadata>" + additionalMetadata + "</additionalMetadata>"); } catch (Throwable t) { throw new PutCollectionException("Error processing additionalMetadata argument: " + t.getMessage(), PutCollectionException.ERROR_CODE_BAD_ADDITIONAL_METADATA); } ((Branch) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']")).add(additionalMetadataDocument.getRootElement()); } return collectionRecordDoc; }
public void appendContent(Branch branch) { target().appendContent( branch ); }
public Dom4JWriter(Branch paramBranch) { this(paramBranch, new DocumentFactory(), new XmlFriendlyNameCoder()); }
public Dom4JWriter(Branch paramBranch, NameCoder paramNameCoder) { this(paramBranch, new DocumentFactory(), paramNameCoder); }
public Dom4JWriter(Branch paramBranch, XmlFriendlyReplacer paramXmlFriendlyReplacer) { this(paramBranch, new DocumentFactory(), paramXmlFriendlyReplacer); }
public Dom4JWriter(Branch paramBranch, DocumentFactory paramDocumentFactory, NameCoder paramNameCoder) { super(paramBranch, paramNameCoder); this.documentFactory = paramDocumentFactory; }
public Dom4JWriter(Branch paramBranch, DocumentFactory paramDocumentFactory, XmlFriendlyReplacer paramXmlFriendlyReplacer) { this(paramBranch, paramDocumentFactory, paramXmlFriendlyReplacer); }
public void startTag(String tagName) { Branch top = stack.getLast(); Element element = top.addElement(tagName); stack.addLast(element); }