Java Code Examples for org.jdom.Element#addNamespaceDeclaration()

The following examples show how to use org.jdom.Element#addNamespaceDeclaration() . 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: XChangeContainer.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public XChangeContainer(){
	doc = new Document();
	eRoot = new Element(XChangeContainer.ROOT_ELEMENT, XChangeContainer.ns);
	eRoot.addNamespaceDeclaration(XChangeContainer.nsxsi);
	eRoot.addNamespaceDeclaration(XChangeContainer.nsschema);
	eRoot.setAttribute(ATTR_TIMESTAMP, new TimeTool().toString(TimeTool.DATETIME_XML));
	eRoot.setAttribute(ATTR_ID, XMLTool.idToXMLID(StringTool.unique(XCHANGE_MAGIC)));
	eRoot.setAttribute(ATTR_ORIGIN, XMLTool.idToXMLID(CoreHub.actMandant.getId()));
	eRoot.setAttribute(ATTR_DESTINATION, "undefined");
	eRoot.setAttribute(ATTR_RESPONSIBLE, XMLTool.idToXMLID(CoreHub.actMandant.getId()));
	doc.setRootElement(eRoot);
	
	eHeader.setAttribute(ATTR_CREATOR_NAME, Hub.APPLICATION_NAME);
	eHeader.setAttribute(ATTR_CREATOR_ID, "ch.elexis");
	eHeader.setAttribute(ATTR_CREATOR_VERSION, CoreHub.Version);
	eHeader.setAttribute(ATTR_PROTOCOL_VERSION, XChangeContainer.Version);
	eHeader.setAttribute(ATTR_LANGUAGE, Locale.getDefault().toString());
	eRoot.addContent(eHeader);
	
}
 
Example 2
Source File: XmlExporterServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public byte[] export(ExportDataSet dataSet) {
    if (dataSet == null) {
        throw new IllegalArgumentException("Xml Exporter cannot handle NULL data.");
    }
    Element rootElement = new Element(DATA_ELEMENT, WORKFLOW_NAMESPACE);
    rootElement.addNamespaceDeclaration(SCHEMA_NAMESPACE);
    rootElement.setAttribute(SCHEMA_LOCATION_ATTR, WORKFLOW_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
    Document document = new Document(rootElement);
    boolean shouldPrettyPrint = true;
    for (XmlExporter exporter : xmlImpexRegistry.getExporters()) {
    	Element exportedElement = exporter.export(dataSet);
    	if (exportedElement != null) {
    		if (!exporter.supportPrettyPrint()) {
    			shouldPrettyPrint = false;
    		}
    		appendIfNotEmpty(rootElement, exportedElement);
    	}
    }

    // TODO: KULRICE-4420 - this needs cleanup
    Format f;
    if (!shouldPrettyPrint) {
        f = Format.getRawFormat();
        f.setExpandEmptyElements(false);
        f.setTextMode(Format.TextMode.PRESERVE);
    } else {
        f = Format.getPrettyFormat();
    }
    XMLOutputter outputer = new XMLOutputter(f);
    StringWriter writer = new StringWriter();
    try {
        outputer.output(document, writer);
    } catch (IOException e) {
        throw new WorkflowRuntimeException("Could not write XML data export.", e);
    }
    return writer.toString().getBytes();
}
 
Example 3
Source File: OvalFileAggregator.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
private void reset() {
    Namespace schema = Namespace.getNamespace(
            "xsi", "http://www.w3.org/2000/10/XMLSchema-instance");
    Namespace oval = Namespace.getNamespace("oval", "removeme");
    aggregate = new Document();
    Element root = new Element("oval_definitions");
    root.setAttribute("schemaLocation",
            "http://oval.mitre.org/XMLSchema/oval-common-5 " +
            "oval-common-schema.xsd " +
            "http://oval.mitre.org/XMLSchema/oval-definitions-5 " +
            "oval-definitions-schema.xsd " +
            "http://oval.mitre.org/XMLSchema/oval-definitions-5#unix " +
            "unix-definitions-schema.xsd " +
            "http://oval.mitre.org/XMLSchema/oval-definitions-5#redhat " +
            "redhat-definitions-schema.xsd", schema);
    aggregate.setRootElement(root);
    Element generator = new Element("generator");
    Element prodName = new Element("product_name", oval);
    prodName.setText("Spacewalk");
    Element schemaVersion = new Element("schema_version", oval);
    schemaVersion.addNamespaceDeclaration(oval);
    schemaVersion.setText("5.0");
    Element timestamp = new Element("timestamp", oval);
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    StringBuilder date = new StringBuilder();
    date.append(cal.get(Calendar.YEAR));
    date.append("-");
    int month = cal.get(Calendar.MONTH);
    if (month < 10) {
        date.append("0");
    }
    date.append(month);
    date.append("-");
    int day = cal.get(Calendar.DATE);
    if (day < 10) {
        date.append("0");
    }
    date.append(day);
    date.append("T").append(cal.get(Calendar.HOUR_OF_DAY));
    date.append(":").append(cal.get(Calendar.MINUTE));
    date.append(":").append(cal.get(Calendar.SECOND));
    timestamp.setText(date.toString());
    root.getChildren().add(generator);
    generator.getChildren().add(prodName);
    generator.getChildren().add(schemaVersion);
    generator.getChildren().add(timestamp);

    defs = new LinkedHashMap();
    tests = new LinkedHashMap();
    objects = new LinkedHashMap();
    states = new LinkedHashMap();
}
 
Example 4
Source File: OvalFileAggregator.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
private void reset() {
    Namespace schema = Namespace.getNamespace(
            "xsi", "http://www.w3.org/2000/10/XMLSchema-instance");
    Namespace oval = Namespace.getNamespace("oval", "removeme");
    aggregate = new Document();
    Element root = new Element("oval_definitions");
    root.setAttribute("schemaLocation",
            "http://oval.mitre.org/XMLSchema/oval-common-5 " +
            "oval-common-schema.xsd " +
            "http://oval.mitre.org/XMLSchema/oval-definitions-5 " +
            "oval-definitions-schema.xsd " +
            "http://oval.mitre.org/XMLSchema/oval-definitions-5#unix " +
            "unix-definitions-schema.xsd " +
            "http://oval.mitre.org/XMLSchema/oval-definitions-5#redhat " +
            "redhat-definitions-schema.xsd", schema);
    aggregate.setRootElement(root);
    Element generator = new Element("generator");
    Element prodName = new Element("product_name", oval);
    prodName.setText("Spacewalk");
    Element schemaVersion = new Element("schema_version", oval);
    schemaVersion.addNamespaceDeclaration(oval);
    schemaVersion.setText("5.0");
    Element timestamp = new Element("timestamp", oval);
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    StringBuilder date = new StringBuilder();
    date.append(cal.get(Calendar.YEAR));
    date.append("-");
    int month = cal.get(Calendar.MONTH);
    if (month < 10) {
        date.append("0");
    }
    date.append(month);
    date.append("-");
    int day = cal.get(Calendar.DATE);
    if (day < 10) {
        date.append("0");
    }
    date.append(day);
    date.append("T").append(cal.get(Calendar.HOUR_OF_DAY));
    date.append(":").append(cal.get(Calendar.MINUTE));
    date.append(":").append(cal.get(Calendar.SECOND));
    timestamp.setText(date.toString());
    root.getChildren().add(generator);
    generator.getChildren().add(prodName);
    generator.getChildren().add(schemaVersion);
    generator.getChildren().add(timestamp);

    defs = new LinkedHashMap();
    tests = new LinkedHashMap();
    objects = new LinkedHashMap();
    states = new LinkedHashMap();
}