/** * Creates a new instance of a configuration parser but with overlayed * variables and the same connection factory as this parser. * * @param variables the variables overlay * @return a new configuration parser instance */ protected RepositoryConfigurationParser createSubParser(Properties variables) { // overlay the properties Properties props = new Properties(getVariables()); props.putAll(variables); return new RepositoryConfigurationParser(props, connectionFactory); }
String home = getVariables().getProperty(WORKSPACE_HOME_VARIABLE); String name = getAttribute(root, "name", new File(home).getName()); getAttribute(root, CLUSTERED_ATTRIBUTE, "true")); Properties tmpVariables = (Properties) getVariables().clone(); tmpVariables.put(WORKSPACE_NAME_VARIABLE, name); RepositoryConfigurationParser tmpParser = createSubParser(tmpVariables); tmpParser.getFileSystemFactory(root, FILE_SYSTEM_ELEMENT); PersistenceManagerConfig pmc = tmpParser.parsePersistenceManagerConfig(root); QueryHandlerFactory qhf = tmpParser.getQueryHandlerFactory(root); tmpParser.getISMLockingFactory(root); WorkspaceSecurityConfig workspaceSecurityConfig = tmpParser.parseWorkspaceSecurityConfig(root); ImportConfig importConfig = tmpParser.parseImportConfig(root); String to = getAttribute(root, "defaultLockTimeout", new Long(Long.MAX_VALUE).toString()); long defaultLockTimeout; try {
/** * Parses security configuration. Security configuration * uses the following format: * <pre> * <Security appName="..."> * <SecurityManager ...> * <AccessManager ...> * <LoginModule ... (optional)> * </Security> * </pre> * <p> * The <code>SecurityManager</code>, the <code>AccessManager</code> * and <code>LoginModule</code> are all * {@link #parseBeanConfig(Element,String) bean configuration} * elements. * <p> * The login module is an optional feature of repository configuration. * * @param security the <security> element. * @return the security configuration. * @throws ConfigurationException if the configuration is broken */ public SecurityConfig parseSecurityConfig(Element security) throws ConfigurationException { String appName = getAttribute(security, APP_NAME_ATTRIBUTE); SecurityManagerConfig smc = parseSecurityManagerConfig(security); AccessManagerConfig amc = parseAccessManagerConfig(security); LoginModuleConfig lmc = parseLoginModuleConfig(security); return new SecurityConfig(appName, smc, amc, lmc); }
throws ConfigurationException { Element root = parseXML(xml); return parseWorkspaceConfig(root);
Element root = parseXML(xml, true); String home = getVariables().getProperty(REPOSITORY_HOME_VARIABLE); FileSystemFactory fsf = getFileSystemFactory(root, FILE_SYSTEM_ELEMENT); Element security = getElement(root, SECURITY_ELEMENT); SecurityConfig securityConfig = parseSecurityConfig(security); Element workspaces = getElement(root, WORKSPACES_ELEMENT); String workspaceDirectory = replaceVariables( getAttribute(workspaces, ROOT_PATH_ATTRIBUTE)); getAttribute(workspaces, CONFIG_ROOT_PATH_ATTRIBUTE, null); String defaultWorkspace = replaceVariables( getAttribute(workspaces, DEFAULT_WORKSPACE_ATTRIBUTE)); getAttribute(workspaces, MAX_IDLE_TIME_ATTRIBUTE, "0")); Element template = getElement(root, WORKSPACE_ELEMENT); VersioningConfig vc = parseVersioningConfig(root); QueryHandlerFactory qhf = getQueryHandlerFactory(root); ClusterConfig cc = parseClusterConfig(root, new File(home)); DataStoreFactory dsf = getDataStoreFactory(root, home);
Element element = getElement(parent, VERSIONING_ELEMENT); replaceVariables(getAttribute(element, ROOT_PATH_ATTRIBUTE)); getFileSystemFactory(element, FILE_SYSTEM_ELEMENT); PersistenceManagerConfig pmc = parsePersistenceManagerConfig(element); getISMLockingFactory(element);
private static LoginModuleConfig getLoginModuleConfig(String config) throws ConfigurationException { return new RepositoryConfigurationParser(new Properties()).parseLoginModuleConfig(parseXML(new InputSource(new StringReader(config)), false)); }
/** * Parses the access manager configuration. * * @param security the <security> element. * @return the access manager configuration or <code>null</code>. * @throws ConfigurationException if the configuration is broken */ public AccessManagerConfig parseAccessManagerConfig(Element security) throws ConfigurationException { // Optional access manager config entry Element accessMgr = getElement(security, ACCESS_MANAGER_ELEMENT, false); if (accessMgr != null) { return new AccessManagerConfig(parseBeanConfig(accessMgr)); } else { return null; } }
public QueryHandler getQueryHandler(QueryHandlerContext context) throws RepositoryException { Element element = (Element) child; // Optional file system implementation FileSystem fs = null; if (getElement(element, FILE_SYSTEM_ELEMENT, false) != null) { fs = getFileSystemFactory( element, FILE_SYSTEM_ELEMENT).getFileSystem(); } // Search implementation class String className = getAttribute( element, CLASS_ATTRIBUTE, DEFAULT_QUERY_HANDLER); BeanConfig config = new BeanConfig( className, parseParameters(element)); QueryHandler handler = config.newInstance(QueryHandler.class); try { handler.init(fs, context); return handler; } catch (IOException e) { throw new RepositoryException( "Unable to initialize query handler: " + handler, e); } } };
/** * Parses the given repository configuration document using the given * parser variables. Note that the ${rep.home} variable should be set * by the caller! * <p> * Note that in addition to parsing the repository configuration, this * method also initializes the configuration (creates the configured * directories, etc.). The {@link ConfigurationParser} class should be * used directly to just parse the configuration. * * @since Apache Jackrabbit 2.1 * @param xml repository configuration document * @param variables parser variables * @return repository configuration * @throws ConfigurationException on configuration errors */ public static RepositoryConfig create(InputSource xml, Properties variables) throws ConfigurationException { RepositoryConfigurationParser parser = new RepositoryConfigurationParser(variables, new ConnectionFactory()); RepositoryConfig config = parser.parseRepositoryConfig(xml); config.init(); return config; }
throws ConfigurationException { Element smElement = getElement(security, SECURITY_MANAGER_ELEMENT, false); if (smElement != null) { BeanConfig bc = parseBeanConfig(smElement); String wspAttr = getAttribute(smElement, WSP_NAME_ATTRIBUTE, null); Element element = getElement(smElement, WORKSPACE_ACCESS_ELEMENT, false); if (element != null) { wac = parseBeanConfig(smElement, WORKSPACE_ACCESS_ELEMENT); element = getElement(smElement, USER_MANAGER_ELEMENT, false); if (element != null) { Element[] acElements = getElements(element, AUTHORIZABLE_ACTION, false); BeanConfig[] aaConfig = new BeanConfig[acElements.length]; for (int i = 0; i < acElements.length; i++) { aaConfig[i] = parseBeanConfig(acElements[i]); umc = new UserManagerConfig(parseBeanConfig(element), aaConfig); element = getElement(smElement, USERID_CLASS_ELEMENT, false); if (element != null) { uidcc = parseBeanConfig(element);
homeDir.mkdir(); Properties variables = new Properties(parser.getVariables()); variables.setProperty( RepositoryConfigurationParser.WORKSPACE_HOME_VARIABLE, homeDir.getPath()); RepositoryConfigurationParser localParser = parser.createSubParser(variables); return localParser.parseWorkspaceConfig(xml); } catch (FileSystemException e) { throw new ConfigurationException("Failed to load workspace configuration", e);
protected void setUp() { Properties variables = new Properties(); variables.setProperty("wsp.home", "target"); parser = new RepositoryConfigurationParser(variables); }
public void testInvalidConfig() { List<InputSource> invalid = new ArrayList<InputSource>(); invalid.add(new InputSource(new StringReader(INVALID_CONFIG_1))); invalid.add(new InputSource(new StringReader(INVALID_CONFIG_2))); invalid.add(new InputSource(new StringReader(INVALID_CONFIG_3))); for (Object anInvalid : invalid) { try { Element xml = parseXML((InputSource) anInvalid, false); parser.parseSecurityConfig(xml); fail("Invalid config -> should fail."); } catch (ConfigurationException e) { // ok } } }
directory.getPath()); RepositoryConfigurationParser localParser = parser.createSubParser(variables); return localParser.parseWorkspaceConfig(xml); } catch (FileNotFoundException e) { return null;
String value = getAttribute(element, ID_ATTRIBUTE, null); if (value != null) { id = replaceVariables(value); } else if (id == null) { File file = new File(home, CLUSTER_NODE_ID_FILE); long syncDelay = Long.parseLong(replaceVariables(getAttribute( element, SYNC_DELAY_ATTRIBUTE, DEFAULT_SYNC_DELAY))); long stopDelay = Long.parseLong(replaceVariables(getAttribute( element, STOP_DELAY_ATTRIBUTE, "-1"))); JournalFactory jf = getJournalFactory(element, home, id); return new ClusterConfig(id, syncDelay, stopDelay, jf);
if (child.getNodeType() == Node.ELEMENT_NODE && DATA_STORE_ELEMENT.equals(child.getNodeName())) { BeanConfig bc = parseBeanConfig(parent, DATA_STORE_ELEMENT); bc.setValidate(false); DataStore store = bc.newInstance(DataStore.class); datastoreElement.setAttribute(CLASS_ATTRIBUTE, item.getNodeValue()); DataStore subDataStore = getDataStoreFactory(newParent, directory).getDataStore(); if (!MultiDataStoreAware.class.isAssignableFrom(subDataStore.getClass())) { throw new ConfigurationException("Only MultiDataStoreAware datastore's can be used within a MultiDataStore."); String type = getAttribute((Element) paramNode, NAME_ATTRIBUTE); if (PRIMARY_DATASTORE_ATTRIBUTE.equals(type)) { primary = subDataStore;
&& DATASOURCE_ELEMENT.equals(child2.getNodeName())) { Element dsdef = (Element) child2; String logicalName = getAttribute(dsdef, "name"); Properties props = parseParameters(dsdef); dsc.addDataSourceDefinition(logicalName, props);
public void testImportConfig() throws Exception { // XML_1 --------------------------------------------------------------- Element xml = parseXML(new InputSource(new StringReader(XML_1)), true); ImportConfig config = parser.parseImportConfig(xml); List<? extends ProtectedItemImporter> ln = config.getProtectedItemImporters(); assertEquals(2, ln.size()); // XML_2 --------------------------------------------------------------- xml = parseXML(new InputSource(new StringReader(XML_2)), true); config = parser.parseImportConfig(xml); ln = config.getProtectedItemImporters(); assertTrue(ln.isEmpty()); // XML_3 --------------------------------------------------------------- xml = parseXML(new InputSource(new StringReader(XML_3)), true); config = parser.parseImportConfig(xml); ln = config.getProtectedItemImporters(); assertEquals(4, ln.size()); // XML_4 --------------------------------------------------------------- xml = parseXML(new InputSource(new StringReader(XML_4)), true); config = parser.parseImportConfig(xml); ln = config.getProtectedItemImporters(); assertEquals(2, ln.size()); // XML_5 --------------------------------------------------------------- xml = parseXML(new InputSource(new StringReader(XML_5)), true); config = parser.parseImportConfig(xml); List<? extends ProtectedItemImporter> lp = config.getProtectedItemImporters(); assertEquals(1, lp.size()); assertTrue(lp.get(0) instanceof UserImporter); assertEquals(UserImporter.ImportBehavior.NAME_BESTEFFORT, ((UserImporter)lp.get(0)).getImportBehavior()); }
/** * Test that a standard workspace configuration file is * correctly parsed. * * @throws Exception on errors */ public void testWorkspaceXml() throws Exception { InputStream xml = getClass().getClassLoader().getResourceAsStream( "org/apache/jackrabbit/core/config/workspace.xml"); WorkspaceConfig config = parser.parseWorkspaceConfig(new InputSource(xml)); assertEquals("target", config.getHomeDir()); assertEquals("default", config.getName()); PersistenceManagerConfig pmc = config.getPersistenceManagerConfig(); assertEquals( "org.apache.jackrabbit.core.persistence.obj.ObjectPersistenceManager", pmc.getClassName()); assertTrue(pmc.getParameters().isEmpty()); assertTrue(config.isSearchEnabled()); WorkspaceSecurityConfig ws = config.getSecurityConfig(); if (ws != null) { BeanConfig ppfConfig = ws.getAccessControlProviderConfig(); if (ppfConfig != null) { ppfConfig.newInstance(AccessControlProvider.class); } } }