Example usage for org.dom4j Element addElement

List of usage examples for org.dom4j Element addElement

Introduction

In this page you can find the example usage for org.dom4j Element addElement.

Prototype

Element addElement(String name);

Source Link

Document

Adds a new Element node with the given name to this branch and returns a reference to the new node.

Usage

From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java

License:Apache License

/**
 * ???/*  w w  w.  ja va 2  s. co m*/
 * @param document
 */
private void generateInsert(Element root) {
    root.addComment("");
    Element insert = root.addElement("insert");
    insert.addAttribute("id", SAVE_ID);
    insert.addAttribute("parameterType", this.domainSimpleName);
    StringBuilder sb = new StringBuilder();
    //sb.append("\n");
    //sb.append("\t\t");
    sb.append("INSERT INTO {tableName} (");
    int i = 0;
    int fileNameSize = fieldNames.size();
    //?
    for (String fieldName : fieldNames) {
        i++;
        sb.append(fieldName.toUpperCase());
        if (i != fileNameSize) {
            sb.append(", ");
        }
    }
    sb.append(") VALUES (");
    i = 0;
    //
    for (String fieldName : fieldNames) {
        i++;
        sb.append("#{");
        sb.append(fieldName);
        sb.append("}");
        if (i != fileNameSize) {
            sb.append(", ");
        }
    }
    sb.append(")");
    //sb.append("\n");
    insert.setText(sb.toString());
}

From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java

License:Apache License

/**
 * ??/*w ww  . jav  a 2  s  .c  o m*/
 * @param root
 */
private void generateGet(Element root) {
    root.addComment("?ID?");
    Element get = root.addElement("select");
    get.addAttribute("id", GET_ID);
    get.addAttribute("parameterType", "int");
    get.addAttribute("resultMap", this.domainSimpleName.toLowerCase() + "Map");
    StringBuilder sb = new StringBuilder();
    //sb.append("\n");
    //sb.append("\t\t");
    sb.append("SELECT ");
    int i = 0;
    int fileNameSize = fieldNames.size();
    //
    for (String fieldName : fieldNames) {
        i++;
        sb.append(fieldName.toUpperCase());
        if (i != fileNameSize) {
            sb.append(", ");
        }
    }
    sb.append(" FROM {tableName} WHERE ID = #{param2}");
    //sb.append("\n");
    get.setText(sb.toString());
}

From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java

License:Apache License

/**
 * ?//from w  w w  . ja  v  a2  s . com
 * @param root
 */
private void generateUpdate(Element root) {
    root.addComment("");
    Element update = root.addElement("update");
    update.addAttribute("id", UPDATE_ID);
    update.addAttribute("parameterType", this.domainSimpleName);
    //sb.append("\n");
    //sb.append("\t\t");
    update.addText("\n\t\tUPDATE {tableName} ");

    Element set = update.addElement("set");

    //
    int i = 0;
    int fileNameSize = fieldNames.size();
    for (String fieldName : fieldNames) {
        i++;
        Element ifElement = set.addElement("if");
        ifElement.addAttribute("test", fieldName + " != null and " + fieldName + " != ''");
        String text = fieldName.toUpperCase() + " = #{" + fieldName + "}";
        if (i != fileNameSize) {
            text += ",";
        }
        ifElement.setText(text);
    }
    update.addText("\n\t\t WHERE ID = #{id}");
    //sb.append("\n");
}

From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java

License:Apache License

/**
 * ?/*from   w w w.j  a v  a2  s  .c  o  m*/
 * @param root
 */
private void generateList(Element root) {
    root.addComment("");
    Element list = root.addElement("select");
    list.addAttribute("id", LIST_ID);
    list.addAttribute("resultMap", this.domainSimpleName.toLowerCase() + "Map");
    StringBuilder sb = new StringBuilder();
    //sb.append("\n");
    //sb.append("\t\t");
    sb.append("SELECT ");
    int i = 0;
    int fileNameSize = fieldNames.size();
    //
    for (String fieldName : fieldNames) {
        i++;
        sb.append(fieldName.toUpperCase());
        if (i != fileNameSize) {
            sb.append(", ");
        }
    }
    sb.append(" FROM {tableName} ");
    //sb.append("\n");
    list.setText(sb.toString());

    Element where = list.addElement("where");

    for (String fieldName : fieldNames) {
        Element ifElement = where.addElement("if");
        ifElement.addAttribute("test", fieldName + " != null and " + fieldName + " != ''");
        ifElement.setText(fieldName.toUpperCase() + " = #{" + fieldName + "}");
    }
}

From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java

License:Apache License

/**
 * ?/*  w  w w .  ja  va2  s.  c  o  m*/
 * @param root
 */
private void generateDelete(Element root) {
    root.addComment("");
    Element delete = root.addElement("delete");
    delete.addAttribute("id", DELETE_ID);
    delete.addAttribute("parameterType", "int");
    delete.setText("DELETE FROM {tableName} WHERE ID = #{param2}");
}

From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java

License:Apache License

/**
 * ?/*from   w w  w. j  a v a2  s.  c o m*/
 * @param root
 */
private void generateResultMap(Element root) {
    root.addComment("");
    Element resultMap = root.addElement("resultMap");
    resultMap.addAttribute("id", this.domainSimpleName.toLowerCase() + "Map");
    resultMap.addAttribute("type", this.domainSimpleName);

    for (String fieldName : fieldNames) {
        Element result = null;
        if (fieldName.equalsIgnoreCase("id")) {
            result = resultMap.addElement("id");
        } else {
            result = resultMap.addElement("result");
        }
        result.addAttribute("column", fieldName.toUpperCase());
        result.addAttribute("property", fieldName);
    }
}

From source file:com.jpsycn.wggl.mobile.androidpn.xmpp.push.NotificationManager.java

License:Open Source License

/**
 * Creates a new notification IQ and returns it.
 *///from   w w w.  j  a  v a  2s  . c  o m
private IQ createNotificationIQ(String apiKey, String title, String message, String uri) {
    Random random = new Random();
    String id = Integer.toHexString(random.nextInt());
    // String id = String.valueOf(System.currentTimeMillis());

    Element notification = DocumentHelper.createElement(QName.get("notification", NOTIFICATION_NAMESPACE));
    notification.addElement("id").setText(id);
    notification.addElement("apiKey").setText(apiKey);
    notification.addElement("title").setText(title);
    notification.addElement("message").setText(message);
    notification.addElement("uri").setText(null == uri ? "" : uri);

    IQ iq = new IQ();
    iq.setType(IQ.Type.set);
    iq.setChildElement(notification);

    return iq;
}

From source file:com.jswiff.xml.ActionXMLWriter.java

License:Open Source License

static void writeAction(Element parentElement, Action action) {
    int actionCode = action.getCode();
    Element element;/*from  www. ja  v a  2  s  .  c om*/
    switch (actionCode) {
    case ActionConstants.ADD:
        element = parentElement.addElement("add");
        break;
    case ActionConstants.ADD_2:
        element = parentElement.addElement("add2");
        break;
    case ActionConstants.AND:
        element = parentElement.addElement("and");
        break;
    case ActionConstants.ASCII_TO_CHAR:
        element = parentElement.addElement("asciitochar");
        break;
    case ActionConstants.BIT_AND:
        element = parentElement.addElement("bitand");
        break;
    case ActionConstants.BIT_L_SHIFT:
        element = parentElement.addElement("bitlshift");
        break;
    case ActionConstants.BIT_OR:
        element = parentElement.addElement("bitor");
        break;
    case ActionConstants.BIT_R_SHIFT:
        element = parentElement.addElement("bitrshift");
        break;
    case ActionConstants.BIT_U_R_SHIFT:
        element = parentElement.addElement("biturshift");
        break;
    case ActionConstants.BIT_XOR:
        element = parentElement.addElement("bitxor");
        break;
    case ActionConstants.CALL:
        element = parentElement.addElement("call");
        break;
    case ActionConstants.CALL_FUNCTION:
        element = parentElement.addElement("callfunction");
        break;
    case ActionConstants.CALL_METHOD:
        element = parentElement.addElement("callmethod");
        break;
    case ActionConstants.CAST_OP:
        element = parentElement.addElement("castop");
        break;
    case ActionConstants.CHAR_TO_ASCII:
        element = parentElement.addElement("chartoascii");
        break;
    case ActionConstants.CLONE_SPRITE:
        element = parentElement.addElement("clonesprite");
        break;
    case ActionConstants.CONSTANT_POOL:
        element = writeConstantPool(parentElement, (ConstantPool) action);
        break;
    case ActionConstants.DECREMENT:
        element = parentElement.addElement("decrement");
        break;
    case ActionConstants.DEFINE_FUNCTION:
        element = writeDefineFunction(parentElement, (DefineFunction) action);
        break;
    case ActionConstants.DEFINE_FUNCTION_2:
        element = writeDefineFunction2(parentElement, (DefineFunction2) action);
        break;
    case ActionConstants.DEFINE_LOCAL:
        element = parentElement.addElement("definelocal");
        break;
    case ActionConstants.DEFINE_LOCAL_2:
        element = parentElement.addElement("definelocal2");
        break;
    case ActionConstants.DELETE:
        element = parentElement.addElement("delete");
        break;
    case ActionConstants.DELETE_2:
        element = parentElement.addElement("delete2");
        break;
    case ActionConstants.DIVIDE:
        element = parentElement.addElement("divide");
        break;
    case ActionConstants.END_DRAG:
        element = parentElement.addElement("enddrag");
        break;
    case ActionConstants.ENUMERATE:
        element = parentElement.addElement("enumerate");
        break;
    case ActionConstants.ENUMERATE_2:
        element = parentElement.addElement("enumerate2");
        break;
    case ActionConstants.EQUALS:
        element = parentElement.addElement("equals");
        break;
    case ActionConstants.EQUALS_2:
        element = parentElement.addElement("equals2");
        break;
    case ActionConstants.EXTENDS:
        element = parentElement.addElement("extends");
        break;
    case ActionConstants.GET_MEMBER:
        element = parentElement.addElement("getmember");
        break;
    case ActionConstants.GET_PROPERTY:
        element = parentElement.addElement("getproperty");
        break;
    case ActionConstants.GET_TIME:
        element = parentElement.addElement("gettime");
        break;
    case ActionConstants.GET_URL:
        element = writeGetURL(parentElement, (GetURL) action);
        break;
    case ActionConstants.GET_URL_2:
        element = writeGetURL2(parentElement, (GetURL2) action);
        break;
    case ActionConstants.GET_VARIABLE:
        element = parentElement.addElement("getvariable");
        break;
    case ActionConstants.GO_TO_FRAME:
        element = writeGoToFrame(parentElement, (GoToFrame) action);
        break;
    case ActionConstants.GO_TO_FRAME_2:
        element = writeGoToFrame2(parentElement, (GoToFrame2) action);
        break;
    case ActionConstants.GO_TO_LABEL:
        element = writeGoToLabel(parentElement, (GoToLabel) action);
        break;
    case ActionConstants.GREATER:
        element = parentElement.addElement("greater");
        break;
    case ActionConstants.IF:
        element = writeIf(parentElement, (If) action);
        break;
    case ActionConstants.IMPLEMENTS_OP:
        element = parentElement.addElement("implementsop");
        break;
    case ActionConstants.INCREMENT:
        element = parentElement.addElement("increment");
        break;
    case ActionConstants.INIT_ARRAY:
        element = parentElement.addElement("initarray");
        break;
    case ActionConstants.INIT_OBJECT:
        element = parentElement.addElement("initobject");
        break;
    case ActionConstants.INSTANCE_OF:
        element = parentElement.addElement("instanceof");
        break;
    case ActionConstants.JUMP:
        element = writeJump(parentElement, (Jump) action);
        break;
    case ActionConstants.LESS:
        element = parentElement.addElement("less");
        break;
    case ActionConstants.LESS_2:
        element = parentElement.addElement("less2");
        break;
    case ActionConstants.M_B_ASCII_TO_CHAR:
        element = parentElement.addElement("mbasciitochar");
        break;
    case ActionConstants.M_B_CHAR_TO_ASCII:
        element = parentElement.addElement("mbchartoascii");
        break;
    case ActionConstants.M_B_STRING_EXTRACT:
        element = parentElement.addElement("mbstringextract");
        break;
    case ActionConstants.M_B_STRING_LENGTH:
        element = parentElement.addElement("mbstringlength");
        break;
    case ActionConstants.MODULO:
        element = parentElement.addElement("modulo");
        break;
    case ActionConstants.MULTIPLY:
        element = parentElement.addElement("multiply");
        break;
    case ActionConstants.NEW_METHOD:
        element = parentElement.addElement("newmethod");
        break;
    case ActionConstants.NEW_OBJECT:
        element = parentElement.addElement("newobject");
        break;
    case ActionConstants.NEXT_FRAME:
        element = parentElement.addElement("nextframe");
        break;
    case ActionConstants.NOT:
        element = parentElement.addElement("not");
        break;
    case ActionConstants.OR:
        element = parentElement.addElement("or");
        break;
    case ActionConstants.PLAY:
        element = parentElement.addElement("play");
        break;
    case ActionConstants.POP:
        element = parentElement.addElement("pop");
        break;
    case ActionConstants.PREVIOUS_FRAME:
        element = parentElement.addElement("previousframe");
        break;
    case ActionConstants.PUSH:
        element = writePush(parentElement, (Push) action);
        break;
    case ActionConstants.PUSH_DUPLICATE:
        element = parentElement.addElement("pushduplicate");
        break;
    case ActionConstants.RANDOM_NUMBER:
        element = parentElement.addElement("randomnumber");
        break;
    case ActionConstants.REMOVE_SPRITE:
        element = parentElement.addElement("removesprite");
        break;
    case ActionConstants.RETURN:
        element = parentElement.addElement("return");
        break;
    case ActionConstants.SET_MEMBER:
        element = parentElement.addElement("setmember");
        break;
    case ActionConstants.SET_PROPERTY:
        element = parentElement.addElement("setproperty");
        break;
    case ActionConstants.SET_TARGET:
        element = writeSetTarget(parentElement, (SetTarget) action);
        break;
    case ActionConstants.SET_TARGET_2:
        element = parentElement.addElement("settarget2");
        break;
    case ActionConstants.SET_VARIABLE:
        element = parentElement.addElement("setvariable");
        break;
    case ActionConstants.STACK_SWAP:
        element = parentElement.addElement("stackswap");
        break;
    case ActionConstants.START_DRAG:
        element = parentElement.addElement("startdrag");
        break;
    case ActionConstants.STOP:
        element = parentElement.addElement("stop");
        break;
    case ActionConstants.STOP_SOUNDS:
        element = parentElement.addElement("stopsounds");
        break;
    case ActionConstants.STORE_REGISTER:
        element = writeStoreRegister(parentElement, (StoreRegister) action);
        break;
    case ActionConstants.STRICT_EQUALS:
        element = parentElement.addElement("strictequals");
        break;
    case ActionConstants.STRING_ADD:
        element = parentElement.addElement("stringadd");
        break;
    case ActionConstants.STRING_EQUALS:
        element = parentElement.addElement("stringequals");
        break;
    case ActionConstants.STRING_EXTRACT:
        element = parentElement.addElement("stringextract");
        break;
    case ActionConstants.STRING_GREATER:
        element = parentElement.addElement("stringgreater");
        break;
    case ActionConstants.STRING_LENGTH:
        element = parentElement.addElement("stringlength");
        break;
    case ActionConstants.STRING_LESS:
        element = parentElement.addElement("stringless");
        break;
    case ActionConstants.SUBTRACT:
        element = parentElement.addElement("subtract");
        break;
    case ActionConstants.TARGET_PATH:
        element = parentElement.addElement("targetpath");
        break;
    case ActionConstants.THROW:
        element = parentElement.addElement("throw");
        break;
    case ActionConstants.TO_INTEGER:
        element = parentElement.addElement("tointeger");
        break;
    case ActionConstants.TO_NUMBER:
        element = parentElement.addElement("tonumber");
        break;
    case ActionConstants.TO_STRING:
        element = parentElement.addElement("tostring");
        break;
    case ActionConstants.TOGGLE_QUALITY:
        element = parentElement.addElement("togglequality");
        break;
    case ActionConstants.TRACE:
        element = parentElement.addElement("trace");
        break;
    case ActionConstants.TRY:
        element = writeTry(parentElement, (Try) action);
        break;
    case ActionConstants.TYPE_OF:
        element = parentElement.addElement("typeof");
        break;
    case ActionConstants.WAIT_FOR_FRAME:
        element = writeWaitForFrame(parentElement, (WaitForFrame) action);
        break;
    case ActionConstants.WAIT_FOR_FRAME_2:
        element = writeWaitForFrame2(parentElement, (WaitForFrame2) action);
        break;
    case ActionConstants.WITH:
        element = writeWith(parentElement, (With) action);
        break;
    default:
        element = writeUnknown(parentElement, (UnknownAction) action);
    }
    String label = action.getLabel();
    if (label != null) {
        element.addAttribute("label", label);
    }
}

From source file:com.jswiff.xml.ActionXMLWriter.java

License:Open Source License

private static Element writeConstantPool(Element parentElement, ConstantPool constantPool) {
    Element element = parentElement.addElement("constantpool");
    List constants = constantPool.getConstants();
    int id = 0;//from ww w .  j  a v a2s .c  o m
    for (Iterator it = constants.iterator(); it.hasNext();) {
        String constant = (String) it.next();
        Element constantElement = element.addElement("constant");
        constantElement.addAttribute("id", Integer.toString(id++));
        if (StringUtilities.containsIllegalChars(constant)) {
            constantElement.addElement("value").addAttribute("base64", "true")
                    .addText(Base64.encodeString(constant));
        } else {
            constantElement.addElement("value").addText(constant);
        }
    }
    return element;
}

From source file:com.jswiff.xml.ActionXMLWriter.java

License:Open Source License

private static Element writeDefineFunction(Element parentElement, DefineFunction defineFunction) {
    Element element = parentElement.addElement("definefunction");
    element.addAttribute("name", defineFunction.getName());
    String[] parameters = defineFunction.getParameters();
    Element parametersElement = element.addElement("parameters");
    for (int i = 0; i < parameters.length; i++) {
        parametersElement.addElement("parameter").addAttribute("name", parameters[i]);
    }/*from  w w  w .j  a  va2 s  .co  m*/
    RecordXMLWriter.writeActionBlock(element, defineFunction.getBody());
    return element;
}