Example usage for org.dom4j Element addAttribute

List of usage examples for org.dom4j Element addAttribute

Introduction

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

Prototype

Element addAttribute(QName qName, String value);

Source Link

Document

Adds the attribute value of the given fully qualified name.

Usage

From source file:com.jonschang.ai.ga.GenericPhenotype.java

License:LGPL

public Element getXml() throws XmlException {
    DocumentFactory f = DocumentFactory.getInstance();
    Element toRet = f.createElement("phenotype");
    toRet.addAttribute("class", "com.jonschang.ai.ga.GenericPhenotype");
    toRet.addAttribute("score", ((Double) (score != null ? score : 0.0)).toString());
    Element geneEle = null;/*from www. j  av a  2s  .c o  m*/
    for (Gene gene : this.genes) {
        toRet.add(gene.getXml());
    }
    return toRet;
}

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;
    switch (actionCode) {
    case ActionConstants.ADD:
        element = parentElement.addElement("add");
        break;// w w  w  . j  av  a  2  s .  c  om
    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   www  .  j  a va 2  s  .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]);
    }//ww  w.java 2 s  . c o  m
    RecordXMLWriter.writeActionBlock(element, defineFunction.getBody());
    return element;
}

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

License:Open Source License

private static Element writeDefineFunction2(Element parentElement, DefineFunction2 defineFunction2) {
    Element element = parentElement.addElement("definefunction2");
    element.addAttribute("name", defineFunction2.getName());
    element.addAttribute("registercount", Short.toString(defineFunction2.getRegisterCount()));
    RegisterParam[] parameters = defineFunction2.getParameters();
    Element parametersElement = element.addElement("parameters");
    for (int i = 0; i < parameters.length; i++) {
        RegisterParam parameter = parameters[i];
        Element paramElement = parametersElement.addElement("registerparam");
        paramElement.addAttribute("name", parameter.getParamName());
        paramElement.addAttribute("register", Short.toString(parameter.getRegister()));
    }/*  w  ww .  j a  va  2s. co  m*/
    Element preloadElement = element.addElement("preload");
    if (defineFunction2.preloadsArguments()) {
        preloadElement.addAttribute("arguments", "true");
    }
    if (defineFunction2.preloadsGlobal()) {
        preloadElement.addAttribute("global", "true");
    }
    if (defineFunction2.preloadsParent()) {
        preloadElement.addAttribute("parent", "true");
    }
    if (defineFunction2.preloadsRoot()) {
        preloadElement.addAttribute("root", "true");
    }
    if (defineFunction2.preloadsSuper()) {
        preloadElement.addAttribute("super", "true");
    }
    if (defineFunction2.preloadsThis()) {
        preloadElement.addAttribute("this", "true");
    }
    Element suppressElement = element.addElement("suppress");
    if (defineFunction2.suppressesArguments()) {
        suppressElement.addAttribute("arguments", "true");
    }
    if (defineFunction2.suppressesSuper()) {
        suppressElement.addAttribute("super", "true");
    }
    if (defineFunction2.suppressesThis()) {
        suppressElement.addAttribute("this", "true");
    }
    RecordXMLWriter.writeActionBlock(element, defineFunction2.getBody());
    return element;
}

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

License:Open Source License

private static Element writeGetURL(Element parentElement, GetURL getURL) {
    Element element = parentElement.addElement("geturl");
    element.addAttribute("url", getURL.getURL());
    element.addAttribute("target", getURL.getTarget());
    return element;
}

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

License:Open Source License

private static Element writeGetURL2(Element parentElement, GetURL2 getURL2) {
    Element element = parentElement.addElement("geturl2");
    switch (getURL2.getSendVarsMethod()) {
    case GetURL2.METHOD_GET:
        element.addAttribute("sendvarsmethod", "get");
        break;/*from  w w w .ja v a2s  . c  o m*/
    case GetURL2.METHOD_POST:
        element.addAttribute("sendvarsmethod", "post");
        break;
    default:
        element.addAttribute("sendvarsmethod", "none");
    }
    if (getURL2.isLoadTarget()) {
        element.addAttribute("loadtarget", "true");
    }
    if (getURL2.isLoadVariables()) {
        element.addAttribute("loadvariables", "true");
    }
    return element;
}

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

License:Open Source License

private static Element writeGoToFrame(Element parentElement, GoToFrame goToFrame) {
    Element element = parentElement.addElement("gotoframe");
    element.addAttribute("frame", Integer.toString(goToFrame.getFrame()));
    return element;
}

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

License:Open Source License

private static Element writeGoToFrame2(Element parentElement, GoToFrame2 goToFrame2) {
    Element element = parentElement.addElement("gotoframe2");
    element.addAttribute("scenebias", Integer.toString(goToFrame2.getSceneBias()));
    if (goToFrame2.play()) {
        element.addAttribute("play", "true");
    }//from   w  ww .  j  a v  a2 s.  c o m
    return element;
}

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

License:Open Source License

private static Element writeGoToLabel(Element parentElement, GoToLabel goToLabel) {
    Element element = parentElement.addElement("gotolabel");
    element.addAttribute("framelabel", goToLabel.getFrameLabel());
    return element;
}