Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

public class Main {
    /**
     * Get the searchHandler Node from the solrconfig.xml file
     *
     * @param solrconfig
     *            the solrconfig.xml File
     *
     * @return searchHandler XML Node or null if not found
     *
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws IOException
     * @throws XPathExpressionException
     */
    public static Node getSearchHandlerNode(final File solrconfig)
            throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
        final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        final Document docSchem = dBuilder.parse(solrconfig);
        final XPathFactory xPathfactory = XPathFactory.newInstance();
        final XPath xpath = xPathfactory.newXPath();
        final XPathExpression expr = xpath
                .compile("//requestHandler[@class=\"solr.SearchHandler\" and @name=\"/select\"]");
        final Node requestHandler = (Node) expr.evaluate(docSchem, XPathConstants.NODE);
        return requestHandler;
    }
}