List of usage examples for org.w3c.dom Document createAttribute
public Attr createAttribute(String name) throws DOMException;
Attr
of the given name. 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;//from w ww . j a va 2s .c om 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); }
From source file:forge.quest.io.QuestDataIO.java
@SuppressWarnings("unchecked") private static <T> T readAsset(final XStream xs, final Document doc, final String tagName, final Class<T> clasz) { final NodeList nn = doc.getElementsByTagName(tagName); final Node n = nn.item(0); final Attr att = doc.createAttribute("resolves-to"); att.setValue(clasz.getCanonicalName()); n.getAttributes().setNamedItem(att); final String xmlData = XmlUtil.nodeToString(n); return (T) xs.fromXML(xmlData); }
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);/* w w w . j a v a 2s . co m*/ } 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:com.amalto.core.history.UniqueIdTransformer.java
private void _addIds(org.w3c.dom.Document document, Element element, Stack<Integer> levels) { NamedNodeMap attributes = element.getAttributes(); Attr id = document.createAttribute(ID_ATTRIBUTE_NAME); int thisElementId = levels.pop() + 1; StringBuilder builder;/* ww w . j av a 2 s .c o m*/ { builder = new StringBuilder(); for (Integer level : levels) { builder.append(level); } } String prefix = builder.toString().isEmpty() ? StringUtils.EMPTY : builder.toString() + '-'; id.setValue(prefix + element.getNodeName() + '-' + thisElementId); attributes.setNamedItem(id); levels.push(thisElementId); { levels.push(0); NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { Element child = (Element) children.item(i); _addIds(document, child, levels); } } levels.pop(); } }
From source file:de.uzk.hki.da.metadata.MetadataStructure.java
private void addXmlNsToEDM(Document edmDoc, Element rootElement) { Attr xmlns_dc = edmDoc.createAttribute("xmlns:dc"); xmlns_dc.setValue(C.DC_NS.getURI()); rootElement.setAttributeNode(xmlns_dc); Attr xmlns_edm = edmDoc.createAttribute("xmlns:edm"); xmlns_edm.setValue(C.EDM_NS.getURI()); rootElement.setAttributeNode(xmlns_edm); Attr xmlns_dcterms = edmDoc.createAttribute("xmlns:dcterms"); xmlns_dcterms.setValue(C.DCTERMS_NS.getURI()); rootElement.setAttributeNode(xmlns_dcterms); Attr xmlns_rdf = edmDoc.createAttribute("xmlns:rdf"); xmlns_rdf.setValue(C.RDF_NS.getURI()); rootElement.setAttributeNode(xmlns_rdf); Attr xmlns_ore = edmDoc.createAttribute("xmlns:ore"); xmlns_ore.setValue(C.ORE_NS.getURI()); rootElement.setAttributeNode(xmlns_ore); }
From source file:com.amalto.core.history.accessor.UnaryFieldAccessor.java
@Override public void markModified(Marker marker) { Document domDocument = document.asDOM(); Element element = getElement(); if (element != null) { Attr newAttribute = domDocument.createAttribute(MODIFIED_MARKER_ATTRIBUTE); switch (marker) { case ADD: newAttribute.setValue(FieldUpdateAction.MODIFY_ADD_MARKER_VALUE); break; case UPDATE: newAttribute.setValue(FieldUpdateAction.MODIFY_UPDATE_MARKER_VALUE); break; case REMOVE: newAttribute.setValue(FieldUpdateAction.MODIFY_REMOVE_MARKER_VALUE); break; default:/*from w ww .j av a 2 s . c om*/ throw new IllegalArgumentException("No support for marker " + marker); //$NON-NLS-1$ } element.getAttributes().setNamedItem(newAttribute); } }
From source file:clus.statistic.RegressionStatBinaryNomiss.java
@Override public Element getPredictElement(Document doc) { Element stats = doc.createElement("RegressionStatBinaryNomiss"); NumberFormat fr = ClusFormat.SIX_AFTER_DOT; Attr examples = doc.createAttribute("examples"); examples.setValue(fr.format(m_SumWeight)); stats.setAttributeNode(examples);/*from w ww .j ava 2 s.c om*/ for (int i = 0; i < m_NbAttrs; i++) { Element attr = doc.createElement("Target"); Attr name = doc.createAttribute("name"); name.setValue(m_Attrs[i].getName()); attr.setAttributeNode(name); attr.setTextContent(fr.format(getMean(i))); stats.appendChild(attr); } return stats; }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static void setQNameAttribute(Element element, String attributeName, QName attributeValue) { Document doc = element.getOwnerDocument(); Attr attr = doc.createAttribute(attributeName); setQNameAttribute(element, attr, attributeValue, element); }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static void setQNameAttribute(Element element, String attributeName, QName attributeValue, Element definitionElement) { Document doc = element.getOwnerDocument(); Attr attr = doc.createAttribute(attributeName); setQNameAttribute(element, attr, attributeValue, definitionElement); }
From source file:com.amalto.core.history.accessor.AttributeAccessor.java
public void markModified(Marker marker) { Document domDocument = document.asDOM(); Node parentNode = parent.getNode(); if (parentNode != null) { Attr newAttribute = domDocument.createAttribute(MODIFIED_MARKER_ATTRIBUTE); switch (marker) { case ADD: newAttribute.setValue(FieldUpdateAction.MODIFY_ADD_MARKER_VALUE); break; case UPDATE: newAttribute.setValue(FieldUpdateAction.MODIFY_UPDATE_MARKER_VALUE); break; case REMOVE: newAttribute.setValue(FieldUpdateAction.MODIFY_REMOVE_MARKER_VALUE); break; default:// ww w . jav a 2s . c om throw new IllegalArgumentException("No support for marker " + marker); //$NON-NLS-1$ } parentNode.getAttributes().setNamedItem(newAttribute); } }