List of usage examples for org.w3c.dom Element getFirstChild
public Node getFirstChild();
From source file:org.getwheat.harvest.library.dom.DomHelper.java
/** * Extracts the value for the specified tag. * /*from w ww . jav a2 s. c o m*/ * @param element the Element to search * @param tag the XML Tag to find * @return a String or null if not found */ public String getStringValue(final Element element, final XmlTag tag) { String value = null; final Element item = getElementByTagName(element, tag); if (isValid(item)) { value = item.getFirstChild().getNodeValue(); } return value; }
From source file:it.intecs.pisa.toolbox.security.handler.EOP_SAMLTokenProcessor.java
public void handleToken(Element elem, Crypto crypto, Crypto decCrypto, CallbackHandler cb, WSDocInfo wsDocInfo, Vector returnResults, WSSConfig wsc) throws WSSecurityException { if (log.isDebugEnabled()) { log.debug("Found SAML Assertion element"); }//from w w w . ja v a 2 s. c o m //the SAML Element is the first child Element child = (Element) elem.getFirstChild(); if (child.getLocalName().indexOf("EncryptedData") != -1) { //STE: feature mancante in WSS4J che non si aspetta di trovare un SAML token encrypted che non sia preceduto nell'xml da una relativa EnryptedKey EncryptedDataProcessor proc = new EncryptedDataProcessor(); proc.handleToken(child, crypto, decCrypto, cb, wsDocInfo, returnResults, wsc); } SAMLAssertion assertion = handleSAMLToken((Element) elem.getFirstChild()); this.id = assertion.getId(); wsDocInfo.setAssertion((Element) elem); returnResults.add(0, new WSSecurityEngineResult(WSConstants.ST_UNSIGNED, assertion)); this.samlTokenElement = elem; }
From source file:de.tudresden.inf.rn.mobilis.clientservices.socialnetwork.SocialNetworkManager.java
public void loginOAuth() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, ClientProtocolException, IOException, IllegalStateException, SAXException, ParserConfigurationException, FactoryConfigurationError, AndroidException { // Build URL and create GET request String url = getAuthentificationURL(); HttpGet reqLogin = new HttpGet(url); // Instantiate consumer with application key and secret consumer = new CommonsHttpOAuthConsumer(getConsumerKey(), getConsumerSecret()); consumer.sign(reqLogin);/*from ww w . ja v a2s.c om*/ // Login HttpClient httpClient = new DefaultHttpClient(); HttpResponse resLogin = httpClient.execute(reqLogin); if (resLogin.getEntity() == null) { throw new AuthRemoteException(); } // Parse response Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(resLogin.getEntity().getContent()); // Get access token Element eOAuthToken = (Element) document.getElementsByTagName("oauth_token").item(0); if (eOAuthToken == null) { throw new AuthRemoteException(); } Node e = eOAuthToken.getFirstChild(); String sOAuthToken = e.getNodeValue(); System.out.println("token: " + sOAuthToken); // Get access secret Element eOAuthTokenSecret = (Element) document.getElementsByTagName("oauth_token_secret").item(0); if (eOAuthTokenSecret == null) { throw new AuthRemoteException(); } e = eOAuthTokenSecret.getFirstChild(); String sOAuthTokenSecret = e.getNodeValue(); System.out.println("Secret: " + sOAuthTokenSecret); // Set access token and secret for further requests consumer.setTokenWithSecret(sOAuthToken, sOAuthTokenSecret); }
From source file:de.elbe5.base.data.XmlData.java
public String getText(Element node) { if (node.hasChildNodes()) { Node child = node.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.TEXT_NODE) { return child.getNodeValue(); }//from w w w. j a v a 2 s . co m child = child.getNextSibling(); } } return ""; }
From source file:de.elatePortal.autotool.SubTasklet_AutotoolImpl.java
private String getText(Element memento, String nodeName, String dflt) { Element element = getElement(memento, nodeName); if (element != null) { String text = element.getFirstChild().getTextContent(); return text; }/* w w w . j a va 2 s .com*/ return dflt; }
From source file:com.enonic.esl.xml.XMLTool.java
public static void removeAllSiblings(Element node) { Element parent = (Element) node.getParentNode(); Element sibling = (Element) parent.getFirstChild(); while (sibling != null) { if (sibling != node) { sibling = removeChildFromParent(parent, sibling); } else {/*from www .j a va2 s . c o m*/ sibling = (Element) sibling.getNextSibling(); } } }
From source file:com.enonic.esl.xml.XMLTool.java
/** * Get an element's first sub-element. Will return null if root is null, root does not have any sub-elements. * * @param root Element the root element to search in * @return Element the first sub-element, or null if none found *//*from w w w. ja v a 2s. c o m*/ public static Element getFirstElement(Element root) { if (root == null) { return null; } Node n = root.getFirstChild(); while (n != null && n.getNodeType() != Node.ELEMENT_NODE) { n = n.getNextSibling(); } if (n != null) { return (Element) n; } return null; }
From source file:com.ibm.bi.dml.conf.DMLConfig.java
/** * //from w w w . j a v a 2s .c om * @param amMem * @param mrMem */ public void updateYarnMemorySettings(String amMem, String mrMem) { //app master memory NodeList list1 = xml_root.getElementsByTagName(YARN_APPMASTERMEM); if (list1 != null && list1.getLength() > 0) { Element elem = (Element) list1.item(0); elem.getFirstChild().setNodeValue(String.valueOf(amMem)); } //mapreduce memory NodeList list2 = xml_root.getElementsByTagName(YARN_MAPREDUCEMEM); if (list2 != null && list2.getLength() > 0) { Element elem = (Element) list2.item(0); elem.getFirstChild().setNodeValue(String.valueOf(mrMem)); } }
From source file:WebAppConfig.java
/** * This method looks for specific Element nodes in the DOM tree in order to * figure out the classname associated with the specified servlet name */// w ww .j a v a2 s . c o m public String getServletClass(String servletName) { // Find all <servlet> elements and loop through them. NodeList servletnodes = document.getElementsByTagName("servlet"); int numservlets = servletnodes.getLength(); for (int i = 0; i < numservlets; i++) { Element servletTag = (Element) servletnodes.item(i); // Get the first <servlet-name> tag within the <servlet> tag Element nameTag = (Element) servletTag.getElementsByTagName("servlet-name").item(0); if (nameTag == null) continue; // The <servlet-name> tag should have a single child of type // Text. Get that child, and extract its text. Use trim() // to strip whitespace from the beginning and end of it. String name = ((Text) nameTag.getFirstChild()).getData().trim(); // If this <servlet-name> tag has the right name if (servletName.equals(name)) { // Get the matching <servlet-class> tag Element classTag = (Element) servletTag.getElementsByTagName("servlet-class").item(0); if (classTag != null) { // Extract the tag's text as above, and return it Text classTagContent = (Text) classTag.getFirstChild(); return classTagContent.getNodeValue().trim(); } } } // If we get here, no matching servlet name was found return null; }
From source file:greenfoot.export.mygame.MyGameClient.java
private List<String> parseTagListXmlElement(Element element) { List<String> tags = new ArrayList<String>(); Node child = element.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) { element = (Element) child; if (element.getTagName().equals("tag")) { tags.add(element.getTextContent()); }//from www. j a va 2 s . c om } child = child.getNextSibling(); } return tags; }