本文整理汇总了Java中org.dom4j.Element.addText方法的典型用法代码示例。如果您正苦于以下问题:Java Element.addText方法的具体用法?Java Element.addText怎么用?Java Element.addText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dom4j.Element
的用法示例。
在下文中一共展示了Element.addText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addRemove
import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addRemove(DaoGen daoGen, String key, MapperMethod method, Element root) {
return (prefix) -> {
Element sql = root.addElement("delete");
sql.addComment(COMMENT);
sql.addAttribute("id", key);
String left = key.replaceFirst(prefix, "");
List<String> params = split(left, daoGen.separator());
if (params.isEmpty()) throw new Error("Remove method needs at least one param");
StringBuilder select = new StringBuilder(50);
select.append("delete from ")
.append(method.getDaoEnv().getTableName());
int len = params.size();
if (!params.isEmpty()) select.append(" where ");
int cur = 0;
appendParams(params, select, len, cur);
sql.addText(select.toString());
};
}
示例2: addCount
import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addCount(DaoGen daoGen, String key, MapperMethod method, Element root,Consumer<List<String>> validator) {
return (prefix) -> {
Element sql = root.addElement("select");
sql.addComment(COMMENT);
sql.addAttribute("id", key);
sql.addAttribute("resultType", "int");
String left = key.replaceFirst(prefix, "");
List<String> params = split(left, daoGen.separator());
validator.accept(params);
StringBuilder select = new StringBuilder(50);
select.append("select count(1) from ")
.append(method.getDaoEnv().getTableName());
int len = params.size();
if (!params.isEmpty()) select.append(" where ");
int cur = 0;
appendParams(params, select, len, cur);
select.append(" order by ").append(daoGen.primaryKey());
sql.addText(select.toString());
};
}
示例3: appendText
import org.dom4j.Element; //导入方法依赖的package包/类
/**
* Append text to a XML element.
*
* @param xpath XPath , pointing to a XML element
* @param text the text , which will be appended to a XML element
* @return this instance
* @throws XMLException
*/
@PublicAtsApi
public XmlText appendText(
String xpath,
String text ) throws XMLException {
if (StringUtils.isNullOrEmpty(xpath)) {
throw new XMLException("Null/empty xpath is not allowed.");
}
if (StringUtils.isNullOrEmpty(text)) {
throw new XMLException("Null/empty text is not allowed.");
}
Element element = findElement(xpath);
if (element == null) {
throw new XMLException("'" + xpath + "' is not a valid path");
}
element.addText(text);
return this;
}
示例4: addCountIn
import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addCountIn(DaoGen daoGen, String key, MapperMethod method, Element root) {
return (prefix) -> {
Element sql = root.addElement("select");
sql.addComment(COMMENT);
sql.addAttribute("id", key);
sql.addAttribute("resultType", "int");
String left = key.replaceFirst(prefix, "");
List<String> params = split(left, daoGen.separator());
StringBuilder select = new StringBuilder(50);
select.append("select count(1) from ")
.append(method.getDaoEnv().getTableName());
int len = params.size();
if (len != 1)
throw new Error("count in method only support one param");
if (!params.isEmpty()) select.append(" where ");
String param = params.get(0);
sql.addText(select.toString());
if (param.endsWith("s")) param = lowerFirst(param.substring(0,param.length()-1));
Element choose = sql.addElement("choose");
String collection = param+"s";
Element when = choose.addElement("when");
when.addAttribute("test", collection + " !=null and " + collection + ".size() > 0");
when.addText("`" + param + "` in ");
Element each = when.addElement("foreach");
each.addAttribute("item", param);
each.addAttribute("collection", param+"s");
each.addAttribute("open", "(");
each.addAttribute("separator", ",");
each.addAttribute("close", ")");
each.addText("#{" + param + "}");
Element otherwise = choose.addElement("otherwise");
otherwise.addText(" 1 = 2 ");
sql.addText(" order by " + daoGen.primaryKey());
};
}
示例5: addUpdateFor
import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addUpdateFor(DaoGen daoGen, String key, MapperMethod method, Element root) {
return (prefix) -> {
Element sql = root.addElement("update");
sql.addComment(COMMENT);
sql.addAttribute("id", key);
StringBuilder updateSql = new StringBuilder(50);
updateSql.append("update ")
.append(method.getDaoEnv().getTableName())
.append(" set \n");
String left = key.replaceFirst(prefix, "");
List<String> fields = split(left, daoGen.separator()).stream().map(this::lowerFirst).collect(Collectors.toList());
fields.add(method.getDaoEnv().getUpdateTime());
String pk = daoGen.primaryKey();
updateSql.append(
Joiner.on(", ").join(
fields.stream().filter((field -> !field.equals(pk) &&
!method.getDaoEnv().getCreateTime().equals(field)))
.map((field -> {
if (method.getDaoEnv().getUpdateTime().equals(field))
return "`" + field + "` = " + "now() ";
else return "`" + field + "` = " + "#{" + field + "} ";
}))
.iterator()));
updateSql.append("Where `")
.append(pk)
.append("` = ")
.append("#{")
.append(pk)
.append("}");
sql.addText(updateSql.toString());
};
}
示例6: addBatchInsert
import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addBatchInsert(DaoGen daoGen, String key, MapperMethod method, Element root) {
return (prefix) -> {
Element sql = root.addElement("insert");
sql.addComment(COMMENT);
sql.addAttribute("id", key);
StringBuilder insertSql = new StringBuilder(50);
insertSql.append("insert into ")
.append(method.getDaoEnv().getTableName())
.append("\n");
String pk = daoGen.primaryKey();
List<String> fields = getFields(method.getFirstParamType());
insertSql.append("(")
.append(Joiner.on(", ").join(getInsertFieldsStream(pk, fields).map(f -> "`"+f + "`").iterator()))
.append(")\n");
insertSql.append("values ");
sql.addText(insertSql.toString());
Element foreach = sql.addElement("foreach");
foreach.addAttribute("collection", "list");
foreach.addAttribute("item", "item");
foreach.addAttribute("separator", ",");
StringBuilder eachSql = new StringBuilder(50);
eachSql.append("(").append(Joiner.on(", ").join(getInsertFieldsStream(pk, fields).map(field -> {
if (method.getDaoEnv().getCreateTime().contains(field)
|| method.getDaoEnv().getUpdateTime().contains(field))
return "now()";
else return "#{item." + field + "}";
}).iterator()));
eachSql.append(")");
foreach.addText(eachSql.toString());
};
}
示例7: addInsert
import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addInsert(DaoGen daoGen, String key, MapperMethod method, Element root) {
return (prefix) -> {
Element sql = root.addElement("insert");
sql.addComment(COMMENT);
sql.addAttribute("id", key);
StringBuilder insertSql = new StringBuilder(50);
insertSql.append("insert into ")
.append(method.getDaoEnv().getTableName())
.append("\n");
String pk = daoGen.primaryKey();
List<String> fields = getFields(method.getFirstParamType());
insertSql.append("(")
.append(Joiner.on(", ").join(getInsertFieldsStream(pk, fields).map(f -> "`"+f + "`").iterator()))
.append(")\n");
insertSql.append("values (");
insertSql.append(Joiner.on(", ").join(getInsertFieldsStream(pk, fields).map(field -> {
if (method.getDaoEnv().getCreateTime().contains(field)
|| method.getDaoEnv().getUpdateTime().contains(field))
return "now()";
else return "#{" + field + "}";
}).iterator()));
insertSql.append(")");
sql.addText(insertSql.toString());
Element selectKey = sql.addElement("selectKey");
selectKey.addAttribute("resultType", "int");
selectKey.addAttribute("keyProperty", pk);
selectKey.addText("SELECT @@IDENTITY AS " + pk);
};
}
示例8: createTextQueryElement
import org.dom4j.Element; //导入方法依赖的package包/类
private static Element createTextQueryElement(String fieldName, String fieldType, String termOrPhrase) throws Exception {
/* if (fieldName == null || fieldName.trim().length() == 0)
throw new Exception("fieldName must not be empty or null");
if (fieldType == null || fieldType.trim().length() == 0)
throw new Exception("fieldType must not be empty or null");
if (!fieldType.equals("matchAnyTerm") && !fieldType.equals("matchPhrase"))
throw new Exception("fieldType must be either 'matchAnyTerm' or 'matchPhrase'"); */
Document document = DocumentHelper.createDocument();
Element fieldQuery = document.addElement("textQuery");
if (fieldName != null)
fieldQuery.addAttribute("field", fieldName);
fieldQuery.addAttribute("type", fieldType);
fieldQuery.addText(termOrPhrase);
return fieldQuery;
}
示例9: createLuceneQueryElement
import org.dom4j.Element; //导入方法依赖的package包/类
private static Element createLuceneQueryElement(String query) throws Exception {
if (query == null || query.trim().length() == 0)
throw new Exception("query must not be empty or null");
Document document = DocumentHelper.createDocument();
Element luceneQuery = document.addElement("luceneQuery");
luceneQuery.addText(query);
return luceneQuery;
}
示例10: attachElementDebugInfo
import org.dom4j.Element; //导入方法依赖的package包/类
/**
* NOT YET DOCUMENTED
*
* @param target NOT YET DOCUMENTED
* @param displayText NOT YET DOCUMENTED
* @param borderColor NOT YET DOCUMENTED
*/
public void attachElementDebugInfo(Element target, String displayText, String borderColor) {
if (showElementDebugInfo) {
Element info = DocumentHelper.createElement("div")
.addAttribute("class", "element-debug-info");
// s + " (" + getLevel() + ")";
info.addText(displayText);
target.add(info);
if (borderColor != null)
target.addAttribute("style", "border__thin dashed " + borderColor);
}
}
示例11: attachLabelDebugInfo
import org.dom4j.Element; //导入方法依赖的package包/类
/**
* Description of the Method
*
* @param e Description of the Parameter
* @param s Description of the Parameter
* @param borderSpec NOT YET DOCUMENTED
*/
protected void attachLabelDebugInfo(Element e, String s, String borderSpec) {
if (rhelper.showLabelDebugInfo) {
Element info = df.createElement("div")
.addAttribute("class", "label-debug-info");
String debugInfo = s;
info.addText(debugInfo);
e.add(info);
if (borderSpec != null)
e.addAttribute("style", "border__" + borderSpec);
}
}
示例12: append2XML
import org.dom4j.Element; //导入方法依赖的package包/类
@Override
public void append2XML(Element root) {
Element kill = root.addElement("kill");
Element msg = kill.addElement("message");
msg.addText("Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]");
kill.addAttribute("name", "fail");
Element end = root.addElement("end");
end.addAttribute("name", getName());
}
示例13: main
import org.dom4j.Element; //导入方法依赖的package包/类
public static void main(String args[]){
Namespace rootNs = new Namespace("", "uri:oozie:workflow:0.4"); // root namespace uri
QName rootQName = QName.get("workflow-app", rootNs); // your root element's name
Element workflow = DocumentHelper.createElement(rootQName);
Document doc = DocumentHelper.createDocument(workflow);
workflow.addAttribute("name", "test");
Element test = workflow.addElement("test");
test.addText("hello");
OutputFormat outputFormat = OutputFormat.createPrettyPrint();
outputFormat.setEncoding("UTF-8");
outputFormat.setIndent(true);
outputFormat.setIndent(" ");
outputFormat.setNewlines(true);
try {
StringWriter stringWriter = new StringWriter();
XMLWriter xmlWriter = new XMLWriter(stringWriter);
xmlWriter.write(doc);
xmlWriter.close();
System.out.println( doc.asXML() );
System.out.println( stringWriter.toString().trim());
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例14: addQueryIn
import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addQueryIn(DaoGen daoGen, String key, MapperMethod method, Element root) {
return (prefix) -> {
Element sql = root.addElement("select");
sql.addComment(COMMENT);
sql.addAttribute("id", key);
sql.addAttribute("resultType", method.getReturnType().toString());
String left = key.replaceFirst(prefix, "");
List<String> params = split(left, daoGen.separator());
StringBuilder select = new StringBuilder(50);
List<String> fields = getFields(method.getReturnType());
select.append("select ")
.append(Joiner.on(", ").join(fields.stream().map(f-> "`" + f + "`").iterator()))
.append(" from ")
.append(method.getDaoEnv().getTableName());
int len = params.size();
if (len != 1)
throw new Error("query in method only support one param");
if (!params.isEmpty()) select.append(" where ");
String param = params.get(0);
sql.addText(select.toString());
if (param.endsWith("s")) param = lowerFirst(param.substring(0,param.length()-1));
Element choose = sql.addElement("choose");
String collection = param+"s";
Element when = choose.addElement("when");
when.addAttribute("test", collection + " !=null and " + collection + ".size() > 0");
when.addText("`" + param + "` in ");
Element each = when.addElement("foreach");
each.addAttribute("item", param);
each.addAttribute("collection", param+"s");
each.addAttribute("open", "(");
each.addAttribute("separator", ",");
each.addAttribute("close", ")");
each.addText("#{" + param + "}");
Element otherwise = choose.addElement("otherwise");
otherwise.addText(" 1 = 2 ");
sql.addText(" order by " + daoGen.primaryKey());
};
}
示例15: addUpdate
import org.dom4j.Element; //导入方法依赖的package包/类
private Consumer<String> addUpdate(DaoGen daoGen, String key, MapperMethod method, Element root) {
return (prefix) -> {
Element sql = root.addElement("update");
sql.addComment(COMMENT);
sql.addAttribute("id", key);
StringBuilder updateSql = new StringBuilder(50);
updateSql.append("update ")
.append(method.getDaoEnv().getTableName())
.append(" set \n");
List<String> fields = getFields(method.getFirstParamType());
String pk = daoGen.primaryKey();
String updateByField;
String entity;
if (key.startsWith("updateBy")){
updateByField = lowerFirst(key.substring(8));
entity = "entity";
}else{
updateByField = pk;
entity = null;
}
updateSql.append(
Joiner.on(", ").join(
fields.stream().filter((field -> !field.equals(pk)
&& !field.equals(updateByField)
&& !method.getDaoEnv().getCreateTime().equals(field)))
.map((field -> {
if (method.getDaoEnv().getUpdateTime().equals(field))
return "`" + field + "` = " + "now() ";
else
return "`" + field + "` = " + "#{" + (entity != null ?
entity + "." :
"") + field + "} ";
}))
.iterator()));
updateSql.append("Where `")
.append(updateByField)
.append("` = ")
.append("#{")
.append(updateByField)
.append("}");
sql.addText(updateSql.toString());
};
}