List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:com.noterik.bart.fs.ingest.SimpleIngestHandler.java
License:Open Source License
/** * This function creates a human readable object from the ingest input XML * and returns it.// w w w. j a va2s . co m * * @param input * @return */ public IngestInputData getInputVariables(Document input) { IngestInputData iid = new IngestInputData(); // set the destination uri OR the user and profile id Node vp = input.selectSingleNode("/fsxml/properties/destinationuri"); if (vp == null) { Node u = input.selectSingleNode("/fsxml/properties/user"); if (u == null) { return null; } else { iid.setUser(u.getText()); Node p = input.selectSingleNode("/fsxml/properties/profile"); if (p == null) { return null; } else { iid.setProfile(p.getText()); } } } else { iid.setDestinationUri(vp.getText()); } // set the source Node fn = input.selectSingleNode("/fsxml/properties/source"); if (fn == null) { return null; } iid.setSource(fn.getText()); // set the collection id Node cid = input.selectSingleNode("/fsxml/properties/collection"); if (cid == null) { return null; } iid.setCollectionId(cid.getText()); // set smart default to true otherwise look at the tag Node s = input.selectSingleNode("/fsxml/properties/smart"); if (s == null) { iid.setSmart(true); } else { iid.setSmart(s.getText().equals("true")); } Node vid = input.selectSingleNode("/fsxml/properties/video"); if (vid != null) { iid.setVideoId(vid.getText()); } // set preferred mount Node pm = input.selectSingleNode("/fsxml/properties/preferred"); if (pm != null) { iid.setPrefferredMount(pm.getText()); } // set momar job Node m = input.selectSingleNode("/fsxml/properties/momar"); if (m == null) { iid.setMomar(true); } else { iid.setMomar(m.getText().equals("true")); } return iid; }
From source file:com.noterik.bart.fs.legacy.tools.FlandersHelper.java
License:Open Source License
public static String processRaw(String uri, String xml) { // parse document Document doc = null;/* w ww . j av a 2s. c o m*/ try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { LOG.error("Could not parse xml", e); return null; } // check mount property Node mountNode = doc.selectSingleNode("//mount"); if (mountNode == null) { LOG.error("No mount property was set"); return null; } // extract single mount String mount = null; String mounts = mountNode.getText(); if (mounts != null && !mounts.equals("")) { mount = mounts.indexOf(",") != -1 ? mounts.substring(0, mounts.indexOf(",")) : mounts; } // determine external or local stream String flandersXml = null; if (mount.toLowerCase().startsWith("rtmp")) { LOG.debug("External stream"); Node filenameNode = doc.selectSingleNode("//filename"); if (filenameNode != null) { String filename = filenameNode.getText(); flandersXml = getXmlFromFlandersExternal(filename, mount); } } else if (mount.toLowerCase().indexOf("drm://") != -1) { LOG.debug("DRM stream"); Node filenameNode = doc.selectSingleNode("//filename"); if (filenameNode != null) { String filename = filenameNode.getText(); flandersXml = getXmlFromFlandersBgDrm(filename, mount); } } else { LOG.debug("Local stream"); Node extNode = doc.selectSingleNode("//extension"); if (extNode != null) { String extension = extNode.getText(); String filename = uri + "/raw." + extension; flandersXml = getXmlFromFlandersLocal(filename, mount); } else { LOG.error("Extension property was not set"); return null; } } LOG.debug("FLANDERS XML: " + flandersXml); xml = processXml(xml, flandersXml); return xml; }
From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java
License:Open Source License
public static String getPropertyValue(String xml, String propertyName) { String value = ""; Document doc = null;// w w w. j a v a 2s.c o m try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { e.printStackTrace(); } Node propNode = null; propNode = doc.selectSingleNode("//" + propertyName); if (propNode != null) value = propNode.getText(); return value; }
From source file:com.noterik.bart.fs.script.FSScriptRequestHandler.java
License:Open Source License
private String handle(String uri, String value, String method) { // send to filessystem String fsResponse = ""; if (method.equals("PUT")) { fsResponse = FSXMLRequestHandler.instance().handlePUT(uri, value); } else {/* w w w. ja v a2 s. c o m*/ fsResponse = FSXMLRequestHandler.instance().handlePOST(uri, value); } Document fsDoc = XMLHelper.asDocument(fsResponse); Node fsUriNode = fsDoc.selectSingleNode("//status/properties/uri"); // initialize fsscript if (fsUriNode != null) { String scriptUri = fsUriNode.getText(); Document doc = XMLHelper.asDocument(value); if (doc != null) { FSScript script = new FSScript(scriptUri, doc); TriggerSystemManager.getInstance().addScript(scriptUri, script); return FSXMLBuilder.getStatusMessage("The script was successfully added", "", scriptUri); } else { return FSXMLBuilder.getErrorMessage("403", "The value you sent is not valid", "You have to POST a valid command XML", "http://teamelements.noterik.nl/team"); } } else { return fsResponse; } }
From source file:com.pactera.edg.am.metamanager.extractor.adapter.mapping.impl.CommonMappingServiceImpl.java
License:Open Source License
/** * ?//from w w w.j a v a2 s. c o m * * @param elements * @param parentMetadata * @param parentMetaModel * @return */ private Set<MMMetaModel> genRootMetaModels(List<Element> elements, MMMetadata parentMetadata, MMMetaModel parentMetaModel) { Set<MMMetaModel> metaModels = new HashSet<MMMetaModel>(2); // list???,???,??? Collections.reverse(elements); /** * ??,?? */ Set<String> duplicateElement = new HashSet<String>(); for (Element element : elements) { String modelId = element.attributeValue("class"); String code = element.selectSingleNode("./attributes/instancecode").getText(); if (code == null || code.equals("")) { log.warn(new StringBuilder("Code!").append(",:").append(modelId).toString()); continue; } String duplicateString = new StringBuilder().append(code).append("_").append(modelId).toString(); if (duplicateElement.contains(duplicateString)) { // ?,?CODE?,?? log.warn(new StringBuilder("??Element:").append(code).append(",:").append(modelId) .toString()); continue; } duplicateElement.add(duplicateString); MMMetadata relativeMetadata = parentMetadata; MMMetaModel relativeModel = parentMetaModel; // ?Excel? Node pathNode = element.selectSingleNode("./path"); if (pathNode != null) { relativeMetadata = genRelativeMetadata(parentMetadata, pathNode.getText()); if (relativeMetadata == null) { continue; } relativeModel = new MMMetaModel(); relativeModel.setCode(relativeMetadata.getClassifierId()); } MMMetaModel cntMetaModel = getMetaModel(relativeModel, metaModels, element); MMMetadata metadata = genMetadata(relativeMetadata, cntMetaModel, element); // cntMetaModel.addMetadata(metadata); // cntMetaModel.setHasMetadata(true); List<Element> childElements = element.selectNodes("./instances/instance"); if (childElements != null && childElements.size() > 0) { genMetaModels(childElements, metadata, cntMetaModel); // cntMetaModel.setHasChildMetaModel(true); } } return metaModels; }
From source file:com.plug.Version_8_5_2.gs.terminology.Definition.java
License:Apache License
/** * Reads and validates a Termbase Definition given in an XML string. *//*from ww w . j av a2 s . co m*/ private void init(String p_definition) throws Exception { XmlParser parser = null; Document dom; try { parser = XmlParser.hire(); dom = parser.parseXml(p_definition); } finally { XmlParser.fire(parser); } try { Element root = dom.getRootElement(); Node nameNode = root.selectSingleNode("/definition/name"); Node descNode = root.selectSingleNode("/definition/description"); if (nameNode != null) { m_name = nameNode.getText(); } if (descNode != null) { m_description = descNode.getText(); } List langs = root.selectNodes("/definition/languages/language"); if (langs.size() == 0) { throw new Exception("no languages defined", null); } for (int i = 0, max = langs.size(); i < max; ++i) { Element lang = (Element) langs.get(i); String name = lang.valueOf("name"); String locale = lang.valueOf("locale"); String hasTerms = lang.valueOf("hasterms"); if (name == null || locale == null || hasTerms == null) { throw new Exception("incomplete language definition", null); } m_languages.add(new Language(name, locale, hasTerms)); } List fields = root.selectNodes("/definition/fields/field"); for (int i = 0, max = fields.size(); i < max; ++i) { Element field = (Element) fields.get(i); String name = field.valueOf("name"); String type = field.valueOf("type"); String system = field.valueOf("system"); String indexed = field.valueOf("indexed"); String values = field.valueOf("values"); if (name == null || type == null || system == null || indexed == null || values == null) { throw new Exception("incomplete field definition", null); } m_fields.add(new Field(name, type, system, indexed, values)); } List indexes = root.selectNodes("/definition/indexes/index"); for (int i = 0, max = indexes.size(); i < max; ++i) { Element index = (Element) indexes.get(i); String languageName = index.valueOf("languagename"); String locale = index.valueOf("locale"); String type = index.valueOf("type"); if (languageName == null || locale == null || type == null) { throw new Exception("incomplete index definition", null); } m_indexes.add(new Index(languageName, locale, type)); } } catch (Exception e) { throw e; } }
From source file:com.sam.moca.alerts.TU_Alert.java
License:Open Source License
@SuppressWarnings("deprecation") public void testAlertCreation() throws Exception { Alert alert = new Alert.AlertBuilder("SomeEvent", "TEST-SYSTEM").primerFlag(false) .priority(Alert.PRIORITY_INFORMATIONAL).duplicateValue("dupval").build(); Date dt = new Date(); assertEquals(dt.getDate(), alert.getDateTime().getDate()); assertEquals(dt.getMonth(), alert.getDateTime().getMonth()); assertEquals(dt.getYear(), alert.getDateTime().getYear()); assertNotNull(alert.getUrl());// w ww . jav a 2 s.c om assertTrue(alert.getUrl().length() > 0); assertTrue(alert.isInTransFlag()); // This should be the default assertFalse(alert.isPrimerFlag()); // This should be FALSE by default assertNull(alert.getEventDefinition()); // This should be NULL by default String xml = alert.asXML(); assertTrue(!xml.equals("")); // Parse the XML and spot check some nodes. Document document = DocumentHelper.parseText(xml); Node version = document.selectSingleNode("//ems-alert/version"); assertEquals("2", version.getText()); Node inTrans = document.selectSingleNode("//ems-alert/in-trans"); assertEquals("1", inTrans.getText()); Node srcSys = document.selectSingleNode("//ems-alert/event-data/source-system"); assertEquals("TEST-SYSTEM", srcSys.getText()); // Before writing, reset the inTransFlag so that it writes // immediately rather than waiting until the end of the transaction alert.setInTransFlag(false); alert.write(); File alertFile = new File(AlertUtils.getSpoolDir(), alert.getFileName()); assertNotNull(alertFile); // Clean everything up AlertFile af = new AlertFile(alertFile); assertTrue(af.getXmlContents().length() > 0); af.complete(true); // See if this went to the success directory File successFile = new File(AlertUtils.getProcessedDir(), alert.getFileName()); assertTrue(successFile.exists()); // Clean up the file if (successFile.exists()) { assertTrue(successFile.delete()); } }
From source file:com.sam.moca.alerts.TU_Alert.java
License:Open Source License
public void testEventPrime() throws Exception { Alert alert = new Alert.AlertBuilder("SomeEvent", "TEST-SYSTEM").priority(Alert.PRIORITY_INFORMATIONAL) .primerFlag(true).inTransFlag(false).duplicateValue("dupval").build(); alert.setEventName("SomeEvent"); alert.setPriority(Alert.PRIORITY_INFORMATIONAL); alert.setPrimerFlag(true);// w w w . j ava2 s. c o m alert.setInTransFlag(false); alert.setDuplicateValue("dupval"); alert.setSourceSystem("TEST-SYSTEM"); EventDefinition ed = new EventDefinition.EventDefBuilder("SomeEvent", "SomeDescription", "SomeSubject", "SomeMessage").htmlMessage("<h1>SomeHTMLMessage</h1>").build(); alert.setEventDefinition(ed); assertEquals(EventDefinition.DEFAULT_PRIME_KEY_VAL, alert.getKeyValue()); String xml = alert.asXML(); assertTrue(!xml.equals("")); // Parse the XML and spot check some nodes. Document document = DocumentHelper.parseText(xml); Node primerFlag = document.selectSingleNode("//ems-alert/event-data/primer-flg"); assertEquals("1", primerFlag.getText()); Node keyValue = document.selectSingleNode("//ems-alert/event-data/key-val"); assertEquals(EventDefinition.DEFAULT_PRIME_KEY_VAL, keyValue.getText()); Node timeZone = document.selectSingleNode("//ems-alert/event-data/stored-tz"); assertEquals("----", timeZone.getText()); // Test the messages and stuff Element locale = (Element) document.selectSingleNode("//ems-alert/event-data/event-def/messages/message"); assertEquals("US_ENGLISH", locale.attributeValue("locale-id")); Node description = document .selectSingleNode("//ems-alert/event-data/event-def/messages/message/description"); assertEquals("SomeDescription", description.getText()); Node subject = document.selectSingleNode("//ems-alert/event-data/event-def/messages/message/subject"); assertEquals("SomeSubject", subject.getText()); Node htmlMessage = document .selectSingleNode("//ems-alert/event-data/event-def/messages/message/html-message"); assertEquals("<h1>SomeHTMLMessage</h1>", htmlMessage.getText()); Node textMessage = document .selectSingleNode("//ems-alert/event-data/event-def/messages/message/text-message"); assertEquals("SomeMessage", textMessage.getText()); // Write and clean this up. alert.write(); File alertFile = new File(AlertUtils.getSpoolDir(), alert.getFileName()); assertNotNull(alertFile); // Clean everything up AlertFile af = new AlertFile(alertFile); assertTrue(af.getXmlContents().length() > 0); af.complete(true); // See if this went to the success directory File successFile = new File(AlertUtils.getProcessedDir(), alert.getFileName()); assertTrue(successFile.exists()); // Clean up the file if (successFile.exists()) { assertTrue(successFile.delete()); } }
From source file:com.ten45.service.aggregator.ConfigurationServiceImpl.java
/** * Expand the original configuration document with the referred node. * It reads the referred document, finds the referred element in the same * path as the original document, and moves all the children of the * referred element into the original element. * /* w ww. j a v a 2 s . c om*/ * @param doc * @param node * @return * @throws DocumentException */ private Document expandReference(Document doc, Node node) throws DocumentException { // Find the 'anchor' element that contains the reference declaration. Element anchor = node.getParent(); XPath anchorXPath = DocumentHelper.createXPath(anchor.getPath()); // Remove the reference declaration node from the document. node.detach(); // Read the new configuration. String resourceName = rootPath + node.getText() + ".xml"; log.debug("Reading resource " + resourceName); InputStream in = this.getClass().getResourceAsStream(resourceName); SAXReader reader = new SAXReader(); try { Document refDoc = reader.read(in); Element refElement = (Element) anchorXPath.selectSingleNode(refDoc); if (refElement != null) { log.debug("Expanding " + anchorXPath.getText() + " with " + refElement.asXML()); // Move all elements from the referenced document into the anchor. List children = refElement.elements(); if (children != null && children.size() > 0) { for (int i = 0; i < children.size(); i++) { Element child = (Element) children.get(i); XPath refXPath = DocumentHelper.createXPath(child.getPath()); if (refXPath.selectSingleNode(doc) == null) { log.debug("Adding element " + refXPath.getText()); child.detach(); anchor.add(child); } else { log.debug("Ignore pre-existing element " + refXPath.getText()); } } } } } catch (DocumentException de) { throw de; } return doc; }
From source file:com.thoughtworks.cruise.context.Configuration.java
License:Apache License
private CurrentConfigState currentConfigState() { CruiseResponse configContent = getConfigContent(); String serverId = null;/* w w w. j a va2s . co m*/ try { Document dom = XmlUtil.parse(configContent.getBody()); Node node = dom.selectSingleNode("//server/@serverId"); serverId = node.getText(); } catch (Exception e) { throw new RuntimeException(e); } return new CurrentConfigState(configContent.getResponseHeader(X_CRUISE_CONFIG_MD5), serverId); }