Example usage for org.w3c.dom Attr setValue

List of usage examples for org.w3c.dom Attr setValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr setValue.

Prototype

public void setValue(String value) throws DOMException;

Source Link

Document

On retrieval, the value of the attribute is returned as a string.

Usage

From source file:com.amalto.core.storage.hibernate.DefaultStorageClassLoader.java

private static void addProperty(Document document, Node sessionFactoryElement, String propertyName,
        String propertyValue) {//from   w ww .j av a2  s . c o  m
    Element property = document.createElement("property"); //$NON-NLS-1$
    Attr name = document.createAttribute("name"); //$NON-NLS-1$
    name.setValue(propertyName);
    property.getAttributes().setNamedItem(name);
    property.appendChild(document.createTextNode(propertyValue));
    sessionFactoryElement.appendChild(property);
}

From source file:com.amalto.core.storage.hibernate.DefaultStorageClassLoader.java

private static void addEvent(Document document, Node sessionFactoryElement, String eventType,
        String listenerClass) {//  w  ww.  ja  v  a 2  s  . com
    Element event = document.createElement("event"); //$NON-NLS-1$
    Attr type = document.createAttribute("type"); //$NON-NLS-1$
    type.setValue(eventType);
    event.getAttributes().setNamedItem(type);
    {
        Element listener = document.createElement("listener"); //$NON-NLS-1$
        Attr clazz = document.createAttribute("class"); //$NON-NLS-1$
        clazz.setValue(listenerClass);
        listener.getAttributes().setNamedItem(clazz);
        event.appendChild(listener);
    }
    sessionFactoryElement.appendChild(event);
}

From source file:cz.incad.cdk.RepairVCProcess.java

private static void repair(String pid, Document relsExt, FedoraAccess fa, Attr resource, String value) {
    File backupFile = null;//from   w ww .ja  v a2s.  c  om
    try {
        backupFile = backup(pid, relsExt);
        PIDParser parse = new PIDParser(value);
        parse.objectPid();
        resource.setValue(PIDParser.INFO_FEDORA_PREFIX + parse.getObjectPid());
        uploadRELSEXT(pid, relsExt, fa);
        boolean deleted = backupFile.delete();
        LOGGER.info(
                "backup file '" + backupFile.getAbsolutePath() + "' " + (deleted ? "deleted" : "not deleted"));
    } catch (LexerException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (TransformerException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (NoSuchAlgorithmException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    }
}

From source file:com.amalto.core.storage.hibernate.DefaultStorageClassLoader.java

private static void setPropertyValue(Document document, String propertyName, String value)
        throws XPathExpressionException {
    XPathExpression compile = pathFactory
            .compile("hibernate-configuration/session-factory/property[@name='" + propertyName + "']"); //$NON-NLS-1$ //$NON-NLS-2$
    Node node = (Node) compile.evaluate(document, XPathConstants.NODE);
    if (node != null) {
        node.setTextContent(value);/*from  w w w  . j av a2  s  .c om*/
    } else {
        XPathExpression parentNodeExpression = pathFactory.compile("hibernate-configuration/session-factory"); //$NON-NLS-1$
        Node parentNode = (Node) parentNodeExpression.evaluate(document, XPathConstants.NODE);
        // Create a new property element for this datasource-specified property (TMDM-4927).
        Element property = document.createElement("property"); //$NON-NLS-1$
        Attr propertyNameAttribute = document.createAttribute("name"); //$NON-NLS-1$
        property.setAttributeNode(propertyNameAttribute);
        propertyNameAttribute.setValue(propertyName);
        property.setTextContent(value);
        parentNode.appendChild(property);
    }
}

From source file:Main.java

/**
 * Copies all attributes from one element to another in the official way.
 *//*from  w  ww.ja  va2s  . c  o  m*/
public static void copyAttributes(Element elementFrom, Element elementTo) {
    NamedNodeMap nodeList = elementFrom.getAttributes();
    if (nodeList == null) {
        // No attributes to copy: just return
        return;
    }

    Attr attrFrom = null;
    Attr attrTo = null;

    // Needed as factory to create attrs
    Document documentTo = elementTo.getOwnerDocument();
    int len = nodeList.getLength();

    // Copy each attr by making/setting a new one and
    // adding to the target element.
    for (int i = 0; i < len; i++) {
        attrFrom = (Attr) nodeList.item(i);

        // Create an set value
        attrTo = documentTo.createAttribute(attrFrom.getName());
        attrTo.setValue(attrFrom.getValue());

        // Set in target element
        elementTo.setAttributeNode(attrTo);
    }
}

From source file:com.hphoto.server.ApiServlet.java

private static void addAttribute(Document doc, Element node, String name, String value) {
    Attr attribute = doc.createAttribute(name);
    attribute.setValue(getLegalXml(value));
    node.getAttributes().setNamedItem(attribute);
}

From source file:de.codesourcery.spring.contextrewrite.XMLRewrite.java

private static Rule wrap(InsertAttributeRule r) {
    return new Rule(r.xpath(), r.id()) {
        @Override/*from   w  w  w.  j  a v a 2 s.c  o  m*/
        public void apply(Document document, Node matchedNode) throws Exception {
            final Attr attribute = document.createAttribute(r.name());
            attribute.setValue(r.value());
            matchedNode.getAttributes().setNamedItem(attribute);
        }

        @Override
        public String toString() {
            return "INSERT ATTRIBUTE: " + r.xpath() + " with " + r.name() + "=" + r.value();
        }
    };
}

From source file:com.evolveum.midpoint.cli.common.ToolsUtils.java

public static void setNamespaceDeclaration(Element element, String prefix, String namespaceUri) {
    Document doc = element.getOwnerDocument();
    NamedNodeMap attributes = element.getAttributes();
    Attr attr;
    if (prefix == null || prefix.isEmpty()) {
        // default namespace
        attr = doc.createAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE);
    } else {/*  w  w  w.ja  v  a 2s .  com*/
        attr = doc.createAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
                XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix);
    }
    checkValidXmlChars(namespaceUri);
    attr.setValue(namespaceUri);
    attributes.setNamedItem(attr);
}

From source file:com.photon.phresco.framework.commons.QualityUtil.java

private static Attr createAttribute(Document document, String attrName, String attrValue) {
    Attr attr = document.createAttribute(attrName);
    attr.setValue(attrValue);
    return attr;/*from   w w  w . j  a  va2s  .  c o m*/
}

From source file:com.amalto.core.storage.hibernate.MappingGenerator.java

private static void addFieldTypeAttribute(FieldMetadata field, Element columnElement, Element propertyElement,
        RDBMSDataSource.DataSourceDialect dialect) {
    Document document = columnElement.getOwnerDocument();
    Document propertyDocument = propertyElement.getOwnerDocument();
    Attr elementType = propertyDocument.createAttribute("type"); //$NON-NLS-1$
    TypeMetadata fieldType = field.getType();
    String elementTypeName;/*  www  .  j  ava2 s  .c o  m*/

    boolean isMultiLingualOrBase64Binary = Types.MULTI_LINGUAL.equalsIgnoreCase(fieldType.getName())
            || Types.BASE64_BINARY.equalsIgnoreCase(fieldType.getName());
    Object maxLength = CommonUtil.getSuperTypeMaxLength(fieldType, fieldType);

    if (isMultiLingualOrBase64Binary) {
        elementTypeName = TypeMapping.SQL_TYPE_TEXT;
    } else {
        Object sqlType = fieldType.getData(TypeMapping.SQL_TYPE);
        if (sqlType != null) { // SQL Type may enforce use of "CLOB" iso. "LONG VARCHAR"
            elementTypeName = String.valueOf(sqlType);
            if (dialect == RDBMSDataSource.DataSourceDialect.DB2) {
                Attr length = document.createAttribute("length"); //$NON-NLS-1$
                length.setValue("1048576"); //$NON-NLS-1$ 1MB CLOB limit for DB2
                columnElement.getAttributes().setNamedItem(length);
            }
        } else if (maxLength != null) {
            String maxLengthValue = String.valueOf(maxLength);
            int maxLengthInt = Integer.parseInt(maxLengthValue);
            if (maxLengthInt > dialect.getTextLimit()) {
                elementTypeName = TypeMapping.SQL_TYPE_TEXT;
            } else {
                Attr length = document.createAttribute("length"); //$NON-NLS-1$
                length.setValue(maxLengthValue);
                columnElement.getAttributes().setNamedItem(length);
                elementTypeName = HibernateMetadataUtils.getJavaType(fieldType);
            }
        } else if (fieldType.getData(MetadataRepository.DATA_TOTAL_DIGITS) != null
                || fieldType.getData(MetadataRepository.DATA_FRACTION_DIGITS) != null) { // TMDM-8022

            Object totalDigits = fieldType.getData(MetadataRepository.DATA_TOTAL_DIGITS);
            Object fractionDigits = fieldType.getData(MetadataRepository.DATA_FRACTION_DIGITS);

            if (totalDigits != null) {
                int totalDigitsInt = Integer.parseInt(totalDigits.toString());
                totalDigitsInt = totalDigitsInt > dialect.getDecimalPrecision() ? dialect.getDecimalPrecision()
                        : totalDigitsInt;

                String totalDigitsValue = String.valueOf(totalDigitsInt);
                Attr length = document.createAttribute("precision"); //$NON-NLS-1$
                length.setValue(totalDigitsValue);
                columnElement.getAttributes().setNamedItem(length);
            }

            if (fractionDigits != null) {
                int fractionDigitsInt = Integer.parseInt(fractionDigits.toString());
                fractionDigitsInt = fractionDigitsInt >= dialect.getDecimalScale() ? dialect.getDecimalScale()
                        : fractionDigitsInt;

                String fractionDigitsValue = String.valueOf(fractionDigitsInt);
                Attr length = document.createAttribute("scale"); //$NON-NLS-1$
                length.setValue(fractionDigitsValue);
                columnElement.getAttributes().setNamedItem(length);
            }
            elementTypeName = HibernateMetadataUtils.getJavaType(fieldType);
        } else {
            elementTypeName = HibernateMetadataUtils.getJavaType(fieldType);
        }
    }
    // TMDM-4975: Oracle doesn't like when there are too many LONG columns.
    if (dialect == RDBMSDataSource.DataSourceDialect.ORACLE_10G
            && TypeMapping.SQL_TYPE_TEXT.equals(elementTypeName)) {
        if (field.getType().getData(LongString.PREFER_LONGVARCHAR) == null
                && isMultiLingualOrBase64Binary == false) {
            elementTypeName = TypeMapping.SQL_TYPE_CLOB;
        } else {// DATA_CLUSTER_POJO.X_VOCABULARY, X_TALEND_STAGING_ERROR, X_TALEND_STAGING_VALUES, and
                // Types.MULTI_LINGUAL, Types.BASE64_BINARY still use VARCHAR2(4000 CHAR)
            elementTypeName = "string"; //$NON-NLS-1$
            Attr length = document.createAttribute("length"); //$NON-NLS-1$
            length.setValue("4000"); //$NON-NLS-1$
            columnElement.getAttributes().setNamedItem(length);
        }
    }
    elementType.setValue(elementTypeName);
    propertyElement.getAttributes().setNamedItem(elementType);
}