本文整理汇总了Java中org.dom4j.Node.setText方法的典型用法代码示例。如果您正苦于以下问题:Java Node.setText方法的具体用法?Java Node.setText怎么用?Java Node.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dom4j.Node
的用法示例。
在下文中一共展示了Node.setText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: put
import org.dom4j.Node; //导入方法依赖的package包/类
/**
* Updates the Document by setting the Text of the Node at the specified
* xpath. If there is no node at the specified path, a new one is created.<p>
*
* ISSUE: what if there is no value (one way this happens is when there is a
* field in the form but no value is supplied by user. In this case we
* shouldn't bother creating a new node because there is no value to insert.
* But what if there was formerly a value and the user has deleted it? if the
* node is an Element, then should that element be deleted? (The user should
* be warned first!) if the node is an attribute, then should that attribute
* be deleted? (the user won't be warned, since this does not have the
* "ripple" effect that deleting an element can have. (maybe the user should
* be warned only if the element has children with values).
*
* @param key unencoded xpath
* @param val value to assign to node at xpath
*/
public void put(Object key, Object val) {
String xpath = XPathUtils.decodeXPath((String) key);
Node node = doc.selectSingleNode(xpath);
if (node == null) {
// prtln("DocMap.put(): creating new node for " + xpath);
try {
node = createNewNode(xpath);
} catch (Exception e) {
prtlnErr("DocMap.put(): couldn't create new node at \"" + xpath + "\": " + e);
return;
}
}
// 2/28/07 no longer trim values!
/* String trimmed_val = "";
if (val != null)
trimmed_val = ((String) val).trim();
node.setText(trimmed_val);*/
node.setText(val != null ? (String) val : "");
}
示例2: smartPut
import org.dom4j.Node; //导入方法依赖的package包/类
/**
* Tests xpath against provided schema (via SchemaHelper) before putting
* value, creating a new Node if one is not found at xpath.
*
* @param xpath NOT YET DOCUMENTED
* @param value NOT YET DOCUMENTED
* @exception Exception NOT YET DOCUMENTED
*/
public void smartPut(String xpath, String value) throws Exception {
if (schemaHelper != null && schemaHelper.getSchemaNode(xpath) == null) {
throw new Exception("stuffValue got an illegal xpath: " + xpath);
}
if (value == null)
throw new Exception("stuffValue got a null value (which is illegal) for " + xpath);
Node node = selectSingleNode(xpath);
if (node == null)
node = createNewNode(xpath);
if (node == null)
throw new Exception("smartPut failed to find or create node: " + xpath);
else {
// 2/18/07 no longer trim values!
// node.setText(value.trim());
node.setText(value);
}
}
示例3: 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 );
}
}
}
}
}
示例4: setNodeText
import org.dom4j.Node; //导入方法依赖的package包/类
/**
* Sets the nodeText for specified path, creating new node if necessary.
*
*@param xpath The new nodeText value
*@param value The new nodeText value
*/
protected void setNodeText(String xpath, String value) {
Node node = getNode(xpath);
if (node == null) {
prtln("setNodeText did not find node at " + xpath + " - creating ...");
try {
node = docMap.createNewNode(xpath);
} catch (Exception e) {
prtln("configReader could not find or create node at " + xpath);
return;
}
}
node.setText(value);
}
示例5: setMetadataProviderHandle
import org.dom4j.Node; //导入方法依赖的package包/类
/**
* Sets the metadataProviderHandle attribute of the CollectionConfigReader
* object
*
* @param handle The new metadataProviderHandle value
*/
public void setMetadataProviderHandle(String handle) {
// prtln("setMetadataProviderHandle() handle: \"" + handle + "\"");
Node node =
DocumentHelper.makeElement(this.getDocument(), metadataProviderHandlePath);
node.setText(handle);
}
示例6: stuffValue
import org.dom4j.Node; //导入方法依赖的package包/类
public void stuffValue (DocMap docMap, String xpath, String value, SchemaHelper schemaHelper) throws Exception {
if (schemaHelper.getSchemaNode(xpath) == null)
throw new Exception ("stuffValue got an illegal xpath: " + xpath);
Node node = docMap.selectSingleNode (xpath);
if (node == null)
node = docMap.createNewNode(xpath);
if (node == null)
throw new Exception ("node not found for " + xpath);
else
node.setText(value);
}
示例7: updateCollectionRecord
import org.dom4j.Node; //导入方法依赖的package包/类
/**
* Updates a collection record Document.
*
* @param collectionRecordDoc A collection record Document (may be from the template)
* @param title Title (must not be null)
* @param description Description (can be null)
* @param additionalMetadata Additional metadata (String, XML, or null)
* @param xmlFormat Format specifier or "DDS_UNCHANGED" to leave unchanged
* @param key Collection key or "DDS_UNCHANGED" to leave unchanged
* @param id Record ID or "DDS_UNCHANGED" to leave unchanged
* @param accessionDate Accession date or null to leave unchanged
* @return An updated Document
* @exception Exception If error
*/
private org.dom4j.Document updateCollectionRecord(
org.dom4j.Document collectionRecordDoc,
String title,
String description,
String additionalMetadata,
String xmlFormat,
String key,
String id,
Date accessionDate) throws Exception {
if (!key.equals("DDS_UNCHANGED"))
collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='access']/*[local-name()='key']").setText(key);
if (!xmlFormat.equals("DDS_UNCHANGED"))
collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='access']/*[local-name()='key']/@libraryFormat").setText(xmlFormat);
if (!id.equals("DDS_UNCHANGED"))
collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='metaMetadata']/*[local-name()='catalogEntries']/*[local-name()='catalog']/@entry").setText(id);
if (accessionDate != null)
collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='approval']/*[local-name()='collectionStatuses']/*[local-name()='collectionStatus']/@date").setText(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(accessionDate));
// Update the short title:
Node shortTitleNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']/*[local-name()='shortTitle']");
if (shortTitleNode != null)
shortTitleNode.setText(title);
// For previous repositories that are upgraded, remove the fullTitle (legacy)
Node fullTitleNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']/*[local-name()='fullTitle']");
if (fullTitleNode != null)
fullTitleNode.detach();
Node descriptionNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']/*[local-name()='description']");
if (descriptionNode == null)
descriptionNode = ((Branch) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='general']")).addElement("description");
if (description == null || description.trim().length() == 0)
description = title;
descriptionNode.setText(description);
// Delete and then re-create the additionalMetadata node:
Node additionalMetadataNode = collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']/*[local-name()='additionalMetadata']");
if (additionalMetadataNode != null)
additionalMetadataNode.detach();
if (additionalMetadata != null && additionalMetadata.trim().length() > 0) {
org.dom4j.Document additionalMetadataDocument;
try {
additionalMetadataDocument = Dom4jUtils.getXmlDocument("<additionalMetadata>" + additionalMetadata + "</additionalMetadata>");
} catch (Throwable t) {
throw new PutCollectionException("Error processing additionalMetadata argument: " + t.getMessage(), PutCollectionException.ERROR_CODE_BAD_ADDITIONAL_METADATA);
}
((Branch) collectionRecordDoc.selectSingleNode("/*[local-name()='collectionRecord']")).add(additionalMetadataDocument.getRootElement());
}
return collectionRecordDoc;
}
示例8: setToXMLNode
import org.dom4j.Node; //导入方法依赖的package包/类
public void setToXMLNode(Node xml, Object value, SessionFactoryImplementor factory)
throws HibernateException {
xml.setText( toXMLString(value, factory) );
}
示例9: setToXMLNode
import org.dom4j.Node; //导入方法依赖的package包/类
public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory) throws HibernateException {
node.setText( toString( value ) );
}
示例10: setToXMLNode
import org.dom4j.Node; //导入方法依赖的package包/类
public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory)
throws HibernateException {
node.setText( toXMLString(value, factory) );
}
示例11: setToXMLNode
import org.dom4j.Node; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked" })
public final void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory) {
node.setText( toString( (T) value ) );
}
示例12: setToXMLNode
import org.dom4j.Node; //导入方法依赖的package包/类
public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory) throws HibernateException {
node.setText( toXMLString(value, factory) );
}
示例13: setAggregatorHandle
import org.dom4j.Node; //导入方法依赖的package包/类
/**
* Sets the aggregatorHandle attribute of the CollectionConfigReader object
*
* @param pid The new aggregatorHandle value
*/
public void setAggregatorHandle(String pid) {
Node node = DocumentHelper.makeElement(this.getDocument(), aggregatorHandlePath);
node.setText(pid);
}
示例14: setAgentHandle
import org.dom4j.Node; //导入方法依赖的package包/类
/**
* Sets the agentHandle attribute of the CollectionConfigReader object
*
* @param pid The new agentHandle value
*/
public void setAgentHandle(String pid) {
Node node = DocumentHelper.makeElement(this.getDocument(), agentHandlePath);
node.setText(pid);
}
示例15: setNdrOaiLink
import org.dom4j.Node; //导入方法依赖的package包/类
/**
* Sets the ndrOaiLink attribute of the CollectionConfigReader object
*
* @param link The new ndrOaiLink value
*/
public void setNdrOaiLink(String link) {
Node node = DocumentHelper.makeElement(this.getDocument(), ndrOaiLinkPath);
node.setText(link);
}