Example usage for org.w3c.dom Document getElementsByTagName

List of usage examples for org.w3c.dom Document getElementsByTagName

Introduction

In this page you can find the example usage for org.w3c.dom Document getElementsByTagName.

Prototype

public NodeList getElementsByTagName(String tagname);

Source Link

Document

Returns a NodeList of all the Elements in document order with a given tag name and are contained in the document.

Usage

From source file:net.frontlinesms.plugins.forms.FormsPluginController.java

/**
 * Fabaris_a.zanchi Counts the actual repetitions of a repeatable section
 *
 * @param xmlContent xml message/*w  w  w  . j  a v a2 s. c  o  m*/
 * @param repContainerName the name of the repeatables container
 * @return count of repetitions
 * @throws Exception
 */
public static int countRepetitionOfRepeatable(String xmlContent, String repContainerName) throws Exception {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    InputSource inStream = new InputSource();
    inStream.setCharacterStream(new StringReader(xmlContent));
    org.w3c.dom.Document xmlDoc = docBuilder.parse(inStream);
    xmlDoc.getDocumentElement().normalize();
    NodeList repetitionList = xmlDoc.getElementsByTagName(repContainerName);
    return repetitionList.getLength();
}

From source file:net.mindengine.oculus.frontend.db.jdbc.BeanMappingFactory.java

/**
 * This method is used for loading the java mapping beans from a specified
 * xml file. Once the {@link #setFile(File)} method was invoked this method
 * wil be invoked as well.//from   w w w  .  j av a 2s. com
 * 
 * @throws Exception
 */
public void loadFactory() throws Exception {
    logger.info("Loading db-mapping factory");

    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document d = db.parse(file);

    beans = new HashMap<String, BeanMapper>();

    NodeList nodeList = d.getElementsByTagName("bean");

    for (int i = 0; i < nodeList.getLength(); i++) {

        Node node = nodeList.item(i);
        loadBean(node);
    }
}

From source file:com.github.ukase.service.XlsxRenderer.java

public byte[] render(String html) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SXSSFWorkbook wb = new SXSSFWorkbook(-1);

    ITextRenderer renderer = provider.getRenderer(html);
    Document document = renderer.getDocument();
    BlockBox box = renderer.getRootBox();
    RenderingTableBuilder builder = new RenderingTableBuilder(wb, box);

    new ElementList(document.getElementsByTagName(TAG_TABLE)).stream().map(builder::build)
            .forEach(RenderingTable::run);

    wb.write(baos);//from w  w  w .j  ava 2s . c om
    wb.dispose();

    return baos.toByteArray();
}

From source file:WSpatern.RootFolderWS.java

private void parseXML(String line) {

    try {/*  ww  w.j av a 2 s.co m*/
        org.w3c.dom.Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new InputSource(new StringReader(line)));
        NodeList response = doc.getElementsByTagName("dirLink");
        if (response.getLength() > 0) {
            Element err = (Element) response.item(0);
            Root_folder = err.getElementsByTagName("name").item(0).getTextContent();
            Root_folder_Id = err.getElementsByTagName("id").item(0).getTextContent();

        }
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.otiliouine.configurablefactory.ConfigurableFactory.java

private void loadConfiguration(InputStream inputStream) {
    try {/* ww w. jav a  2  s .c  o m*/
        Document document = loadDocument(inputStream);
        document.getDocumentElement().normalize();
        NodeList nList = document.getElementsByTagName("factory");
        for (int index = 0; index < nList.getLength(); index++) {
            Element node = (Element) nList.item(index);
            String superClass = node.getAttribute("interface");
            String implementation = node.getAttribute("implementation");
            Class<?> superClazz = Class.forName(superClass);
            Class<?> subClazz = Class.forName(implementation);
            mapping.put(superClazz, subClazz);
        }
    } catch (ClassNotFoundException e) {
        throw new InvalidMappingValuesException(e.getMessage(), e);
    }
}

From source file:com.vmware.lightwaveui.Login.java

private String getClientId(String domain)
        throws ParserConfigurationException, IOException, SAXException, Exception {
    String clientId = "";
    String multiTenantClientId = "";
    Boolean found = false;/*from  ww  w.j  a  v a 2 s. co  m*/
    File inputFile = new File("/opt/vmware/share/config/lightwave-ui-oidc.xml");
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(inputFile);
    doc.getDocumentElement().normalize();
    NodeList nList = doc.getElementsByTagName("tenant");

    if (nList != null) {
        for (int i = 0; i < nList.getLength(); i++) {
            Node node = nList.item(i);
            NodeList children = node.getChildNodes();
            String key = children.item(0).getNodeName();
            String value = children.item(0).getTextContent();

            if (key.equals("clientId")) {
                multiTenantClientId = value;
            }

            if (value.toLowerCase().equals(domain)) {
                clientId = children.item(1).getTextContent();
                found = true;
                break;
            }
        }
    }

    if (!found) {
        if (StringUtils.isNotEmpty(multiTenantClientId)) {
            return multiTenantClientId;
        }
        throw new Exception("No OIDC client registered for tenant " + domain);
    }
    return clientId;
}

From source file:Servlet.Change.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w  w w . j a va2 s. co  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {
        //grabbing the event parameter
        String eventUrl = request.getParameter("eventUrl");
        System.out.print(eventUrl);

        //Obtaining authority of event
        OAuthConsumer consumer = new DefaultOAuthConsumer("test6-40942", "oQ4q4oBiv9y4jPr7");
        URL url = new URL(eventUrl);
        HttpURLConnection requestUrl = (HttpURLConnection) url.openConnection();
        consumer.sign(requestUrl);
        requestUrl.connect();

        //Reading in the xml file as a string
        String result = null;
        StringBuilder sb = new StringBuilder();
        InputStream is = new BufferedInputStream(requestUrl.getInputStream());
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String inputLine = "";
        while ((inputLine = br.readLine()) != null) {
            sb.append(inputLine);
        }

        result = sb.toString();

        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource src = new InputSource();
        src.setCharacterStream(new StringReader(result));

        //parsing elements by name tags from event url
        Document doc = builder.parse(src);
        String creatorName = doc.getElementsByTagName("fullName").item(0).getTextContent();
        String companyName = doc.getElementsByTagName("name").item(0).getTextContent();
        String edition = doc.getElementsByTagName("editionCode").item(0).getTextContent();
        String returnUrl = doc.getElementsByTagName("returnUrl").item(0).getTextContent();

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost xmlResponse = new HttpPost(returnUrl);
        StringEntity input = new StringEntity(
                "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><result><success>true</success><message>Account change successful</message>");
        input.setContentType("text/xml");
        xmlResponse.setEntity(input);
        httpClient.execute(xmlResponse);

    } catch (OAuthMessageSignerException ex) {
        Logger.getLogger(Change.class.getName()).log(Level.SEVERE, null, ex);
    } catch (OAuthExpectationFailedException ex) {
        Logger.getLogger(Change.class.getName()).log(Level.SEVERE, null, ex);
    } catch (OAuthCommunicationException ex) {
        Logger.getLogger(Change.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        Logger.getLogger(Change.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(Change.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.googlecode.osde.internal.editors.locale.LocaleModel.java

private void loadMessageBundleFile(IProject project) {
    String fileName = MESSAGE_BUNDLE_FILENAME_PREFIX + lang + "_" + country + ".xml";
    IFile file = project.getFile(fileName);
    if (file.exists()) {
        try {/*  w ww .  j a  va  2 s .c o m*/
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document document = documentBuilder.parse(file.getContents());
            NodeList msgList = document.getElementsByTagName("msg");
            for (int i = 0; i < msgList.getLength(); i++) {
                Element msg = (Element) msgList.item(i);
                String name = msg.getAttribute("name");
                String value = msg.getTextContent();
                messages.put(name, value);
            }
        } catch (ParserConfigurationException e) {
            logger.warn("Loading message bundle file failed.", e);
        } catch (SAXException e) {
            logger.warn("Loading message bundle file failed.", e);
        } catch (IOException e) {
            logger.warn("Loading message bundle file failed.", e);
        } catch (CoreException e) {
            logger.warn("Loading message bundle file failed.", e);
        }
    }
}

From source file:Servlet.Notification.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w w w  .j av a  2 s.  c  o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {
        //grabbing the event parameter
        String eventUrl = request.getParameter("eventUrl");
        System.out.print(eventUrl);

        //Obtaining authority of event
        OAuthConsumer consumer = new DefaultOAuthConsumer("test6-40942", "oQ4q4oBiv9y4jPr7");
        URL url = new URL(eventUrl);
        HttpURLConnection requestUrl = (HttpURLConnection) url.openConnection();
        consumer.sign(requestUrl);
        requestUrl.connect();

        //Reading in the xml file as a string
        String result = null;
        StringBuilder sb = new StringBuilder();
        InputStream is = new BufferedInputStream(requestUrl.getInputStream());
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String inputLine = "";
        while ((inputLine = br.readLine()) != null) {
            sb.append(inputLine);
        }

        result = sb.toString();

        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource src = new InputSource();
        src.setCharacterStream(new StringReader(result));

        Document doc = builder.parse(src);
        String creatorName = doc.getElementsByTagName("fullName").item(0).getTextContent();
        String companyName = doc.getElementsByTagName("name").item(0).getTextContent();
        String edition = doc.getElementsByTagName("editionCode").item(0).getTextContent();
        String returnUrl = doc.getElementsByTagName("returnUrl").item(0).getTextContent();

        //parsing elements by name tags from event url
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost xmlResponse = new HttpPost(returnUrl);
        StringEntity input = new StringEntity(
                "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><result><success>true</success><message>Account change successful</message>");
        input.setContentType("text/xml");
        xmlResponse.setEntity(input);
        httpClient.execute(xmlResponse);

    } catch (OAuthMessageSignerException ex) {
        Logger.getLogger(Notification.class.getName()).log(Level.SEVERE, null, ex);
    } catch (OAuthExpectationFailedException ex) {
        Logger.getLogger(Notification.class.getName()).log(Level.SEVERE, null, ex);
    } catch (OAuthCommunicationException ex) {
        Logger.getLogger(Notification.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(Notification.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        Logger.getLogger(Notification.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:WSpatern.ValidTokenWS.java

private void parseXML(String line) {
    try {//  w w w.j ava  2s  .c  o  m
        org.w3c.dom.Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new InputSource(new StringReader(line)));
        NodeList response = doc.getElementsByTagName("userToken");
        if (response.getLength() > 0) {
            Element err = (Element) response.item(0);
            expire = err.getElementsByTagName("expires").item(0).getTextContent();
            tokekn = err.getElementsByTagName("token").item(0).getTextContent();

            userId = err.getElementsByTagName("userId").item(0).getTextContent();
            valid = Boolean.valueOf(err.getElementsByTagName("valid").item(0).getTextContent());
        }
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    }
}