List of usage examples for org.w3c.dom Attr getValue
public String getValue();
From source file:com.marklogic.dom.ElementImpl.java
/** {@inheritDoc} */ public String getAttribute(String name) { Attr attr = getAttributeNode(name); return attr == null ? "" : attr.getValue(); }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static boolean isEmpty(Attr attr) { if (attr == null) { return true; }/*from www. j a va 2 s . co m*/ return StringUtils.isEmpty(attr.getValue()); }
From source file:jp.igapyon.selecrawler.SeleCrawlerWebContentTrimmer.java
public void processElement(final Element element) throws IOException { final NodeList nodeList = element.getChildNodes(); for (int index = nodeList.getLength() - 1; index >= 0; index--) { final Node node = nodeList.item(index); if (node instanceof Element) { final Element lookup = (Element) node; if ("script".equals(lookup.getTagName())) { // REMOVE script tag. element.removeChild(node); continue; }//from w w w. ja v a2 s . c o m if ("noscript".equals(lookup.getTagName())) { // REMOVE noscript tag. element.removeChild(node); continue; } if ("iframe".equals(lookup.getTagName())) { final NamedNodeMap nnm = lookup.getAttributes(); for (int indexNnm = 0; indexNnm < nnm.getLength(); indexNnm++) { final Attr attr = (Attr) nnm.item(indexNnm); // System.out.println(" " + attr.getName() + " [" + // attr.getValue() + "]"); if ("style".equals(attr.getName())) { final String value = attr.getValue().replaceAll(" ", ""); if (value.indexOf("display:none") >= 0) { // REMOVE iframe tag which is display:none // style.. element.removeChild(node); continue; } } } } processElement(lookup); } } }
From source file:com.amalto.core.history.accessor.ManyFieldAccessor.java
public String getActualType() { Attr type = getCollectionItemNode().getAttributeNodeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); //$NON-NLS-1$ if (type == null) { return StringUtils.EMPTY; } else {//from w ww .jav a2 s . co m return type.getValue(); } }
From source file:com.sap.research.connectivity.gw.GwOperationsImpl.java
public void createEntity(final String endpointName, final String remoteEntitySetName) throws Exception { final String subPackagePath = getSubPackagePath(oDataFolder); // Verify if the endpoint and remote entity set are valid if (!fileManager.exists(subPackagePath + SEPARATOR + endpointName + "_metadata.xml")) { throw new Exception("Namespace \"" + endpointName + "\" does not exist or is corrupted. Please specify a valid namespace."); } else {//w w w .j a v a2 s . co m InputStream metaDataIs = fileManager .getInputStream(subPackagePath + SEPARATOR + endpointName + "_metadata.xml"); Document doc = XmlUtils.getDocumentBuilder().parse(metaDataIs); NodeList nodeList = doc.getElementsByTagName("entity"); boolean remoteEntityExists = false; for (int i = 0; i < nodeList.getLength(); i++) { Attr attr = (Attr) nodeList.item(i).getAttributes().getNamedItem("name"); if (attr.getValue().toString().equals(remoteEntitySetName)) { remoteEntityExists = true; break; } } if (!remoteEntityExists) { throw new Exception("Remote entity set \"" + remoteEntitySetName + "\" does not exist. Please specify a valid remote entity."); } } // Create entity class and add JPA Annotations. int modifier = Modifier.PUBLIC; String localEntityPath = typeLocationService.getTopLevelPackageForModule( projectOperations.getFocusedModule()) + "." + domain + "." + remoteEntitySetName; JavaType localEntity = new JavaType(localEntityPath); final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(localEntity, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder( declaredByMetadataId, modifier, localEntity, PhysicalTypeCategory.CLASS); final List<AnnotationMetadataBuilder> annotationBuilder = new ArrayList<AnnotationMetadataBuilder>(); annotationBuilder.add(ROO_JAVA_BEAN_BUILDER); annotationBuilder.add(ROO_TO_STRING_BUILDER); annotationBuilder.add(ROO_JPA_ACTIVE_RECORD_BUILDER); cidBuilder.setAnnotations(annotationBuilder); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build()); }
From source file:gov.nih.nci.caadapter.ws.AddNewScenario.java
/** * Update the reference in .map to the .scs and .h3s files. * * @param mapplingFileName mapping file name *///from w w w . j a v a 2s. c om public void updateMapping(String mapplingBakFileName) throws Exception { Document xmlDOM = readFile(mapplingBakFileName); NodeList components = xmlDOM.getElementsByTagName("component"); for (int i = 0; i < components.getLength(); i++) { Element component = (Element) components.item(i); //update location of SCS, H3S Attr locationAttr = component.getAttributeNode("location"); Attr kindAttr = component.getAttributeNode("kind"); if (locationAttr != null) { String cmpKind = ""; if (kindAttr != null) cmpKind = kindAttr.getValue(); if (cmpKind != null && cmpKind.equalsIgnoreCase("v2")) continue; String localName = extractOriginalFileName(locationAttr.getValue()); locationAttr.setValue(localName); } //update VOM reference Attr groupAttr = component.getAttributeNode("group"); if (groupAttr != null && groupAttr.getValue() != null && groupAttr.getValue().equalsIgnoreCase("vocabulary")) { NodeList chldComps = component.getElementsByTagName("data"); for (int j = 0; j < chldComps.getLength(); j++) { Element chldElement = (Element) chldComps.item(j); Attr valueAttr = chldElement.getAttributeNode("value"); if (valueAttr != null) { String localFileName = extractOriginalFileName(valueAttr.getValue()); valueAttr.setValue(localFileName); } } } } System.out.println("AddNewScenario.updateMapping()..mapbakfile:" + mapplingBakFileName); outputXML(xmlDOM, mapplingBakFileName.substring(0, mapplingBakFileName.lastIndexOf(".bak"))); }
From source file:net.sourceforge.ajaxtags.tags.AjaxAnchorsTag.java
/** * Rewrite link. Change (or create) "onclick" attribute, set "href" attribute to * "javascript://nop/"./*w w w .j av a2 s .c om*/ * * @param link * node of document with link * @param target * target of request */ protected final void rewriteLink(final Node link, final String target) { final NamedNodeMap map = link.getAttributes(); final Attr href = (Attr) map.getNamedItem("href"); if (href != null) { Attr onclick = (Attr) map.getNamedItem("onclick"); if (onclick == null) { onclick = link.getOwnerDocument().createAttribute("onclick"); map.setNamedItem(onclick); } onclick.setValue(getOnclickAjax(target, href.getValue(), getOptionsBuilder())); href.setValue("javascript://nop/"); } }
From source file:com.amalto.core.history.accessor.UnaryFieldAccessor.java
@Override public String getActualType() { Attr type = ((Element) getNode()).getAttributeNodeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); //$NON-NLS-1$ if (type == null) { type = ((Element) getNode()).getAttributeNodeNS(SkipAttributeDocumentBuilder.TALEND_NAMESPACE, "type"); //$NON-NLS-1$ }//from w ww .ja va2 s . co m if (type == null) { return StringUtils.EMPTY; } else { return type.getValue(); } }
From source file:curam.molsa.test.customfunctions.MOLSATestDatastore.java
/** * this is to map the attribute//from w w w . j a v a 2 s . c om * @param entityXMLElement * @param dsEntity * @param knownAttributeName */ private void mapAttribute(final Element entityXMLElement, final Entity dsEntity, final String knownAttributeName) { final Attr attributeNode = entityXMLElement.getAttributeNode(knownAttributeName); if (attributeNode != null) { final String attributeValue = attributeNode.getValue(); dsEntity.setAttribute(knownAttributeName, attributeValue); } }
From source file:com.photon.maven.plugins.android.standalonemojos.ManifestUpdateMojo.java
public void updateManifest(File manifestFile) throws IOException, ParserConfigurationException, SAXException, TransformerException, MojoFailureException { Document doc = readManifest(manifestFile); Element manifestElement = doc.getDocumentElement(); boolean dirty = false; if (StringUtils.isEmpty(parsedVersionName)) { // default to ${project.version} parsedVersionName = project.getVersion(); }//from www.j a v a 2s .c o m Attr versionNameAttrib = manifestElement.getAttributeNode(ATTR_VERSION_NAME); if (versionNameAttrib == null || !StringUtils.equals(parsedVersionName, versionNameAttrib.getValue())) { getLog().info("Setting " + ATTR_VERSION_NAME + " to " + parsedVersionName); manifestElement.setAttribute(ATTR_VERSION_NAME, parsedVersionName); dirty = true; } if ((parsedVersionCodeAutoIncrement && parsedVersionCode != null) || (parsedVersionCodeUpdateFromVersion && parsedVersionCode != null) || (parsedVersionCodeAutoIncrement && parsedVersionCodeUpdateFromVersion)) { throw new MojoFailureException("versionCodeAutoIncrement, versionCodeUpdateFromVersion and versionCode " + "are mutual exclusive. They cannot be specified at the same time. " + "Please specify either versionCodeAutoIncrement, versionCodeUpdateFromVersion or versionCode!"); } if (parsedVersionCodeAutoIncrement) { Attr versionCode = manifestElement.getAttributeNode(ATTR_VERSION_CODE); int currentVersionCode = 0; if (versionCode != null) { currentVersionCode = NumberUtils.toInt(versionCode.getValue(), 0); } currentVersionCode++; manifestElement.setAttribute(ATTR_VERSION_CODE, String.valueOf(currentVersionCode)); dirty = true; } if (parsedVersionCodeUpdateFromVersion) { String verString = project.getVersion(); getLog().debug("Generating versionCode for " + verString); ArtifactVersion artifactVersion = new DefaultArtifactVersion(verString); String verCode = Integer.toString(artifactVersion.getMajorVersion()) + Integer.toString(artifactVersion.getMinorVersion()) + Integer.toString(artifactVersion.getIncrementalVersion()); getLog().info("Setting " + ATTR_VERSION_CODE + " to " + verCode); manifestElement.setAttribute(ATTR_VERSION_CODE, verCode); dirty = true; } if (parsedVersionCode != null) { Attr versionCodeAttr = manifestElement.getAttributeNode(ATTR_VERSION_CODE); int currentVersionCode = 0; if (versionCodeAttr != null) { currentVersionCode = NumberUtils.toInt(versionCodeAttr.getValue(), 0); } if (currentVersionCode != parsedVersionCode) { getLog().info("Setting " + ATTR_VERSION_CODE + " to " + parsedVersionCode); manifestElement.setAttribute(ATTR_VERSION_CODE, String.valueOf(parsedVersionCode)); dirty = true; } } if (!StringUtils.isEmpty(parsedSharedUserId)) { Attr sharedUserIdAttrib = manifestElement.getAttributeNode(ATTR_SHARED_USER_ID); if (sharedUserIdAttrib == null || !StringUtils.equals(parsedSharedUserId, sharedUserIdAttrib.getValue())) { getLog().info("Setting " + ATTR_SHARED_USER_ID + " to " + parsedSharedUserId); manifestElement.setAttribute(ATTR_SHARED_USER_ID, parsedSharedUserId); dirty = true; } } if (parsedDebuggable != null) { NodeList appElems = manifestElement.getElementsByTagName(ELEM_APPLICATION); // Update all application nodes. Not sure whether there will ever be more than one. for (int i = 0; i < appElems.getLength(); ++i) { Node node = appElems.item(i); getLog().info("Testing if node " + node.getNodeName() + " is application"); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; Attr debuggableAttrib = element.getAttributeNode(ATTR_DEBUGGABLE); if (debuggableAttrib == null || parsedDebuggable != BooleanUtils.toBoolean(debuggableAttrib.getValue())) { getLog().info("Setting " + ATTR_DEBUGGABLE + " to " + parsedDebuggable); element.setAttribute(ATTR_DEBUGGABLE, String.valueOf(parsedDebuggable)); dirty = true; } } } } if (dirty) { if (!manifestFile.delete()) { getLog().warn("Could not remove old " + manifestFile); } getLog().info("Made changes to manifest file, updating " + manifestFile); writeManifest(manifestFile, doc); } else { getLog().info("No changes found to write to manifest file"); } }