Example usage for org.dom4j Namespace Namespace

List of usage examples for org.dom4j Namespace Namespace

Introduction

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

Prototype

public Namespace(String prefix, String uri) 

Source Link

Document

DOCUMENT ME!

Usage

From source file:org.orbeon.oxf.xforms.XFormsUtils.java

License:Open Source License

/**
 * Return the underlying Node from the given NodeInfo, possibly converting it to a Dom4j Node. Changes to the returned Node may or may not
 * reflect on the original, depending on its type.
 *
 * @param nodeInfo      NodeInfo to process
 * @return              Node/*from   w  w  w .  j a  v  a  2 s. c o m*/
 */
public static Node getNodeFromNodeInfoConvert(NodeInfo nodeInfo) {
    if (nodeInfo instanceof VirtualNode)
        return (Node) ((VirtualNode) nodeInfo).getUnderlyingNode();
    else if (nodeInfo.getNodeKind() == org.w3c.dom.Node.ATTRIBUTE_NODE) {
        return Dom4jUtils.createAttribute(
                new QName(nodeInfo.getLocalPart(), new Namespace(nodeInfo.getPrefix(), nodeInfo.getURI())),
                nodeInfo.getStringValue());
    } else
        return TransformerUtils.tinyTreeToDom4j(
                (nodeInfo.getParent() instanceof DocumentInfo) ? nodeInfo.getParent() : nodeInfo);
}

From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java

License:Open Source License

/**
 * Extract a QName from a string value, given namespace mappings. Return null if the text is empty.
 *
 * @param namespaces                prefix -> URI mappings
 * @param qNameString               QName to analyze
 * @param unprefixedIsNoNamespace   if true, an unprefixed value is in no namespace; if false, it is in the default namespace
 * @return                          a QName object or null if not found
 *//*from w w w  .  ja  v a  2  s  .  c om*/
public static QName extractTextValueQName(Map<String, String> namespaces, String qNameString,
        boolean unprefixedIsNoNamespace) {
    if (qNameString == null)
        return null;
    qNameString = qNameString.trim();
    if (qNameString.length() == 0)
        return null;

    final int colonIndex = qNameString.indexOf(':');
    final String prefix;
    final String localName;
    final String namespaceURI;
    if (colonIndex == -1) {
        prefix = "";
        localName = qNameString;
        if (unprefixedIsNoNamespace) {
            namespaceURI = "";
        } else {

            final String nsURI = namespaces.get(prefix);
            namespaceURI = nsURI == null ? "" : nsURI;
        }
    } else if (colonIndex == 0) {
        throw new OXFException("Empty prefix for QName: " + qNameString);
    } else {
        prefix = qNameString.substring(0, colonIndex);
        localName = qNameString.substring(colonIndex + 1);
        namespaceURI = namespaces.get(prefix);
        if (namespaceURI == null) {
            throw new OXFException("No namespace declaration found for prefix: " + prefix);
        }
    }
    return new QName(localName, new Namespace(prefix, namespaceURI));
}

From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java

License:Open Source License

/**
 * Decode a String containing an exploded QName (also known as a "Clark name") into a QName.
 *///from   w  ww  .  ja  va 2  s. com
public static QName explodedQNameToQName(String qName) {
    int openIndex = qName.indexOf("{");

    if (openIndex == -1)
        return new QName(qName);

    String namespaceURI = qName.substring(openIndex + 1, qName.indexOf("}"));
    String localName = qName.substring(qName.indexOf("}") + 1);
    return new QName(localName, new Namespace("p1", namespaceURI));
}

From source file:org.panopticode.report.treemap.BaseTreemap.java

License:Open Source License

void renderSVG(PanopticodeProject project, Element svgElement, boolean interactive, Rect bounds) {
    Map<String, Rect> layout;

    StringBuffer viewBox = new StringBuffer();
    viewBox.append(bounds.x);//from   w ww. j  a v a2  s  . c o m
    viewBox.append(" ");
    viewBox.append(bounds.y);
    viewBox.append(" ");
    viewBox.append(bounds.w);
    viewBox.append(" ");
    viewBox.append(bounds.h);

    svgElement.add(new Namespace("", "http://www.w3.org/2000/svg"));
    svgElement.add(new Namespace("xlink", "http://www.w3.org/1999/xlink"));
    svgElement.addAttribute("viewBox", viewBox.toString());

    layout = getLayout(bounds, interactive);

    renderTitle(svgElement, layout.get("title"), project);

    renderDetails(layout.get("details"), svgElement, project, interactive);

    getData(project, interactive).renderSVG(layout.get("contents"), svgElement, project);

    getCategorizer().renderHorizontalLegend(layout.get("legend"), svgElement);
}

From source file:org.pentaho.ui.xul.impl.XulParser.java

License:Open Source License

protected XulComponent getElement(org.dom4j.Element srcEle, XulContainer parent) throws XulException {

    String handlerName = srcEle.getName().toUpperCase();
    Attribute att = srcEle/*from w w  w.j  a  va  2  s.co m*/
            .attribute(new QName("customclass", new Namespace("pen", "http://www.pentaho.org/2008/xul")));

    // If the custom handler is registered, use it; otherwise, fall back to the original element handler...
    if (att != null) {
        String potentialHandlerName = att.getValue().toUpperCase();
        if (handlers.get(potentialHandlerName) != null) {
            handlerName = potentialHandlerName;
        }
    }

    Object handler = handlers.get(handlerName);

    if (handler == null) {
        logger.error("handler not found: " + handlerName);
        return null;
        // throw new XulException(String.format("No handler available for input: %s", srcEle.getName()));
    }

    String tagName = srcEle.getName();
    try {

        Constructor<?> constructor = getContructor((String) handler);

        // create a generic element representation of the current Dom4J node
        Element domEle = DocumentFactory.createElement(srcEle.getName().toLowerCase());
        List<Attribute> attrs = srcEle.attributes();
        for (Attribute attr : attrs) {
            domEle.setAttribute(attr.getName(), attr.getValue());
        }

        XulComponent ele = (XulComponent) constructor.newInstance(domEle, parent, xulDomContainer, tagName);

        // preserve atributes in new Generic Dom node
        for (Attribute attr : attrs) {
            ele.setAttribute(attr.getName(), attr.getValue());
        }

        Map<String, String> attributesMap = XulUtil.AttributesToMap(srcEle.attributes());
        BeanUtils.populate(ele, attributesMap);
        return ele;

    } catch (Exception e) {
        throw new XulException(e);
    }

}

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 {//from ww w  .j  av  a 2 s.  c om
        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.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);
    }//from w w w  .java  2  s . c  o  m
    if (!value.equals(currentElement.attributeValue(xsiTypeQName))) {
        currentElement.setAttributeValue(xsiTypeQName, value);
    }
}

From source file:org.talend.mdm.webapp.browserecords.server.util.CommonUtil.java

License:Open Source License

public static void dynamicAssembleByResultOrder(ItemBean itemBean, List<String> viewableXpaths,
        EntityModel entityModel, Map<String, EntityModel> map, String language, boolean isStaging)
        throws Exception {

    if (itemBean.getItemXml() != null) {
        org.dom4j.Document docXml = DocumentHelper.parseText(itemBean.getItemXml());
        int i = 0;
        List<?> els = docXml.getRootElement().elements();
        for (String path : viewableXpaths) {
            String leafPath = path.substring(path.lastIndexOf('/') + 1);
            if (leafPath.startsWith("@")) { //$NON-NLS-1$
                String[] xsiType = leafPath.substring(leafPath.indexOf("@") + 1).split(":"); //$NON-NLS-1$//$NON-NLS-2$
                itemBean.set(path,//from  w w  w . ja va2s .c  o  m
                        docXml.getRootElement()
                                .element(new QName(xsiType[1],
                                        new Namespace(xsiType[0], "http://www.w3.org/2001/XMLSchema-instance"))) //$NON-NLS-1$
                                .getText());
            } else {
                TypeModel typeModel = entityModel.getMetaDataTypes().get(path);
                org.dom4j.Element el = (org.dom4j.Element) els.get(i);
                if (typeModel != null && typeModel.getForeignkey() != null) {
                    String modelType = el.attributeValue(
                            new QName("type", new Namespace("tmdm", "http://www.talend.com/mdm"))); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
                    itemBean.set(path, path + "-" + el.getText()); //$NON-NLS-1$
                    itemBean.setForeignkeyDesc(path + "-" + el.getText(), //$NON-NLS-1$
                            org.talend.mdm.webapp.browserecords.server.util.CommonUtil.getForeignKeyDesc(
                                    typeModel, el.getText(), false, modelType, map.get(typeModel.getXpath()),
                                    isStaging, language));
                } else if (typeModel != null && DataTypeConstants.BOOLEAN.equals(typeModel.getType())) {
                    if (Constants.BOOLEAN_TRUE_DISPLAY_VALUE.equals(el.getText())
                            || Constants.BOOLEAN_TRUE_VALUE.equals(el.getText())) {
                        itemBean.set(path, Constants.BOOLEAN_TRUE_VALUE);
                    } else if (Constants.BOOLEAN_FALSE_DISPLAY_VALUE.equals(el.getText())
                            || Constants.BOOLEAN_FALSE_VALUE.equals(el.getText())) {
                        itemBean.set(path, Constants.BOOLEAN_FALSE_VALUE);
                    } else {
                        itemBean.set(path, el.getText());
                    }
                } else {
                    itemBean.set(path, el.getText());
                }
            }
            i++;
        }
    }
}

From source file:seostudio.Sitemap.java

License:Apache License

public static String generateSitemap(Collection<Result> results) throws IOException {
    Namespace namespace = new Namespace("", "http://www.sitemaps.org/schemas/sitemap/0.9");
    Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

    Element urlset = DocumentHelper.createElement(new QName("urlset", namespace));
    urlset.addAttribute(new QName("schemaLocation", xsi),
            "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd");
    Document document = DocumentHelper.createDocument(urlset);

    for (Result result : results) {
        if (!result.visited || !result.index)
            continue;

        Element url = DocumentHelper.createElement(new QName("url", namespace));
        Element loc = DocumentHelper.createElement(new QName("loc", namespace));
        Element priority = DocumentHelper.createElement(new QName("priority", namespace));

        loc.setText(result.url);/*from ww  w .  j av a2s. co m*/
        if (result.depth == 0) {
            priority.setText("1.0");
        } else {
            priority.setText("0.8");
        }

        url.add(loc);
        url.add(priority);
        urlset.add(url);
    }

    StringWriter out = new StringWriter();
    new XMLWriter(out, OutputFormat.createCompactFormat()).write(document);
    return out.toString();
}

From source file:to.networld.android.divedroid.model.rdf.RDFParser.java

License:Open Source License

@SuppressWarnings("unchecked")
protected String getResourceLinkNodes(String _query, String _resource) {
    try {//from  w w w .j  a v a  2  s  .  com
        XPath xpath = new Dom4jXPath(_query);
        xpath.setNamespaceContext(new SimpleNamespaceContext(this.namespace));
        List<Element> elements = (List<Element>) xpath.selectNodes(this.document);
        if (elements.size() > 0)
            return elements.get(0).attributeValue(
                    new QName("resource", new Namespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")));
    } catch (JaxenException e) {
        e.printStackTrace();
    }
    return null;
}