List of usage examples for org.apache.commons.configuration DefaultConfigurationBuilder DefaultConfigurationBuilder
public DefaultConfigurationBuilder()
DefaultConfigurationBuilder
. From source file:org.apache.james.mailetcontainer.impl.MailetConfigImpl.java
/** * Set the Avalon Configuration object for the mailet. * //from w w w .jav a 2s.c o m * @param newConfiguration * the new Configuration for the mailet */ public void setConfiguration(Configuration newConfiguration) { DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); // Disable the delimiter parsing. See JAMES-1232 builder.setDelimiterParsingDisabled(true); Iterator<String> keys = newConfiguration.getKeys(); while (keys.hasNext()) { String key = keys.next(); String[] values = newConfiguration.getStringArray(key); // See JAMES-1177 // Need to replace ".." with "." // See // http://commons.apache.org/configuration/userguide-1.2/howto_xml.html // Escaping dot characters in XML tags key = key.replaceAll("\\.\\.", "\\."); // Convert array values to a "," delimited string value StringBuilder valueBuilder = new StringBuilder(); for (int i = 0; i < values.length; i++) { valueBuilder.append(values[i]); if (i + 1 < values.length) { valueBuilder.append(","); } } builder.addProperty(key, valueBuilder.toString()); } configuration = builder; }
From source file:org.apache.james.mailetcontainer.impl.MailetConfigImplTest.java
@Before public void setUp() throws Exception { builder = new DefaultConfigurationBuilder(); config = new MailetConfigImpl(); }
From source file:org.apache.james.mailetcontainer.lib.AbstractStateCompositeProcessorTest.java
private HierarchicalConfiguration createConfig(List<String> states) throws ConfigurationException { StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\"?>"); sb.append("<processors>"); for (String state : states) { sb.append("<processor state=\""); sb.append(state);//from ww w . j a va 2s . com sb.append("\"/>"); } sb.append("</processors>"); DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); builder.load(new ByteArrayInputStream(sb.toString().getBytes())); return builder; }
From source file:org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessorTest.java
private HierarchicalConfiguration createConfig(Class<?> matcherClass, Class<?> mailetClass, int count) throws ConfigurationException { StringBuilder sb = new StringBuilder(); sb.append("<processor state=\"" + Mail.DEFAULT + "\">"); sb.append("<mailet match=\"").append(matcherClass.getName()).append("=").append(count).append("\"") .append(" class=\"").append(mailetClass.getName()).append("\">"); sb.append("<state>test</state>"); sb.append("</mailet>"); sb.append("</processor>"); DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); builder.load(new ByteArrayInputStream(sb.toString().getBytes())); return builder; }
From source file:org.apache.james.mailrepository.file.FileMailRepository.java
@Override @PostConstruct/*from w w w.jav a 2 s.co m*/ public void init() throws Exception { try { DefaultConfigurationBuilder reposConfiguration = new DefaultConfigurationBuilder(); reposConfiguration.addProperty("[@destinationURL]", destination); objectRepository = new FilePersistentObjectRepository(); objectRepository.setLog(getLogger()); objectRepository.setFileSystem(fileSystem); objectRepository.configure(reposConfiguration); objectRepository.init(); streamRepository = new FilePersistentStreamRepository(); streamRepository.setLog(getLogger()); streamRepository.setFileSystem(fileSystem); streamRepository.configure(reposConfiguration); streamRepository.init(); if (cacheKeys) keys = Collections.synchronizedSet(new HashSet<String>()); // Finds non-matching pairs and deletes the extra files HashSet<String> streamKeys = new HashSet<String>(); for (Iterator<String> i = streamRepository.list(); i.hasNext();) { streamKeys.add(i.next()); } HashSet<String> objectKeys = new HashSet<String>(); for (Iterator<String> i = objectRepository.list(); i.hasNext();) { objectKeys.add(i.next()); } @SuppressWarnings("unchecked") Collection<String> strandedStreams = (Collection<String>) streamKeys.clone(); strandedStreams.removeAll(objectKeys); for (Object strandedStream : strandedStreams) { String key = (String) strandedStream; remove(key); } @SuppressWarnings("unchecked") Collection<String> strandedObjects = (Collection<String>) objectKeys.clone(); strandedObjects.removeAll(streamKeys); for (Object strandedObject : strandedObjects) { String key = (String) strandedObject; remove(key); } if (keys != null) { // Next get a list from the object repository // and use that for the list of keys keys.clear(); for (Iterator<String> i = objectRepository.list(); i.hasNext();) { keys.add(i.next()); } } if (getLogger().isDebugEnabled()) { String logBuffer = getClass().getName() + " created in " + destination; getLogger().debug(logBuffer); } } catch (Exception e) { final String message = "Failed to retrieve Store component:" + e.getMessage(); getLogger().error(message, e); throw e; } }
From source file:org.apache.james.mailrepository.FileMailRepositoryTest.java
/** * @return//from w w w.j a v a2 s . c om * @throws ServiceException * @throws ConfigurationException * @throws Exception */ @Override protected MailRepository getMailRepository() throws Exception { MockFileSystem fs = new MockFileSystem(); FileMailRepository mr = new FileMailRepository(); mr.setFileSystem(fs); mr.setLog(LoggerFactory.getLogger("MockLog")); DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder(); defaultConfiguration.addProperty("[@destinationURL]", "file://target/var/mr"); defaultConfiguration.addProperty("[@type]", "MAIL"); mr.configure(defaultConfiguration); mr.init(); return mr; }
From source file:org.apache.james.mailrepository.jdbc.JDBCMailRepository.java
/** * Initialises the JDBC repository./* w w w. j a v a 2s . c om*/ * <ol> * <li>Tests the connection to the database.</li> * <li>Loads SQL strings from the SQL definition file, choosing the * appropriate SQL for this connection, and performing paramter * substitution,</li> * <li>Initialises the database with the required tables, if necessary.</li> * </ol> * * @throws Exception * if an error occurs */ @Override @PostConstruct public void init() throws Exception { StringBuffer logBuffer; if (getLogger().isDebugEnabled()) { getLogger().debug(this.getClass().getName() + ".initialize()"); } try { if (filestore != null) { // prepare Configurations for stream repositories DefaultConfigurationBuilder streamConfiguration = new DefaultConfigurationBuilder(); streamConfiguration.addProperty("[@destinationURL]", filestore); sr = new FilePersistentStreamRepository(); sr.setLog(getLogger()); sr.setFileSystem(fileSystem); sr.configure(streamConfiguration); sr.init(); if (getLogger().isDebugEnabled()) { getLogger().debug("Got filestore for JdbcMailRepository: " + filestore); } } if (getLogger().isDebugEnabled()) { String logBuf = this.getClass().getName() + " created according to " + destination; getLogger().debug(logBuf); } } catch (Exception e) { final String message = "Failed to retrieve Store component:" + e.getMessage(); getLogger().error(message, e); throw new ConfigurationException(message, e); } theJDBCUtil = new JDBCUtil() { protected void delegatedLog(String logString) { JDBCMailRepository.this.getLogger().warn("JDBCMailRepository: " + logString); } }; // Test the connection to the database, by getting the DatabaseMetaData. Connection conn = datasource.getConnection(); PreparedStatement createStatement = null; try { // Initialise the sql strings. InputStream sqlFile; try { sqlFile = fileSystem.getResource(sqlFileName); } catch (Exception e) { getLogger().error(e.getMessage(), e); throw e; } if (getLogger().isDebugEnabled()) { logBuffer = new StringBuffer(128).append("Reading SQL resources from file: ").append(sqlFileName) .append(", section ").append(this.getClass().getName()).append("."); getLogger().debug(logBuffer.toString()); } // Build the statement parameters Map<String, String> sqlParameters = new HashMap<String, String>(); if (tableName != null) { sqlParameters.put("table", tableName); } if (repositoryName != null) { sqlParameters.put("repository", repositoryName); } sqlQueries = new SqlResources(); sqlQueries.init(sqlFile, this.getClass().getName(), conn, sqlParameters); // Check if the required table exists. If not, create it. DatabaseMetaData dbMetaData = conn.getMetaData(); // Need to ask in the case that identifiers are stored, ask the // DatabaseMetaInfo. // Try UPPER, lower, and MixedCase, to see if the table is there. if (!(theJDBCUtil.tableExists(dbMetaData, tableName))) { // Users table doesn't exist - create it. createStatement = conn.prepareStatement(sqlQueries.getSqlString("createTable", true)); createStatement.execute(); if (getLogger().isInfoEnabled()) { logBuffer = new StringBuffer(64).append("JdbcMailRepository: Created table '").append(tableName) .append("'."); getLogger().info(logBuffer.toString()); } } checkJdbcAttributesSupport(dbMetaData); } finally { theJDBCUtil.closeJDBCStatement(createStatement); theJDBCUtil.closeJDBCConnection(conn); } }
From source file:org.apache.james.mailrepository.jdbc.JDBCMailRepositoryTest.java
/** * @return/*w w w. j a v a2 s . c o m*/ * @throws ServiceException * @throws ConfigurationException * @throws Exception */ @Override protected MailRepository getMailRepository() throws Exception { MockFileSystem fs = new MockFileSystem(); DataSource datasource = getDataSource(); JDBCMailRepository mr = new JDBCMailRepository(); DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder(); defaultConfiguration.addProperty("[@destinationURL]", "db://maildb/mr/testrepo"); defaultConfiguration.addProperty("sqlFile", "file://conf/sqlResources.xml"); defaultConfiguration.addProperty("[@type]", "MAIL"); mr.setFileSystem(fs); mr.setDatasource(datasource); mr.setLog(LoggerFactory.getLogger("MockLog")); mr.configure(defaultConfiguration); mr.init(); return mr; }
From source file:org.apache.james.mailrepository.MBoxMailRepositoryTest.java
protected MailRepository getMailRepository() throws Exception { MBoxMailRepository mr = new MBoxMailRepository(); DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder(); File fInbox = new MockFileSystem().getFile("file://conf/org/apache/james/mailrepository/testdata/Inbox"); String mboxPath = "mbox://" + fInbox.toURI().toString().substring(new File("").toURI().toString().length()); defaultConfiguration.addProperty("[@destinationURL]", mboxPath); defaultConfiguration.addProperty("[@type]", "MAIL"); mr.setLog(LoggerFactory.getLogger("MockLog")); mr.configure(defaultConfiguration);/* www .j a v a 2 s . co m*/ return mr; }
From source file:org.apache.james.mailrepository.memory.MemoryMailRepositoryStore.java
private CombinedConfiguration createRepositoryCombinedConfig(MailRepositoryUrl mailRepositoryUrl) { CombinedConfiguration config = new CombinedConfiguration(); HierarchicalConfiguration defaultProtocolConfig = perProtocolMailRepositoryDefaultConfiguration .get(mailRepositoryUrl.getProtocol()); if (defaultProtocolConfig != null) { config.addConfiguration(defaultProtocolConfig); }/*from w ww . ja va2 s . c o m*/ DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); builder.addProperty("[@destinationURL]", mailRepositoryUrl.asString()); config.addConfiguration(builder); return config; }