Example usage for org.dom4j QName QName

List of usage examples for org.dom4j QName QName

Introduction

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

Prototype

public QName(String name, Namespace namespace, String qualifiedName) 

Source Link

Usage

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

License:Open Source License

/**
 * create the dom4j qualified name of given generated node
 * @param node//w  ww. ja  v a  2 s  .c o m
 * @return the dom4j qualified name of given generated node
 */
public QName createType(INode node) {
    String qualifiedName = services.getQualifiedName(node);
    String name = services.getName(qualifiedName);
    String prefix = services.getPrefix(qualifiedName);
    String uri = services.getSIDEUri(node);
    Namespace namespace = new Namespace(prefix, uri);
    return new QName(name, namespace, qualifiedName);
}

From source file:org.nuxeo.ecm.jsf2.migration.parser.NamespaceParser.java

License:Open Source License

@Override
public void migrate(Document input) throws Exception {
    Element root = input.getRootElement();
    for (String prefix : listPrefixToMigrate) {
        Namespace newNamespace = new Namespace(prefix, EnumPrefixes.getPrefix(prefix).getNamespace());
        Namespace oldNamespace = root.getNamespaceForPrefix(prefix);
        if (oldNamespace != null) {
            root.remove(oldNamespace);//from w ww.  j  av a 2  s . com
        }
        root.add(newNamespace);

        // Change the name of every elements with the prefix
        StringBuilder prefixXpath = new StringBuilder("//");
        prefixXpath.append(prefix);
        prefixXpath.append(":*");
        // Create a new XPath expression, with the old namespace in order
        // to
        // get the elements matching the expression
        XPath xpath = new Dom4jXPath(prefixXpath.toString());
        SimpleNamespaceContext nc = new SimpleNamespaceContext();
        nc.addNamespace(prefix, oldNamespace.getURI());
        xpath.setNamespaceContext(nc);

        @SuppressWarnings("unchecked")
        List<Element> elementsToMigrate = xpath.selectNodes(input);
        for (Element element : elementsToMigrate) {
            // The namespace to change is not hold by the element but the
            // QName
            QName qname = element.getQName();
            QName newQName = new QName(qname.getName(), newNamespace, qname.getQualifiedName());
            element.setQName(newQName);
        }
    }
}

From source file:org.talend.mdm.webapp.browserecords.server.actions.BrowseRecordsAction.java

License:Open Source License

@Override
public ItemBean getItem(ItemBean itemBean, String viewPK, EntityModel entityModel, boolean staging,
        String language) throws ServiceException {
    try {//  w  w w  .  j a v a  2  s . c  o m
        String dateFormat = "yyyy-MM-dd"; //$NON-NLS-1$
        String dateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss"; //$NON-NLS-1$

        String dataCluster = getCurrentDataCluster(staging);
        String dataModel = getCurrentDataModel();
        String concept = itemBean.getConcept();
        // get item
        WSDataClusterPK wsDataClusterPK = new WSDataClusterPK(dataCluster);
        String[] ids = CommonUtil.extractIdWithDots(entityModel.getKeys(), itemBean.getIds());

        // parse schema firstly, then use element declaration (DataModelHelper.getEleDecl)
        DataModelHelper.parseSchema(dataModel, concept, entityModel, LocalUser.getLocalUser().getRoles());

        WSItem wsItem = CommonUtil.getPort()
                .getItem(new WSGetItem(new WSItemPK(wsDataClusterPK, itemBean.getConcept(), ids)));
        itemBean.setItemXml(wsItem.getContent());
        extractUsingTransformerThroughView(concept, viewPK, ids, dataModel, dataCluster,
                DataModelHelper.getEleDecl(), itemBean);
        itemBean.set("time", wsItem.getInsertionTime()); //$NON-NLS-1$
        if (wsItem.getTaskId() != null && !"".equals(wsItem.getTaskId()) //$NON-NLS-1$
                && !"null".equals(wsItem.getTaskId())) { //$NON-NLS-1$
            itemBean.setTaskId(wsItem.getTaskId());
        }

        SimpleDateFormat sdf = null;
        Map<String, String[]> formatMap = this.checkDisplayFormat(entityModel, language);
        Set<String> keySet = formatMap.keySet();
        for (String key : keySet) {
            String[] value = formatMap.get(key);
            org.dom4j.Document doc = org.talend.mdm.webapp.base.server.util.XmlUtil
                    .parseText(itemBean.getItemXml());
            TypeModel tm = entityModel.getMetaDataTypes().get(key);
            String xpath = tm.getXpath();
            org.dom4j.Node node = null;
            if (!key.equals(xpath)) {
                Namespace namespace = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); //$NON-NLS-1$//$NON-NLS-2$
                List<?> nodeList = doc.selectNodes(xpath);
                if (nodeList != null && nodeList.size() > 0) {
                    for (int i = 0; i < nodeList.size(); i++) {
                        org.dom4j.Element current = (org.dom4j.Element) nodeList.get(i);
                        String realType = current.getParent()
                                .attributeValue(new QName("type", namespace, "xsi:type")); //$NON-NLS-1$ //$NON-NLS-2$
                        if (key.replaceAll(":" + realType, "").equals(xpath)) { //$NON-NLS-1$//$NON-NLS-2$
                            node = current;
                            break;
                        }
                    }
                }
            } else {
                node = doc.selectSingleNode(key);
            }

            if (node != null && itemBean.getOriginalMap() != null) {
                String dataText = node.getText();

                if (dataText != null) {
                    if (dataText.trim().length() != 0) {
                        if (dateTypeNames.contains(tm.getType().getBaseTypeName())) {
                            if (value[1].equalsIgnoreCase("DATE")) { //$NON-NLS-1$
                                sdf = new SimpleDateFormat(dateFormat, java.util.Locale.ENGLISH);
                            } else if (value[1].equalsIgnoreCase("DATETIME")) { //$NON-NLS-1$
                                sdf = new SimpleDateFormat(dateTimeFormat, java.util.Locale.ENGLISH);
                            }

                            try {
                                Date date = sdf.parse(dataText.trim());
                                itemBean.getOriginalMap().put(key, date);
                                Calendar calendar = Calendar.getInstance();
                                calendar.setTime(date);
                                String formatValue = com.amalto.webapp.core.util.Util.formatDate(value[0],
                                        calendar);
                                itemBean.getFormateMap().put(key, formatValue);
                            } catch (Exception e) {
                                itemBean.getOriginalMap().remove(key);
                                itemBean.getFormateMap().remove(key);
                            }
                        } else if (numberTypeNames.contains(tm.getType().getBaseTypeName())) {
                            try {
                                NumberFormat nf = NumberFormat.getInstance();
                                Number num = nf.parse(dataText.trim());
                                String formatValue = ""; //$NON-NLS-1$
                                if (tm.getType().getBaseTypeName()
                                        .equals(DataTypeConstants.DOUBLE.getBaseTypeName())) {
                                    formatValue = String.format(value[0], num.doubleValue()).trim();
                                } else if (tm.getType().getBaseTypeName()
                                        .equals(DataTypeConstants.FLOAT.getBaseTypeName())) {
                                    formatValue = String.format(value[0], num.floatValue()).trim();
                                } else if (tm.getType().getBaseTypeName()
                                        .equals(DataTypeConstants.DECIMAL.getBaseTypeName())) {
                                    formatValue = String.format(value[0], new BigDecimal(dataText.trim()))
                                            .trim();
                                } else {
                                    formatValue = String.format(value[0], num).trim();
                                }
                                itemBean.getOriginalMap().put(key, num);
                                itemBean.getFormateMap().put(key, formatValue);
                            } catch (Exception e) {
                                itemBean.getOriginalMap().remove(key);
                                itemBean.getFormateMap().remove(key);
                            }
                        }
                    }
                }
            }
        }

        // dynamic Assemble
        dynamicAssemble(itemBean, entityModel, language);

        return itemBean;
    } catch (WebBaseException e) {
        throw new ServiceException(BASEMESSAGE.getMessage(new Locale(language), e.getMessage(), e.getArgs()));
    } catch (Exception exception) {
        String errorMessage;
        if (CoreException.class.isInstance(exception.getCause())) {
            CoreException webCoreException = (CoreException) exception.getCause();
            errorMessage = getErrorMessageFromWebCoreException(webCoreException, itemBean.getConcept(),
                    itemBean.getIds(), new Locale(language));
        } else {
            errorMessage = exception.getLocalizedMessage();
        }
        LOG.error(errorMessage, exception);
        throw new ServiceException(errorMessage);
    }
}

From source file:org.talend.mdm.webapp.browserecords.server.ruleengine.DisplayRuleEngine.java

License:Open Source License

private String getRealTypePath(org.dom4j.Element el) {
    String realXPath = ""; //$NON-NLS-1$
    org.dom4j.Element current = el;
    boolean isFirst = true;
    while (current != null) {
        String name;/*from  ww  w . j  a  v a 2 s .c  o  m*/
        String realType = current.attributeValue(new QName("type", namespace, "xsi:type")); //$NON-NLS-1$ //$NON-NLS-2$
        if (realType != null && realType.trim().length() > 0) {
            name = current.getName() + ":" + realType; //$NON-NLS-1$
        } else {
            name = current.getName();
        }

        current = current.getParent();
        if (isFirst) {
            realXPath = name;
            isFirst = false;
            continue;
        }
        realXPath = name + "/" + realXPath; //$NON-NLS-1$
    }
    return realXPath;
}

From source file:org.talend.mdm.webapp.browserecords.server.service.UploadService.java

License:Open Source License

private void setAttributeValue(Element currentElement, String value) {
    if (xsiTypeQName == null) {
        xsiTypeQName = new QName(Constants.XSI_TYPE_NAME,
                new Namespace(Constants.XSI_PREFIX, Constants.XSI_URI), Constants.XSI_TYPE_QUALIFIED_NAME);
    }/* ww  w  .  j a  v a 2  s  .  co  m*/
    if (!value.equals(currentElement.attributeValue(xsiTypeQName))) {
        currentElement.setAttributeValue(xsiTypeQName, value);
    }
}