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:org.apache.tuscany.sca.implementation.bpel.ode.TuscanyProcessConfImpl.java
/** * Gets the variable initializer DOM sequence for a given property, in the context of a supplied * DOM model of the BPEL process// ww w. j a v a2 s. co m * @param bpelDOM - DOM representation of the BPEL process * @param property - SCA Property which relates to one of the variables in the BPEL process * @return - a DOM model representation of the XML statements required to initialize the * BPEL variable with the value of the SCA property. */ private Element getInitializerSequence(Document bpelDOM, ComponentProperty property) { // For an XML simple type (string, int, etc), the BPEL initializer sequence is: // <assign><copy><from><literal>value</literal></from><to variable="variableName"/></copy></assign> QName type = property.getXSDType(); if (type != null) { if (mapper.isSimpleXSDType(type)) { // Simple types String NS_URI = bpelDOM.getDocumentElement().getNamespaceURI(); String valueText = getPropertyValueText(property.getValue()); Element literalElement = bpelDOM.createElementNS(NS_URI, "literal"); literalElement.setTextContent(valueText); Element fromElement = bpelDOM.createElementNS(NS_URI, "from"); fromElement.appendChild(literalElement); Element toElement = bpelDOM.createElementNS(NS_URI, "to"); Attr variableAttribute = bpelDOM.createAttribute("variable"); variableAttribute.setValue(property.getName()); toElement.setAttributeNode(variableAttribute); Element copyElement = bpelDOM.createElementNS(NS_URI, "copy"); copyElement.appendChild(fromElement); copyElement.appendChild(toElement); Element assignElement = bpelDOM.createElementNS(NS_URI, "assign"); assignElement.appendChild(copyElement); return assignElement; } // end if // TODO Deal with Properties which have a non-simple type } else { // TODO Deal with Properties which have an element as the type } // end if return null; }
From source file:org.apache.xml.security.test.utils.resolver.ResourceResolverTest.java
/** * Tests registering a custom resolver implementation. */// w w w .jav a2 s . com public static void testCustomResolver() throws Exception { String className = "org.apache.xml.security.test.utils.resolver.OfflineResolver"; ResourceResolver.registerAtStart(className); Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Attr uriAttr = doc.createAttribute("URI"); uriAttr.setValue("http://www.apache.org"); ResourceResolver res = ResourceResolver.getInstance(uriAttr, "http://www.apache.org"); try { uriAttr.setValue("http://xmldsig.pothole.com/xml-stylesheet.txt"); res.resolve(uriAttr, null); } catch (Exception e) { e.printStackTrace(); fail(uriAttr.getValue() + " should be resolvable by the OfflineResolver"); } try { uriAttr.setValue("http://www.apache.org"); res.resolve(uriAttr, null); fail(uriAttr.getValue() + " should not be resolvable by the OfflineResolver"); } catch (Exception e) { } }
From source file:org.apache.xml.security.test.utils.resolver.ResourceResolverTest.java
public static void testLocalFileWithEmptyBaseURI() throws Exception { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Attr uriAttr = doc.createAttribute("URI"); String basedir = System.getProperty("basedir"); String file = new File(basedir, "build.xml").toURI().toString(); uriAttr.setValue(file);/*from w w w . j a v a 2 s .c o m*/ ResourceResolver res = ResourceResolver.getInstance(uriAttr, file); try { res.resolve(uriAttr, ""); } catch (Exception e) { fail(e.getMessage()); } }
From source file:org.bigtextml.topics.ParallelTopicModel.java
private Attr getAttribute(String name, String value, Document doc) { Attr attr = doc.createAttribute(name); attr.setValue(value);//from w w w .j av a2 s. com return attr; }
From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java
/** * Adds the index.// w ww.j av a 2s. com * * @param indexTypeName * the index type name * * @throws DataDictionaryException * the data dictionary exception */ public static void addIndex(final String indexTypeName) throws DataDictionaryException { synchronized (dd) { ensureLoaded(); final Enumeration<DIndex> indiceTypes = _dataDictionaryTypes.getIndices(); while (indiceTypes.hasMoreElements()) { final DIndex dIndexType = indiceTypes.nextElement(); if (dIndexType.getName().equalsIgnoreCase(indexTypeName)) { // CLONE // encode to XML final Document doc = XMLUtils.getDocument(); final Element rootElement = doc.createElementNS(DAnyFinderDataDictionaryCodec.NS, "AnyFinderDataDictionary"); Attr attr = null; attr = doc.createAttribute("xmlns:xsi"); attr.setValue("http://www.w3.org/2001/XMLSchema-instance"); rootElement.setAttributeNode(attr); attr = doc.createAttribute("xsi:schemaLocation"); attr.setValue(DAnyFinderDataDictionaryCodec.NS + " ../xml/AnyFinderDataDictionary.xsd"); rootElement.setAttributeNode(attr); doc.appendChild(rootElement); final DIndex dIndex; try { DIndexCodec.encode(dIndexType, rootElement); } catch (final DDException e) { throw new DataDictionaryException(e); } final Document doc2; try { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); XMLUtils.stream(doc.getDocumentElement(), true, "UTF-8", bos); doc2 = XMLUtils.parse(bos.toByteArray(), true); } catch (final XMLUtilsException e) { throw new DataDictionaryException(e); } final DAnyFinderDataDictionary dictionary; // decode again to DIndex try { dictionary = DAnyFinderDataDictionaryCodec.decode(doc2.getDocumentElement()); } catch (final DDException e) { throw new DataDictionaryException(e); } dIndex = dictionary.getIndex(dIndexType.getName()); addIndex(dIndex); return; } } } throw new DataDictionaryException(String.format("Index type [%s] was not found!", indexTypeName)); }
From source file:org.exoplatform.cms.common.CommonUtils.java
static public File getXMLFile(ByteArrayOutputStream bos, String appName, String objectType, Date createDate, String fileName) throws Exception { byte[] byteData = bos.toByteArray(); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputStream is = new ByteArrayInputStream(byteData); Document document = docBuilder.parse(is); org.w3c.dom.Attr namespace = document.createAttribute("xmlns:exoks"); namespace.setValue("http://www.exoplatform.com/exoks/2.0"); document.getFirstChild().getAttributes().setNamedItem(namespace); org.w3c.dom.Attr attName = document.createAttribute("exoks:applicationName"); attName.setValue(appName);/* ww w . j a va 2 s .c o m*/ document.getFirstChild().getAttributes().setNamedItem(attName); org.w3c.dom.Attr dataType = document.createAttribute("exoks:objectType"); dataType.setValue(objectType); document.getFirstChild().getAttributes().setNamedItem(dataType); org.w3c.dom.Attr exportDate = document.createAttribute("exoks:exportDate"); exportDate.setValue(createDate.toString()); document.getFirstChild().getAttributes().setNamedItem(exportDate); org.w3c.dom.Attr checkSum = document.createAttribute("exoks:checkSum"); checkSum.setValue(generateCheckSum(byteData)); document.getFirstChild().getAttributes().setNamedItem(checkSum); DOMSource source = new DOMSource(document.getFirstChild()); File file = new File(fileName + ".xml"); file.deleteOnExit(); file.createNewFile(); StreamResult result = new StreamResult(file); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.transform(source, result); return file; }
From source file:org.firesoa.common.schema.DOMInitializer.java
protected static void createAttribute(Document doc, Element elem, XmlSchemaAttributeGroupMember attrMember) { if (attrMember instanceof XmlSchemaAttribute) { XmlSchemaAttribute attrSchema = (XmlSchemaAttribute) attrMember; XmlSchemaForm attrForm = attrSchema.getForm(); Attr attr = null;//from www . j ava 2s .com QName attrSchemaQName = attrSchema.getQName(); if (XmlSchemaForm.QUALIFIED.equals(attrForm)) { String attrQualifiedName = getQualifiedName(doc, attrSchemaQName); attr = doc.createAttributeNS(attrSchemaQName.getNamespaceURI(), attrQualifiedName); } else { attr = doc.createAttribute(attrSchema.getName()); } elem.setAttributeNode(attr); String value = ""; if (!StringUtils.isEmpty(attrSchema.getFixedValue())) { value = attrSchema.getFixedValue(); } else if (!StringUtils.isEmpty(attrSchema.getDefaultValue())) { value = attrSchema.getDefaultValue(); } if (!StringUtils.isEmpty(value)) { attr.setValue(value); } } else if (attrMember instanceof XmlSchemaAttributeGroupRef) { XmlSchemaAttributeGroupRef attrGroupRef = (XmlSchemaAttributeGroupRef) attrMember; List<XmlSchemaAttributeGroupMember> groupMembers = attrGroupRef.getRef().getTarget().getAttributes(); for (XmlSchemaAttributeGroupMember groupMember : groupMembers) { createAttribute(doc, elem, groupMember); } } else if (attrMember instanceof XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup attrGroup = (XmlSchemaAttributeGroup) attrMember; List<XmlSchemaAttributeGroupMember> groupMembers = attrGroup.getAttributes(); for (XmlSchemaAttributeGroupMember groupMember : groupMembers) { createAttribute(doc, elem, groupMember); } } }
From source file:org.globus.wsrf.tools.wsdl.TypesProcessor.java
private Element getSchema() throws Exception { Types types = this.definition.getTypes(); if (types == null) { types = definition.createTypes(); this.definition.setTypes(types); }/* www. j av a 2 s . c om*/ Element schema = null; List elementList = types.getExtensibilityElements(); if (elementList.isEmpty()) { UnknownExtensibilityElement extensibilityElement = new UnknownExtensibilityElement(); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = docBuilder.newDocument(); schema = doc.createElementNS(XSD_NS, "xsd:schema"); Attr nameSpace = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsd"); nameSpace.setValue(XSD_NS); schema.setAttributeNode(nameSpace); nameSpace = doc.createAttribute("targetNamespace"); nameSpace.setValue(definition.getTargetNamespace()); schema.setAttributeNode(nameSpace); schema.appendChild(doc.createTextNode("\n ")); doc.appendChild(schema); extensibilityElement.setElement(schema); types.addExtensibilityElement(extensibilityElement); } else { schema = ((UnknownExtensibilityElement) elementList.get(0)).getElement(); } return schema; }
From source file:org.mrgeo.resources.tms.TileMapServiceResource.java
protected static Document mrsPyramidMetadataToTileMapXml(final String raster, final String url, final MrsPyramidMetadata mpm) throws ParserConfigurationException { /*/*from w w w.jav a 2 s. c om*/ * String tileMap = "<?xml version='1.0' encoding='UTF-8' ?>" + * "<TileMap version='1.0.0' tilemapservice='http://localhost/mrgeo-services/api/tms/1.0.0'>" + * " <Title>AfPk Elevation V2</Title>" + " <Abstract>A test of V2 MrsPyramid.</Abstract>" * + " <SRS>EPSG:4326</SRS>" + " <BoundingBox minx='68' miny='33' maxx='72' maxy='35' />" + * " <Origin x='68' y='33' />" + * " <TileFormat width='512' height='512' mime-type='image/tiff' extension='tif' />" + * " <TileSets profile='global-geodetic'>" + * " <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/1' units-per-pixel='0.3515625' order='1' />" * + * " <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/2' units-per-pixel='0.17578125' order='2' />" * + * " <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/3' units-per-pixel='0.08789063' order='3' />" * + * " <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/4' units-per-pixel='0.08789063' order='4' />" * + * " <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/5' units-per-pixel='0.08789063' order='5' />" * + * " <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/6' units-per-pixel='0.08789063' order='6' />" * + * " <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/7' units-per-pixel='0.08789063' order='7' />" * + * " <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/8' units-per-pixel='0.08789063' order='8' />" * + * " <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/9' units-per-pixel='0.08789063' order='9' />" * + * " <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/10' units-per-pixel='0.08789063' order='10' />" * + " </TileSets>" + "</TileMap>"; */ final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // root elements final Document doc = docBuilder.newDocument(); final Element rootElement = doc.createElement("TileMap"); doc.appendChild(rootElement); final Attr v = doc.createAttribute("version"); v.setValue(VERSION); rootElement.setAttributeNode(v); final Attr tilemapservice = doc.createAttribute("tilemapservice"); tilemapservice.setValue(normalizeUrl(normalizeUrl(url).replace(raster, ""))); rootElement.setAttributeNode(tilemapservice); // child elements final Element title = doc.createElement("Title"); title.setTextContent(raster); rootElement.appendChild(title); final Element abst = doc.createElement("Abstract"); abst.setTextContent(""); rootElement.appendChild(abst); final Element srs = doc.createElement("SRS"); srs.setTextContent(SRS); rootElement.appendChild(srs); final Element bbox = doc.createElement("BoundingBox"); rootElement.appendChild(bbox); final Attr minx = doc.createAttribute("minx"); minx.setValue(String.valueOf(mpm.getBounds().w)); bbox.setAttributeNode(minx); final Attr miny = doc.createAttribute("miny"); miny.setValue(String.valueOf(mpm.getBounds().s)); bbox.setAttributeNode(miny); final Attr maxx = doc.createAttribute("maxx"); maxx.setValue(String.valueOf(mpm.getBounds().e)); bbox.setAttributeNode(maxx); final Attr maxy = doc.createAttribute("maxy"); maxy.setValue(String.valueOf(mpm.getBounds().n)); bbox.setAttributeNode(maxy); final Element origin = doc.createElement("Origin"); rootElement.appendChild(origin); final Attr x = doc.createAttribute("x"); x.setValue(String.valueOf(mpm.getBounds().w)); origin.setAttributeNode(x); final Attr y = doc.createAttribute("y"); y.setValue(String.valueOf(mpm.getBounds().s)); origin.setAttributeNode(y); final Element tileformat = doc.createElement("TileFormat"); rootElement.appendChild(tileformat); final Attr w = doc.createAttribute("width"); w.setValue(String.valueOf(mpm.getTilesize())); tileformat.setAttributeNode(w); final Attr h = doc.createAttribute("height"); h.setValue(String.valueOf(mpm.getTilesize())); tileformat.setAttributeNode(h); final Attr mt = doc.createAttribute("mime-type"); mt.setValue("image/tiff"); tileformat.setAttributeNode(mt); final Attr ext = doc.createAttribute("extension"); ext.setValue("tif"); tileformat.setAttributeNode(ext); final Element tilesets = doc.createElement("TileSets"); rootElement.appendChild(tilesets); final Attr profile = doc.createAttribute("profile"); profile.setValue("global-geodetic"); tilesets.setAttributeNode(profile); for (int i = 0; i <= mpm.getMaxZoomLevel(); i++) { final Element tileset = doc.createElement("TileSet"); tilesets.appendChild(tileset); final Attr href = doc.createAttribute("href"); href.setValue(normalizeUrl(normalizeUrl(url)) + "/" + i); tileset.setAttributeNode(href); final Attr upp = doc.createAttribute("units-per-pixel"); upp.setValue(String.valueOf(180d / 256d / Math.pow(2, i))); tileset.setAttributeNode(upp); final Attr order = doc.createAttribute("order"); order.setValue(String.valueOf(i)); tileset.setAttributeNode(order); } return doc; }
From source file:org.mrgeo.resources.tms.TileMapServiceResource.java
protected static Document mrsPyramidToTileMapServiceXml(final String url, final List<String> pyramidNames) throws ParserConfigurationException, DOMException, UnsupportedEncodingException { /*/*w ww. java 2s . c om*/ * String tileMapService = "<?xml version='1.0' encoding='UTF-8' ?>" + * "<TileMapService version='1.0.0' services='http://localhost/mrgeo-services/api/tms/'>" + * " <Title>Example Tile Map Service</Title>" + * " <Abstract>This is a longer description of the example tiling map service.</Abstract>" + * " <TileMaps>" + " <TileMap " + " title='AfPk Elevation V2' " + * " srs='EPSG:4326' " + " profile='global-geodetic' " + * " href='http:///localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2' />" + * " </TileMaps>" + "</TileMapService>"; */ final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // root elements final Document doc = docBuilder.newDocument(); final Element rootElement = doc.createElement("TileMapService"); doc.appendChild(rootElement); final Attr v = doc.createAttribute("version"); v.setValue(VERSION); rootElement.setAttributeNode(v); final Attr service = doc.createAttribute("services"); service.setValue(normalizeUrl(normalizeUrl(url).replace(VERSION, ""))); rootElement.setAttributeNode(service); // child elements final Element title = doc.createElement("Title"); title.setTextContent("Tile Map Service"); rootElement.appendChild(title); final Element abst = doc.createElement("Abstract"); abst.setTextContent("MrGeo MrsPyramid rasters available as TMS"); rootElement.appendChild(abst); final Element tilesets = doc.createElement("TileMaps"); rootElement.appendChild(tilesets); Collections.sort(pyramidNames); for (final String p : pyramidNames) { final Element tileset = doc.createElement("TileMap"); tilesets.appendChild(tileset); final Attr href = doc.createAttribute("href"); href.setValue(normalizeUrl(url) + "/" + URLEncoder.encode(p, "UTF-8")); tileset.setAttributeNode(href); final Attr maptitle = doc.createAttribute("title"); maptitle.setValue(p); tileset.setAttributeNode(maptitle); final Attr srs = doc.createAttribute("srs"); srs.setValue(SRS); tileset.setAttributeNode(srs); final Attr profile = doc.createAttribute("profile"); profile.setValue("global-geodetic"); tileset.setAttributeNode(profile); } return doc; }