public List operate(Object node) { if (node instanceof Element) return Collections.singletonList(((Element) node).getTextTrim()); if (node instanceof Attribute) return Collections.singletonList(((Attribute) node).getValue()); if (node instanceof CDATA) return Collections.singletonList(((CDATA) node).getText()); if (node instanceof Comment) return Collections.singletonList(((Comment) node).getText()); if (node instanceof ProcessingInstruction) return Collections.singletonList(((ProcessingInstruction) node).getData()); // 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; // throw new TemplateModelException("_text can not be applied on " + node.getClass()); } }
@Override String getText(Object node) { if (node instanceof Element) { return ((Element) node).getTextTrim(); } if (node instanceof Attribute) { return ((Attribute) node).getValue(); } if (node instanceof CDATA) { return ((CDATA) node).getText(); } if (node instanceof Comment) { return ((Comment) node).getText(); } if (node instanceof ProcessingInstruction) { return ((ProcessingInstruction) node).getData(); } return null; }
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; }
public static String getDoneFlag(Element doneFlagElement) { if (doneFlagElement != null) { return doneFlagElement.getTextTrim(); } else { return CoordELConstants.DEFAULT_DONE_FLAG; } }
/** * *f value is null, does nothing * If value is not null, sets actionConf value displayName to XML trimmed text value */ void trimAndSet(String displayName, Element value) { if (value != null) { actionConf.set(displayName, value.getTextTrim()); } }
/** * @param elem * @return */ private String readDocumentations(Element elem) { Element documentation = elem.getChild(DOCUMENTATION_TAG); if (documentation == null) { return null; } return documentation.getTextTrim(); }
/** * *f value is null, does nothing * If value is not null, sets actionConf value displayName to XML trimmed text value */ void trimAndSet(String displayName, Element value) { if (value != null) { actionConf.set(displayName, value.getTextTrim()); } }
/** * Calls helper function to verify value not null and throw an exception if so. * Otherwise, set actionConf value displayName to XML trimmed text value */ void checkTrimAndSet(String displayName, Element value) { Preconditions.checkNotNull(value, "Action Configuration does not have [%s] property", displayName); actionConf.set(displayName, value.getTextTrim()); }
/** * Calls helper function to verify value not null and throw an exception if so. * Otherwise, set actionConf value displayName to XML trimmed text value */ void checkTrimAndSet(String displayName, Element value) { Preconditions.checkNotNull(value, "Action Configuration does not have [%s] property", displayName); actionConf.set(displayName, value.getTextTrim()); }
private List<String> extractBaseTypeArrayFromChildren(List<Element> children) { List<String> result = new ArrayList<String>(); for (Element child : children) { result.add(child.getTextTrim()); } return result; }
private void injectConfigClass(Configuration conf, Element actionXml) { // Inject config-class for launcher to use for action Element e = actionXml.getChild("config-class", actionXml.getNamespace()); if (e != null) { conf.set(LauncherAMUtils.OOZIE_ACTION_CONFIG_CLASS, e.getTextTrim()); } }
private void setJavaMain(Configuration actionConf, Element actionXml) { Namespace ns = actionXml.getNamespace(); Element e = actionXml.getChild("main-class", ns); if (e != null) { actionConf.set(JavaMain.JAVA_MAIN_CLASS, e.getTextTrim()); } }
public static String getStringVal(final Element e, final boolean trim) { if (e == null) { return null; } else { if (trim) { return e.getTextTrim(); } else { return e.getText(); } } }
public static String getStringValIgnoreNamespace( final Element parentEl, final String childName, final Namespace[] namespaces, final boolean tryLowerCase) { final Element el = getChildIgnoreNamespace(parentEl, childName, namespaces, tryLowerCase); if (el != null) { return el.getTextTrim(); } else { return null; } }
private void removeMissingIdEntries() { List<Element> Plugins = trackerDoc.getRootElement().getChild(PluginStatus.CURRENT.getTagName()).getChildren(pluginTag); List<Element> PluginsToRemove = new ArrayList<Element>(); for (Element plugin: Plugins) { if (plugin.getChild(uniqueIdTag) == null || plugin.getChild(uniqueIdTag).getTextTrim().length() <= 0) PluginsToRemove.add(plugin); } for (Element child: PluginsToRemove) trackerDoc.getRootElement().getChild(PluginStatus.CURRENT.getTagName()).removeContent(child); }
public String getExternalPackItem(String packUri, String title) throws RegistryException { for (Element externalPackItem : getResourceElements(packUri, "external-pack-items")) { String itemTitle = externalPackItem.getTextTrim(); if (title.equals(itemTitle)) return externalPackItem.getAttributeValue("resource"); } throw new RegistryException("Item " + title + " not found in external-pack-items at " + packUri); }
@Override public synchronized String internalGetDescription() { MyExperimentComponentRegistry componentRegistry = (MyExperimentComponentRegistry) this .getComponentRegistry(); String result = ""; Element descriptionElement = componentRegistry.getResourceElement(uri, "description"); if (descriptionElement != null) { result = descriptionElement.getTextTrim(); } return result; }
public void testCoordEndOfWeeksStartingFromPrevWeek() throws Exception { List<?> elementList = getSyncDatasetEvents("coord-dataset-endOfWeeks.xml", "coord:endOfWeeks(-2)", "coord:current(0)", "2009-08-20T01:00Z", "2009-08-20T01:00Z"); Element e2 = (Element) elementList.get(1); e2 = (Element) elementList.get(1); // startInstance = coord:endOfWeeks(-2) // endInstance = coord:current(0) i.e. 2009-08-20T01:00Z Calendar start = DateUtils.getCalendar("2009-08-10T01:00Z", DateUtils.UTC); start.add(Calendar.DAY_OF_WEEK, start.getFirstDayOfWeek() - start.get(Calendar.DAY_OF_WEEK)); checkUris(e2.getChild("uris", e2.getNamespace()).getTextTrim(), start, Calendar.DATE, 1, "YYYY/MM/dd"); }
public void testCoordEndOfMonthsStartingFromPrevMonth() throws Exception { List<?> elementList = getSyncDatasetEvents("coord-dataset-endOfMonths.xml", "coord:endOfMonths(-2)", "coord:current(0)", "2009-08-20T01:00Z", "2009-08-20T01:00Z"); Element e2 = (Element) elementList.get(1); e2 = (Element) elementList.get(1); // startInstance = coord:endOfMonths(-2) i.e.2009-07-01T01:00Z and // endInstance = coord:current(0) i.e. 2009-08-20T01:00Z Calendar start = DateUtils.getCalendar("2009-07-01T01:00Z", DateUtils.UTC); checkUris(e2.getChild("uris", e2.getNamespace()).getTextTrim(), start, Calendar.DATE, 1, "YYYY/MM/dd"); }
public void testCoordEndOfDaysStartingFromPrevDay() throws Exception { List<?> elementList = getSyncDatasetEvents("coord-dataset-endOfDays.xml", "coord:endOfDays(-2)", "coord:current(0)", "2009-08-20T18:00Z", "2009-08-20T18:00Z"); Element e2 = (Element) elementList.get(1); // startInstance = coord:endOfDays(-2) i.e 2009-08-19T01:00Z and // endInstance = coord:current(0) i.e. 2009-08-20T01:00Z Calendar start = DateUtils.getCalendar("2009-08-19T00:00Z", DateUtils.UTC); checkUris(e2.getChild("uris", e2.getNamespace()).getTextTrim(), start, Calendar.MINUTE, 30, "YYYY/MM/dd/HH/mm"); }