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:com.haulmont.cuba.web.gui.components.WebAbstractTable.java

License:Apache License

@Override
public void setDatasource(final CollectionDatasource datasource) {
    Preconditions.checkNotNullArgument(datasource, "datasource is null");

    if (this.datasource != null) {
        if (!this.datasource.getMetaClass().equals(datasource.getMetaClass())) {
            throw new IllegalArgumentException("The new datasource must correspond to the same MetaClass");
        }// ww  w .  j av a2 s.  c o  m

        if (fieldDatasources != null) {
            fieldDatasources.clear();
        }

        if (collectionDsListenersWrapper != null) {
            collectionDsListenersWrapper.unbind(this.datasource);
            if (containerDatasource != null) {
                containerDatasource.unsubscribe();
                containerDatasource = null;
            }
        }
    }

    MessageTools messageTools = AppBeans.get(MessageTools.NAME);

    final Collection<Object> columns;
    if (this.columns.isEmpty()) {
        Collection<MetaPropertyPath> paths = datasource.getView() != null ?
        // if a view is specified - use view properties
                metadataTools.getViewPropertyPaths(datasource.getView(), datasource.getMetaClass()) :
                // otherwise use all properties from meta-class
                metadataTools.getPropertyPaths(datasource.getMetaClass());
        for (MetaPropertyPath metaPropertyPath : paths) {
            MetaProperty property = metaPropertyPath.getMetaProperty();
            if (!property.getRange().getCardinality().isMany() && !metadataTools.isSystem(property)) {
                Table.Column column = new Table.Column(metaPropertyPath);

                String propertyName = property.getName();
                MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);

                column.setCaption(messageTools.getPropertyCaption(propertyMetaClass, propertyName));
                column.setType(metaPropertyPath.getRangeJavaClass());

                Element element = DocumentHelper.createElement("column");
                column.setXmlDescriptor(element);

                addColumn(column);
            }
        }
    }
    columns = this.columns.keySet();

    this.datasource = datasource;

    if (collectionDsListenersWrapper == null) {
        collectionDsListenersWrapper = createCollectionDsListenersWrapper();
    }

    containerDatasource = createContainerDatasource(datasource, getPropertyColumns(),
            collectionDsListenersWrapper);

    component.setContainerDataSource(containerDatasource);

    List<MetaPropertyPath> editableColumns = null;
    if (isEditable()) {
        editableColumns = new LinkedList<>();
    }

    MetaClass metaClass = datasource.getMetaClass();
    for (final Object columnId : columns) {
        final Table.Column column = this.columns.get(columnId);

        final String caption;
        if (column != null) {
            caption = getColumnCaption(columnId, column);
        } else {
            caption = StringUtils.capitalize(getColumnCaption(columnId));
        }

        setColumnHeader(columnId, caption);

        if (column != null) {
            if (editableColumns != null && column.isEditable() && (columnId instanceof MetaPropertyPath)) {
                MetaPropertyPath propertyPath = ((MetaPropertyPath) columnId);
                if (security.isEntityAttrUpdatePermitted(metaClass, propertyPath.toString())) {
                    editableColumns.add(propertyPath);
                }
            }

            if (column.isCollapsed() && component.isColumnCollapsingAllowed()) {
                if (!(columnId instanceof MetaPropertyPath)
                        || security.isEntityAttrReadPermitted(metaClass, columnId.toString())) {
                    component.setColumnCollapsed(column.getId(), true);
                }
            }

            if (column.getAggregation() != null && isAggregatable()) {
                checkAggregation(column.getAggregation());

                component.addContainerPropertyAggregation(column.getId(),
                        WebComponentsHelper.convertAggregationType(column.getAggregation().getType()));
            }
        }
    }

    if (editableColumns != null && !editableColumns.isEmpty()) {
        setEditableColumns(editableColumns);
    }

    createColumns(containerDatasource);

    for (Table.Column column : this.columnsOrder) {
        if (editable && column.getAggregation() != null
                && (BooleanUtils.isTrue(column.isEditable()) || BooleanUtils.isTrue(column.isCalculatable()))) {
            addAggregationCell(column);
        }
    }

    createStubsForGeneratedColumns();

    setVisibleColumns(getInitialVisibleColumns());

    if (security.isSpecificPermitted(ShowInfoAction.ACTION_PERMISSION)) {
        ShowInfoAction action = (ShowInfoAction) getAction(ShowInfoAction.ACTION_ID);
        if (action == null) {
            action = new ShowInfoAction();
            addAction(action);
        }
        action.setDatasource(datasource);
    }

    if (rowsCount != null) {
        rowsCount.setDatasource(datasource);
    }

    collectionDsListenersWrapper.bind(datasource);

    for (Action action : getActions()) {
        action.refreshState();
    }

    if (!canBeSorted(datasource))
        setSortable(false);

    assignAutoDebugId();
}

From source file:com.heren.turtle.server.utils.XmlUtils.java

License:Open Source License

/**
 * back failure information//from  w ww . j  a  v a  2s  . co m
 *
 * @param message
 * @return
 */
public static String errorMessage(String message) {
    Document document = DocumentHelper.createDocument();
    Element payload = DocumentHelper.createElement("payload");
    document.setRootElement(payload);
    Element response = payload.addElement("response");
    Element result = response.addElement("result");
    result.setText("true");
    Element resultText = response.addElement("resultText");
    resultText.setText(message == null ? "" : message);
    Element userId = response.addElement("userId");
    userId.setText("0001");
    return document.asXML();
}

From source file:com.heren.turtle.server.utils.XmlUtils.java

License:Open Source License

/**
 * back correct information/*from www.  j  a  va  2 s.  c o  m*/
 *
 * @param flag 0 no data 1 some exception
 * @return
 */
public static String correctMessage(int flag) {
    Document document = DocumentHelper.createDocument();
    Element payload = DocumentHelper.createElement("payload");
    document.setRootElement(payload);
    Element response = payload.addElement("response");
    Element result = response.addElement("result");
    result.setText("true");
    Element resultText = response.addElement("resultText");
    switch (flag) {
    case 0:
        resultText.setText("no data found!");
        break;
    case -1:
        resultText.setText("success!");
        break;
    default:
        break;
    }
    Element userId = response.addElement("userId");
    userId.setText("0001");
    return document.asXML();
}

From source file:com.heren.turtle.server.utils.XmlUtils.java

License:Open Source License

/**
 * back successful information/* w  w w .  j av a2 s.  com*/
 *
 * @return
 */
public static String resultMessage() {
    Document document = DocumentHelper.createDocument();
    Element payload = DocumentHelper.createElement("payload");
    document.setRootElement(payload);
    Element response = payload.addElement("response");
    Element result = response.addElement("result");
    result.setText("true");
    Element resultText = response.addElement("resultText");
    resultText.setText("??");
    Element userId = response.addElement("userId");
    userId.setText("0001");
    return document.asXML();
}

From source file:com.ibm.cognos.API.java

License:Open Source License

public API() {
    Element reportElement = DocumentHelper.createElement("report");

    // In dom4j 1.6.1, can no longer add xmlns with addAttribute
    reportElement.addNamespace("", "http://developer.cognos.com/schemas/report/8.0/");
    reportElement.addAttribute("expressionLocale", "en-us");
    oDocument = DocumentHelper.createDocument(reportElement);
}

From source file:com.ibm.cognos.API.java

License:Open Source License

public void addLayouts() {
    Element e = DocumentHelper.createElement("layouts");
    oDocument.getRootElement().add(e);
}

From source file:com.ibm.cognos.API.java

License:Open Source License

public void addLayout() {
    Element n = (Element) oDocument.selectSingleNode("/report/layouts");
    if (n == null) {
        addLayouts();//from   w  ww.  jav  a2  s  . c  om
        n = (Element) oDocument.selectSingleNode("/report/layouts");
    }

    Element e = DocumentHelper.createElement("layout");
    n.add(e);
}

From source file:com.ibm.cognos.API.java

License:Open Source License

public void addReportPages() {
    Element n = (Element) oDocument.selectSingleNode("/report/layouts/layout");
    if (n == null) {
        addLayout();/* ww  w . j a v  a  2  s . co m*/
        n = (Element) oDocument.selectSingleNode("/report/layouts/layout");
    }

    Element e = DocumentHelper.createElement("reportPages");
    n.add(e);
}

From source file:com.ibm.cognos.API.java

License:Open Source License

public void addPage(String p_sName) {
    Element n = (Element) oDocument.selectSingleNode("/report/layouts/layout/reportPages");
    if (n == null) {
        addReportPages();// w w  w.  j ava2  s .co m
        n = (Element) oDocument.selectSingleNode("/report/layouts/layout/reportPages");
    }

    Element e = DocumentHelper.createElement("page");
    Element eStyle = buildStyle("pg");

    e.addAttribute("name", p_sName);
    e.add(eStyle);
    n.add(e);
}

From source file:com.ibm.cognos.API.java

License:Open Source License

public void addPageBody() {
    Element n = (Element) oDocument.selectSingleNode("/report/layouts/layout/reportPages/page");
    if (n == null) {
        addPage("Page1");
        n = (Element) oDocument.selectSingleNode("/report/layouts/layout/reportPages/page");
    }/*w w  w  .  j  a va  2s .c  om*/

    Element e = DocumentHelper.createElement("pageBody");
    Element eStyle = buildStyle("pb");

    e.add(eStyle);
    n.add(e);
}