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

The following are Jave code examples for showing how to use addText() 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: pndao   File: DaoGenHelper.java   View Source Code Vote up 6 votes
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());
    };
}
 
Example 2
Project: pndao   File: DaoGenHelper.java   View Source Code Vote up 6 votes
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());
    };
}
 
Example 3
Project: ats-framework   File: XmlText.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 4
Project: pndao   File: DaoGenHelper.java   View Source Code Vote up 5 votes
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());
    };
}
 
Example 5
Project: pndao   File: DaoGenHelper.java   View Source Code Vote up 5 votes
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());
    };
}
 
Example 6
Project: pndao   File: DaoGenHelper.java   View Source Code Vote up 5 votes
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());
    };
}
 
Example 7
Project: pndao   File: DaoGenHelper.java   View Source Code Vote up 5 votes
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);
    };
}
 
Example 8
Project: joai-project   File: OAISetsXMLConfigManager.java   View Source Code Vote up 5 votes
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;
}
 
Example 9
Project: joai-project   File: OAISetsXMLConfigManager.java   View Source Code Vote up 5 votes
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;
}
 
Example 10
Project: joai-project   File: RendererHelper.java   View Source Code Vote up 5 votes
/**
 *  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);
	}
}
 
Example 11
Project: joai-project   File: MdeNode.java   View Source Code Vote up 5 votes
/**
 *  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);
	}
}
 
Example 12
Project: EasyML   File: EndNodeDef.java   View Source Code Vote up 5 votes
@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());
}
 
Example 13
Project: EasyML   File: WFGraph.java   View Source Code Vote up 5 votes
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();
		}
	}
 
Example 14
Project: pndao   File: DaoGenHelper.java   View Source Code Vote up 4 votes
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());
    };
}
 
Example 15
Project: pndao   File: DaoGenHelper.java   View Source Code Vote up 4 votes
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());
    };
}
 
Example 16
Project: directory-ldap-api   File: LdapResultDsml.java   View Source Code Vote up 4 votes
/**
 * {@inheritDoc}
 */
@Override
public Element toDsml( Element root )
{

    // RequestID
    int requestID = message.getMessageId();
    if ( requestID > 0 )
    {
        root.addAttribute( "requestID", Integer.toString( requestID ) );
    }

    // Matched Dn
    Dn matchedDn = result.getMatchedDn();

    if ( !Dn.isNullOrEmpty( matchedDn ) )
    {
        root.addAttribute( "matchedDn", matchedDn.getName() );
    }

    // Controls
    ParserUtils.addControls( codec, root, message.getControls().values() );

    // ResultCode
    Element resultCodeElement = root.addElement( "resultCode" );
    resultCodeElement.addAttribute( "code", Integer.toString( result.getResultCode().getResultCode() ) );
    resultCodeElement.addAttribute( "descr", result.getResultCode().getMessage() );

    // ErrorMessage
    String errorMessage = result.getDiagnosticMessage();
    
    if ( ( errorMessage != null ) && ( errorMessage.length() != 0 ) )
    {
        Element errorMessageElement = root.addElement( "errorMessage" );
        errorMessageElement.addText( errorMessage );
    }

    // Referrals
    Referral referral = result.getReferral();
    if ( referral != null )
    {
        Collection<String> ldapUrls = referral.getLdapUrls();
        if ( ldapUrls != null )
        {
            for ( String ldapUrl : ldapUrls )
            {
                Element referalElement = root.addElement( "referal" );
                referalElement.addText( ldapUrl );
            }
        }
    }

    return root;
}
 
Example 17
Project: EasyML   File: ActionNodeDef.java   View Source Code Vote up 4 votes
protected void generateElement(Element root, String tag, String content) {
	if(content == null) content = "";
	Element ele = root.addElement(tag);
	ele.addText(content);
}
 
Example 18
Project: parabuild-ci   File: Dom4JXMLOutput.java   View Source Code Vote up 4 votes
public void writeText(String text) {
	Element top = (Element) stack.getLast();
	top.addText(text);
}