Java Code Examples for org.dom4j.Branch

The following are top voted examples for showing how to use org.dom4j.Branch. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: parabuild-ci   File: ProjectStats.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Project: lams   File: Dom4JWriter.java   View source code 5 votes vote down vote up
@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;
}
 
Example 3
Project: gitplex-mit   File: JpaConverter.java   View source code 5 votes vote down vote up
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();
	}
}
 
Example 4
Project: parabuild-ci   File: Dom4JXMLOutput.java   View source code 5 votes vote down vote up
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());
	}
}
 
Example 5
Project: cernunnos   File: NewDocumentPhrase.java   View source code 5 votes vote down vote up
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;
		
	}
 
Example 6
Project: xstream   File: Dom4JWriter.java   View source code 5 votes vote down vote up
@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;
}
 
Example 7
Project: jaxen   File: DocumentNavigator.java   View source code 5 votes vote down vote up
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;
}
 
Example 8
Project: findbugs-all-the-bugs   File: Dom4JXMLOutput.java   View source code 5 votes vote down vote up
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());
    }
}
 
Example 9
Project: FindBug-for-Domino-Designer   File: Dom4JXMLOutput.java   View source code 5 votes vote down vote up
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());
    }
}
 
Example 10
Project: projectforge-webapp   File: XmlObjectWriter.java   View source code 5 votes vote down vote up
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);
  }
}
 
Example 11
Project: visual-programming   File: XmlSerialzationVisitor.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 12
Project: joai-project   File: RepositoryManager.java   View source code 4 votes vote down vote up
/**
 *  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;
}
 
Example 13
Project: lams   File: Dom4JWriter.java   View source code 4 votes vote down vote up
/**
 * @since 1.4
 */
public Dom4JWriter(final Branch root, final DocumentFactory factory, final NameCoder nameCoder) {
    super(root, nameCoder);
    documentFactory = factory;
}
 
Example 14
Project: lams   File: Dom4JWriter.java   View source code 4 votes vote down vote up
/**
 * @since 1.4
 */
public Dom4JWriter(final Branch root, final NameCoder nameCoder) {
    this(root, new DocumentFactory(), nameCoder);
}
 
Example 15
Project: lams   File: Dom4JWriter.java   View source code 4 votes vote down vote up
/**
 * @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);
}
 
Example 16
Project: lams   File: Dom4JWriter.java   View source code 4 votes vote down vote up
/**
 * @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);
}
 
Example 17
Project: lams   File: Dom4JWriter.java   View source code 4 votes vote down vote up
public Dom4JWriter(final Branch root) {
    this(root, new DocumentFactory(), new XmlFriendlyNameCoder());
}
 
Example 18
Project: lams   File: Dom4JWriter.java   View source code 4 votes vote down vote up
private Branch top() {
    return (Branch)getCurrent();
}
 
Example 19
Project: lams   File: ElementWrapper.java   View source code 4 votes vote down vote up
public void appendContent(Branch branch) {
	element.appendContent( branch );
}
 
Example 20
Project: gitplex-mit   File: VersionedDocument.java   View source code 4 votes vote down vote up
public void appendContent(Branch branch) {
	getWrapped().appendContent(branch);
}
 
Example 21
Project: parabuild-ci   File: PackageStats.java   View source code 4 votes vote down vote up
private void toElement(XMLWriteable obj, Branch parent) {
	Dom4JXMLOutput treeBuilder = new Dom4JXMLOutput(parent);
	treeBuilder.write(obj);
}
 
Example 22
Project: parabuild-ci   File: Dom4JXMLOutput.java   View source code 4 votes vote down vote up
public void openTag(String tagName) {
	Branch top = stack.getLast();
	Element element = top.addElement(tagName);
	stack.addLast(element);
}
 
Example 23
Project: dls-repository-stack   File: RepositoryManager.java   View source code 4 votes vote down vote up
/**
 * 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;
}
 
Example 24
Project: cacheonix-core   File: ElementWrapper.java   View source code 4 votes vote down vote up
public void appendContent(Branch branch) {
	element.appendContent( branch );
}
 
Example 25
Project: cacheonix-core   File: Dom4jProxy.java   View source code 4 votes vote down vote up
public void appendContent(Branch branch) {
	target().appendContent( branch );
}
 
Example 26
Project: xstream   File: Dom4JWriter.java   View source code 4 votes vote down vote up
/**
 * @since 1.4
 */
public Dom4JWriter(final Branch root, final DocumentFactory factory, final NameCoder nameCoder) {
    super(root, nameCoder);
    documentFactory = factory;
}
 
Example 27
Project: xstream   File: Dom4JWriter.java   View source code 4 votes vote down vote up
/**
 * @since 1.4
 */
public Dom4JWriter(final Branch root, final NameCoder nameCoder) {
    this(root, new DocumentFactory(), nameCoder);
}
 
Example 28
Project: xstream   File: Dom4JWriter.java   View source code 4 votes vote down vote up
/**
 * @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);
}
 
Example 29
Project: xstream   File: Dom4JWriter.java   View source code 4 votes vote down vote up
/**
 * @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);
}
 
Example 30
Project: xstream   File: Dom4JWriter.java   View source code 4 votes vote down vote up
public Dom4JWriter(final Branch root) {
    this(root, new DocumentFactory(), new XmlFriendlyNameCoder());
}
 
Example 31
Project: xstream   File: Dom4JWriter.java   View source code 4 votes vote down vote up
private Branch top() {
    return (Branch)getCurrent();
}
 
Example 32
Project: QuizUpWinner   File: Dom4JWriter.java   View source code 4 votes vote down vote up
public Dom4JWriter(Branch paramBranch)
{
  this(paramBranch, new DocumentFactory(), new XmlFriendlyNameCoder());
}
 
Example 33
Project: QuizUpWinner   File: Dom4JWriter.java   View source code 4 votes vote down vote up
public Dom4JWriter(Branch paramBranch, NameCoder paramNameCoder)
{
  this(paramBranch, new DocumentFactory(), paramNameCoder);
}
 
Example 34
Project: QuizUpWinner   File: Dom4JWriter.java   View source code 4 votes vote down vote up
public Dom4JWriter(Branch paramBranch, XmlFriendlyReplacer paramXmlFriendlyReplacer)
{
  this(paramBranch, new DocumentFactory(), paramXmlFriendlyReplacer);
}
 
Example 35
Project: QuizUpWinner   File: Dom4JWriter.java   View source code 4 votes vote down vote up
public Dom4JWriter(Branch paramBranch, DocumentFactory paramDocumentFactory, NameCoder paramNameCoder)
{
  super(paramBranch, paramNameCoder);
  this.documentFactory = paramDocumentFactory;
}
 
Example 36
Project: QuizUpWinner   File: Dom4JWriter.java   View source code 4 votes vote down vote up
public Dom4JWriter(Branch paramBranch, DocumentFactory paramDocumentFactory, XmlFriendlyReplacer paramXmlFriendlyReplacer)
{
  this(paramBranch, paramDocumentFactory, paramXmlFriendlyReplacer);
}
 
Example 37
Project: QuizUpWinner   File: Dom4JWriter.java   View source code 4 votes vote down vote up
private Branch top()
{
  return (Branch)getCurrent();
}
 
Example 38
Project: findbugs-all-the-bugs   File: Dom4JXMLOutput.java   View source code 4 votes vote down vote up
public void openTag(String tagName) {
    Branch top = stack.getLast();
    Element element = top.addElement(tagName);
    stack.addLast(element);
}
 
Example 39
Project: findbugs-all-the-bugs   File: Dom4JXMLOutput.java   View source code 4 votes vote down vote up
public void startTag(String tagName) {
    Branch top = stack.getLast();
    Element element = top.addElement(tagName);
    stack.addLast(element);
}
 
Example 40
Project: FindBug-for-Domino-Designer   File: Dom4JXMLOutput.java   View source code 4 votes vote down vote up
public void openTag(String tagName) {
    Branch top = stack.getLast();
    Element element = top.addElement(tagName);
    stack.addLast(element);
}