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.rayo.core.xml.providers.ColibriProvider.java

License:Apache License

private void createLeaveBridgeEvent(LeaveBridgeEvent unjoined, Document document) {
    Element root = document.addElement(new QName("unjoined", NAMESPACE));
    root.addAttribute("mixer-name", unjoined.getMixer());
    root.addAttribute("nickname", unjoined.getNickname());
    root.addAttribute("participant", unjoined.getParticipant().toString());
}

From source file:com.rayo.core.xml.providers.ColibriProvider.java

License:Apache License

private void createInviteAcceptedEvent(InviteAcceptedEvent accepted, Document document) {
    Element root = document.addElement(new QName("inviteaccepted", NAMESPACE));
    root.addAttribute("callid", accepted.getCallId());
}

From source file:com.rayo.core.xml.providers.ColibriProvider.java

License:Apache License

private void createInviteCompletedEvent(InviteCompletedEvent completed, Document document) {
    Element root = document.addElement(new QName("invitecompleted", NAMESPACE));
    root.addAttribute("callid", completed.getCallId());
}

From source file:com.rayo.core.xml.providers.HandsetProvider.java

License:Apache License

private void createOffHookCommand(OffHookCommand command, Document document) throws Exception {
    Handset handset = command.getHandset();

    Element root = document.addElement(new QName("offhook", NAMESPACE));
    root.addAttribute("cryptoSuite", handset.cryptoSuite);
    root.addAttribute("localCrypto", handset.localCrypto);
    root.addAttribute("remoteCrypto", handset.cryptoSuite);
    root.addAttribute("codec", handset.codec);
    root.addAttribute("stereo", handset.stereo);
    root.addAttribute("mixer", handset.mixer);
}

From source file:com.safi.workshop.sqlexplorer.dbproduct.AliasManager.java

License:Open Source License

/**
 * Upgrades a v3 definition (java beans style) to v3.5.0beta2 and onwards
 * //w  w w  .  j  a v a 2 s  .  com
 * @param beans
 * @return
 */
protected Element convertToV350(Element beans) {
    Element result = new DefaultElement(Alias.ALIASES);
    for (Object o : beans.elements("Bean")) {
        Element bean = (Element) o;
        Element alias = result.addElement(Alias.ALIAS);
        alias.addAttribute(Alias.AUTO_LOGON,
                Boolean.toString(getBoolean(bean.elementText("autoLogon"), false)));
        alias.addAttribute(Alias.CONNECT_AT_STARTUP,
                Boolean.toString(getBoolean(bean.elementText("connectAtStartup"), false)));
        alias.addAttribute(Alias.DRIVER_ID, bean.element("driverIdentifier").elementText("string"));
        alias.addElement(Alias.NAME).setText(bean.elementText("name"));
        Element userElem = alias.addElement(Alias.USERS).addElement(User.USER);
        userElem.addElement(User.USER_NAME).setText(bean.elementText("userName"));
        userElem.addElement(User.PASSWORD).setText(bean.elementText("password"));
        alias.addElement(Alias.URL).setText(bean.elementText("url"));
        alias.addElement(Alias.FOLDER_FILTER_EXPRESSION).setText(bean.elementText("folderFilterExpression"));
        alias.addElement(Alias.NAME_FILTER_EXPRESSION).setText(bean.elementText("nameFilterExpression"));
        alias.addElement(Alias.SCHEMA_FILTER_EXPRESSION).setText(bean.elementText("schemaFilterExpression"));
    }

    return result;
}

From source file:com.safi.workshop.sqlexplorer.dbproduct.DriverManager.java

License:Open Source License

/**
 * Converts from the old v3 format (which is a JavaBean encoding)
 * /*from  w  w w .  j a  v  a2  s. c om*/
 * @param root
 * @return
 */
protected Element convertFromV3(Element root) {
    Element result = new DefaultElement(DRIVERS);
    for (Object o : root.elements("Bean")) {
        Element elem = (Element) o;
        String str;
        Element driver = result.addElement(DRIVER);

        try {
            str = elem.element("identifier").elementText("string");
            driver.addAttribute(ID, str);

            str = elem.elementText("driverClass");
            if (str != null)
                driver.addElement(DRIVER_CLASS).setText(str);

            str = elem.elementText("name");
            driver.addElement(NAME).setText(str);

            str = elem.elementText("url");
            driver.addElement(URL).setText(str);

            Element jars = driver.addElement(JARS);
            Element jarFileNames = elem.element("jarFileNames");
            for (Object o2 : jarFileNames.elements("Bean")) {
                Element jarBeanElem = (Element) o2;
                str = jarBeanElem.elementText("string");
                if (str != null && str.trim().length() > 0)
                    jars.addElement(JAR).setText(str);
            }
        } catch (IllegalArgumentException e) {
            SQLExplorerPlugin.error("Error loading v3 driver " + driver.attributeValue(ID), e);
            throw e;
        }
    }

    return result;
}

From source file:com.sammyun.util.XmlHelper.java

License:Open Source License

/**
 * Dto??XML?(?)// w  w w .  j  ava  2  s .c o  m
 * 
 * @param pDto Dto
 * @param pRootNodeName ??
 * @param pFirstNodeName ??
 * @return string XML?
 */
public static final String parseDto2Xml(Dto pDto, String pRootNodeName, String pFirstNodeName) {
    if (EduUtil.isEmpty(pDto)) {
        logger.warn("DTO,");
        return "<root />";
    }
    Document document = DocumentHelper.createDocument();
    // 
    document.addElement(pRootNodeName);
    Element root = document.getRootElement();
    root.addElement(pFirstNodeName);
    Element firstEl = (Element) document.selectSingleNode("/" + pRootNodeName + "/" + pFirstNodeName);
    Iterator keyIterator = pDto.keySet().iterator();
    while (keyIterator.hasNext()) {
        String key = (String) keyIterator.next();
        String value = pDto.getAsString(key);
        firstEl.addAttribute(key, value);
    }
    // XML?
    String outXml = document.asXML().substring(39);
    return outXml;
}

From source file:com.sammyun.util.XmlHelper.java

License:Open Source License

/**
 * List???XML?(?)/*from w w  w .jav  a  2  s. co m*/
 * 
 * @param pList List?(List?Dto?VO?Domain)
 * @param pRootNodeName ??
 * @param pFirstNodeName ??
 * @return string XML?
 */
public static final String parseList2Xml(List pList, String pRootNodeName, String pFirstNodeName) {
    Document document = DocumentHelper.createDocument();
    Element elRoot = document.addElement(pRootNodeName);
    for (int i = 0; i < pList.size(); i++) {
        Dto dto = (Dto) pList.get(i);
        Element elRow = elRoot.addElement(pFirstNodeName);
        Iterator it = dto.entrySet().iterator();
        while (it.hasNext()) {
            Dto.Entry entry = (Dto.Entry) it.next();
            elRow.addAttribute((String) entry.getKey(), String.valueOf(entry.getValue()));
        }
    }
    String outXml = document.asXML().substring(39);
    return outXml;
}

From source file:com.sap.data.db.dao.StructureUtil.java

public void addStructure(String entity, String structure)
        throws DocumentException, FileNotFoundException, SAXException, IOException, NotFoundException {
    synchronized (lockhu) {
        if (entity != null && !entity.trim().isEmpty()) {
            Document document = this.getDocument(PropertyUtil.getHbDtoXml());
            Element rootElement = document.getRootElement();
            rootElement.addAttribute("package", PropertyUtil.getHbPjPkgn());
            String comment = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            rootElement.addComment(comment + " " + entity);
            this.addStructure(rootElement.addElement("class"), entity, structure);
            String classpath = StructureUtil.class.getResource("/").getPath() + PropertyUtil.getHbPjResource();
            this.save(document, classpath + entity + ".dto.xml");
        }//from  w w w.java 2s .c o  m
    }
}

From source file:com.sap.data.db.dao.StructureUtil.java

private Element addStructure(Element element, String entityName, String structure) throws NotFoundException {
    List<BapiDD03LPojo> list = new BapiDD03LDao().selectTabFields(structure);
    if (list.size() > 0) {
        String type = "java.lang.String";
        element.addAttribute("entity-name", entityName);
        element.addAttribute("name", entityName);
        element.addAttribute("table", entityName);
        Element idElement = element.addElement("composite-id");
        idElement.addAttribute("name", "DId");
        idElement.addAttribute("class", entityName + "Id");
        if (!entityName.startsWith("E0015")) {
            Vector<FieldUtil> fieldUtils = ThreadLocalUtil.getFieldType();
            for (FieldUtil fieldUtil : fieldUtils) {
                if ("key".equals(fieldUtil.getFieldType())) {
                    this.addElement(idElement, "key-property", type, fieldUtil.getFieldName(),
                            fieldUtil.getFieldLeng());
                } else if ("field".equals(fieldUtil.getFieldType())) {
                    this.addElement(element, "property", type, fieldUtil.getFieldName(),
                            fieldUtil.getFieldLeng());
                }//from  w  w  w  .  j a v  a  2 s .c o  m
            }
        }

        for (int i = 0; i < list.size(); i++) {
            BapiDD03LPojo pojo = list.get(i);
            final String fieldName = pojo.getId().getFIELDNAME().toUpperCase();
            if (fieldName.startsWith(".") || (null != pojo.getDd03ldm()
                    && "X".equalsIgnoreCase(pojo.getDd03ldm().getDM_EXCLUDE_FLAG()))) {
                continue;
            }
            final String fieldLength = this.getFieldLength(pojo.getLENG());
            if ("X".equalsIgnoreCase(pojo.getKEYFLAG())
                    || (null != pojo.getDd03ldm() && "X".equalsIgnoreCase(pojo.getDd03ldm().getDM_KEYFLAG()))) {
                this.addElement(idElement, "key-property", type, fieldName, fieldLength);
            } else {
                this.addElement(element, "property", type, fieldName, fieldLength);
            }
        }
    }
    return element;
}