Java Code Examples for org.dom4j.Element.getText()

The following are Jave code examples for showing how to use getText() of the org.dom4j.Element class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: joai-project   File: ResourceRecord.java   View Source Code Vote up 6 votes
/**
 *  we want to collect all the gradeRange Values and return them as an Array
 *
 *@return                The gradeRanges value
 *@exception  Exception  Description of the Exception
 */
public String[] getGradeRanges()
	throws Exception {
	List list = docMap.selectNodes(gradeRangeXPath);

	// create a normalized list, gr
	ArrayList gr = new ArrayList();
	for (Iterator i = list.iterator(); i.hasNext(); ) {
		Element e = (Element) i.next();
		String val = e.getText();
		if (!val.trim().equals("")) {
			gr.add(val);
		}
	}
	// now return a string array
	return (String[]) gr.toArray(new String[]{});
}
 
Example 2
Project: EasyML   File: OozieGraphXMLParser.java   View Source Code Vote up 6 votes
/** Parse a edge from xml
 * @param enode  edge node
 */
private static OozieEdge parseOozieEdge(Element enode) {

	String src = "";
	String dst = "";
	List<Element> children = enode.elements();
	for( Element child: children){
		if ("source".equals(child.getName())) {
			src = child.getText();
		} else if ("destination".equals(child.getName())) {
			dst = child.getText();
			break;
		}
	}
	if (src.isEmpty() || dst.isEmpty()) {
		logger.warning("Empty edge, src:" + src + ", dst:" + dst);
		return null;
	}
	else{
		OozieEdge edge = new OozieEdge();
		edge.init(src, dst);
		return edge;
	}
}
 
Example 3
Project: EasyML   File: OozieGraphXMLParser.java   View Source Code Vote up 6 votes
/** parse a dataset node from xml */
private static OozieDatasetNode parseDatasetNode(Element xml_node) {
	List<Element> childNodes = xml_node.elements();
	OozieDatasetNode node = new OozieDatasetNode();

	for( Element child : childNodes){
		String value = child.getText();
		String name = child.getName();

		if ("id".equals(name))
			node.setId(value);
		else if ("moduleId".equals(name))
			node.setModuleId(value);
		else if ("x".equals(name))
			node.setX((int) Float.parseFloat(value));
		else if ("y".equals(name))
			node.setY((int) Float.parseFloat(value));
		else if ("file".equals(name))
			node.setFile(value);
	}

	return node;
}
 
Example 4
Project: lams   File: HbmBinder.java   View Source Code Vote up 5 votes
private static String getSubselect(Element element) {
	String subselect = element.attributeValue( "subselect" );
	if ( subselect != null ) {
		return subselect;
	}
	else {
		Element subselectElement = element.element( "subselect" );
		return subselectElement == null ? null : subselectElement.getText();
	}
}
 
Example 5
Project: joai-project   File: ADNItemDocReader.java   View Source Code Vote up 5 votes
public List getMirrorUrls () {
	String xpath = "/itemRecord/technical/online/mirrorURLs/mirrorURL";
	List nodes = getElements (xpath);
	
	List mirrorUrls = new ArrayList ();
	
	for (Iterator i=nodes.iterator();i.hasNext();) {
		Element mElement = (Element)i.next();
		String url = mElement.getText();
		if (url != null && url.trim().length() > 0)
			mirrorUrls.add (url.trim());
	}
	// return (String []) mirrorUrls.toArray(new String [] {});
	return mirrorUrls;
}
 
Example 6
Project: ureport   File: SlashValueParser.java   View Source Code Vote up 5 votes
@Override
public Value parse(Element element) {
	SlashValue value=new SlashValue();
	List<Slash> slashes=new ArrayList<Slash>();
	value.setSlashes(slashes);
	for(Object obj:element.elements()){
		if(obj==null || !(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		if(ele.getName().equals("slash")){
			Slash slash=new Slash();
			slashes.add(slash);
			slash.setDegree(Integer.valueOf(ele.attributeValue("degree")));
			slash.setX(Integer.valueOf(ele.attributeValue("x")));
			slash.setY(Integer.valueOf(ele.attributeValue("y")));
			slash.setText(ele.attributeValue("text"));				
		}else if(ele.getName().equals("base64-data")){
			String prefix="data:image/png;base64,";
			String base64Data=ele.getText();
			if(base64Data.startsWith(prefix)){
				base64Data=base64Data.substring(prefix.length(),base64Data.length());
			}
			value.setBase64Data(base64Data);
		}
	}
	return value;
}
 
Example 7
Project: joai-project   File: RemoteResultDoc.java   View Source Code Vote up 5 votes
/**
 *  Construct a RemoteResultDoc from a MatchingRecord element (of the reponse
 *  from the UrlCheck Web Service)
 *
 *@param  record  matching record {@link org.dom4j.Element}
 *@param  rs      instance of {@link RemoteSearcher}
 */
public RemoteResultDoc(Element record, RemoteSearcher rs) {
	// prtln ("constructor with element:\n\t " + e.asXML());
	this.rs = rs;
	url = record.element("url").getText();
	Element head = record.element("head");
	try {
		Element collectionElement = (Element) head.selectSingleNode("collection");
		collection = collectionElement.getText();
		id = head.selectSingleNode("id").getText();
	} catch (Throwable te) {
		prtln("RemoteResultDoc unable to parse element: " + te.getMessage());
	}
}
 
Example 8
Project: joai-project   File: SchemaPath.java   View Source Code Vote up 5 votes
/**
 *  Constructor for the SchemaPath object
 *
 *@param  e  Description of the Parameter
 */
public SchemaPath(Element e) {
	// prtln ("SchemaPath with \n" + e.asXML());
	xpath = e.getText();
	pathName = e.attributeValue("pathName");
	defaultValue = e.attributeValue("defaultValue");
	valueType = e.attributeValue("valueType");
	inputHelper = e.attributeValue("inputHelper");
	initialFieldCollapse = e.attributeValue("initialFieldCollapse");
	String copyRecord = e.attributeValue("requiredByCopyRecord");
	if (copyRecord != null && copyRecord.equals("true")) {
		requiredByCopyRecord = true;
	}

	String minimalRecord = e.attributeValue("requiredByMinimalRecord");
	if (minimalRecord != null && minimalRecord.equals("true")) {
		requiredByMinimalRecord = true;
	}

	String ro = e.attributeValue("readOnly");
	if (ro != null && ro.equals("true")) {
		readOnly = true;
	}
	
	String maxLenStr = e.attributeValue("maxLen");
	if (maxLenStr != null) {
		try {
			maxLen = Integer.parseInt(maxLenStr);
		} catch (NumberFormatException nfe) {
			prtln ("WARNING: could not parse \"" + maxLenStr + "\" as an integer");
		}
	}
}
 
Example 9
Project: joai-project   File: DleseCollectionFileIndexingWriter.java   View Source Code Vote up 5 votes
/**
 *  Gets whether the collection is part of the DRC [true|false].
 *
 * @return                The partOfDRC Value
 * @exception  Exception  If error
 */
protected String getPartOfDRC() throws Exception {
	List nodes = getDom4jDoc().selectNodes("/*[local-name()='collectionRecord']/*[local-name()='access']/*[local-name()='drc']");
	if (nodes.size() != 1)
		return "false";
	Element element = (Element) nodes.get(0);
	return element.getText();
}
 
Example 10
Project: joai-project   File: DleseCollectionFileIndexingWriter.java   View Source Code Vote up 5 votes
/**
 *  Gets the URL to the collection.
 *
 * @return                The collectionUrl value
 * @exception  Exception  If error
 */
public String[] getUrls() throws Exception {
	List nodes = getDom4jDoc().selectNodes("/*[local-name()='collectionRecord']/*[local-name()='access']/*[local-name()='collectionLocation']");
	if (nodes.size() == 0)
		return null;
	Element element = (Element) nodes.get(0);
	return new String[]{element.getText()};
}
 
Example 11
Project: joai-project   File: Dom4jUtils.java   View Source Code Vote up 5 votes
/**
 *  isEmpty returns true if neither the element, or any children recursively, have textual content or have a
 *  non-empty attribute.
 *
 * @param  e                 an Element to test
 * @param  ignoreWhiteSpace  determines whether whitespace is considered as textual content .
 * @return                   true if Element and all children recursively are empty
 */
public static boolean isEmpty(Element e, boolean ignoreWhiteSpace) {
	String t = e.getText();
	// if ((t == null) || (t.trim().length() > 0)) {

	// 02/28/07 no longer ignore whitespace!
	if (ignoreWhiteSpace && t.trim().length() > 0) {
		return false;
	}
	if (!ignoreWhiteSpace && t.length() > 0) {
		return false;
	}

	// is there a non-empty attribute? (note: we don't ignore whitespace for attributes ...)
	for (Iterator i = e.attributeIterator(); i.hasNext(); ) {
		Attribute a = (Attribute) i.next();
		String value = a.getValue();
		if ((value == null) || (value.trim().length() > 0)) {
			return false;
		}
	}

	// is there a non-empty child element?
	for (Iterator i = e.elementIterator(); i.hasNext(); ) {
		Element child = (Element) i.next();
		boolean isChildEmpty = isEmpty(child);
		if (!isChildEmpty) {
			return false;
		}
	}

	return true;
}
 
Example 12
Project: joai-project   File: NCSCollectionFileIndexingWriter.java   View Source Code Vote up 5 votes
/**
 *  Returns the title for the collection.
 *
 * @return                The title value
 * @exception  Exception  If error reading XML.
 */
public String getTitle() throws Exception {
	List nodes = getDom4jDoc().selectNodes("/record/general/title");
	if (nodes.size() == 0)
		return "";
	Element element = (Element) nodes.get(0);
	return element.getText();
}
 
Example 13
Project: parabuild-ci   File: AccurevChangeLogParser.java   View Source Code Vote up 5 votes
public List parseChangeLog(final File logFile) throws MalformedURLException, DocumentException {
    final List result = new ArrayList(11);
    final SAXReader saxReader = new SAXReader();
    final Document document = saxReader.read(logFile);
    final Element rootElement = document.getRootElement();
//    if (LOG.isDebugEnabled()) {
//      LOG.debug("rootElement: " + rootElement);
//    }
    // Iterate transactions
    int changeListCounter = 0;
    final Iterator iter = rootElement.elementIterator();
    while (iter.hasNext() && changeListCounter++ < maxChangeLists) {
      final Element transactionElement = (Element) iter.next();
      if (!transactionElement.getName().equals("transaction")) {
        continue;
      }
//      if (LOG.isDebugEnabled()) {
//        LOG.debug("transactionElement: " + transactionElement);
//      }
      // Create change list
      final String type = transactionElement.attributeValue("type");
      final byte changeType = toChangeType(type);
      if (changeType == Change.TYPE_UNKNOWN) {
        continue;
      }
      final String id = transactionElement.attributeValue("id");
      final String time = transactionElement.attributeValue("time");
      final String user = transactionElement.attributeValue("user");
      final Element elementComment = transactionElement.element("comment");
      final String comment = elementComment.getText();
      final ChangeList changeList = new ChangeList();
      changeList.setCreatedAt(new Date(Long.parseLong(time) * 1000L));
      changeList.setDescription(comment);
      changeList.setNumber(id);
      changeList.setUser(user);
      // Iterate versions
      int changeCounter = 0;
      final Set changes = new HashSet(11);
      final Iterator versionIter = transactionElement.elementIterator("version");
      while (versionIter.hasNext() && changeCounter++ < maxChangeListSize) {
        final Element versionElement = (Element) versionIter.next();
        final String path = versionElement.attributeValue("path");
        final String version = versionElement.attributeValue("virtualNamedVersion");
        final Change change = new Change(path, version, changeType);
        changes.add(change);
      }
      changeList.setChanges(changes);
      // Add to result
      result.add(changeList);
    }
    return result;
  }
 
Example 14
Project: joai-project   File: AsnStatement.java   View Source Code Vote up 5 votes
/**
 *  Gets the textual content of the named subelement of provided element.
 *
 * @param  e               element containing subelement
 * @param  subElementName  name of subelement
 * @return                 the textual content of named subelement
 */
public String getSubElementText(Element e, String subElementName) {
	Element sub = e.element(subElementName);
	if (sub == null) {
		prtln("getSubElementText could not find subElement for " + subElementName);
		return "";
	}
	return sub.getText();
}
 
Example 15
Project: ureport   File: SimpleValueParser.java   View Source Code Vote up 4 votes
@Override
public Value parse(Element element) {
	SimpleValue simpleValue=new SimpleValue(element.getText());
	return simpleValue;
}
 
Example 16
Project: alfresco-repository   File: QueryParameterDefImpl.java   View Source Code Vote up 4 votes
public static QueryParameterDefinition createParameterDefinition(Element element, DictionaryService dictionaryService,  NamespacePrefixResolver nspr)
{

    if (element.getQName().getName().equals(ELEMENT_QNAME.getName()))
    {
        QName qName = null;
        Element qNameElement = element.element(DEF_QNAME.getName());
        if (qNameElement != null)
        {
            qName = QName.createQName(qNameElement.getText(), nspr);
        }

        PropertyDefinition propDef = null;
        Element propDefElement = element.element(PROPERTY_QNAME.getName());
        if (propDefElement != null)
        {
            propDef = dictionaryService.getProperty(QName.createQName(propDefElement.getText(), nspr));
        }

        DataTypeDefinition typeDef = null;
        Element typeDefElement = element.element(PROPERTY_TYPE_QNAME.getName());
        if (typeDefElement != null)
        {
            typeDef = dictionaryService.getDataType(QName.createQName(typeDefElement.getText(), nspr));
        }

        boolean hasDefault = false;
        String defaultValue = null;
        Element defaultValueElement = element.element(DEFAULT_VALUE.getName());
        if(defaultValueElement != null)
        {
            hasDefault = true;
            defaultValue = defaultValueElement.getText();
        }
        
        if (propDef != null)
        {
            return new QueryParameterDefImpl(qName, propDef, hasDefault, defaultValue);
        }
        else
        {
            return new QueryParameterDefImpl(qName, typeDef, hasDefault, defaultValue);
        }
    }
    else
    {
        return null;
    }
}
 
Example 17
Project: ureport   File: ExpressionValueParser.java   View Source Code Vote up 4 votes
@Override
public ExpressionValue parse(Element element) {
	ExpressionValue value=new ExpressionValue(element.getText());
	return value;
}
 
Example 18
Project: joai-project   File: RemoteSearcher.java   View Source Code Vote up 4 votes
/**
 *  analogus to SimpleLuceneIndex.searchDoc, performs a search and returns an
 *  array of {@link RemoteResultDoc} objects that represent the results of the
 *  search. <p>
 *
 *  Note: the urlCheck WebService returns information about duplicate records
 *  (that don't match the query, but which refer to the same resource) returned
 *  as an <b>alsoCatalogedBy</b> element of <b>MatchingRecord</b> . These
 *  duplicates are treated as search results by searchDocs - they are expanded
 *  into RemoteResultDoc objects and added to the results returned.
 *
 *@param  s  Description of the Parameter
 *@return    Description of the Return Value
 */
public RemoteResultDoc[] searchDocs(String s) {
	RemoteResultDoc[] emptyResults = new RemoteResultDoc[]{};
	if (s == null) {
		prtln("RemoteResultDoc: got null for the search parameter");
		return emptyResults;
	}
	Document webServiceResultDoc = null;
	try {
		prtln("about to call webserviceClient.urlCheck with " + s);
		webServiceResultDoc = wsc.urlCheck(s);
	} catch (WebServiceClientException e) {
		prtln(e.getMessage());
		return emptyResults;
	}
	if (webServiceResultDoc == null) {
		prtln("urlCheck returned null");
		return emptyResults;
	}
	// parse results document
	List matchingRecords = webServiceResultDoc.selectNodes("//results/matchingRecord");
	if (matchingRecords.size() == 0) {
		prtln("urlCheck returned no matches");
		return emptyResults;
	}
	else {
		ArrayList matches = new ArrayList();
		for (Iterator i = matchingRecords.iterator(); i.hasNext(); ) {
			Element matchingRecord = (Element) i.next();
			// prtln ("about to parse matchingRecord:\n" + Dom4jUtils.prettyPrint(matchingRecord));

			RemoteResultDoc m = new RemoteResultDoc(matchingRecord, this);
			matches.add(m);

			// now deal with the alsoCatalogedBys
			List alsoCatalogedBys = matchingRecord.selectNodes("//additionalMetadata[@realm='adn']/alsoCatalogedBy");
			if (alsoCatalogedBys == null) {
				// prtln ("no alsoCatalogedBys found");
			}
			else {
				// prtln (alsoCatalogedBys.size() + " alsoCatalogedBys found");
				for (Iterator n = alsoCatalogedBys.iterator(); n.hasNext(); ) {
					Element ae = (Element) n.next();
					String collection = ae.attributeValue("collectionLabel");
					String id = ae.getText();
					RemoteResultDoc am = new RemoteResultDoc(id, m.getUrl(), collection, this);
					matches.add(am);
				}
			}
		}
		prtln("searchDocs found " + matches.size() + " items");
		return (RemoteResultDoc[]) matches.toArray(emptyResults);
	}
}
 
Example 19
Project: EasyML   File: OozieGraphXMLParser.java   View Source Code Vote up 4 votes
/** parse a program node from xml */
private static OozieProgramNode parseProgramNode(Element xml_node) {
	List<Element> childNodes = xml_node.elements();
	OozieProgramNode node = new OozieProgramNode();

	for( Element child : childNodes){
		String value = child.getText();
		String name = child.getName();

		if ("id".equals(name))
			node.setId(value);
		else if ("moduleId".equals(name))
			node.setModuleId(value);
		else if ( "oozJob".equals(name))
			node.setOozJobId( value );
		else if ("x".equals(name))
			node.setX((int) Float.parseFloat(value));
		else if ("y".equals(name))
			node.setY((int) Float.parseFloat(value));
		else if ("file".equals(name))
			node.addFile(value);
		else if( "input_aliases".equals( name ) ){
			node.addInputAliases( value );
		}else if("output_aliases".equals(name)){
			node.addOutputAliases( value );
		}else if ("param".equals(name))
			node.addParam(value);
		else if( "script".equals(name))
			node.setScript(value);
		else if( "incount".equals(name))
			node.setInputFileCount( Integer.parseInt(value));
		else if( "outcount".equals(name))
			node.setOutputFileCount( Integer.parseInt(value));
		else if("is_distributed".equals(name))
			node.setDistributed(Boolean.valueOf(value));
		else if("is_standalone_script".equals(name)){
			node.setStandaloneScript(Boolean.valueOf(value));
		}else if("work_path".equals(name)){
			node.setWorkPath(value);
		}
		else if("cmd_line".equals(name)){
			node.setCmdLine(value);
		}
	}

	return node;
}
 
Example 20
Project: bdf2   File: NexusAddonParser.java   View Source Code Vote up 4 votes
@SuppressWarnings({ "rawtypes", "unchecked" })
public AddonInfo parseAddonInfoMetaData(String xml) throws Exception {
	if (xml == null) {
		return null;
	}
	AddonInfo addonInfo = new AddonInfo();
	InputStream inputStream = toInputStream(xml);
	try {
		Document document = saxReader.read(inputStream);
		String groupId = document.getRootElement().element("groupId").getText();
		String artifactId = document.getRootElement().element("artifactId").getText();
		Element versioning = document.getRootElement().element("versioning");
		Element elementLatest = versioning.element("latest");
		if (elementLatest == null) {
			elementLatest = versioning.element("release");
		}
		String latest = "";
		if (elementLatest != null) {
			latest = elementLatest.getText();
		}
		String lastUpdated = versioning.element("lastUpdated").getText();
		addonInfo.setArtifactId(artifactId);
		addonInfo.setName(artifactId);
		addonInfo.setGroupId(groupId);
		addonInfo.setLastVersion(latest);
		addonInfo.setLastUpdated(lastUpdated);
		Element versions = versioning.element("versions");
		VersionInfo versionInfo;
		List<VersionInfo> versionInfos = new ArrayList<VersionInfo>();
		int index = 1;
		for (Iterator iterInner = versions.elementIterator(); iterInner.hasNext();) {
			Element elementInner = (Element) iterInner.next();
			versionInfo = new VersionInfo();
			versionInfo.setName(elementInner.getText());
			versionInfo.setLastVersion(false);
			if (latest.equals(elementInner.getText())) {
				//versionInfo.setLastVersion(true);
			}
			versionInfo.setIndex(index);
			versionInfos.add(versionInfo);
			index++;
		}
		Collections.sort(versionInfos, new SortVersionInfoClass());
		/*if (!versionInfos.isEmpty() && StringUtils.isEmpty(addonInfo.getLastVersion())) {
		}*/
		versionInfos.get(0).setLastVersion(true);
		addonInfo.setLastVersion(versionInfos.get(0).getName());
		if (versionInfos.size() > 4) {
			versionInfos = versionInfos.subList(0, 3);
		}
		addonInfo.setVersions(versionInfos);
	} finally {
		inputStream.close();
	}
	return addonInfo;
}