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.bluexml.side.Framework.alfresco.dataGenerator.serialization.mapping.XMLForACPMappingHelper.java

License:Open Source License

/**
 * create xml's elements corresponding to native Alfresco's aspects of given node
 * @param type/*from  w ww.  j  a v  a 2s .c o  m*/
 * @param node
 */
public void createAspects(Element type, INode node) {
    Element aspects = type
            .addElement(services.createTag(NamespaceService.REPOSITORY_VIEW_PREFIX, Constants.ASPECTS));
    createNativeAspects(aspects, node);
}

From source file:com.bluexml.side.Framework.alfresco.dataGenerator.serialization.mapping.XMLForACPMappingHelper.java

License:Open Source License

/**
 * create and fill xml's elements corresponding to all properties of given generated node
 * @param type/*  w ww . j a v a  2  s . c o  m*/
 * @param node
 */
public void createProperties(Element type, INode node) {
    Element properties = type
            .addElement(services.createTag(NamespaceService.REPOSITORY_VIEW_PREFIX, Constants.PROPERTIES));

    Map<PropertyDefinition, Object> dataSIDEProperties = ((AlfrescoNode) node).getDatasProperties();
    createAndFillSIDEProperties(properties, dataSIDEProperties);

    Map<QNamePattern, Object> dataNativeProperties = ((NativeAlfrescoNode) ((AlfrescoNode) node)
            .getNativeNode()).getNativeDatasProperties();
    createAndFillNativeProperties(properties, dataNativeProperties);

    Map<AspectDefinition, Map<PropertyDefinition, Object>> dataSIDEAspects = ((AlfrescoNode) node)
            .getDataAspects();
    Set<AspectDefinition> sideAspects = dataSIDEAspects.keySet();
    for (AspectDefinition sideAspect : sideAspects) {
        createAndFillSIDEProperties(properties, dataSIDEAspects.get(sideAspect));
    }
}

From source file:com.bsoft.baseframe.baseframe_utils.beanUtils.CreateXMLFile.java

License:Open Source License

/**
 * xml??/*from   w  w w.  j av a 2s  .c  o m*/
 * @return ??
 */
public boolean createXMLFile() {
    String clsName = FileUtils.getClassName(tbName);
    String fileName = path + clsName + ".xml";
    String beanName = beanPkg + "." + clsName;

    List<GenaBean> list = GenaBeanDBUtils.getFields(tbName);
    if (list.size() == 0) {
        return false;
    }
    StringBuffer fields = new StringBuffer();
    StringBuffer values = new StringBuffer();
    GenaBean gb = null;
    String fn = null;
    for (int i = 0; i < list.size(); i++) {
        gb = list.get(i);
        fn = gb.getColumnName();
        fields.append(fn);
        if ("delflag".equals(fn)) {
            values.append("'0'");
        } else if ("ctb1".equals(fn)) {
            values.append("getdate()");
        } else {
            values.append("#").append(fn).append("#");
        }
        if (i != list.size() - 1) {
            fields.append(", ");
            values.append(", ");
        }
    }
    System.out.println(fields.toString());
    System.out.println(values.toString());

    //Document
    Document document = DocumentHelper.createDocument();

    //
    document.addDocType("sqlMap", "-//ibatis.apache.org//DTD SQL Map 2.0//EN",
            "http://ibatis.apache.org/dtd/sql-map-2.dtd");

    // document
    Element rootElement = document.addElement("sqlMap");

    //??
    rootElement.addAttribute("namespace", clsName.toUpperCase());

    //insert
    Element insertNode = rootElement.addElement("insert");
    insertNode.addAttribute("id", "add" + clsName);
    insertNode.addAttribute("parameterClass", beanName);
    insertNode.setText("insert into " + tbName + "(" + fields + ") values (" + values + ")");

    //?
    Element removeNode = rootElement.addElement("delete");
    removeNode.addAttribute("id", "remove" + clsName);
    removeNode.addAttribute("parameterClass", beanName);
    removeNode.setText("delete from " + tbName + " where id = #id#");

    //
    Element deleteNode = rootElement.addElement("update");
    deleteNode.addAttribute("id", "del" + clsName);
    deleteNode.addAttribute("parameterClass", beanName);
    deleteNode.setText("update " + tbName + " set delflag=#delflag# where id = #id#");

    //selectOne
    Element selectOneNode = rootElement.addElement("select");
    selectOneNode.addAttribute("id", "getOne" + clsName);
    selectOneNode.addAttribute("parameterClass", beanName);
    selectOneNode.addAttribute("resultClass", beanName);
    selectOneNode.setText("select *  from " + tbName + " where id = #id# ");

    //select
    Element selectNode = rootElement.addElement("select");
    selectNode.addAttribute("id", "queryCount");
    selectNode.addAttribute("resultClass", "int");
    selectNode.setText("select count(*) as countnum from " + tbName + " where 1=1");

    //select
    Element selectNode2 = rootElement.addElement("select");
    selectNode2.addAttribute("id", "list" + clsName);
    selectNode2.addAttribute("resultClass", beanName);
    selectNode2.addAttribute("parameterClass", "java.util.Map");
    selectNode2.setText("select * from (select top  $endNum$ row_number()over(order by TT.id) as RN,* from"
            + "(SELECT * FROM " + tbName + " where 1=1) as TT)as H where RN > #startNum#");

    //update
    Element updateNode = rootElement.addElement("update");
    updateNode.addAttribute("id", "upSap" + clsName);
    updateNode.addAttribute("parameterClass", beanName);
    updateNode.setText("UPDATE " + tbName + " ");
    Element erElement = updateNode.addElement("dynamic");
    erElement.addAttribute("prepend", "set");
    for (int i = 0; i < list.size(); i++) {
        gb = list.get(i);
        fn = gb.getColumnName();
        if (!"id".equals(fn)) {
            Element saElement = erElement.addElement("isNotNull");
            saElement.addAttribute("property", fn);
            saElement.addAttribute("removeFirstPrepend", "true");
            saElement.addAttribute("prepend", ",");
            saElement.setText(fn + "=#" + fn + "#");
        }
    }
    updateNode.addText(" where ");
    Element terElement = updateNode.addElement("isNotNull");
    terElement.addAttribute("property", "id");
    terElement.setText(" id = #id# ");

    //update
    Element updateSimpleNode = rootElement.addElement("update");
    updateSimpleNode.addAttribute("id", "update" + clsName);
    updateSimpleNode.addAttribute("parameterClass", beanName);

    StringBuffer sb = new StringBuffer();
    sb.append("update ").append(tbName).append(" set ");

    for (int i = 0; i < list.size(); i++) {
        gb = list.get(i);
        fn = gb.getColumnName();
        if (!"id".equals(fn)) {
            if ("ctb3".equals(fn)) {
                sb.append(fn).append("=").append("getdate()");
            } else {
                sb.append(fn).append("=#").append(fn).append("#");
            }
            if (i != list.size() - 1) {
                sb.append(", ");
            }

        }
    }
    sb.append(" where id = #id# ");
    updateSimpleNode.setText(sb.toString());
    return FileUtils.wrieteXML2Doc(document, new File(fileName));
}

From source file:com.buddycloud.channeldirectory.search.handler.common.ChannelQueryHandler.java

License:Apache License

protected IQ createIQResponse(IQ iq, List<ChannelData> allContent, RSM rsm) {
    IQ result = IQ.createResultIQ(iq);/*  w ww.  j a  v a  2 s. c om*/

    Element queryEl = iq.getElement().element("query");
    Set<String> options = FeatureUtils.parseOptions(queryEl);

    Element queryElement = result.getElement().addElement("query", getNamespace());

    for (ChannelData channelObject : allContent) {
        Element itemElement = queryElement.addElement("item");

        FeatureUtils.addAttribute(options, itemElement, "jid", channelObject.getId());
        FeatureUtils.addAttribute(options, itemElement, "type", channelObject.getType());
        FeatureUtils.addAttribute(options, itemElement, "description", channelObject.getDescription());

        if (channelObject.getCreationDate() != null) {
            FeatureUtils.addAttribute(options, itemElement, "created",
                    DATE_FORMAT.format(channelObject.getCreationDate()));
        }

        FeatureUtils.addElement(options, itemElement, "title", channelObject.getTitle());
        FeatureUtils.addElement(options, itemElement, "channel_type", channelObject.getChannelType());
        FeatureUtils.addElement(options, itemElement, "default_affiliation",
                channelObject.getDefaultAffiliation());

        if (channelObject.getGeolocation() != null) {
            Element geoElement = FeatureUtils.addNamespaceElement(options, itemElement, "geoloc",
                    Geolocation.NAMESPACE);
            GeolocationUtils.appendGeoLocation(geoElement, channelObject.getGeolocation());
        }

    }

    RSMUtils.appendRSMElement(queryElement, rsm);

    return result;
}

From source file:com.buddycloud.channeldirectory.search.handler.common.PostQueryHandler.java

License:Apache License

protected IQ createIQResponse(IQ iq, List<PostData> allContent, RSM rsm) {
    IQ result = IQ.createResultIQ(iq);/*  w ww.  j  av  a2s .c  o  m*/

    Element queryEl = iq.getElement().element("query");

    Set<String> options = FeatureUtils.parseOptions(queryEl);

    Element queryElement = result.getElement().addElement("query", getNamespace());

    for (PostData postObject : allContent) {
        Element itemElement = queryElement.addElement("item");

        FeatureUtils.addAttribute(options, itemElement, "id", postObject.getId());
        FeatureUtils.addAttribute(options, itemElement, "type", postObject.getType());

        Element entryElement = itemElement.addElement("entry", ATOM_NAMESPACE);

        FeatureUtils.addElement(options, entryElement, "author", postObject.getAuthor());

        Element contentElement = FeatureUtils.addElement(options, entryElement, "content",
                postObject.getContent());
        if (contentElement != null) {
            contentElement.addAttribute("type", "text");
        }

        if (postObject.getUpdated() != null) {
            FeatureUtils.addElement(options, entryElement, "updated",
                    DATE_FORMAT.format(postObject.getUpdated()));
        }

        if (postObject.getPublished() != null) {
            FeatureUtils.addElement(options, entryElement, "published",
                    DATE_FORMAT.format(postObject.getPublished()));
        }

        FeatureUtils.addElement(options, entryElement, "parent_fullid", postObject.getParentFullId());
        FeatureUtils.addElement(options, entryElement, "parent_simpleid", postObject.getParentSimpleId());

        Element geoElement = FeatureUtils.addNamespaceElement(options, entryElement, "geoloc",
                Geolocation.NAMESPACE);
        GeolocationUtils.appendGeoLocation(geoElement, postObject.getGeolocation());

        Element inReplyEl = FeatureUtils.addNamespaceElement(options, entryElement, "in-reply-to",
                THREAD_NAMESPACE);
        if (inReplyEl != null) {
            inReplyEl.addAttribute("ref", postObject.getInReplyTo());
        }
    }

    RSMUtils.appendRSMElement(queryElement, rsm);

    return result;
}

From source file:com.buddycloud.channeldirectory.search.utils.FeatureUtils.java

License:Apache License

/**
 * Adds an element to the parent element and set its text
 * if the corresponding feature is contained in the options map
 * or this map is empty.//ww  w  . j a  v a2 s.c  om
 * 
 * @param options
 * @param parentElement
 * @param key
 * @param value
 * @return
 */
public static Element addElement(Set<String> options, Element parentElement, String key, String value) {
    if (options.contains(key) || options.isEmpty()) {
        Element el = parentElement.addElement(key);
        if (value != null) {
            el.setText(value);
        }
        return el;
    }
    return null;
}

From source file:com.buddycloud.channeldirectory.search.utils.GeolocationUtils.java

License:Apache License

public static void appendGeoLocation(Element geoElement, Geolocation geoLocation) {

    if (geoElement == null || geoLocation == null) {
        return;/*  w  w w.j a v a  2 s  . co m*/
    }

    if (geoLocation.getLat() != null) {
        geoElement.addElement("lat").setText(geoLocation.getLat().toString());
    }

    if (geoLocation.getLng() != null) {
        geoElement.addElement("lon").setText(geoLocation.getLng().toString());
    }

    if (geoLocation.getText() != null) {
        geoElement.addElement("text").setText(geoLocation.getText());
    }
}

From source file:com.buddycloud.friendfinder.handler.MatchContactFromContactProviderHandler.java

License:Apache License

private IQ createResponse(IQ iq, List<MatchedUser> matchedUsers) {
    IQ result = IQ.createResultIQ(iq);/*  www . ja va  2s.c o  m*/
    Element queryElement = result.getElement().addElement("query", getNamespace());
    for (MatchedUser user : matchedUsers) {
        Element itemEl = queryElement.addElement("item");
        itemEl.addAttribute("jid", user.getJid());
        itemEl.addAttribute("matched-hash", user.getHash());
    }
    return result;
}

From source file:com.buddycloud.friendfinder.handler.MatchContactHandler.java

License:Apache License

/**
 * @param iq//from   ww  w  .j  av a  2s.  co m
 * @param matchedUsers
 * @return
 */
private IQ createResponse(IQ iq, List<MatchedUser> matchedUsers) {
    IQ result = IQ.createResultIQ(iq);
    Element queryElement = result.getElement().addElement("query", getNamespace());
    for (MatchedUser user : matchedUsers) {
        Element itemEl = queryElement.addElement("item");
        itemEl.addAttribute("jid", user.getJid());
        itemEl.addAttribute("matched-hash", user.getHash());
    }
    return result;
}

From source file:com.buddycloud.mediaserver.xmpp.MediaServerComponent.java

License:Apache License

private void addField(Element xEl, String var, String type, String value) {
    Element fieldEl = xEl.addElement("field");
    fieldEl.addAttribute("var", var);
    fieldEl.addAttribute("type", type);
    fieldEl.addElement("value").setText(value);
}