Java Code Examples for org.jdom2.Element#setContent()

The following examples show how to use org.jdom2.Element#setContent() . 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: CatalogXmlWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Element writeMetadata(ThreddsMetadata.MetadataOther mdata) {
  Element mdataElem = new Element("metadata", Catalog.defNS);
  if (mdata.getType() != null)
    mdataElem.setAttribute("metadataType", mdata.getType());
  if (mdata.isInherited())
    mdataElem.setAttribute("inherited", "true");

  String ns = mdata.getNamespaceURI();
  if ((ns != null) && !ns.equals(Catalog.CATALOG_NAMESPACE_10)) {
    Namespace mdataNS = Namespace.getNamespace(mdata.getPrefix(), ns);
    mdataElem.addNamespaceDeclaration(mdataNS);
  }

  if (mdata.getXlinkHref() != null) {
    mdataElem.setAttribute("href", mdata.getXlinkHref(), Catalog.xlinkNS);
    if (mdata.getTitle() != null)
      mdataElem.setAttribute("title", mdata.getTitle(), Catalog.xlinkNS);

  } else if (mdata.getContentObject() != null && mdata.getContentObject() instanceof Element) {
    Element content = (Element) mdata.getContentObject();
    mdataElem.setContent(content);
  }

  return mdataElem;
}
 
Example 2
Source File: WorkletService.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * updates the input datalist with the changed data in the output datalist
 *
 * @param in  - the JDOM Element containing the input params
 * @param out - the JDOM Element containing the output params
 * @return a JDOM Element with the data updated
 */
public Element updateDataList(Element in, Element out) {

    // get a copy of the 'in' list   	
    Element result = in.clone();

    // for each child in 'out' list, get its value and copy to 'in' list
    for (Element e : out.getChildren()) {

        // if there's a matching 'in' data item, update its value
        Element resData = result.getChild(e.getName());
        if (resData != null) {
            if (resData.getContentSize() > 0) resData.setContent(e.cloneContent());
            else resData.setText(e.getText());
        } else {
            // if the item is not in the 'in' list, add it.
            result.getChildren().add(e.clone());
        }
    }

    return result;
}
 
Example 3
Source File: ResourceManager.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * updates the input datalist with the changed data in the output datalist
 *
 * @param in  - the JDOM Element containing the input params
 * @param out - the JDOM Element containing the output params
 * @return a JDOM Element with the data updated
 */
private Element updateOutputDataList(Element in, Element out) {

    // get a copy of the 'in' list
    Element result = in.clone();

    // for each child in 'out' list, get its value and copy to 'in' list
    for (Element e : out.getChildren()) {

        // if there's a matching 'in' data item, update its value
        Element resData = result.getChild(e.getName());
        if (resData != null) {
            if (resData.getContentSize() > 0) resData.setContent(e.cloneContent());
            else resData.setText(e.getText());
        } else {
            result.addContent(e.clone());
        }
    }

    return result;
}
 
Example 4
Source File: DigitalSignature.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String PrepareDocumentToBeSign(Element element)
{

	try{
	     //extract the Document to sign and transform it in a valid XML DOM 
	   	Element rootElement = new Element(element.getName());
	 	rootElement.setContent(element.cloneContent());
	 	//convert the Element in a JDOM Document
	 	Document xdoc = new Document( rootElement );
	 	//create a DOMOutputter to write the content of the JDOM document in a DOM document
	 	DOMOutputter outputter = new DOMOutputter();
	 	org.w3c.dom.Document Doctosign = outputter.output(xdoc);
	 	
	 	// Show the document before being sign 
	 	System.out.println("xml to Sign:");
	   	XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
	    sortie.output(xdoc, System.out);
	     
	 	//Transform the XML DOM in a String using the xml transformer
	     DOMSource domSource = new DOMSource(Doctosign);
	     StringWriter writer = new StringWriter();
	     StreamResult result = new StreamResult(writer);
	     TransformerFactory tf = TransformerFactory.newInstance();
	     Transformer transformer = tf.newTransformer();
	     transformer.transform(domSource, result);
	     String StringTobeSign = writer.toString();
	     
	     return StringTobeSign;
	     
	}   catch (Exception e) {
	    e.printStackTrace();  
	    return null;
	    }
		
	}