Refine search
public List<StoreDefinition> readStoreList(Reader input, boolean verifySchema) { try { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(input); if(verifySchema) { Validator validator = schema.newValidator(); validator.validate(new JDOMSource(doc)); } Element root = doc.getRootElement(); if(!root.getName().equals(STORES_ELMT)) throw new MappingException("Invalid root element: " + doc.getRootElement().getName()); List<StoreDefinition> stores = new ArrayList<StoreDefinition>(); for(Object store: root.getChildren(STORE_ELMT)) stores.add(readStore((Element) store)); for(Object view: root.getChildren(VIEW_ELMT)) stores.add(readView((Element) view, stores)); return stores; } catch(JDOMException e) { throw new MappingException(e); } catch(SAXException e) { throw new MappingException(e); } catch(IOException e) { throw new MappingException(e); } }
public String writeCluster(Cluster cluster) { Document doc = new Document(new Element(CLUSTER_ELMT)); doc.getRootElement().addContent(new Element(CLUSTER_NAME_ELMT).setText(cluster.getName())); boolean displayZones = cluster.getZones().size() > 1; if(displayZones) { for(Zone n: cluster.getZones()) doc.getRootElement().addContent(mapZone(n)); } for(Node n: cluster.getNodes()) doc.getRootElement().addContent(mapServer(n, displayZones)); XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat()); return serializer.outputString(doc.getRootElement()); }
@Override public void writeSolution() throws IOException { Element solutionElement = new Element("Solution"); document.setRootElement(solutionElement); Element schedulingPeriodIDElement = new Element("SchedulingPeriodID"); schedulingPeriodIDElement.setText(nurseRoster.getCode()); solutionElement.addContent(schedulingPeriodIDElement);
@Override public String writeUser(UserData userData) throws ExportException { Namespace ns = Namespace.getNamespace(USERCATALOG_NAMESPACE_PREFIX, USERCATALOG_NAMESPACE); Namespace nsXsi = Namespace.getNamespace(XSI_NAMESPACE_PREFIX, XSI_NAMESPACE); Document doc = new Document(dumpUser(userData, ns)); doc.getRootElement().setNamespace(ns); doc.getRootElement().addNamespaceDeclaration(nsXsi); doc.getRootElement().setAttribute( new Attribute("schemaLocation", USERCATALOG_NAMESPACE + " " + USER_SCHEMA_LOCATION, nsXsi)); XMLOutputter xmlOutputter = getOutputter(); String xml = xmlOutputter.outputString(doc); SAXBuilder saxBuilder = getBuilder(USER_SCHEMA_RESOURCE); try { saxBuilder.build(IOUtils.toInputStream(xml)); return xml; } catch (Exception e) { throw new ExportException("Error during validating output.", e); } }
private void buildDOM() { this._doc = new Document(); this._root = new Element(ROOT); for (int i = 0; i < TAGS.length; i++) { Element tag = new Element(TAGS[i]); this._root.addContent(tag); } this._doc.setRootElement(this._root); }
private void populateBeanElementFromXStream(Object obj, Element bean) throws JDOMException, IOException { bean.setAttribute(BEAN_ENCODING, XSTREAM_ENCODING); XStream xstream = new XStream(new DomDriver()); SAXBuilder builder = new SAXBuilder(); Element configElement = builder.build( new StringReader(xstream.toXML(obj))).getRootElement(); configElement.getParent().removeContent(configElement); bean.addContent(configElement); }
public Element visit(final ASTFloat node, final Element data) throws XPathExpressionException { final Element res = new Element("value"); res.setAttribute("type", "xsd:float"); res.addNamespaceDeclaration(Namespace.getNamespace("xsd", Constants.SCHEMA_NAMESPACE)); this.log.finest(this.indentString() + node); ++this.indent; final Document doc = new Document(res); this.log.finest(this.indentString() + node); res.setText(String.valueOf(ExpressionNode.getFloat(node.getImage()))); --this.indent; return doc.getRootElement(); }
private static SerializerDefinition parseSerializerDefinition(String serializerInfoXml, String elementName) { SAXBuilder builder = new SAXBuilder(); try { Document doc = builder.build(new StringReader(serializerInfoXml)); Element root = doc.getRootElement(); Element serializerElement = root.getChild(elementName); return StoreDefinitionsMapper.readSerializer(serializerElement); } catch(JDOMException e) { throw new MappingException(e); } catch(IOException e) { throw new MappingException(e); } }
public static Map loadMapping(String fileName, String nodeName, String keyName, String valueName) { Map map = new HashMap(); FileLocator fileLocator = new FileLocator(); try { String xmlFile = fileLocator.getConfFile(fileName); Debug.logVerbose("[JdonFramework] mapping file:" + xmlFile, module); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new File(xmlFile)); Debug.logVerbose("[JdonFramework] got mapping file ", module); // Get the root element Element root = doc.getRootElement(); List mappings = root.getChildren(nodeName); Iterator i = mappings.iterator(); while (i.hasNext()) { Element mapping = (Element) i.next(); String key = mapping.getChild(keyName).getTextTrim(); String value = mapping.getChild(valueName).getTextTrim(); Debug.logVerbose("[JdonFramework] get the " + key + "=" + value, module); map.put(key, value); } Debug.logVerbose("[JdonFramework] read finished", module); } catch (Exception ex) { Debug.logError("[JdonFramework] error: " + ex, module); } return map; }
SAXBuilder builder = new SAXBuilder(false); Document doc = builder.build(in); Element configRoot = doc.getRootElement(); List<?> configList = configRoot.getChildren("book"); fileNames.clear(); Element configItem = (Element) configObject; String fileName = configItem.getAttributeValue("name"); fileNames.add(fileName); fileSheetNameClassMap.put(fileName, sheetNameList); List<Element> sheetElementList = configItem.getChildren("sheet");
public boolean isMyType(Document document) { boolean ok; Element rssRoot = document.getRootElement(); ok = rssRoot.getName().equals("rss"); if (ok) { ok = false; Attribute version = rssRoot.getAttribute("version"); if (version!=null) { ok = version.getValue().equals(getRSSVersion()); } } return ok; }
private static Element parse(String s) throws GNLibException { try{ SAXBuilder builder = new SAXBuilder(); s = s.trim(); Document doc = builder.build(new StringReader(s)); return (Element)doc.getRootElement().detach(); } catch (Exception ex) { LOGGER.warn("Error parsing input string: >>>" + s +"<<<"); throw new GNLibException("Error parsing input string", ex); } } }
public static Element createElementFromText(String xml) { SAXBuilder jdom = new SAXBuilder(); Document doc; try { doc = jdom.build(new StringReader(xml)); } catch (JDOMException | IOException ex) { throw new RuntimeException(ex); } return (Element) doc.getRootElement().clone(); }
public static StoreDefinition readStore(Reader input) { SAXBuilder builder = new SAXBuilder(); try { Document doc = builder.build(input); Element root = doc.getRootElement(); return readStore(root); } catch(JDOMException e) { throw new MappingException(e); } catch(IOException e) { throw new MappingException(e); } }
Element node = (Element) contextNode; if (namespaceURI == null) { return node.getChildren(localName).iterator(); return node.getChildren(localName, Namespace.getNamespace(namespacePrefix, namespaceURI)).iterator(); Element el = node.getRootElement(); if (el.getName().equals(localName) == false) { return JaxenConstants.EMPTY_ITERATOR; if (!Namespace.getNamespace(namespacePrefix, namespaceURI).equals(el.getNamespace())) { return JaxenConstants.EMPTY_ITERATOR;
public List operate(Object node, String localName, Namespace namespace) { if (node instanceof Element) { return((Element) node).getChildren(localName, namespace); } else if (node instanceof Document) { Element root = ((Document) node).getRootElement(); if (root != null && root.getName().equals(localName) && root.getNamespaceURI().equals(namespace.getURI())) { return Collections.singletonList(root); } else return Collections.EMPTY_LIST; } // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; /* else throw new TemplateModelException("_namedChildren can not be applied on " + node.getClass()); */ } }
@Override void getChildren(Object node, String localName, String namespaceUri, List result) { if (node instanceof Element) { Element e = (Element) node; if (localName == null) { result.addAll(e.getChildren()); } else { result.addAll(e.getChildren(localName, Namespace.getNamespace("", namespaceUri))); } } else if (node instanceof Document) { Element root = ((Document) node).getRootElement(); if (localName == null || (equal(root.getName(), localName) && equal(root.getNamespaceURI(), namespaceUri))) { result.add(root); } } }
protected String extractWorkflowName(String definition) throws FlowDefinitionException { try { // jdom final org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(); Document doc = builder.build(new StringReader(definition)); Element process_definition = doc.getRootElement(); return process_definition.getAttribute("name").getValue(); } catch(Exception e){ throw new FlowDefinitionException("can't extract name out of the definition", e); } }
public boolean isMyType(Document document) { Element rssRoot = document.getRootElement(); Namespace defaultNS = rssRoot.getNamespace(); return (defaultNS!=null) && defaultNS.equals(getAtomNamespace()); }
protected static String getGeoNetworkErrorMessage(String msg) { try { SAXBuilder builder = new SAXBuilder(); Document error = builder.build(new StringReader(msg)); return error.getRootElement().getChildText("message"); } catch (Exception ex) { return "-"; } }