Example usage for org.dom4j Attribute getValue

List of usage examples for org.dom4j Attribute getValue

Introduction

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

Prototype

String getValue();

Source Link

Document

Returns the value of the attribute.

Usage

From source file:org.hibernate.metamodel.source.hbm.AbstractEntityBinder.java

License:Open Source License

int getOptimisticLockMode(Attribute olAtt) throws MappingException {
    if (olAtt == null) {
        return Versioning.OPTIMISTIC_LOCK_VERSION;
    }//from  w  w  w .  ja v a2s .  c  om
    String olMode = olAtt.getValue();
    if (olMode == null || "version".equals(olMode)) {
        return Versioning.OPTIMISTIC_LOCK_VERSION;
    } else if ("dirty".equals(olMode)) {
        return Versioning.OPTIMISTIC_LOCK_DIRTY;
    } else if ("all".equals(olMode)) {
        return Versioning.OPTIMISTIC_LOCK_ALL;
    } else if ("none".equals(olMode)) {
        return Versioning.OPTIMISTIC_LOCK_NONE;
    } else {
        throw new MappingException("Unsupported optimistic-lock style: " + olMode);
    }
}

From source file:org.hibernate.metamodel.source.hbm.HbmHelper.java

License:Open Source License

public static boolean isCallable(Element element, boolean supportsCallable) {
    Attribute attrib = element.attribute("callable");
    if (attrib != null && "true".equals(attrib.getValue())) {
        if (!supportsCallable) {
            throw new MappingException("callable attribute not supported yet!");
        }/*from   ww  w. java  2 s .  com*/
        return true;
    }
    return false;
}

From source file:org.hibernate.metamodel.source.hbm.HbmHelper.java

License:Open Source License

public static String getClassName(Attribute att, String unqualifiedPackageName) {
    if (att == null) {
        return null;
    }/*from  ww  w.j a va  2s .  c  o m*/
    return getClassName(att.getValue(), unqualifiedPackageName);
}

From source file:org.hibernate.metamodel.source.hbm.RootEntityBinder.java

License:Open Source License

public void process(Element entityElement) {
    String entityName = getHibernateMappingBinder().extractEntityName(entityElement);
    if (entityName == null) {
        throw new MappingException("Unable to determine entity name");
    }/*w  ww  . j  ava  2  s  .co m*/

    EntityBinding entityBinding = new EntityBinding();
    basicEntityBinding(entityElement, entityBinding, null);
    basicTableBinding(entityElement, entityBinding);

    Attribute mutableAttribute = entityElement.attribute("mutable");
    if (mutableAttribute != null) {
        entityBinding.setMutable(Boolean.valueOf(mutableAttribute.getValue()));
    }

    Attribute whereAttribute = entityElement.attribute("where");
    if (whereAttribute != null) {
        entityBinding.setWhereFilter(whereAttribute.getValue());
    }

    Attribute polymorphismAttribute = entityElement.attribute("polymorphism");
    if (polymorphismAttribute != null) {
        entityBinding.setExplicitPolymorphism("explicit".equals(polymorphismAttribute.getValue()));
    }

    Attribute rowidAttribute = entityElement.attribute("rowid");
    if (rowidAttribute != null) {
        entityBinding.setRowId(rowidAttribute.getValue());
    }

    bindIdentifier(entityElement, entityBinding);
    bindDiscriminator(entityElement, entityBinding);
    bindVersion(entityElement, entityBinding);
    bindCaching(entityElement, entityBinding);

    // called createClassProperties in HBMBinder...
    buildAttributeBindings(entityElement, entityBinding);

    getHibernateXmlBinder().getMetadata().addEntity(entityBinding);
}

From source file:org.hibernate.metamodel.source.hbm.RootEntityBinder.java

License:Open Source License

private void basicTableBinding(Element entityElement, EntityBinding entityBinding) {
    final Schema schema = getHibernateXmlBinder().getMetadata().getDatabase().getSchema(getSchemaName());

    final String subSelect = HbmHelper.getSubselect(entityElement);
    if (subSelect != null) {
        final String logicalName = entityBinding.getEntity().getName();
        InLineView inLineView = schema.getInLineView(logicalName);
        if (inLineView == null) {
            inLineView = schema.createInLineView(logicalName, subSelect);
        }//from w  ww . j a v a 2  s  . c om
        entityBinding.setBaseTable(inLineView);
    } else {
        final Identifier tableName = Identifier
                .toIdentifier(getClassTableName(entityElement, entityBinding, null));
        org.hibernate.metamodel.relational.Table table = schema.getTable(tableName);
        if (table == null) {
            table = schema.createTable(tableName);
        }
        entityBinding.setBaseTable(table);
        Element comment = entityElement.element("comment");
        if (comment != null) {
            table.addComment(comment.getTextTrim());
        }
        Attribute checkAttribute = entityElement.attribute("check");
        if (checkAttribute != null) {
            table.addCheckConstraint(checkAttribute.getValue());
        }
    }
}

From source file:org.hibernate.metamodel.source.hbm.state.relational.HbmColumnRelationalState.java

License:Open Source License

public Size getSize() {
    // TODO: should this set defaults if length, scale, precision is not specified?
    Size size = new Size();
    org.dom4j.Attribute lengthNode = getElement().attribute("length");
    if (lengthNode != null) {
        size.setLength(Integer.parseInt(lengthNode.getValue()));
    }/*  w w  w  . j a  v a 2s.co  m*/
    org.dom4j.Attribute scaleNode = getElement().attribute("scale");
    if (scaleNode != null) {
        size.setScale(Integer.parseInt(scaleNode.getValue()));
    }
    org.dom4j.Attribute precisionNode = getElement().attribute("precision");
    if (precisionNode != null) {
        size.setPrecision(Integer.parseInt(precisionNode.getValue()));
    }
    // TODO: is there an attribute for lobMultiplier?
    return size;
}

From source file:org.hibernate.metamodel.source.internal.MetadataSourceQueue.java

License:Open Source License

public void add(XmlDocument metadataXml) {
    final Document document = metadataXml.getDocumentTree();
    final Element hmNode = document.getRootElement();
    Attribute packNode = hmNode.attribute("package");
    String defaultPackage = packNode != null ? packNode.getValue() : "";
    Set<String> entityNames = new HashSet<String>();
    findClassNames(defaultPackage, hmNode, entityNames);
    for (String entity : entityNames) {
        hbmMetadataByEntityNameXRef.put(entity, metadataXml);
    }//from  ww w .j  ava  2s  .  com
    this.hbmMetadataToEntityNamesMap.put(metadataXml, entityNames);
}

From source file:org.hibernate.metamodel.source.internal.MetadataSourceQueue.java

License:Open Source License

private String getClassName(Attribute name, String defaultPackage) {
    if (name == null) {
        return null;
    }//  w  ww.j a va  2  s .  co m
    String unqualifiedName = name.getValue();
    if (unqualifiedName == null) {
        return null;
    }
    if (unqualifiedName.indexOf('.') < 0 && defaultPackage != null) {
        return defaultPackage + '.' + unqualifiedName;
    }
    return unqualifiedName;
}

From source file:org.hudsonci.xpath.impl.Dom2Dom.java

License:Open Source License

private org.w3c.dom.Node createChild(Node child, org.w3c.dom.Node wparent) {
    int type = child.getNodeType();

    // Collapse multiple consecutive text nodes to a single text node
    // with trimmed value.
    if (type != Node.TEXT_NODE)
        endText(wparent);/*from   ww w .  j  av  a 2 s  .  c o  m*/

    Name name;
    org.w3c.dom.Node node = null;

    switch (type) {
    case Node.ATTRIBUTE_NODE:
        break;
    case Node.CDATA_SECTION_NODE:
        CDATA cd = (CDATA) child;
        wparent.appendChild(node = wdoc.createCDATASection(cd.getText()));
        break;
    case Node.COMMENT_NODE:
        Comment co = (Comment) child;
        wparent.appendChild(node = wdoc.createComment(co.getText()));
        break;
    case Node.DOCUMENT_TYPE_NODE:
        DocumentType dt = (DocumentType) child;
        wparent.appendChild(new XDocumentType(dt, wparent));
        break;
    case Node.ELEMENT_NODE:
        Element el = (Element) child;
        name = new Name(el);
        org.w3c.dom.Element e = name.namespaceURI == null ? wdoc.createElement(name.qualifiedName)
                : wdoc.createElementNS(name.namespaceURI, name.qualifiedName);
        wparent.appendChild(e);
        node = currentElement = e;

        for (int i = 0, n = el.attributeCount(); i < n; i++) {
            Attribute at = el.attribute(i);
            name = new Name(at);
            if (name.namespaceURI == null)
                e.setAttribute(name.qualifiedName, at.getValue());
            else
                e.setAttributeNS(name.namespaceURI, name.qualifiedName, at.getValue());
        }
        return e;
    case Node.ENTITY_REFERENCE_NODE:
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        ProcessingInstruction p = (ProcessingInstruction) child;
        wparent.appendChild(node = wdoc.createProcessingInstruction(p.getTarget(), p.getText()));
        break;
    case Node.TEXT_NODE:
        textBuilder.append(child.getText());
        lastText = (Text) child;
        break;
    case Node.NAMESPACE_NODE:
        Namespace ns = (Namespace) child;
        name = new Name(ns);
        currentElement.setAttribute(name.qualifiedName, ns.getURI());
        break;
    default:
        throw new IllegalStateException("Unknown node type");
    }
    if (node != null)
        reverseMap.put(node, child);
    return null;
}

From source file:org.infoglue.deliver.controllers.kernel.impl.simple.ComponentLogic.java

License:Open Source License

private Map parsePropertiesWithDOM4J(String inheritedPageComponentsXML, Integer componentId,
        String propertyName, Integer siteNodeId, Integer languageId) throws Exception {
    Map property = null;//from w  w  w . j  a va 2s . c  om

    org.dom4j.Document document = domBuilder.getDocument(inheritedPageComponentsXML);
    String propertyXPath = "//component[@id=" + componentId + "]/properties/property[@name='" + propertyName
            + "']";

    List anl = document.getRootElement().selectNodes(propertyXPath);
    //If not found on the same component id - let's check them all and use the first we find.
    if (anl == null || anl.size() == 0) {
        String globalPropertyXPath = "(//component/properties/property[@name='" + propertyName + "'])[1]";
        anl = document.getRootElement().selectNodes(globalPropertyXPath);
    }

    Iterator anlIterator = anl.iterator();
    while (anlIterator.hasNext()) {
        org.dom4j.Element propertyElement = (org.dom4j.Element) anlIterator.next();

        String name = propertyElement.attributeValue("name");
        String type = propertyElement.attributeValue("type");
        String entity = propertyElement.attributeValue("entity");
        boolean isMultipleBinding = new Boolean(propertyElement.attributeValue("multiple")).booleanValue();

        String value = null;

        if (type.equalsIgnoreCase("textfield") || type.equalsIgnoreCase("textarea")
                || type.equalsIgnoreCase("select")) {
            value = propertyElement.attributeValue("path");

            Locale locale = LanguageDeliveryController.getLanguageDeliveryController()
                    .getLocaleWithId(templateController.getDatabase(), languageId);
            Locale masterLocale = LanguageDeliveryController.getLanguageDeliveryController()
                    .getMasterLanguageForSiteNode(templateController.getDatabase(), siteNodeId).getLocale();

            if (propertyElement.attributeValue("path_" + locale.getLanguage()) != null
                    && !propertyElement.attributeValue("path_" + locale.getLanguage()).equals(""))
                value = propertyElement.attributeValue("path_" + locale.getLanguage());

            if ((value == null || value.equals("")) && (propertyElement
                    .attributeValue("path_" + masterLocale.getLanguage()) != null
                    && !propertyElement.attributeValue("path_" + masterLocale.getLanguage()).equals("")))
                value = propertyElement.attributeValue("path_" + masterLocale.getLanguage());

            if (value != null)
                value = value.replaceAll("igbr", separator);
        } else {
            Locale locale = LanguageDeliveryController.getLanguageDeliveryController()
                    .getLocaleWithId(templateController.getDatabase(), languageId);

            //Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8"));
            String componentXPath = "//component[@id=" + componentId + "]/properties/property[@name='" + name
                    + "']";
            //logger.info("componentXPath:" + componentXPath);
            List propertyNL = document.getRootElement().selectNodes(componentXPath);
            Iterator propertyNLIterator = propertyNL.iterator();
            while (propertyNLIterator.hasNext()) {
                org.dom4j.Element propertyElement2 = (org.dom4j.Element) propertyNLIterator.next();

                String id = propertyElement2.attributeValue("type");
                String path = propertyElement2.attributeValue("path");

                if (propertyElement2.attributeValue("path_" + locale.getLanguage()) != null
                        && !propertyElement2.attributeValue("path_" + locale.getLanguage()).equals(""))
                    path = propertyElement2.attributeValue("path_" + locale.getLanguage());

                value = path;

                if (value != null)
                    value = value.replaceAll("igbr", separator);
            }

            //value = getComponentPropertyValue(inheritedPageComponentsXML, componentId, languageId, name);
        }

        property = new HashMap();
        property.put("name", name);
        //property.put("path", "Inherited");
        property.put("path", value);
        property.put("type", type);

        List attributes = propertyElement.attributes();
        Iterator attributesIterator = attributes.iterator();
        while (attributesIterator.hasNext()) {
            Attribute attribute = (Attribute) attributesIterator.next();
            if (attribute.getName().startsWith("path_"))
                property.put(attribute.getName(), attribute.getValue());
        }

        List bindings = new ArrayList();
        List bindingNodeList = propertyElement.elements("binding");
        Iterator bindingNodeListIterator = bindingNodeList.iterator();
        while (bindingNodeListIterator.hasNext()) {
            org.dom4j.Element bindingElement = (org.dom4j.Element) bindingNodeListIterator.next();
            String entityName = bindingElement.attributeValue("entity");
            String entityId = bindingElement.attributeValue("entityId");
            String assetKey = bindingElement.attributeValue("assetKey");
            //logger.info("Binding found:" + entityName + ":" + entityId);

            ComponentBinding componentBinding = new ComponentBinding();
            //componentBinding.setId(new Integer(id));
            //componentBinding.setComponentId(componentId);
            componentBinding.setEntityClass(entity);
            componentBinding.setEntityId(entityId);
            componentBinding.setAssetKey(assetKey);
            //componentBinding.setBindingPath(path);

            bindings.add(componentBinding);
            /*
            if(entityName.equalsIgnoreCase("Content"))
            {
               //logger.info("Content added:" + entityName + ":" + entityId);
               bindings.add(entityId);
            }
            else
            {
               //logger.info("SiteNode added:" + entityName + ":" + entityId);
               bindings.add(entityId); 
            } 
            */
        }

        property.put("bindings", bindings);
    }

    return property;
}