Java Code Examples for org.w3c.dom.Element#setAttribute()
The following examples show how to use
org.w3c.dom.Element#setAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataUploadService.java From open with GNU General Public License v3.0 | 6 votes |
private void addTrackPoint(DateTimeFormatter isoDateParser, Cursor cursor, Document document, Element trksegElement) { int latIndex = cursor.getColumnIndex(COLUMN_LAT); int lonIndex = cursor.getColumnIndex(COLUMN_LNG); int altIndex = cursor.getColumnIndex(COLUMN_ALT); int timeIndex = cursor.getColumnIndex(COLUMN_TIME); int speedIndex = cursor.getColumnIndex(COLUMN_SPEED); Element trkptElement = document.createElement("trkpt"); Element elevationElement = document.createElement("ele"); Element timeElement = document.createElement("time"); Element speedElement = document.createElement("speed"); trkptElement.setAttribute("lat", cursor.getString(latIndex)); trkptElement.setAttribute("lon", cursor.getString(lonIndex)); elevationElement.setTextContent(cursor.getString(altIndex)); DateTime date = new DateTime(cursor.getLong(timeIndex)); timeElement.setTextContent(date.toString(isoDateParser)); speedElement.setTextContent(String.valueOf(cursor.getDouble(speedIndex))); trkptElement.appendChild(elevationElement); trkptElement.appendChild(timeElement); trkptElement.appendChild(speedElement); trksegElement.appendChild(trkptElement); }
Example 2
Source File: PlanBodyImpl.java From jason with GNU Lesser General Public License v3.0 | 6 votes |
/** get as XML */ public Element getAsDOM(Document document) { Element eb = (Element) document.createElement("body"); PlanBody bl = this; while (bl != null && !bl.isEmptyBody()) { Element u = (Element) document.createElement("body-literal"); if (bl.getBodyType().toString().length() > 0) { u.setAttribute("type", bl.getBodyType().toString()); } u.appendChild( ((Structure)bl.getBodyTerm()).getAsDOM(document)); eb.appendChild(u); bl = bl.getBodyNext(); } return eb; }
Example 3
Source File: RDFUtils.java From oodt with Apache License 2.0 | 6 votes |
public static Element getRDFElement(String key, String val, RDFConfig conf, Document doc) { // first apply the rewrite rules String tagName = conf.getRewriteMap().containsKey(key) ? conf .getRewriteMap().get(key) : key; // does this tag have a namespace? if not, use the default String ns = conf.getKeyNs(key); Element elem; // is this a resource link? if (conf.getResLinkMap().containsKey(key)) { elem = doc.createElement(ns + ":" + tagName); String linkBase = conf.getResLinkMap().get(key).endsWith("/") ? conf .getResLinkMap().get(key) : conf.getResLinkMap().get(key) + "/"; elem.setAttribute(RDF_RES_ATTR, linkBase + val); } else { elem = doc.createElement(ns + ":" + tagName); elem.appendChild(doc.createTextNode(val)); } return elem; }
Example 4
Source File: AbstractXMLConfigurationAction.java From walkmod-core with GNU Lesser General Public License v3.0 | 6 votes |
public List<Element> createIncludeList(String[] includes, String path) { List<Element> result = null; if (includes != null) { result = new LinkedList<Element>(); Document document = provider.getDocument(); int limit = path.length(); if (!path.endsWith("/")) { limit++; } for (String include : includes) { Element includeElem = document.createElement("include"); if(include.startsWith(path)){ include = include.substring(limit); } includeElem.setAttribute("wildcard", include); result.add(includeElem); } } return result; }
Example 5
Source File: PDFDomTree.java From Pdf2Dom with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates an element that represents an image drawn at the specified coordinates in the page. * @param x the X coordinate of the image * @param y the Y coordinate of the image * @param width the width coordinate of the image * @param height the height coordinate of the image * @param type the image type: <code>"png"</code> or <code>"jpeg"</code> * @param resource the image data depending on the specified type * @return */ protected Element createImageElement(float x, float y, float width, float height, ImageResource resource) throws IOException { StringBuilder pstyle = new StringBuilder("position:absolute;"); pstyle.append("left:").append(x).append(UNIT).append(';'); pstyle.append("top:").append(y).append(UNIT).append(';'); pstyle.append("width:").append(width).append(UNIT).append(';'); pstyle.append("height:").append(height).append(UNIT).append(';'); //pstyle.append("border:1px solid red;"); Element el = doc.createElement("img"); el.setAttribute("style", pstyle.toString()); String imgSrc = config.getImageHandler().handleResource(resource); if (!disableImageData && !imgSrc.isEmpty()) el.setAttribute("src", imgSrc); else el.setAttribute("src", ""); return el; }
Example 6
Source File: XMLHelpersTest.java From SAMLRaider with MIT License | 6 votes |
@Test public void testXSW() throws SAXException, ParserConfigurationException, TransformerException{ Document document = xmlHelpers.getXMLDocumentOfSAMLMessage(messageSignedResponse); Element response = (Element) document.getElementsByTagNameNS("*", "Response").item(0); Element assertion = (Element) response.getElementsByTagNameNS("*", "Assertion").item(0); DocumentBuilderFactory documentBuilderFactory = xmlHelpers.getDBF(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document newDoc = documentBuilder.newDocument(); Element newRootResponse = (Element) newDoc.importNode(response, false); Element newAssertion = (Element) newDoc.importNode(assertion, true); newRootResponse.setAttribute("ID", "_evil_response_ID"); newDoc.appendChild(newRootResponse); newDoc.adoptNode(response); Element clonedAssertion = (Element) newAssertion.cloneNode(true); clonedAssertion.setAttribute("ID", "_evil_Assertion_ID"); newRootResponse.appendChild(response); newRootResponse.appendChild(clonedAssertion); Element newClonedSignature = (Element) clonedAssertion.getElementsByTagNameNS("*", "Signature").item(0); clonedAssertion.removeChild(newClonedSignature); }
Example 7
Source File: XMLCipher.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * @return the XML Element form of that Reference */ public Element toElement() { String tagName = getType(); Element result = ElementProxy.createElementForFamily( contextDocument, EncryptionConstants.EncryptionSpecNS, tagName ); result.setAttribute(EncryptionConstants._ATT_URI, uri); // TODO: Need to martial referenceInformation // Figure out how to make this work.. // <any namespace="##other" minOccurs="0" maxOccurs="unbounded"/> return result; }
Example 8
Source File: CatalogExportModuleDispatcher.java From olat with Apache License 2.0 | 6 votes |
protected void createXML() { log.debug("Creating catalog export XML file..."); final Document doc = domBuilder.newDocument(); // create new XML document final Element cat = doc.createElement(XML_CAT); // catalog element doc.appendChild(cat); cat.setAttribute("date", String.valueOf(System.currentTimeMillis())); // set date in catalog element final Element root = doc.createElement(XML_NODE); // root node root.setAttribute("name", "root"); cat.appendChild(root); final List ces = catalogService.getRootCatalogEntries(); for (final Iterator it = ces.iterator(); it.hasNext();) { // for every root entry (currently only one) final CatalogEntry ce = (CatalogEntry) it.next(); getCatalogSubStructure(doc, root, catalogService, ce); // scan this entry } try { catalogExportModuleEBL.transformCatalogXml(doc); } catch (final Exception e) { log.error("Error writing catalog export file.", e); } }
Example 9
Source File: WSDLDocCreator.java From jolie with GNU Lesser General Public License v2.1 | 5 votes |
private void addMessageType( TypeDefinition rootType, String typename ) throws Exception { // when converting from Jolie type of messages must have root type = "void" // no type link are allowed for conversion // message types define elements if( !rootTypes.contains( rootType.id() ) ) { Element newEl = schemaDocument.createElement( "xs:element" ); newEl.setAttribute( "name", typename ); if( rootType instanceof TypeInlineDefinition ) { newEl.appendChild( createTypeDefinition( (TypeInlineDefinition) rootType, true ) ); rootTypes.add( typename ); schemaRootElement.appendChild( newEl ); if( ((TypeInlineDefinition) rootType).nativeType() != NativeType.VOID ) { throw (new Exception( "ERROR, type " + rootType.id() + ": conversion not allowed when the types defined as operation messages have native type different from void!" )); } } else if( rootType instanceof TypeDefinitionLink ) { throw (new Exception( "ERROR, type " + rootType.id() + ":conversion not allowed when the types defined as operation messages are linked type!" )); // newEl.appendChild( lookForLinkedType( (TypeDefinitionLink ) rootType, typename )); // schemaRootElement.appendChild( createTypeDefinitionLink( ( TypeDefinitionLink ) rootType, true, // typename )); } else if( rootType instanceof TypeChoiceDefinition ) { throw (new Exception( "ERROR, type " + rootType.id() + ":conversion not allowed when the types defined as operation messages are choice types!" )); } } }
Example 10
Source File: SamlSignatureTest.java From keycloak with Apache License 2.0 | 5 votes |
public static void applyXSW5(Document document){ Element evilAssertion = (Element) document.getElementsByTagNameNS(ASSERTION_NSURI.get(), "Assertion").item(0); Element assertion = (Element) evilAssertion.cloneNode(true); Element copiedSignature = (Element) assertion.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature").item(0); Assume.assumeThat("Assertion needs to be signed", copiedSignature, notNullValue()); assertion.removeChild(copiedSignature); document.getDocumentElement().appendChild(assertion); evilAssertion.setAttribute("ID", "_evil_assertion_ID"); }
Example 11
Source File: XMLSchemaBuilder.java From regxmllib with BSD 2-Clause "Simplified" License | 5 votes |
void applyRule6_3(Element root, ExtendibleEnumerationTypeDefinition definition) throws RuleException { /* NOTE: ST 2001-1 does not allow arbitrary AUIDs. This should be corrected. */ Element simpleType = root.getOwnerDocument().createElementNS(XSD_NS, "xs:simpleType"); simpleType.setAttribute("name", definition.getSymbol()); Element restriction = root.getOwnerDocument().createElementNS(XSD_NS, "xs:restriction"); restriction.setAttribute("base", "reg:AUID"); root.appendChild(simpleType).appendChild(restriction); }
Example 12
Source File: DOMOutputCapsule.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * appends a new Element with the given name to currentElement, sets * currentElement to be new Element, and returns the new Element as well */ private Element appendElement(String name) { Element ret = doc.createElement(name); if (currentElement == null) { ret.setAttribute("format_version", Integer.toString(FormatVersion.VERSION)); doc.appendChild(ret); } else { currentElement.appendChild(ret); } currentElement = ret; return ret; }
Example 13
Source File: DPPParameterValueWrapper.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
public void saveValueToXML(@Nonnull Element xmlElement) { final Document document = xmlElement.getOwnerDocument(); final Element[] msLevelElements = new Element[MSLevel.cropValues().length]; xmlElement.setAttribute(DIFFMSN_ELEMENT, differentiateMSn.toString()); for (MSLevel mslevel : MSLevel.cropValues()) { msLevelElements[mslevel.ordinal()] = document.createElement(WRAPPER_ELEMENT); msLevelElements[mslevel.ordinal()].setAttribute(MSLEVEL_ELEMENT, MSLEVEL_VALUE_ELEMENT[mslevel.ordinal()]); xmlElement.appendChild(msLevelElements[mslevel.ordinal()]); queues[mslevel.ordinal()].saveToXML(msLevelElements[mslevel.ordinal()]); } }
Example 14
Source File: STSServiceImpl.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
private void addDesignators(List<SAMLAttributeDesignator> designators, Document doc) { Element attributeQuery = (Element)doc.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:protocol", "AttributeQuery").item(0); Iterator i$ = designators.iterator(); while(i$.hasNext()) { SAMLAttributeDesignator attr = (SAMLAttributeDesignator)i$.next(); Element attrEl = doc.createElementNS("urn:oasis:names:tc:SAML:1.0:assertion", "saml:AttributeDesignator"); attrEl.setAttribute("AttributeName", attr.getName()); attrEl.setAttribute("AttributeNamespace", attr.getNamespace()); attributeQuery.appendChild(attrEl); } }
Example 15
Source File: BarFileUtilsTest.java From io with Apache License 2.0 | 5 votes |
/** * スキーマなしBoxへのインストールでACL_URLのBoxが正しくない場合にバリデートがfalseで返却されること. */ @Test @Ignore public void スキーマなしBoxへのインストールでACL_URLのBoxが正しくない場合にバリデートがfalseで返却されること() { // デフォルトBoxではない final String baseUrl = "https://baseserver/testcell1/__role/_a_/col1/"; final String schemaUrl = null; try { DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docbuilder; docbuilder = dbfactory.newDocumentBuilder(); Document document = docbuilder.newDocument(); Element element = document.createElement("acl"); element.setAttribute("xml:base", baseUrl); assertFalse(BarFileUtils.aclNameSpaceValidate("90_rootprops.xml", element, schemaUrl)); return; } catch (ParserConfigurationException e) { fail("DOM Parsing Error: " + e.getMessage()); } catch (DcCoreException dce) { String code = dce.getCode(); assertEquals(DcCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.getCode(), code); return; } catch (Exception ex) { fail("Unexpected exception"); } fail("DcCoreExceptionが返却されない"); }
Example 16
Source File: XMLModel40Serializer.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 4 votes |
@Override protected void serialize(Model aModel, Document aDocument) { Element theRootElement = addElement(aDocument, aDocument, MODEL); theRootElement.setAttribute(VERSION, getVersion()); Element theConfigurationElement = addElement(aDocument, theRootElement, CONFIGURATION); Element theDialectElement = addElement(aDocument, theConfigurationElement, PROPERTY); theDialectElement.setAttribute(NAME, DIALECT); theDialectElement.setAttribute(VALUE, aModel.getDialect().getUniqueName()); for (Map.Entry<String, String> theEntry : aModel.getProperties().getProperties().entrySet()) { Element thePropertyElement = addElement(aDocument, theConfigurationElement, PROPERTY); thePropertyElement.setAttribute(NAME, theEntry.getKey()); thePropertyElement.setAttribute(VALUE, theEntry.getValue()); } Element theCustomTypesElement = addElement(aDocument, theRootElement, CUSTOMTYPES); for (CustomType theCustomType : aModel.getCustomTypes()) { getXMLCustomTypeSerializer(this).serialize(theCustomType, aDocument, theCustomTypesElement); } Element theDomainsElement = addElement(aDocument, theRootElement, DOMAINS); for (Domain theDomain : aModel.getDomains()) { getXMLDomainSerializer().serialize(theDomain, aDocument, theDomainsElement); } Element theTablesElement = addElement(aDocument, theRootElement, TABLES); for (Table theTable : aModel.getTables()) { getXMLTableSerializer(this).serialize(theTable, aDocument, theTablesElement); } Element theRelationsElement = addElement(aDocument, theRootElement, RELATIONS); for (Relation theRelation : aModel.getRelations()) { getXMLRelationSerializer().serialize(theRelation, aDocument, theRelationsElement); } Element theViewsElement = addElement(aDocument, theRootElement, VIEWS); for (View theView : aModel.getViews()) { getXMLViewSerializer().serialize(theView, aDocument, theViewsElement); } Element theSubjectAreasElement = addElement(aDocument, theRootElement, SUBJECTAREAS); for (SubjectArea theSubjectArea : aModel.getSubjectAreas()) { getXMLSubjectAreaSerializer().serialize(theSubjectArea, aDocument, theSubjectAreasElement); } Element theCommentsElement = addElement(aDocument, theRootElement, COMMENTS); for (Comment theComment : aModel.getComments()) { getXMLCommentSerializer().serialize(theComment, aDocument, theCommentsElement); } }
Example 17
Source File: XmlStructFactory.java From oodt with Apache License 2.0 | 4 votes |
public static Document getProductTypeMapXmlDocument(ConcurrentHashMap<String, List<org.apache.oodt.cas.filemgr.structs.Element>> productTypeMap, ConcurrentHashMap<String, String> subToSuperMap) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document document; try { DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); Element root = (Element) document .createElement("cas:producttypemap"); root.setAttribute("xmlns:cas", "http://oodt.jpl.nasa.gov/1.0/cas"); document.appendChild(root); // Also print types without elements but just with parents ArrayList<String> allTypes = new ArrayList<String>(productTypeMap.keySet()); for(String type: subToSuperMap.keySet()) { if(!allTypes.contains(type)) { allTypes.add(type); } } for (String typeId : allTypes) { Element typeElem = document.createElement("type"); typeElem.setAttribute("id", typeId); boolean hasParent = false; if (subToSuperMap.containsKey(typeId)) { typeElem.setAttribute("parent", subToSuperMap .get(typeId)); hasParent = true; } List<org.apache.oodt.cas.filemgr.structs.Element> elementIds = productTypeMap.get(typeId); if (!hasParent && (elementIds == null || elementIds.size() == 0)) { // If no parent, and no elements, don't add this type to the xml continue; } if (elementIds != null) { for (org.apache.oodt.cas.filemgr.structs.Element elementId1 : elementIds) { String elementId = elementId1.getElementId(); Element elementElem = document.createElement("element"); elementElem.setAttribute("id", elementId); typeElem.appendChild(elementElem); } } root.appendChild(typeElem); } return document; } catch (ParserConfigurationException pce) { LOG.log(Level.WARNING, "Error generating product-type-element-map xml file!: " + pce.getMessage()); } return null; }
Example 18
Source File: BaseSiteService.java From sakai with Educational Community License v2.0 | 4 votes |
/** * @inheritDoc */ public String merge(String siteId, Element el, String creatorId) { StringBuilder msg = new StringBuilder(); try { // if the target site already exists, don't change the site attributes Site s = getSite(siteId); } catch (IdUnusedException e) { try { // reserve a site with this id from the info store - if it's in use, this will return null // check security (throws if not permitted) // TODO: why security on add_user_site? -ggolden unlock(SECURE_ADD_USER_SITE, siteReference(siteId)); // reserve a site with this id from the info store - if it's in use, this will return null BaseSite site = (BaseSite) storage().put(siteId); if (site == null) { msg.append(this + "cannot find site: " + siteId); } else { site.setEvent(SECURE_ADD_SITE); if (creatorId != null) { el.setAttribute("created-id", creatorId); } // assign source site's attributes to the target site ((BaseSite) site).set(new BaseSite(this, el, timeService()), false); try { save(site); } catch (Exception t) { log.warn(".merge: " + t); } } } catch (PermissionException ignore) { } } return msg.toString(); }
Example 19
Source File: XsltFOFunctions.java From docx4j-export-FO with Apache License 2.0 | 4 votes |
/** * This is invoked on every paragraph, whether it has a pPr or not. * * @param wmlPackage * @param pPrNodeIt * @param pStyleVal * @param childResults - the already transformed contents of the paragraph. * @return */ public static DocumentFragment createBlockForPPr( FOConversionContext context, NodeIterator pPrNodeIt, String pStyleVal, NodeIterator childResults) { DocumentFragment df = createBlock( context, pPrNodeIt, pStyleVal, childResults, false); // Arabic (and presumably Hebrew) fix // If we have inline direction="rtl" (created by TextDirection class) // wrap the inline with: // <bidi-override direction="rtl" unicode-bidi="embed"> /* See further: From: Glenn Adams <[email protected]> Date: Fri, Mar 21, 2014 at 8:41 AM Subject: Re: right align arabic in table-cell To: FOP Users <[email protected]> */ Element block = (Element)df.getFirstChild(); NodeList blockChildren = block.getChildNodes(); for (int i = 0 ; i <blockChildren.getLength(); i++ ) { if (blockChildren.item(i) instanceof Element) { Element inline = (Element)blockChildren.item(i); if (inline !=null && inline.getAttribute("direction")!=null && inline.getAttribute("direction").equals("rtl")) { inline.removeAttribute("direction"); Element bidiOverride = df.getOwnerDocument().createElementNS("http://www.w3.org/1999/XSL/Format", "fo:bidi-override"); bidiOverride.setAttribute("unicode-bidi", "embed" ); bidiOverride.setAttribute("direction", "rtl" ); block.replaceChild(bidiOverride, inline); bidiOverride.appendChild(inline); } } } if (foContainsElement(block, "leader")) { // ptab to leader implementation: // for leader to work as expected in fop, we need text-align-last; see http://xmlgraphics.apache.org/fop/faq.html#leader-expansion // this code adds that. // Note that it doesn't seem to be necessary for leader in TOC, but it doesn't hurt block.setAttribute("text-align-last", "justify"); } return df; }
Example 20
Source File: XMLSchemaBuilder.java From regxmllib with BSD 2-Clause "Simplified" License | 4 votes |
/** * Generates a single XML Schema document from a single Metadictionary. A * definition from the latter may reference a definition from another * Metadictionary, i.e. in a different namespace, as long as this second * Metadictionary can be resolved by the {@link DefinitionResolver} provided * a creation-time. * * @param dict Metadictionary for which an XML Schema will be generated. * * @return XML Schema document * * @throws javax.xml.parsers.ParserConfigurationException * @throws com.sandflow.smpte.klv.exceptions.KLVException * @throws com.sandflow.smpte.regxml.XMLSchemaBuilder.RuleException * @throws org.xml.sax.SAXException * @throws java.io.IOException */ public Document fromDictionary(MetaDictionary dict) throws ParserConfigurationException, KLVException, RuleException, SAXException, IOException { /* reset namespace prefixes */ this.prefixes.clear(); /* create the DOM from the STD_DECL template */ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); doc.setXmlStandalone(true); Element schema = doc.createElementNS(XSD_NS, "xs:schema"); schema.setAttribute("targetNamespace", dict.getSchemeURI().toString()); schema.setAttributeNS(XMLNS_NS, "xmlns:reg", REGXML_NS); schema.setAttributeNS(XMLNS_NS, "xmlns:xlink", XLINK_NS); schema.setAttribute("elementFormDefault", "qualified"); schema.setAttribute("attributeFormDefault", "unqualified"); doc.appendChild(schema); Element importelem = doc.createElementNS(XSD_NS, "xs:import"); importelem.setAttribute("namespace", XLINK_NS); importelem.setAttribute("schemaLocation", XLINK_LOC); doc.getDocumentElement().appendChild(importelem); importelem = doc.createElementNS(XSD_NS, "xs:import"); importelem.setAttribute("namespace", REGXML_NS); doc.getDocumentElement().appendChild(importelem); for (Definition definition : dict.getDefinitions()) { if (definition instanceof ClassDefinition) { applyRule4(doc.getDocumentElement(), (ClassDefinition) definition); } else if (definition.getClass() == PropertyDefinition.class) { applyRule5(doc.getDocumentElement(), (PropertyDefinition) definition); } else if (definition.getClass() == PropertyAliasDefinition.class) { /* need to supress alias declaration since they use the same symbol and AUID as parent */ } else { applyRule6(doc.getDocumentElement(), definition); } } /* hack to clean-up namespace prefixes */ for (URI uri : prefixes.getURIs()) { doc.getDocumentElement().setAttributeNS( XMLNS_NS, "xmlns:" + prefixes.getPrefixOrCreate(uri), uri.toString() ); if (!uri.equals(dict.getSchemeURI())) { importelem = doc.createElementNS(XSD_NS, "xs:import"); importelem.setAttribute("namespace", uri.toString()); doc.getDocumentElement().insertBefore(importelem, doc.getDocumentElement().getFirstChild()); } } return doc; }