Example usage for org.dom4j DocumentHelper createElement

List of usage examples for org.dom4j DocumentHelper createElement

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createElement.

Prototype

public static Element createElement(String name) 

Source Link

Usage

From source file:org.frogx.service.core.iq.IQSearchHandler.java

License:Open Source License

/**
 * Creates a Jabber Search form and returns the XML query element.
 * //from w w w .  j a  va 2  s .  com
 * @return A search element with an empty form.
 */
private Element getSearchForm() {
    Element element = DocumentHelper.createElement(QName.get("query", "jabber:iq:search"));
    DataForm searchForm = new DataForm(DataForm.Type.form);
    Map<String, MultiUserGame> games = service.getSupportedGames();

    searchForm.setTitle(locale.getLocalizedString("mug.search.form.title"));
    searchForm.addInstruction(locale.getLocalizedString("mug.search.form.instruction"));

    FormField field = searchForm.addField();
    field.setVariable("FORM_TYPE");
    field.setType(FormField.Type.hidden);
    field.addValue("jabber:iq:search");

    field = searchForm.addField();
    field.setVariable(nameField);
    field.setType(FormField.Type.text_single);
    field.setLabel(locale.getLocalizedString("mug.search.form.name"));
    field.setRequired(false);

    field = searchForm.addField();
    field.setVariable(exactNameField);
    field.setType(FormField.Type.boolean_type);
    field.setLabel(locale.getLocalizedString("mug.search.form.exact_name"));
    field.setRequired(false);

    field = searchForm.addField();
    field.setVariable(savedRoomsField);
    field.setType(FormField.Type.boolean_type);
    field.setLabel(locale.getLocalizedString("mug.search.form.saved"));
    field.setRequired(false);

    field = searchForm.addField();
    field.setVariable(rolesField);
    field.setType(FormField.Type.list_single);
    field.setLabel(locale.getLocalizedString("mug.search.form.min_roles"));
    field.setRequired(false);
    for (int i = 0; i <= 15; i++) {
        field.addOption(Integer.toString(i), Integer.toString(i));
    }
    field.addValue("0");

    field = searchForm.addField();
    field.setVariable(occupantsField);
    field.setType(FormField.Type.list_single);
    field.setLabel(locale.getLocalizedString("mug.search.form.max_occupants"));
    field.setRequired(false);
    for (int i = 5; i <= 40; i = i + 5) {
        field.addOption(Integer.toString(i), Integer.toString(i));
    }
    field.addValue("20");

    if (games != null && !games.isEmpty()) {
        Collection<String> categories = service.getGameCategories();
        field = searchForm.addField();
        field.setVariable(categoryField);
        field.setType(FormField.Type.list_single);
        field.setLabel(locale.getLocalizedString("mug.search.form.category"));
        field.setRequired(false);
        if (categories.size() > 1) {
            field.addOption("any", "any");
            field.addValue("any");
        }
        for (String category : categories) {
            field.addOption(category, category);
        }

        field = searchForm.addField();
        field.setVariable(gameField);
        field.setType(FormField.Type.list_multi);
        field.setLabel(locale.getLocalizedString("mug.search.form.games"));
        field.setRequired(false);
        for (MultiUserGame game : games.values()) {
            field.addOption(game.getDescription(), game.getNamespace());
        }
    }

    element.add(searchForm.getElement());
    return element;
}

From source file:org.hightides.annotations.processor.SpringConfigProcessor.java

License:Apache License

/**
 * Adds controller bean and url mapping to spring config
 * @param params// w w  w. ja va 2s.  c  om
 */
private void addControllerConfiguration(Map<String, Object> params) {
    // Add controller bean
    //      <!-- Template Controller -->
    //      <bean id="templateController" class="com.ideyatech.veeui.controller.TemplateController" autowire="byName">
    //         <property name="service" ref="templateService"></property>
    //         <property name="commandName" value="template" />
    //         <property name="commandClass" value="com.ideyatech.veeui.bean.Template" />
    //         <property name="formView" value="template/template-form" />
    //         <property name="searchView" value="template/template-list" />
    //         <property name="refreshView" value="template/template-refresh" />
    //         <property name="pageSize" value="${search.page.size}" />
    //         <property name="numLinks" value="${search.links.displayed}" />
    //      </bean>
    String xmlFilename = (new File(".")).getAbsolutePath() + contextPath + controllerContextFile;
    Element bean = DocumentHelper.createElement("bean");
    bean.addAttribute("id", params.get("modelName") + "Controller");
    bean.addAttribute("class", params.get("package") + "." + params.get("className") + "Controller");
    bean.addAttribute("autowire", "byName");
    addPropertyByRef(bean, "service", params.get("modelName") + "Service");
    if (BaseParamReader.isValidation()) {
        addPropertyByRef(bean, "validator", params.get("modelName") + "Validator");
    }
    addPropertyByValue(bean, "commandName", params.get("modelName") + "");
    addPropertyByValue(bean, "commandClass", params.get("modelPackage") + "." + params.get("className"));
    addPropertyByValue(bean, "formView", params.get("jspFolder") + "/" + params.get("modelName") + "-form");
    addPropertyByValue(bean, "searchView", params.get("jspFolder") + "/" + params.get("modelName") + "-list");
    if (params.get("pageType") == PageType.PARENT) {
        addPropertyByValue(bean, "refreshView", "redirect:" + params.get("modelName") + ".jspx");
    } else {
        addPropertyByValue(bean, "refreshView",
                params.get("jspFolder") + "/" + params.get("modelName") + "-refresh");
    }
    addPropertyByValue(bean, "pageSize", "${search.page.size}");
    addPropertyByValue(bean, "numLinks", "${search.links.displayed}");
    Element ret = SpringXMLUtil.addBean(xmlFilename, bean, params.get("syncMode").toString());
    if (ret != null && params.get("pageType") != PageType.CHILD) {
        // if URL mapping is not yet present and page is not a CHILD
        // Then add URL mapping
        // <prop key="/template.jspx">templateController</prop>
        Element urlMap = DocumentHelper.createElement("prop");
        urlMap.addAttribute("key", params.get("pageName") + "");
        urlMap.addText(params.get("modelName") + "Controller");
        // no need to backup because backup is already done by addBean earlier
        SpringXMLUtil.addURLMapProperty(xmlFilename, urlMap, false);
    }
}

From source file:org.hightides.annotations.processor.SpringConfigProcessor.java

License:Apache License

/**
 * Adds service bean to spring config/*from  w  w  w .  java2s . com*/
 * @param params
 */
private void addServiceConfiguration(Map<String, Object> params) {
    // Add service bean
    //   <bean id="templateService" class="com.ideyatech.veeui.service.impl.TemplateServiceImpl"
    //      autowire="byName">
    //      <property name="dao" ref="templateDAO" />
    //   </bean>
    String xmlFilename = (new File(".")).getAbsolutePath() + contextPath + serviceContextFile;
    Element bean = DocumentHelper.createElement("bean");
    bean.addAttribute("id", params.get("modelName") + "Service");
    bean.addAttribute("class", params.get("package") + "." + params.get("className") + "ServiceImpl");
    bean.addAttribute("autowire", "byName");
    addPropertyByRef(bean, "dao", params.get("modelName") + "DAO");
    SpringXMLUtil.addBean(xmlFilename, bean, params.get("syncMode").toString());
}

From source file:org.hightides.annotations.processor.SpringConfigProcessor.java

License:Apache License

/**
 * Adds dao bean to spring config/*from  w  w  w.  j a va  2 s .co  m*/
 * @param params
 */
private void addDaoConfiguration(Map<String, Object> params) {
    //      <bean id="templateDAO" class="com.ideyatech.veeui.dao.impl.TemplateJpaImpl"
    //         parent="baseDAO" autowire="byName" />      
    String xmlFilename = (new File(".")).getAbsolutePath() + contextPath + daoContextFile;
    Element bean = DocumentHelper.createElement("bean");
    bean.addAttribute("id", params.get("modelName") + "DAO");
    bean.addAttribute("class", params.get("package") + "." + params.get("className") + "DAOJpaImpl");
    bean.addAttribute("autowire", "byName");
    bean.addAttribute("parent", "baseDAO");
    SpringXMLUtil.addBean(xmlFilename, bean, params.get("syncMode").toString());
}

From source file:org.hightides.annotations.processor.SpringConfigProcessor.java

License:Apache License

/**
 * Adds validator bean to spring config//from   w  ww. jav a 2s . co  m
 * @param params
 */
protected void addValidatorConfiguration(Map<String, Object> params) {
    //      <bean id="templateValidator" class="com.ideyatech.veeui.validator.TemplateValidator"/>      
    String xmlFilename = (new File(".")).getAbsolutePath() + contextPath + controllerContextFile;
    Element bean = DocumentHelper.createElement("bean");
    bean.addAttribute("id", params.get("modelName") + "Validator");
    bean.addAttribute("class", params.get("package") + "." + params.get("className") + "Validator");
    SpringXMLUtil.addBean(xmlFilename, bean, params.get("syncMode").toString());
}

From source file:org.infoglue.cms.applications.common.actions.SimpleXmlServiceAction.java

License:Open Source License

public String doContentTypeDefinitions() throws Exception {
    List contentTypeDefinitions = getContentTypeDefinitions();
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("definitions");
    TransactionHistoryController transactionHistoryController = TransactionHistoryController.getController();

    for (Iterator i = contentTypeDefinitions.iterator(); i.hasNext();) {
        ContentTypeDefinitionVO vo = (ContentTypeDefinitionVO) i.next();
        if (vo.getType().compareTo(ContentTypeDefinitionVO.CONTENT) == 0) {
            TransactionHistoryVO transactionHistoryVO = transactionHistoryController
                    .getLatestTransactionHistoryVOForEntity(ContentTypeDefinitionImpl.class,
                            vo.getContentTypeDefinitionId());

            Element definition = DocumentHelper.createElement("definition");
            definition.addAttribute("id", "" + vo.getContentTypeDefinitionId())
                    .addAttribute("type", "" + vo.getType()).addAttribute("name", vo.getName());

            if (transactionHistoryVO != null)
                definition.addAttribute("mod", formatDate(transactionHistoryVO.getTransactionDateTime()));

            Element schemaValue = definition.addElement("schemaValue");
            schemaValue.addCDATA(vo.getSchemaValue());
            root.add(definition);//w  ww.  j  a va  2s  .  c  om
        }
    }

    return out(getFormattedDocument(doc));
}

From source file:org.infoglue.cms.applications.contenttool.actions.ContentTreeXMLAction.java

License:Open Source License

public Element getContentVersionElement(ContentVersionVO vo)
        throws SystemException, Bug, UnsupportedEncodingException {
    Element element = DocumentHelper.createElement("contentVersion");
    Element head = DocumentHelper.createElement("head");
    Element value = DocumentHelper.createElement("value");

    head.addAttribute("id", "" + vo.getContentVersionId());
    head.addAttribute("languageId", "" + vo.getLanguageId());
    head.addAttribute("languageName", vo.getLanguageName());
    head.addAttribute("isActive", "" + vo.getIsActive());

    TransactionHistoryController transactionHistoryController = TransactionHistoryController.getController();
    TransactionHistoryVO transactionHistoryVO = transactionHistoryController
            .getLatestTransactionHistoryVOForEntity(ContentVersionImpl.class, vo.getContentVersionId());
    if (transactionHistoryVO != null)
        head.addAttribute("mod", formatDate(transactionHistoryVO.getTransactionDateTime()));
    // head.addAttribute("mod", formatDate(vo.getModifiedDateTime()));
    value.addCDATA(URLEncoder.encode(vo.getVersionValue(), "UTF-8"));
    element.add(head);//from  ww w  .j av a  2s  .co m
    element.add(value);
    return element;
}

From source file:org.infoglue.cms.applications.contenttool.actions.ContentTreeXMLAction.java

License:Open Source License

public String doContentTypeDefinitions() throws Exception {
    List contentTypeDefinitions = getContentTypeDefinitions();
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("definitions");
    TransactionHistoryController transactionHistoryController = TransactionHistoryController.getController();

    for (Iterator i = contentTypeDefinitions.iterator(); i.hasNext();) {
        ContentTypeDefinitionVO vo = (ContentTypeDefinitionVO) i.next();
        if (vo.getType().compareTo(ContentTypeDefinitionVO.CONTENT) == 0) {
            TransactionHistoryVO transactionHistoryVO = transactionHistoryController
                    .getLatestTransactionHistoryVOForEntity(ContentTypeDefinitionImpl.class,
                            vo.getContentTypeDefinitionId());

            Element definition = DocumentHelper.createElement("definition");
            definition.addAttribute("id", "" + vo.getContentTypeDefinitionId())
                    .addAttribute("type", "" + vo.getType()).addAttribute("name", vo.getName());

            if (transactionHistoryVO != null)
                definition.addAttribute("mod", formatDate(transactionHistoryVO.getTransactionDateTime()));

            Element schemaValue = definition.addElement("schemaValue");
            schemaValue.addCDATA(vo.getSchemaValue());
            root.add(definition);// ww w  .j a  v a 2s  .  c  om
        }
    }
    return out(getFormattedDocument(doc));

}

From source file:org.infoglue.cms.applications.contenttool.actions.SimpleContentXmlAction.java

License:Open Source License

public Element getContentElement(ContentVO vo) throws Bug, Exception {
    Element elm = DocumentHelper.createElement("content");

    ContentVersionController contentVersionController = ContentVersionController.getContentVersionController();
    ContentVersionVO activeVersion = contentVersionController.getLatestActiveContentVersionVO(vo.getContentId(),
            LanguageController.getController().getMasterLanguage(vo.getRepositoryId()).getLanguageId());
    if (activeVersion != null) {
        elm.addAttribute("id", "" + vo.getContentId());
        elm.addAttribute("creatorName", "" + vo.getCreatorName());
        elm.addAttribute("name", "" + vo.getName());
        elm.addAttribute("typedefid", "" + vo.getContentTypeDefinitionId());
        elm.addAttribute("expiredatetime", "" + vo.getExpireDateTime().getTime());
        elm.addAttribute("publishdatetime", "" + vo.getPublishDateTime().getTime());
        elm.addAttribute("isbranch", "" + vo.getIsBranch());
        elm.addAttribute("activeVersion", "" + activeVersion.getContentVersionId());
        elm.addAttribute("activeVersionStateId", "" + activeVersion.getStateId());
        elm.addAttribute("activeVersionModifier", "" + activeVersion.getVersionModifier());
        Element versionsElement = DocumentHelper.createElement("versions");
        elm.add(versionsElement);/*  w w  w.jav  a  2  s .  c  o m*/

        List<ContentVersionVO> versions = contentVersionController
                .getContentVersionVOWithParent(vo.getContentId());
        for (ContentVersionVO version : versions) {
            Element contentVersionElement = DocumentHelper.createElement("contentVersion");
            contentVersionElement.add(getContentVersionHeadElement(version));
            versionsElement.add(contentVersionElement);
        }

    }

    return elm;
}

From source file:org.infoglue.cms.applications.contenttool.actions.SimpleContentXmlAction.java

License:Open Source License

public Element getPlainContentElement(ContentVO vo) throws Bug, Exception {
    Element elm = DocumentHelper.createElement("content");

    elm.addAttribute("id", "" + vo.getContentId());
    elm.addAttribute("creatorName", "" + vo.getCreatorName());
    elm.addAttribute("name", "" + vo.getName());
    elm.addAttribute("typedefid", "" + vo.getContentTypeDefinitionId());
    elm.addAttribute("expiredatetime", "" + vo.getExpireDateTime().getTime());
    elm.addAttribute("publishdatetime", "" + vo.getPublishDateTime().getTime());
    elm.addAttribute("isbranch", "" + vo.getIsBranch());

    return elm;// ww w  .ja v a 2s .  com
}