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:cc.warlock.rcp.application.WarlockPerspectiveLayout.java

License:Open Source License

public List<Element> getTopLevelElements() {
    Element windowLayout = DocumentHelper.createElement("window-layout");
    windowLayout.addAttribute("x", "" + bounds.x);
    windowLayout.addAttribute("y", "" + bounds.y);
    windowLayout.addAttribute("width", "" + bounds.width);
    windowLayout.addAttribute("height", "" + bounds.height);

    return Arrays.asList(new Element[] { windowLayout });
}

From source file:cc.warlock.rcp.configuration.GameViewConfiguration.java

License:Open Source License

public List<Element> getTopLevelElements() {
    ArrayList<Element> elements = new ArrayList<Element>();
    Element gameView = DocumentHelper.createElement("game-view");
    gameView.addAttribute("buffer", bufferLines + "");
    gameView.addAttribute("suppressPrompt", suppressPrompt + "");

    Element defaultColors = DocumentHelper.createElement("default-colors");
    gameView.add(defaultColors);/*from   www.j a  va2  s.c  om*/

    defaultColors.addAttribute("background", defaultBackground.toHexString());
    defaultColors.addAttribute("foreground", defaultForeground.toHexString());
    defaultColors.addAttribute("echo-background", defaultEchoBackground.toHexString());
    defaultColors.addAttribute("echo-foreground", defaultEchoForeground.toHexString());

    Element defaultFont = DocumentHelper.createElement("default-font");
    gameView.add(defaultFont);
    defaultFont.addAttribute("face", defaultFontFace);
    defaultFont.addAttribute("size", defaultFontSize + "");

    elements.add(gameView);
    return elements;
}

From source file:cc.warlock.rcp.stormfront.StormFrontGameViewConfiguration.java

License:Open Source License

public List<Element> getTopLevelElements() {
    ArrayList<Element> elements = new ArrayList<Element>();

    for (Map.Entry<String, String> entry : profileViewMappings.entrySet()) {
        Element profileView = DocumentHelper.createElement("profileView");
        profileView.addAttribute("viewId", entry.getKey());
        profileView.addAttribute("profileId", entry.getValue());
        elements.add(profileView);//  w ww  . j a  v a 2 s. com
    }

    return elements;
}

From source file:ch.epfl.codimsd.qep.QEPFactory.java

License:Open Source License

/**
 * Add an operator template to the QEP Document.
 * /*w  ww  . ja v a 2  s .  c  om*/
 * @param document dom4j document.
 * @param opNode opNode structure of the operator to build.
 * @param opID identifier of the operator.
 */
private static void createOperator(Document document, OpNode opNode, int opID) {

    Element root = document.getRootElement();
    Iterator ittRoot = root.elementIterator();
    Element qepElement = (Element) ittRoot.next();

    // create new operator xml template (attributes, name)
    Element newOp = qepElement.addElement("op:Operator").addAttribute("id", opID + "").addAttribute("prod",
            buildProducers(opNode));

    if (opNode.getType() != null)
        newOp.addAttribute("type", opNode.getType());

    Element newNameOp = newOp.addElement("Name");
    newNameOp.addText(opNode.getOpName());

    // create operator xml parameters
    if (opNode.getParams() != null) {
        if (opNode.getParams().length != 0) {
            Element newParameterList = newOp.addElement("ParameterList");
            for (int i = 0; i < opNode.getParams().length; i++) {
                Element newParam = newParameterList.addElement("Param");
                newParam.addText(opNode.getParams()[i]);
            }
        }
    }
}

From source file:ch.javasoft.xml.config.XmlConfig.java

License:BSD License

/**
 * Returns a copy of the underlying xml document, including main arguments 
 * if any have been specified. From the returned document, 
 *//*from www .j  a va  2s.  c o  m*/
public Document toXmlDocument() {
    final Document doc = (Document) mDocument.clone();
    doc.getRootElement().elements(XmlElement.application.getXmlName()).clear();
    final Element app = doc.getRootElement().addElement(XmlElement.application.getXmlName());
    app.addAttribute(XmlAttribute.name.getXmlName(), mAppName);
    for (String arg : mArgs) {
        final Element elArg = app.addElement(XmlElement.arg.getXmlName());
        elArg.addAttribute(XmlAttribute.value.getXmlName(), arg);
    }
    return doc;
}

From source file:ch.javasoft.xml.config.XmlConfig.java

License:BSD License

private static Document createDocument(Element configElement, String configName) {
    final Document doc = DocumentHelper.createDocument();
    final Element configList = DocumentHelper.createElement(XmlElement.config_list.getXmlName());
    configElement.addAttribute(XmlAttribute.name.getXmlName(), configName);
    configList.addAttribute(XmlAttribute.def.getXmlName(), configName);
    configList.add(configElement);/*from www .  j  a  v a  2  s  .  c  o m*/
    doc.setRootElement(configList);
    return doc;
}

From source file:client.ManageNets.java

License:Open Source License

private void buttonOpenActionPerformed(ActionEvent evt) {
    System.out.println("buttonOpen.actionPerformed, event=" + evt);

    int i1 = comboUser.getSelectedIndex();
    int i2 = comboNet.getSelectedIndex();
    int i3 = comboVersion.getSelectedIndex();

    String user = null;//w w w  . ja v  a  2  s . co m
    String name = null;
    String version = null;

    if (i1 != -1 && i2 != -1 && i3 != -1) {
        user = names[i1];
        name = nets[i1][i2];
        version = convVerToSave(versions[i1][i2][i3]);
    } else {
        JOptionPane.showMessageDialog(this, "Choose user, net and version.", "Information",
                JOptionPane.INFORMATION_MESSAGE);
        return;
    }

    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("open");
    root.addAttribute("user", user);
    root.addAttribute("name", name);
    root.addAttribute("version", version);

    Data data = new Data(MessageType.OPEN, null, null, doc);

    try {
        ClConf.server.send(data);
        data = ClConf.server.receive();
    } catch (BadConnect e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "Bad connection to server. Disconnection recommended.", "Error",
                JOptionPane.ERROR_MESSAGE);
        this.dispose();
    }

    if (data.getType() == MessageType.ERR) {
        JOptionPane.showMessageDialog(this, "Net wasn't transmitted.", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }

    //vytvorim novou sit v novem panelu
    //novy panel
    MyPanel jpanel = new MyPanel(frame);

    try {
        jpanel.fromDoc(data.getDoc());

    } catch (FalseXML e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "Net is badly formatted.", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    } catch (DocumentException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "Net is badly formatted.", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }

    jpanel.setBackground(NetConf.getColorBack());
    jpanel.setServername(name);
    //pridame tab do paneu
    pane.addTab(null, jpanel);
    //prepne aktivitu na vytvoreny tab
    pane.setSelectedIndex(pane.getTabCount() - 1);
    //nastavim headline
    pane.setTabComponentAt(pane.getSelectedIndex(), new MyPanelHeadline(name, pane));

    pane.repaint();
    this.dispose();
}

From source file:client.ManageNets.java

License:Open Source License

private void buttonDeleteActionPerformed(ActionEvent evt) {
    System.out.println("buttonDelete.actionPerformed, event=" + evt);

    int i1 = comboUser.getSelectedIndex();
    int i2 = comboNet.getSelectedIndex();
    int i3 = comboVersion.getSelectedIndex();

    String user = null;/* w w w .j  a  va  2 s. com*/
    String name = null;
    String version = null;

    if (i1 != -1 && i2 != -1 && i3 != -1) {
        user = names[i1];
        name = nets[i1][i2];
        version = convVerToSave(versions[i1][i2][i3]);
    } else {
        JOptionPane.showMessageDialog(this, "Choose user, net and version.", "Information",
                JOptionPane.INFORMATION_MESSAGE);
        return;
    }

    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("delete");
    root.addAttribute("user", user);
    root.addAttribute("name", name);
    root.addAttribute("version", version);

    Data data = new Data(MessageType.DELETE, null, null, doc);

    try {
        ClConf.server.send(data);
        data = ClConf.server.receive();
    } catch (BadConnect e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "Bad connection to server. Disconnection recommended.", "Error",
                JOptionPane.ERROR_MESSAGE);
        this.dispose();
    }

    if (data.getType() == MessageType.ERR) {
        JOptionPane.showMessageDialog(this, "Net wasn't deleted.", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }

    try {
        init();
    } catch (BadConnect e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "Bad connection to server. Disconnection recommended.", "Error",
                JOptionPane.ERROR_MESSAGE);
        this.dispose();
        return;
    }

    //zmenim uzivatele na toho co tam byl
    comboUser.setSelectedItem(user);
    int index = comboUser.getSelectedIndex();

    comboNet.setModel(new DefaultComboBoxModel(nets[index]));
    comboNet.setSelectedItem(name);

    int ind2 = comboNet.getSelectedIndex();
    try {
        comboVersion.setModel(new DefaultComboBoxModel(versions[index][ind2]));
    } catch (ArrayIndexOutOfBoundsException e) {
        comboVersion.setModel(new DefaultComboBoxModel(new String[] {}));
    }
    this.repaint();

}

From source file:cn.buk.api.service.CtripHotelServiceImpl.java

License:LGPL

private Element createRequestHeaderElement(Document document, String requestType) {
    Element returnElement = document.addElement("Request");
    Element element = returnElement.addElement("Header");
    element.addAttribute("AllianceID", this.allianceId);
    element.addAttribute("SID", this.sid);
    long timestamp = SignatureUtils.GetTimeStamp();
    String signature = null;/*from   w  ww . jav a2  s  .c  o m*/
    try {
        signature = SignatureUtils.CalculationSignature(timestamp + "", this.allianceId, this.secretKey,
                this.sid, requestType);
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
    element.addAttribute("TimeStamp", timestamp + "");
    element.addAttribute("Signature", signature);
    element.addAttribute("RequestType", requestType);

    return returnElement;
}

From source file:cn.itcreator.android.reader.util.XMLUtil.java

License:Open Source License

/**
 * save the list to a xml file//from w  ww  . j a va2s .  c  om
 * @param list the list u wanna save
 * @return
 */
public boolean saveToFile(List<BookMark> list) {
    boolean result = true;
    Element root = null;
    root = mDocument.getRootElement();
    if (null == root) {
        root = mDocument.addElement("bookmark");
    }
    for (BookMark bookMark : list) {
        Element mark = root.addElement("mark");
        mark.addAttribute("markName", bookMark.getMarkName());
        mark.addAttribute("currentOffset", "" + bookMark.getCurrentOffset());
    }
    OutputFormat format = OutputFormat.createPrettyPrint();
    /** Give the xml file encode */
    format.setEncoding(Constant.UTF8);
    try {
        XMLWriter writer = new XMLWriter(new FileOutputStream(mFilePath), format);
        writer.write(mDocument);
        writer.close();
    } catch (IOException e) {
        result = false;
    }
    return result;
}