String file = "server.xml"; String dbHome = System.getProperty("exist.home"); File f = new File(file); if ((!f.isAbsolute()) && dbHome != null) { file = dbHome + File.separatorChar + file; f = new File(file); }
String file = "server.xml"; File f = Configuration.lookup(file);
    private void configure(Properties properties) throws ParserConfigurationException, SAXException, IOException {        // try to read configuration from file. Guess the location if        // necessary        InputStream is = null;        String file = "server.xml";        String dbHome = System.getProperty("exist.home");        File f = new File(file);        if ((!f.isAbsolute()) && dbHome != null) {            file = dbHome + File.separatorChar + file;            f = new File(file);        }        if (!f.canRead()) {            is = StandaloneServer.class.getClassLoader().getResourceAsStream("org/exist/server.xml");            if (is == null)                throw new IOException("Server configuration not found!");        } else {            is = new FileInputStream(f);        }                // initialize xml parser        SAXParserFactory factory = SAXParserFactory.newInstance();        factory.setNamespaceAware(true);        factory.setValidating(false);        InputSource src = new InputSource(is);        SAXParser parser = factory.newSAXParser();        XMLReader reader = parser.getXMLReader();        SAXAdapter adapter = new SAXAdapter();        reader.setContentHandler(adapter);        reader.parse(src);                Document doc = adapter.getDocument();        Element root = doc.getDocumentElement();        if (!root.getLocalName().equals("server")) {            LOG.warn("Configuration should have a root element <server>");            return;        }        String port = root.getAttribute("port");        if (port != null && port.length() > 0)            properties.setProperty("port", port);                NodeList cl = root.getChildNodes();        for (int i = 0; i < cl.getLength(); i++) {            Node node = cl.item(i);            if (node.getNodeType() == Node.ELEMENT_NODE) {                Element elem = (Element) node;                String name = elem.getLocalName();                if ("rest".equals(name)) {                    parseDefaultAttrs(properties, elem, "rest");                    parseParams(properties, elem, "rest");                } else if ("webdav".equals(name))                    parseDefaultAttrs(properties, elem, "webdav");                else if ("xmlrpc".equals(name))                    parseDefaultAttrs(properties, elem, "xmlrpc");                else if ("forwarding".equals(name))                    configureForwards(elem);            }        }    }