private boolean isJndiConfig() throws ConfigurationException { Class<?> driverClass = null; try { if (driver.length() > 0) { driverClass = Class.forName(driver); } } catch (ClassNotFoundException e) { throw new ConfigurationException("Could not load JDBC driver class " + driver, e); } return driverClass != null && Context.class.isAssignableFrom(driverClass); }
private boolean isJndiConfig() throws ConfigurationException { Class<?> driverClass = null; try { if (driver.length() > 0) { driverClass = Class.forName(driver); } } catch (ClassNotFoundException e) { throw new ConfigurationException("Could not load JDBC driver class " + driver, e); } return driverClass != null && Context.class.isAssignableFrom(driverClass); }
private boolean isJndiConfig() throws ConfigurationException { Class<?> driverClass = null; try { if (driver.length() > 0) { driverClass = Class.forName(driver); } } catch (ClassNotFoundException e) { throw new ConfigurationException("Could not load JDBC driver class " + driver, e); } return driverClass != null && Context.class.isAssignableFrom(driverClass); }
/** * Returns the value of the named attribute of the given element. * * @param element element * @param name attribute name * @return attribute value * @throws ConfigurationException if the attribute is not found */ protected String getAttribute(Element element, String name) throws ConfigurationException { Attr attribute = element.getAttributeNode(name); if (attribute != null) { return attribute.getValue(); } else { throw new ConfigurationException( "Configuration attribute " + name + " not found in " + element.getNodeName() + "."); } }
/** * Returns the value of the named attribute of the given element. * * @param element element * @param name attribute name * @return attribute value * @throws ConfigurationException if the attribute is not found */ protected String getAttribute(Element element, String name) throws ConfigurationException { Attr attribute = element.getAttributeNode(name); if (attribute != null) { return attribute.getValue(); } else { throw new ConfigurationException( "Configuration attribute " + name + " not found in " + element.getNodeName() + "."); } }
/** * Adds the given workspace configuration to the repository. * * @param wc workspace configuration * @throws ConfigurationException if a workspace with the same name * already exists */ private void addWorkspaceConfig(WorkspaceConfig wc) throws ConfigurationException { String name = wc.getName(); if (!workspaces.containsKey(name)) { workspaces.put(name, wc); } else { throw new ConfigurationException( "Duplicate workspace configuration: " + name); } }
/** * Adds the given workspace configuration to the repository. * * @param wc workspace configuration * @throws ConfigurationException if a workspace with the same name * already exists */ private void addWorkspaceConfig(WorkspaceConfig wc) throws ConfigurationException { String name = wc.getName(); if (!workspaces.containsKey(name)) { workspaces.put(name, wc); } else { throw new ConfigurationException( "Duplicate workspace configuration: " + name); } }
/** * Performs variable replacement on the given string value. * Each <code>${...}</code> sequence within the given value is replaced * with the value of the named parser variable. The replacement is not * done if the named variable does not exist. * * @param value original value * @return value after variable replacements * @throws ConfigurationException if the replacement of a referenced * variable is not found */ protected String replaceVariables(String value) throws ConfigurationException { try { return Text.replaceVariables(variables, value, false); } catch (IllegalArgumentException e) { throw new ConfigurationException(e.getMessage(), e); } }
/** * Returns the configuration of a repository with the given configuration * file and repository home directory. * <p> * An exception is thrown if the directory does not exist or if * the repository configuration file can not be read. * * @param xml The configuration file. * @param dir repository home directory * @return repository configuration * @throws ConfigurationException on configuration errors * @since Apache Jackrabbit 1.6 */ public static RepositoryConfig create(File xml, File dir) throws ConfigurationException { if (!dir.isDirectory()) { throw new ConfigurationException( "Repository directory " + dir + " does not exist"); } if (!xml.isFile()) { throw new ConfigurationException( "Repository configuration file " + xml + " does not exist"); } return create(new InputSource(xml.toURI().toString()), dir.getPath()); }
/** * Performs variable replacement on the given string value. * Each <code>${...}</code> sequence within the given value is replaced * with the value of the named parser variable. The replacement is not * done if the named variable does not exist. * * @param value original value * @return value after variable replacements * @throws ConfigurationException if the replacement of a referenced * variable is not found */ protected String replaceVariables(String value) throws ConfigurationException { try { return Text.replaceVariables(variables, value, false); } catch (IllegalArgumentException e) { throw new ConfigurationException(e.getMessage(), e); } }
private static void installRepositorySkeleton( File dir, File xml, URL resource) throws IOException, ConfigurationException { if (!dir.exists()) { log.info("Creating repository directory {}", dir); boolean dirCreated = dir.mkdirs(); if (!dirCreated) { throw new ConfigurationException("Cannot create repository directory " + dir); } } if (!xml.exists()) { log.info("Copying configuration from {} to {}", resource, xml); OutputStream output = new FileOutputStream(xml); try { InputStream input = resource.openStream(); try { IOUtils.copy(input, output); } finally { input.close(); } } finally { output.close(); } } }
/** * Returns the configuration of a repository with the given configuration * file and repository home directory. * <p> * An exception is thrown if the directory does not exist or if * the repository configuration file can not be read. * * @param xml The configuration file. * @param dir repository home directory * @return repository configuration * @throws ConfigurationException on configuration errors * @since Apache Jackrabbit 1.6 */ public static RepositoryConfig create(File xml, File dir) throws ConfigurationException { if (!dir.isDirectory()) { throw new ConfigurationException( "Repository directory " + dir + " does not exist"); } if (!xml.isFile()) { throw new ConfigurationException( "Repository configuration file " + xml + " does not exist"); } return create(new InputSource(xml.toURI().toString()), dir.getPath()); }
/** * Creates a DataSourceDefinition from the given properties and * throws a {@link ConfigurationException} when the set of properties does not * satisfy some validity constraints. * * @param name the logical name of the data source * @param props the properties (string keys and values) * @throws ConfigurationException on error */ public DataSourceDefinition(String name, Properties props) throws ConfigurationException { this.logicalName = name; this.driver = (String) props.getProperty(DRIVER); this.url = (String) props.getProperty(URL); this.user = (String) props.getProperty(USER); this.password = (String) props.getProperty(PASSWORD); this.dbType = (String) props.getProperty(DB_TYPE); this.validationQuery = (String) props.getProperty(VALIDATION_QUERY); try { this.maxPoolSize = Integer.parseInt((String) props.getProperty(MAX_POOL_SIZE, "-1")); } catch (NumberFormatException e) { throw new ConfigurationException("failed to parse " + MAX_POOL_SIZE + " property for DataSource " + logicalName); } verify(props); }
/** * Creates a DataSourceDefinition from the given properties and * throws a {@link ConfigurationException} when the set of properties does not * satisfy some validity constraints. * * @param name the logical name of the data source * @param props the properties (string keys and values) * @throws ConfigurationException on error */ public DataSourceDefinition(String name, Properties props) throws ConfigurationException { this.logicalName = name; this.driver = (String) props.getProperty(DRIVER); this.url = (String) props.getProperty(URL); this.user = (String) props.getProperty(USER); this.password = (String) props.getProperty(PASSWORD); this.dbType = (String) props.getProperty(DB_TYPE); this.validationQuery = (String) props.getProperty(VALIDATION_QUERY); try { this.maxPoolSize = Integer.parseInt((String) props.getProperty(MAX_POOL_SIZE, "-1")); } catch (NumberFormatException e) { throw new ConfigurationException("failed to parse " + MAX_POOL_SIZE + " property for DataSource " + logicalName); } verify(props); }
/** * Adds a DataSourceDefinition from the given properties. * * @param props the properties (key and values must be strings) * @throws ConfigurationException on error */ public void addDataSourceDefinition(String name, Properties props) throws ConfigurationException { DataSourceDefinition def = new DataSourceDefinition(name, props); for (DataSourceDefinition existing : defs) { if (existing.getLogicalName().equals(def.getLogicalName())) { throw new ConfigurationException("Duplicate logicalName for a DataSource: " + def.getLogicalName()); } } defs.add(def); }
/** * Adds a DataSourceDefinition from the given properties. * * @param props the properties (key and values must be strings) * @throws ConfigurationException on error */ public void addDataSourceDefinition(String name, Properties props) throws ConfigurationException { DataSourceDefinition def = new DataSourceDefinition(name, props); for (DataSourceDefinition existing : defs) { if (existing.getLogicalName().equals(def.getLogicalName())) { throw new ConfigurationException("Duplicate logicalName for a DataSource: " + def.getLogicalName()); } } defs.add(def); }
/** * Adds a DataSourceDefinition from the given properties. * * @param props the properties (key and values must be strings) * @throws ConfigurationException on error */ public void addDataSourceDefinition(String name, Properties props) throws ConfigurationException { DataSourceDefinition def = new DataSourceDefinition(name, props); for (DataSourceDefinition existing : defs) { if (existing.getLogicalName().equals(def.getLogicalName())) { throw new ConfigurationException("Duplicate logicalName for a DataSource: " + def.getLogicalName()); } } defs.add(def); }
private static Element parseXML(InputSource xml, boolean validate) throws ConfigurationException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validate); DocumentBuilder builder = factory.newDocumentBuilder(); if (validate) { builder.setErrorHandler(new ConfigurationErrorHandler()); } builder.setEntityResolver(ConfigurationEntityResolver.INSTANCE); Document document = builder.parse(xml); return document.getDocumentElement(); } catch (ParserConfigurationException e) { throw new ConfigurationException("Unable to create configuration XML parser", e); } catch (SAXParseException e) { throw new ConfigurationException("Configuration file syntax error. (Line: " + e.getLineNumber() + " Column: " + e.getColumnNumber() + ")", e); } catch (SAXException e) { throw new ConfigurationException("Configuration file syntax error. ", e); } catch (IOException e) { throw new ConfigurationException("Configuration file could not be read.", e); } }
private static Element parseXML(InputSource xml, boolean validate) throws ConfigurationException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validate); DocumentBuilder builder = factory.newDocumentBuilder(); if (validate) { builder.setErrorHandler(new ConfigurationErrorHandler()); } builder.setEntityResolver(ConfigurationEntityResolver.INSTANCE); Document document = builder.parse(xml); return document.getDocumentElement(); } catch (ParserConfigurationException e) { throw new ConfigurationException("Unable to create configuration XML parser", e); } catch (SAXParseException e) { throw new ConfigurationException("Configuration file syntax error. (Line: " + e.getLineNumber() + " Column: " + e.getColumnNumber() + ")", e); } catch (SAXException e) { throw new ConfigurationException("Configuration file syntax error. ", e); } catch (IOException e) { throw new ConfigurationException("Configuration file could not be read.", e); } } }
private static Element parseXML(InputSource xml, boolean validate) throws ConfigurationException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validate); DocumentBuilder builder = factory.newDocumentBuilder(); if (validate) { builder.setErrorHandler(new ConfigurationErrorHandler()); } builder.setEntityResolver(ConfigurationEntityResolver.INSTANCE); Document document = builder.parse(xml); return document.getDocumentElement(); } catch (ParserConfigurationException e) { throw new ConfigurationException("Unable to create configuration XML parser", e); } catch (SAXParseException e) { throw new ConfigurationException("Configuration file syntax error. (Line: " + e.getLineNumber() + " Column: " + e.getColumnNumber() + ")", e); } catch (SAXException e) { throw new ConfigurationException("Configuration file syntax error. ", e); } catch (IOException e) { throw new ConfigurationException("Configuration file could not be read.", e); } }