本文整理匯總了Java中org.dom4j.Node.getText方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.getText方法的具體用法?Java Node.getText怎麽用?Java Node.getText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dom4j.Node
的用法示例。
在下文中一共展示了Node.getText方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: get
import org.dom4j.Node; //導入方法依賴的package包/類
/**
* Given an encoded xpath, return the value of the referred to node
*
* @param key xpath encoded as necessary for use in jsp
* @return text of the node referred to by the xpath or an empty string if
* the node cannot be found
*/
public Object get(String key) {
String xpath = XPathUtils.decodeXPath(key);
Node node = doc.selectSingleNode(xpath);
String val = "";
if (node == null) {
// prtln("DocMap.get(): couldn't find node for " + xpath);
}
else {
try {
val = node.getText();
} catch (Exception e) {
prtlnErr("DocMap.get(): unable to get Text for " + xpath);
}
}
return val;
}
示例2: handleRelationField
import org.dom4j.Node; //導入方法依賴的package包/類
private void handleRelationField(String xPathToField, Document xmlDocument)
{
List nodes = xmlDocument.selectNodes( xPathToField );
if(nodes != null){
for(int i = 0; i< nodes.size(); i++){
Node currentNode = (Node)nodes.get(i);
String relation = currentNode.getText();
// Insert the URL if an ID is present...
if(!relation.toLowerCase().matches(".*http\\:\\/\\/.*|.*ftp\\:\\/\\/.*")){
String relatedID = relation.substring(relation.indexOf(" ")+1,relation.length());
ResultDocList results =
index.searchDocs("id:" + SimpleLuceneIndex.encodeToTerm(relatedID));
if(results == null || results.size() == 0){
currentNode.detach();
}else{
String url = ((ItemDocReader)((ResultDoc)results.get(0)).getDocReader()).getUrl();
currentNode.setText(relation.substring(0,relation.indexOf(" ") + 1) + url );
}
}
}
}
}
示例3: getEnumerationValuesOf
import org.dom4j.Node; //導入方法依賴的package包/類
/**
* Gets the curently assigned values for the given xpath in the current
* Document. This method can be called very many times for the same page, so
* we cache values in the multiValuesCache
*
* @param encodedPath a jsp-encoded xpath
* @return The enumerationValuesOf value
*/
public String[] getEnumerationValuesOf(String encodedPath) {
// prtln("getEnumerationValuesOf() with " + encodedPath);
String xpath = XPathUtils.decodeXPath(encodedPath);
if (multiValuesCache.containsKey(xpath)) {
String[] foundValues = (String[]) multiValuesCache.get(xpath);
return foundValues;
}
List nodes = docMap.selectNodes(xpath);
if (nodes == null) {
prtlnErr("\tunable to find any nodes for " + xpath);
return null;
}
String[] values = new String[nodes.size()];
for (int i = 0; i < nodes.size(); i++) {
Node node = (Node) nodes.get(i);
String value = node.getText();
values[i] = value;
}
multiValuesCache.put(xpath, values);
// prtln("put " + values.length + " items in cache");
return values;
}
示例4: readConfig
import org.dom4j.Node; //導入方法依賴的package包/類
private static String readConfig(List<String> configPaths) throws DocumentException {
SAXReader reader = new SAXReader();
for (String path : configPaths) {
File file = new File(path);
if (file.exists()) {
Document doc = reader.read(file);
Element root = doc.getRootElement();
Iterator<Node> it = root.elementIterator();
while (it.hasNext()) {
Node node = it.next();
if (node != null && "localRepository".equals(node.getName())) {
return node.getText();
}
}
}
}
return null;
}
示例5: getInstanceValue
import org.dom4j.Node; //導入方法依賴的package包/類
public String getInstanceValue(Element element, String appName) throws MissingNodeException {
Object value = element.selectObject(xpath);
if (value == null)
throw new MissingNodeException("Could not get value from element (path=" +
xpath + ")");
if (value instanceof List) {
List list = (List) value;
value = list.get(0);
}
if (value instanceof Node) {
Node node = (Node) value;
return node.getText();
} else if (value instanceof String) {
return (String) value;
} else if (value instanceof Number) {
String s = value.toString();
if (s.endsWith(".0"))
s = s.substring(0, s.length() - 2);
return s;
} else
throw new IllegalStateException("Unexpected object returned from xpath query: " + value);
}
示例6: getValue
import org.dom4j.Node; //導入方法依賴的package包/類
private String getValue(String xpath) {
XPath xpathObj = DocumentHelper.createXPath(xpath);
xpathObj.setNamespaceURIs(getNSMap());
Node node = xpathObj.selectSingleNode(doc);
if (node != null)
return node.getText();
else
return null;
}
示例7: getValue
import org.dom4j.Node; //導入方法依賴的package包/類
private String getValue (String xpath) {
XPath xpathObj = DocumentHelper.createXPath(xpath);
xpathObj.setNamespaceURIs(getNSMap());
Node node = xpathObj.selectSingleNode(doc);
if (node != null)
return node.getText();
else
return null;
}
示例8: getNodeText
import org.dom4j.Node; //導入方法依賴的package包/類
/**
* return the Text of a Node satisfying the given XPath.
*
* @param xpath an XPath\
* @return Text of Node or empty String if no Node is found
*/
protected String getNodeText(String xpath) {
Node node = getNode(xpath);
try {
return node.getText();
} catch (Throwable t) {
// prtln ("getNodeText() failed with " + xpath + "\n" + t.getMessage());
// Dom4jUtils.prettyPrint (docMap.getDocument());
}
return "";
}
示例9: getUrls
import org.dom4j.Node; //導入方法依賴的package包/類
public String[] getUrls() throws Exception {
// Announcement url
Node node = getDom4jDoc().selectSingleNode("/news-oppsRecord/announcementURL");
if (node == null)
return null;
return new String[]{node.getText()};
}
示例10: getDescription
import org.dom4j.Node; //導入方法依賴的package包/類
public String getDescription() throws Exception {
// Description
Node node = getDom4jDoc().selectSingleNode("/news-oppsRecord/description");
if (node != null)
return node.getText();
return null;
}
示例11: isEmpty
import org.dom4j.Node; //導入方法依賴的package包/類
/**
* Returns true if an element (recursively) has no textual content, no
* children, and no attributes with values.<p>
*
* Note: returns FALSE if no node exists at the given path.
*
* @param xpath Description of the Parameter
* @return true if empty, false if any errors are encountered
*/
public boolean isEmpty(String xpath) {
Node node = doc.selectSingleNode(xpath);
String msg = "";
// return FALSE if a node is not found (this is kind of a wierd convention?)
if (node == null) {
msg = " ... couldn't find node at " + xpath + " returning FALSE";
// prtlnErr(msg);
return false;
}
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
String content = node.getText();
// return (content == null || content.trim().length() == 0);
// 2/28/07 - no longer ignore whitespace!
return (content == null || content.length() == 0);
}
if (node.getNodeType() != Node.ELEMENT_NODE) {
msg = " ... called with an unknown type of node - returning false";
// prtlnErr(msg);
return false;
}
boolean ret = Dom4jUtils.isEmpty((Element) node);
return ret;
}
示例12: getNodeText
import org.dom4j.Node; //導入方法依賴的package包/類
/**
* return the Text of a Node satisfying the given XPath.
*
* @param xpath an XPath\
* @return Text of Node or empty String if no Node is found
*/
private String getNodeText(String xpath) {
Node node = getNode(xpath);
String val = "";
try {
return node.getText();
} catch (Throwable t) {
// prtlnErr("getNodeText() failed with " + xpath + ": " + t.getMessage());
}
return "";
}
示例13: getNodeText
import org.dom4j.Node; //導入方法依賴的package包/類
/**
* return the Text of a Node satisfying the given XPath.
*
*@param xpath an XPath\
*@return Text of Node or empty String if no Node is found
*/
public String getNodeText(String xpath) {
Node node = getNode(xpath);
try {
return node.getText();
} catch (Throwable t) {
// prtln ("getNodeText() failed with " + xpath + "\n" + t.getMessage());
// Dom4jUtils.prettyPrint (docMap.getDocument());
}
return "";
}
示例14: tryGetItemText
import org.dom4j.Node; //導入方法依賴的package包/類
public static String tryGetItemText(Node node, String itemName, String defaultValue) {
if (node == null)
return defaultValue;
Node item = node.selectSingleNode(itemName);
if (item == null)
return defaultValue;
return item.getText();
}
示例15: id
import org.dom4j.Node; //導入方法依賴的package包/類
/**
* Assumes id is already placed in the xmlRecord. Note - the ID within the recordXml is ultimately
used by the indexer, NOT the provided id (see RepositoryManger.putRecord).
*
*@param recordXml xml record to be put
*@param xmlFormat metadata format of xml record (e.g., "adn")
*@param collection destination collection (e.g., "dcc")
*@param id xml record id
*@return ID of created record
*@exception WebServiceClientException Description of the Exception
*/
public String doPutRecord(String recordXml, String xmlFormat, String collection, String id, String status, String statusNote)
throws WebServiceClientException {
// prtln("doPutRecord()");
// prtln (recordXml);
String errorMsg;
try {
String encodedRecord = URLEncoder.encode(recordXml, "UTF-8");
// package up the request URL
String argString = "recordXml=" + encodedRecord.trim();
argString += "&xmlFormat=" + xmlFormat.trim();
argString += "&collection=" + collection.trim();
argString += "&id=" + id.trim();
if (status != null)
argString += "&dcsStatus=" + status;
if (statusNote != null)
argString += "&dcsStatusNote=" + URLEncoder.encode(statusNote, "UTF-8");
// URL url = new URL(baseUrl + "?" + argString);
// Document response = Dom4jUtils.getXmlDocument(url);
String logMsg = "doPutRecord() params:";
logMsg += "\n\t" + "xmlFormat: " + xmlFormat;
logMsg += "\n\t" + "collection: " + collection;
logMsg += "\n\t" + "id: " + id;
logMsg += "\n\t" + "status: " + status;
logMsg += "\n\t" + "statusNote: " + statusNote;
prtln (logMsg);
setRequestUrl("PutRecord", argString);
Document doc = getResponseDoc();
// now we have to parse the doc looking for errors
prtln(Dom4jUtils.prettyPrint(doc));
Node errorNode = doc.selectSingleNode("/DCSWebService/error");
if (errorNode != null) {
throw new Exception(errorNode.getText());
}
} catch (UnsupportedEncodingException e) {
errorMsg = "xmlRecord encoding error: " + e.getMessage();
throw new WebServiceClientException(errorMsg);
} catch (Throwable t) {
errorMsg = t.getMessage();
throw new WebServiceClientException(errorMsg);
}
return id;
}