Package org.apache.xindice.util

Examples of org.apache.xindice.util.Configuration


        } else {
            final String name = collection.getName();
            boolean dropped = collection.drop();
            if (dropped) {
                collections.remove(name);
                Configuration colConfig = config.getChild(COLLECTIONS);
                colConfig.processChildren(COLLECTION, new ConfigurationCallback() {
                    public void process(Configuration cfg) {
                        try {
                            if (cfg.getAttribute(NAME).equals(name)) {
                                cfg.delete();
                            }
View Full Code Here


            log.info("Database name: '" + this.database.getName() + "'");
        }
    }

    protected Configuration loadConfiguration() throws IOException, XindiceException  {
        Configuration config;
        String configDir = null;

        String configFile = null;
        try {
            // Try configuration first
            configFile = getProperty(Xindice.PROP_XINDICE_CONFIGURATION);
        } catch (XMLDBException ignored) {
        }
        if (configFile == null) {
            // Fallback to system property
            configFile = System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION);
        }

        if (configFile != null && !configFile.equals("")) {
            if (log.isInfoEnabled()) {
                log.info("Specified configuration file: '" + configFile + "'");
            }
            FileInputStream configXMLFile = new FileInputStream(configFile);

            config = new Configuration(DOMParser.toDocument(configXMLFile), false);
            configDir = new File(configFile).getAbsoluteFile().getParent();
        } else {
            if (log.isInfoEnabled()) {
                log.info("No configuration file specified, going with the default configuration");
            }

            config = new Configuration(DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION), false);
        }

        config = config.getChild("root-collection", false);

        String dbRoot = config.getAttribute(Database.DBROOT, Database.DBROOT_DEFAULT);
        if (!new File(dbRoot).isAbsolute()) {
            // Let's see if the property was specified.
            String home = null;
            try {
                // Try configuration first
                home = getProperty(Xindice.PROP_XINDICE_DB_HOME);
            } catch (XMLDBException ignored) {
            }
            if (home == null) {
                // Fallback to system property
                home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME);
            }

            if (home != null) {
                dbRoot = new File(home + File.separator + dbRoot).getCanonicalPath();
            } else if (configDir != null) {
                dbRoot = configDir + File.separator + dbRoot;
            } else {
                log.warn("The database configuration file is not specified and there was no "
                         + Xindice.PROP_XINDICE_DB_HOME + " property set, "
                         + "so Xindice was unable to determine a database location. "
                         + "Database will be created relative to the current directory.");
                dbRoot = new File("." + File.separator + dbRoot).getCanonicalPath();
            }
            config.setAttribute(Database.DBROOT, dbRoot);
        }

        return config;
    }
View Full Code Here

     * @see org.apache.xindice.util.Configurable#setConfig(org.apache.xindice.util.Configuration)
     */
    public void setConfig(Configuration config) throws XindiceException {
        this.config = config;

        Configuration colConfig = config.getChild(COLLECTIONS);
        if (colConfig != null) {
            colConfig.processChildren(COLLECTION, new ConfigurationCallback() {
                public void process(Configuration cfg) throws XindiceException {
                    // check for an existing Collection by name and, if found, skip creating a new Collection
                    // else, create a new child Collection, configure it an add it
                    // if the Collection already exists in our collections list,
                    // creating a new one will cause the old one to be discarded
View Full Code Here

    }

    public void setUp() throws Exception {
        root.mkdir();
        filer.setLocation(root, TEST_COLLECTION_NAME);
        filer.setConfig(new Configuration(DOMParser.toDocument("<filer location=\"" + TEST_COLLECTION_NAME + "\"/>")));
        if (!filer.exists()) {
            filer.create();
        }
        filer.open();
View Full Code Here

        if (config.getBooleanAttribute(CACHE, true)) {
            documentCache = getDatabase().getDocumentCache();
        }

        // If no Filer is defined, skip Symbols and Indexes
        Configuration filerConfig = config.getChild(FILER);
        if (filerConfig != null) {
            if (log.isTraceEnabled()) {
                log.trace(localDebugHeader + "Have filer config...");
            }

            // Symbol Table Setup
            Configuration symConfig = config.getChild(SYMBOLS);
            internalSymbols = (symConfig != null);
            if (internalSymbols) {
                if (log.isTraceEnabled()) {
                    log.trace(localDebugHeader
                              + "Internal symbols=<" + TextWriter.toString(symConfig.getElement()) + ">");
                }

                try {
                    symbols = new SymbolTable(symConfig.getElement());
                } catch (Exception e) {
                    if (log.isWarnEnabled()) {
                        log.warn(localDebugHeader + "Error building symbol table from internal symbols", e);
                    }
                }
            } else {
                if (log.isTraceEnabled()) {
                    log.trace(localDebugHeader + "No internal symbols...");
                }

                try {
                    symbols = getSystemCollection().loadSymbols(this);
                    if (log.isDebugEnabled()) {
                        log.debug(localDebugHeader + "Loaded symbols=<" +
                                  TextWriter.toString(symbols.streamToXML(new DocumentImpl())) + ">");
                    }
                } catch (Exception e) {
                    if (log.isWarnEnabled()) {
                        log.warn(localDebugHeader + "Error building symbol table from system collection", e);
                    }
                }
            }

            String className = filerConfig.getAttribute(CLASS);
            if (log.isDebugEnabled()) {
                log.debug(localDebugHeader + "Filer class=<" + className + ">");
            }
            try {
                filer = (Filer) Class.forName(className).newInstance();
                //            filer.setCollection(this);
                filer.setLocation(getCollectionRoot(), getName());
                filer.setConfig(filerConfig);
                if (!filer.exists()) {
                    filer.create();
                }
                filer.open();
            } catch (Exception e) {
                if (log.isWarnEnabled()) {
                    log.warn("Filer '" + className + "' is not available", e);
                }
            }

            // Index Manager
            try {
                indexManager = new IndexManager(this);
                Configuration idxConfig = config.getChild(INDEXES, true);
                indexManager.setConfig(idxConfig);
            } catch (Exception e) {
                if (log.isWarnEnabled()) {
                    log.warn("ignored exception", e);
                }
View Full Code Here

    }

    public void setUp() throws Exception {
        if (db == null) {
            Database db = new Database();
            db.setConfig(new Configuration(DOMParser.toDocument(DATABASE)));
            col = db.createCollection("testcol", new Configuration(DOMParser.toDocument(COLLECTION)));
            col.insertDocument(DOMParser.toDocument(DOCUMENT));

            XPathQueryResolverTest.db = db;
        }
View Full Code Here

    /**
     * Initializes database
     */
    public void init(ServletConfig servletConfig) throws ServletException {

        Configuration configuration = loadConfiguration(servletConfig);

        //
        // The configuration is wrapped in a <xindice> element so we need to get the "root-collection" configuration.
        //
        try {
            Configuration rootCollectionConfiguration = configuration.getChild("root-collection");
            if (rootCollectionConfiguration == null) {
                throw new ConfigurationException("The database configuration is missing the <root-collection> element");
            } else {

                //
                // We need to ensure that the database points to a place where it makes
                // sense. If the path in the system.xml file is an absolute path, then
                // honor it. If it's not, we first check for the system property "xindice.db.home"
                // and if the lookup is successful we use it as the database root parent. If
                // the property is not set, we use /WEB-INF relative to the servlet context, unless
                // the war has not been unpacked. In this case, we throw an exception and
                // ask the user to specify the location of database root
                //
                String dbRoot = rootCollectionConfiguration.getAttribute(Database.DBROOT, Database.DBROOT_DEFAULT);

                //
                // If there is no absolute path, we have to perform some checks.
                //
                if (!new File(dbRoot).isAbsolute()) {

                    // Stupid hack but spec compliant:
                    // If getRealPath() returns null the war archive has not been unpacked.
                    String realPath = servletConfig.getServletContext().getRealPath("/WEB-INF");

                    // Let's see if the property was specified.
                    String home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME);
                    if (log.isDebugEnabled()) {
                        log.debug(Xindice.PROP_XINDICE_DB_HOME + " is set to " + home);
                    }

                    if (home != null) {
                        dbRoot = new File(home + File.separator + dbRoot).getCanonicalPath();
                    } else if (realPath != null) {
                        dbRoot = new File(realPath + File.separator + dbRoot).getCanonicalPath();
                        log.warn("The database root directory has been set to " + dbRoot +
                                 ". Keep in mind that if a war upgrade will take place the database will be lost.");
                    } else {
                        throw new ConfigurationException(
                                "The database configuration points to a relative path, "
                                + "but there was no " + Xindice.PROP_XINDICE_DB_HOME + " property set. "
                                + "Furthermore, the war was not unpacked by the application server "
                                + "so Xindice was unable to find a database location "
                                + "Please check /WEB-INF/system.xml and set an absolute path "
                                + "as the \"dbroot\" attribute of \"root-collection\" "
                                + "or specify a suitable " + Xindice.PROP_XINDICE_DB_HOME + " system property.");
                    }
                    rootCollectionConfiguration.setAttribute(Database.DBROOT, dbRoot);
                }

                //
                // We need to use this method to be consistent between deployments (embed, standalone, etc)
                // and let the Database object maintain the set of Databases.
                //
                this.database = Database.getDatabase(rootCollectionConfiguration);
            }

            // Setup the XML-RPC impl to support UTF-8 input via Xerces.
            XmlRpc.setEncoding("UTF8");

            /*
             * Setup the SAX parser XML-RPC impl will use.
             * The XmlRpc.setDriver() method takes either the classname or a shorthand
             * name for the SAX parser it will use.  The default (for backwards compatibility
             * if nothing else) is xerces.
             */
            String xmlrpcDriver = DEFAULT_XMLRPC_DRIVER;

            Configuration xmlRpcConfiguration = configuration.getChild("xml-rpc");
            if (xmlRpcConfiguration != null) {
                Configuration xmlRpcDriverConfiguration = xmlRpcConfiguration.getChild("driver");
                if (xmlRpcDriverConfiguration != null) {
                    // xmlrpcDriver will have non-empty value, guaranteed by providing default value
                    xmlrpcDriver = xmlRpcDriverConfiguration.getAttribute("name", DEFAULT_XMLRPC_DRIVER);
                }
            }

            try {
                XmlRpc.setDriver(xmlrpcDriver);
View Full Code Here

            } else {
                log.debug("Loading the standard configuration");
                configurationDocument = DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION);
            }

            return new Configuration(configurationDocument, false);
        } catch (Exception e) {
            throw new ConfigurationException("Failed to load configuration.", e);
        }
    }
View Full Code Here

            log.info("Database name: '" + db.getName() + "'");
        }
    }

    protected Configuration loadConfiguration() throws IOException, XindiceException {
        Configuration config;
        String configDir = null;
        String configFile = System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION);
        if (configFile != null && !configFile.equals("")) {
            if (log.isInfoEnabled()) {
                log.info("Specified configuration file: '" + configFile + "'");
            }
            FileInputStream configXMLFile = new FileInputStream(new File(configFile));

            config = new Configuration(DOMParser.toDocument(configXMLFile), false);
            configDir = new File(configFile).getAbsoluteFile().getParent();
        } else {
            if (log.isInfoEnabled()) {
                log.info("No configuration file specified, going with the default configuration");
            }

            config = new Configuration(DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION), false);
        }

        config = config.getChild("root-collection", false);

        String dbRoot = config.getAttribute(Database.DBROOT, Database.DBROOT_DEFAULT);
        if (!new File(dbRoot).isAbsolute()) {
            // Let's see if the property was specified.
            String home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME);
            if (home != null) {
                dbRoot = new File(home + File.separator + dbRoot).getCanonicalPath();
            } else if (configDir != null) {
                dbRoot = configDir + File.separator + dbRoot;
            } else {
                dbRoot = new File("." + File.separator + dbRoot).getCanonicalPath();
                log.warn("The database configuration file is not specified and there was no "
                         + Xindice.PROP_XINDICE_DB_HOME + " property set, "
                         + "so Xindice was unable to determine a database location. "
                         + "Database will be created relative to the current directory.");
            }
            config.setAttribute(Database.DBROOT, dbRoot);
        }

        return config;
    }
View Full Code Here

          if (type != null)
          {
            e.setAttribute("type", type);
          }

          idxMgr.create(new Configuration(e));
        }
      }
      catch (Exception e)
      {
        if (log.isWarnEnabled())
View Full Code Here

TOP

Related Classes of org.apache.xindice.util.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.