List of usage examples for org.jdom2 Element Element
public Element(final String name, final String uri)
From source file:ca.nrc.cadc.vosi.Capabilities.java
License:Open Source License
public Document toXmlDocument() { Namespace xsi = Namespace.getNamespace("xsi", VOSI.XSI_NS_URI); Namespace cap = Namespace.getNamespace("vosi", VOSI.CAPABILITIES_NS_URI); Namespace vod = Namespace.getNamespace("vod", VOSI.VODATASERVICE_NS_URI); Element eleCapabilities = new Element("capabilities", cap); eleCapabilities.addNamespaceDeclaration(xsi); eleCapabilities.addNamespaceDeclaration(cap); eleCapabilities.addNamespaceDeclaration(vod); //Attribute attSchemaLocation = new Attribute("schemaLocation", XSI_LOC, xsi); //eleCapabilities.setAttribute(attSchemaLocation); Document document = new Document(); document.addContent(eleCapabilities); for (Capability capability : this._caps) { eleCapabilities.addContent(capability.toXmlElement(xsi, cap, vod)); }/*from w w w. j ava 2 s . c om*/ return document; }
From source file:ca.nrc.cadc.vosi.TableSet.java
License:Open Source License
/** * @param ts//from www . j a va2s. c o m * @return */ private Element toXmlElement(TapSchema ts) { if (ts.getSchemaDescs().isEmpty()) throw new IllegalArgumentException("Error: at least one schema is required."); Element eleTableset = new Element("tableset", vosi); for (SchemaDesc sd : ts.getSchemaDescs()) { eleTableset.addContent(toXmlElement(sd, Namespace.NO_NAMESPACE)); } return eleTableset; }
From source file:ca.nrc.cadc.vosi.TableSet.java
License:Open Source License
/** * @param sd//from w w w . j a va 2s. c om * @return */ private Element toXmlElement(SchemaDesc sd, Namespace ns) { Element eleSchema = new Element("schema", ns); Element ele; ele = new Element("name"); if (sd.getSchemaName() == null) ele.setText(DEFAULT_SCHEMA); else ele.setText(sd.getSchemaName()); eleSchema.addContent(ele); if (sd.getTableDescs() != null) for (TableDesc td : sd.getTableDescs()) { eleSchema.addContent(toXmlElement(td, Namespace.NO_NAMESPACE)); } return eleSchema; }
From source file:ca.nrc.cadc.vosi.TableSet.java
License:Open Source License
/** * @param td//from www . j a v a 2 s . c o m * @return */ private Element toXmlElement(TableDesc td, Namespace ns) { Element eleTable = new Element("table", ns); eleTable.setAttribute("type", "output"); Element ele; ele = new Element("name"); ele.setText(td.getTableName()); eleTable.addContent(ele); if (td.getColumnDescs() != null) for (ColumnDesc cd : td.getColumnDescs()) { Element e = toXmlElement(cd); if (e != null) eleTable.addContent(e); } if (td.getKeyDescs() != null) for (KeyDesc kd : td.getKeyDescs()) { Element e = toXmlElement(kd); if (e != null) eleTable.addContent(e); } return eleTable; }
From source file:ca.nrc.cadc.vosi.util.Util.java
License:Open Source License
public static Element addChild(Element ele0, Namespace ns, String chdName, String chdText) { Element ele = null;//from w w w. j av a 2s . c o m if (chdText != null && !chdText.equals("")) { if (ns != null) ele = new Element(chdName, ns); else ele = new Element(chdName); ele.setText(chdText); ele0.addContent(ele); } return ele; }
From source file:ca.nrc.cadc.xml.JsonInputter.java
License:Open Source License
public Document input(final String json) throws JSONException { JSONObject rootJson = new JSONObject(json); List<String> keys = Arrays.asList(JSONObject.getNames(rootJson)); List<Namespace> namespaces = new ArrayList<Namespace>(); Namespace namespace = getNamespace(namespaces, rootJson, keys); String rootKey = null;//from w w w . j ava2 s .co m List<Attribute> attributes = new ArrayList<Attribute>(); for (String key : keys) { if (!key.startsWith("@xmlns")) { if (key.startsWith("@")) { String value; if (rootJson.isNull(key)) { value = ""; } else { value = getStringValue(rootJson.get(key)); } attributes.add(new Attribute(key.substring(1), value)); } else { // DOM can only have one root element. if (rootKey != null) { throw new IllegalStateException("Found multiple root entries"); } rootKey = key; } } } Element rootElement = new Element(rootKey, namespace); for (Attribute attribute : attributes) { rootElement.setAttribute(attribute); } Object value = rootJson.get(rootKey); processObject(rootKey, value, rootElement, namespace, namespaces); Document document = new Document(); document.setRootElement(rootElement); return document; }
From source file:ca.nrc.cadc.xml.JsonInputter.java
License:Open Source License
private void processJSONObject(JSONObject jsonObject, Element element, List<Namespace> namespaces) throws JSONException { List<String> keys = Arrays.asList(JSONObject.getNames(jsonObject)); Namespace namespace = getNamespace(namespaces, jsonObject, keys); if (namespace == null) { namespace = element.getNamespace(); }//from w w w . ja v a 2 s .c o m for (String key : keys) { if (jsonObject.isNull(key)) { continue; } // attribute if (key.startsWith("@")) { Object value = jsonObject.get(key); element.setAttribute(new Attribute(key.substring(1), getStringValue(value))); continue; } // text content Object value = jsonObject.get(key); if (key.equals("$")) { element.setText(getStringValue(value)); continue; } Element child = new Element(key, namespace); if (listElementMap.containsKey(key)) { final String childKey = listElementMap.get(key); final Object childObject = ((JSONObject) value).get("$"); Element grandChild = new Element(childKey, namespace); if (childObject instanceof JSONArray) { processJSONArray(key, (JSONArray) childObject, child, namespace, namespaces); } else if (childObject instanceof JSONObject) { processJSONObject((JSONObject) childObject, grandChild, namespaces); child.addContent(grandChild); } } else if (value instanceof JSONObject) { processJSONObject((JSONObject) value, child, namespaces); } element.addContent(child); } }
From source file:ca.nrc.cadc.xml.JsonInputter.java
License:Open Source License
private void processJSONArray(String key, JSONArray jsonArray, Element arrayElement, Namespace namespace, List<Namespace> namespaces) throws JSONException { String childTypeName = getListElementMap().get(key); for (int i = 0; i < jsonArray.length(); i++) { if (jsonArray.isNull(i)) { continue; }/*from w ww .ja v a 2s . co m*/ Element child; if (childTypeName == null) { child = arrayElement; } else { child = new Element(childTypeName, namespace); arrayElement.addContent(child); } Object value = jsonArray.get(i); processObject(childTypeName, value, child, namespace, namespaces); } }
From source file:cager.parser.test.SimpleTest2.java
License:Open Source License
private Element inicializaKDM(String segmentName) { // Creamos el builder basado en SAX SAXBuilder builder = new SAXBuilder(); Namespace xmi = Namespace.getNamespace("xmi", "http://www.omg.org/XMI"); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Namespace action = Namespace.getNamespace("action", "http://kdm.omg.org/action"); Namespace code = Namespace.getNamespace("code", "http://kdm.omg.org/code"); Namespace kdm = Namespace.getNamespace("kdm", "http://kdm.omg.org/kdm"); Namespace source = Namespace.getNamespace("source", "http://kdm.omg.org/source"); Element segmento = new Element("Segment", kdm); segmento.addNamespaceDeclaration(xmi); segmento.addNamespaceDeclaration(xsi); segmento.addNamespaceDeclaration(action); segmento.addNamespaceDeclaration(code); segmento.addNamespaceDeclaration(kdm); segmento.addNamespaceDeclaration(source); segmento.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); Element modelo = new Element("model"); modelo.setAttribute("id", "id.0", xmi); idCount++;/*from w w w. ja v a2 s .c o m*/ modelo.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); modelo.setAttribute("type", "code:CodeModel", xmi); Element codeElement = new Element("codeElement"); codeElement.setAttribute("id", "id.1", xmi); idCount++; codeElement.setAttribute("name", segmentName); codeElement.setAttribute("type", "code:CompilationUnit", xmi); modelo.addContent(codeElement); elementoTipos = inicializaDataTypes(); modelo.addContent(elementoTipos); segmento.addContent(modelo); return segmento; }
From source file:cager.parser.test.SimpleTest3.java
License:Open Source License
private Element inicializaKDM(String segmentName) { // Creamos el builder basado en SAX SAXBuilder builder = new SAXBuilder(); //Namespace xmi = Namespace.getNamespace("xmi", "http://www.omg.org/XMI"); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Namespace action = Namespace.getNamespace("action", "http://kdm.omg.org/action"); Namespace code = Namespace.getNamespace("code", "http://kdm.omg.org/code"); Namespace kdm = Namespace.getNamespace("kdm", "http://kdm.omg.org/kdm"); Namespace source = Namespace.getNamespace("source", "http://kdm.omg.org/source"); Element segmento = new Element("Segment", kdm); segmento.addNamespaceDeclaration(xmi); segmento.addNamespaceDeclaration(xsi); segmento.addNamespaceDeclaration(action); segmento.addNamespaceDeclaration(code); segmento.addNamespaceDeclaration(kdm); segmento.addNamespaceDeclaration(source); segmento.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); Element modelo = new Element("model"); modelo.setAttribute("id", "id.0", xmi); idCount++;// w w w . j a va 2s .c om modelo.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); modelo.setAttribute("type", "code:CodeModel", xmi); Element codeElement = new Element("codeElement"); codeElement.setAttribute("id", "id.1", xmi); idCount++; codeElement.setAttribute("name", segmentName); codeElement.setAttribute("type", "code:CompilationUnit", xmi); modelo.addContent(codeElement); elementoTipos = inicializaDataTypes(); modelo.addContent(elementoTipos); segmento.addContent(modelo); return segmento; }