svn commit: r1525353 - in /commons/proper/compress/trunk: ./ src/changes/ src/main/java/org/apache/commons/compress/archivers/sevenz/ src/main/java/org/apache/commons/compress/archivers/tar/ src/main/
Author: bodewig Date: Sun Sep 22 13:09:29 2013 New Revision: 1525353 URL: http://svn.apache.org/r1525353 Log: XZ for Java 1.4 has been released, merge the LZMA branch. Added: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/lzma/ - copied from r1525352, commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/lzma/ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java - copied unchanged from r1525352, commons/proper/compress/branches/LZMA/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java commons/proper/compress/trunk/src/test/resources/bla.7z - copied unchanged from r1525352, commons/proper/compress/branches/LZMA/src/test/resources/bla.7z commons/proper/compress/trunk/src/test/resources/bla.tar.lzma - copied unchanged from r1525352, commons/proper/compress/branches/LZMA/src/test/resources/bla.tar.lzma Modified: commons/proper/compress/trunk/ (props changed) commons/proper/compress/trunk/pom.xml commons/proper/compress/trunk/src/changes/changes.xml commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/ (props changed) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ (props changed) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java commons/proper/compress/trunk/src/site/xdoc/examples.xml commons/proper/compress/trunk/src/site/xdoc/index.xml commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java Propchange: commons/proper/compress/trunk/ -- Merged /commons/proper/compress/branches/LZMA:r1491183-1525352 Modified: commons/proper/compress/trunk/pom.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/pom.xml?rev=1525353r1=1525352r2=1525353view=diff == --- commons/proper/compress/trunk/pom.xml (original) +++ commons/proper/compress/trunk/pom.xml Sun Sep 22 13:09:29 2013 @@ -60,7 +60,7 @@ These include: bzip2, gzip, pack200, xz dependency groupIdorg.tukaani/groupId artifactIdxz/artifactId - version1.3/version + version1.4/version /dependency /dependencies Modified: commons/proper/compress/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1525353r1=1525352r2=1525353view=diff == --- commons/proper/compress/trunk/src/changes/changes.xml (original) +++ commons/proper/compress/trunk/src/changes/changes.xml Sun Sep 22 13:09:29 2013 @@ -51,8 +51,7 @@ The action type attribute can be add,u /action action type=add date=2013-05-07 issue=COMPRESS-54 due-to=Damjan Jovanovic -Added read-only support for 7z archives that don't use -LZMA compression. +Added support for 7z archives. /action action type=add date=2013-05-19 issue=COMPRESS-226 due-to=Damjan Jovanovic Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java?rev=1525353r1=1525352r2=1525353view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java Sun Sep 22 13:09:29 2013 @@ -31,6 +31,7 @@ import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.SecretKeySpec; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; +import org.tukaani.xz.LZMAInputStream; import org.tukaani.xz.LZMA2InputStream; class Coders { @@ -47,6 +48,7 @@ class Coders { static CoderId[] coderTable = new CoderId[] { new CoderId(new byte[] { (byte)0x00 }, new CopyDecoder()), +new CoderId(new byte[] { (byte)0x03, (byte)0x01, (byte)0x01 }, new LZMADecoder()), new CoderId(new byte[] { (byte)0x21 }, new LZMA2Decoder()), // FIXME: gives corrupt output //new CoderId(new byte[] { (byte)0x04, (byte)0x01, (byte)0x08 }, new DeflateDecoder()), @@ -98,6 +100,22 @@ class Coders { } } +static class LZMADecoder extends CoderBase { +@Override +InputStream decode(final InputStream in,
svn commit: r1525354 - /commons/proper/compress/branches/LZMA/
Author: bodewig Date: Sun Sep 22 13:11:02 2013 New Revision: 1525354 URL: http://svn.apache.org/r1525354 Log: LZMA branch has been merged to trunk Removed: commons/proper/compress/branches/LZMA/
svn commit: r1525394 - /commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocationStrategy.java
Author: oheger Date: Sun Sep 22 17:46:34 2013 New Revision: 1525394 URL: http://svn.apache.org/r1525394 Log: Added FileLocationStrategy interface. This interface will be used for making the process of resolving files customizable. Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocationStrategy.java Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocationStrategy.java?rev=1525394view=auto == --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocationStrategy.java Sun Sep 22 17:46:34 2013 @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import java.net.URL; + +/** + * p + * An interface allowing applications to customize the process of locating a + * file. + * /p + * p + * {@link FileHandler} uses {@link FileLocator} objects for referencing files. + * These objects are not guaranteed to identify a file in a unique way. For + * instance, if only a file name is defined, this could mean a relative file + * name in the current directory, the name of a resource to be loaded from the + * class path, or something else. Before the file described by a + * {@code FileLocator} can be actually accessed, an unambiguous URL pointing to + * this file has to be obtained. This is the job of a + * {@code FileLocationStrategy}. + * /p + * p + * This interface defines a method for locating a file provided as a + * {@code FileLocator} object. If location is successful, a URL is returned. A + * concrete implementation can perform arbitrary actions to search for the file + * in question at various places. There will also be an implementation allowing + * the combination of multiple {@code FileLocationStrategy} implementations; so + * a file can be searched using multiple strategies until one of them is + * successful. + * /p + * + * @version $Id: $ + * @since 2.0 + */ +public interface FileLocationStrategy +{ +/** + * Tries to locate the specified file. The method also expects the + * {@code FileSystem} to be used. Note that the {@code FileLocator} object + * may also contain a {@code FileSystem}, but this is optional. The passed + * in {@code FileSystem} should be used, and callers must not pass a + * bnull/b reference for this argument. A concrete implementation has to + * evaluate the properties stored in the {@code FileLocator} object and try + * to match them to an existing file. If this can be done, a corresponding + * URL is returned. Otherwise, result is bnull/b. Implementations should + * not throw an exception (unless parameters are bnull/b) as there might + * be alternative strategies which can find the file in question. + * + * @param fileSystem the {@code FileSystem} to be used for this operation + * @param locator the object describing the file to be located + * @return a URL pointing to the referenced file if location was successful; + * bnull/b if the file could not be resolved + */ +URL locate(FileSystem fileSystem, FileLocator locator); +}
svn commit: r1525395 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/io/ProvidedURLLocationStrategy.java test/java/org/apache/commons/configuration/io/TestProv
Author: oheger Date: Sun Sep 22 17:47:08 2013 New Revision: 1525395 URL: http://svn.apache.org/r1525395 Log: Added ProvidedURLLocationStrategy. This is a simple FileLocationStrategy implementation which checks whether the passed in FileLocator already has a URL set. In this case, the file can be accessed directly. Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/ProvidedURLLocationStrategy.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestProvidedURLLocationStrategy.java Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/ProvidedURLLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/ProvidedURLLocationStrategy.java?rev=1525395view=auto == --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/ProvidedURLLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/ProvidedURLLocationStrategy.java Sun Sep 22 17:47:08 2013 @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import java.net.URL; + +/** + * p + * A specialized implementation of {@code FileLocationStrategy} which checks + * whether a passed in {@link FileLocator} already has a defined URL. + * /p + * p + * {@code FileLocator} objects that have a URL already reference a file in an + * unambiguous way. Therefore, this strategy just returns the URL of the passed + * in {@code FileLocator}. It can be used as a first step of the file resolving + * process. If it fails, more sophisticated attempts for resolving the file can + * be made. + * /p + * + * @version $Id: $ + * @since 2.0 + */ +public class ProvidedURLLocationStrategy implements FileLocationStrategy +{ +/** + * {@inheritDoc} This implementation just returns the URL stored in the + * given {@code FileLocator}. + */ +public URL locate(FileSystem fileSystem, FileLocator locator) +{ +return locator.getSourceURL(); +} +} Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestProvidedURLLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestProvidedURLLocationStrategy.java?rev=1525395view=auto == --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestProvidedURLLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestProvidedURLLocationStrategy.java Sun Sep 22 17:47:08 2013 @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + +import java.net.URL; + +import org.apache.commons.configuration.ConfigurationAssert; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; + +/** + * Test class for {@code ProvidedURLLocationStrategy}. + * + * @version $Id: $ + */ +public class TestProvidedURLLocationStrategy +{ +/** The
svn commit: r1525396 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/io/FileSystemLocationStrategy.java test/java/org/apache/commons/configuration/io/TestFileS
Author: oheger Date: Sun Sep 22 17:47:45 2013 New Revision: 1525396 URL: http://svn.apache.org/r1525396 Log: Added FileSystemLocationStrategy class. This is a specialized FileLocationStrategy which delegates to the FileSystem in order to resolve the file in question. Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileSystemLocationStrategy.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileSystemLocationStrategy.java Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileSystemLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileSystemLocationStrategy.java?rev=1525396view=auto == --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileSystemLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileSystemLocationStrategy.java Sun Sep 22 17:47:45 2013 @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import java.net.URL; + +/** + * p + * A specialized implementation of {@code FileLocationStrategy} which uses the + * passed in {@link FileSystem} to locate a file. + * /p + * p + * This strategy implementation ignores the URL of the passed in + * {@link FileLocator} and operates on its base path and file name. These + * properties are passed to the {@code locateFromURL()} method of + * {@code FileSystem}. So the burden of resolving the file is delegated to the + * {@code FileSystem}. + * /p + * + * @version $Id: $ + * @since 2.0 + */ +public class FileSystemLocationStrategy implements FileLocationStrategy +{ +/** + * {@inheritDoc} This implementation delegates to the {@code FileSystem}. + */ +public URL locate(FileSystem fileSystem, FileLocator locator) +{ +return fileSystem.locateFromURL(locator.getBasePath(), +locator.getFileName()); +} +} Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileSystemLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileSystemLocationStrategy.java?rev=1525396view=auto == --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileSystemLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileSystemLocationStrategy.java Sun Sep 22 17:47:45 2013 @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import static org.junit.Assert.assertSame; + +import java.net.URL; + +import org.apache.commons.configuration.ConfigurationAssert; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; + +/** + * Test class for {@code FileSystemLocationStrategy}. + * + * @version $Id: $ + */ +public class TestFileSystemLocationStrategy +{ +/** The strategy to be tested. */ +private FileSystemLocationStrategy strategy; + +@Before +public void setUp()
svn commit: r1525397 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/io/FileLocatorUtils.java test/java/org/apache/commons/configuration/io/TestFileLocatorUtil
Author: oheger Date: Sun Sep 22 17:48:22 2013 New Revision: 1525397 URL: http://svn.apache.org/r1525397 Log: Added methods for file to URL conversions to FileLocatorUtils. When locating files it is often necessary to convert a File object to a URL. The new methods simplify this task by already handling exceptions and returning null in this case. This is the result returned by location strategies if a file could not be resolved. Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocatorUtils.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileLocatorUtils.java Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocatorUtils.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocatorUtils.java?rev=1525397r1=1525396r2=1525397view=diff == --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocatorUtils.java (original) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocatorUtils.java Sun Sep 22 17:48:22 2013 @@ -18,6 +18,7 @@ package org.apache.commons.configuration import java.io.File; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import org.apache.commons.configuration.ConfigurationUtils; @@ -450,6 +451,37 @@ public final class FileLocatorUtils } /** + * Tries to convert the specified URI to a URL. If this causes an exception, + * result is bnull/b. + * + * @param uri the URI to be converted + * @return the resulting URL or bnull/b + */ +static URL convertURIToURL(URI uri) +{ +try +{ +return uri.toURL(); +} +catch (MalformedURLException e) +{ +return null; +} +} + +/** + * Tries to convert the specified file to a URL. If this causes an + * exception, result is bnull/b. + * + * @param file the file to be converted + * @return the resulting URL or bnull/b + */ +static URL convertFileToURL(File file) +{ +return convertURIToURL(file.toURI()); +} + +/** * Tries to find a resource with the given name in the classpath. * * @param resourceName the name of the resource Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileLocatorUtils.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileLocatorUtils.java?rev=1525397r1=1525396r2=1525397view=diff == --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileLocatorUtils.java (original) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileLocatorUtils.java Sun Sep 22 17:48:22 2013 @@ -25,6 +25,8 @@ import static org.junit.Assert.assertTru import java.io.File; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import org.apache.commons.configuration.ConfigurationAssert; @@ -378,4 +380,26 @@ public class TestFileLocatorUtils assertFalse(Wrong result, FileLocatorUtils.isFullyInitialized(locator)); } + +/** + * Tests whether exceptions are handled when converting a URI to a URL. + */ +@Test +public void testConvertToURIException() throws URISyntaxException +{ +URI uri = new URI(test://test/path/file.tst); +assertNull(Got a URL, FileLocatorUtils.convertURIToURL(uri)); +} + +/** + * Tests a successful conversion from a file to a URL. + */ +@Test +public void testConvertFileToURL() throws ConfigurationException +{ +File file = ConfigurationAssert.getTestFile(FILE_NAME); +FileHandler handler = new FileHandler(); +handler.setURL(FileLocatorUtils.convertFileToURL(file)); +checkTestConfiguration(handler); +} }
svn commit: r1525399 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/io/BasePathLocationStrategy.java test/java/org/apache/commons/configuration/io/TestBasePat
Author: oheger Date: Sun Sep 22 17:49:36 2013 New Revision: 1525399 URL: http://svn.apache.org/r1525399 Log: Added BasePathLocationStrategy. This FileLocationStrategy implementation tries to construct a path name from the specified base path and file name. Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/BasePathLocationStrategy.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestBasePathLocationStrategy.java Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/BasePathLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/BasePathLocationStrategy.java?rev=1525399view=auto == --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/BasePathLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/BasePathLocationStrategy.java Sun Sep 22 17:49:36 2013 @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import java.io.File; +import java.net.URL; + +import org.apache.commons.lang3.StringUtils; + +/** + * p + * A specialized implementation of {@code FileLocationStrategy} which tries to + * construct a file path from the locator's base path and file name. + * /p + * p + * This strategies ignores the URL stored in the passed in {@link FileLocator}. + * It generates a path by concatenating the base path (if present) and the file + * name. If the resulting path points to a valid file, the corresponding URL is + * returned. + * /p + * + * @version $Id: $ + * @since 2.0 + */ +public class BasePathLocationStrategy implements FileLocationStrategy +{ +/** + * {@inheritDoc} This implementation uses utility methods from + * {@code FileLocatorUtils} to generate a {@code File} from the locator's + * base path and file name. If this {@code File} exists, its URL is + * returned. + */ +public URL locate(FileSystem fileSystem, FileLocator locator) +{ +if (StringUtils.isNotEmpty(locator.getFileName())) +{ +File file = +FileLocatorUtils.constructFile(locator.getBasePath(), +locator.getFileName()); +if (file.isFile()) +{ +return FileLocatorUtils.convertFileToURL(file); +} +} + +return null; +} +} Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestBasePathLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestBasePathLocationStrategy.java?rev=1525399view=auto == --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestBasePathLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestBasePathLocationStrategy.java Sun Sep 22 17:49:36 2013 @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import static
svn commit: r1525398 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/io/AbsoluteNameLocationStrategy.java test/java/org/apache/commons/configuration/io/TestAbs
Author: oheger Date: Sun Sep 22 17:48:59 2013 New Revision: 1525398 URL: http://svn.apache.org/r1525398 Log: Added AbsoluteNameLocationStrategy. This FileLocationStrategy implementation checks whether the provided file name is an absolute file name and whether this file exists. Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/AbsoluteNameLocationStrategy.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestAbsoluteNameLocationStrategy.java Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/AbsoluteNameLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/AbsoluteNameLocationStrategy.java?rev=1525398view=auto == --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/AbsoluteNameLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/AbsoluteNameLocationStrategy.java Sun Sep 22 17:48:59 2013 @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import java.io.File; +import java.net.URL; + +import org.apache.commons.lang3.StringUtils; + +/** + * p + * A specialized implementation of {@code FileLocationStrategy} which checks + * whether the provided file name is already an absolute file name. + * /p + * p + * This strategy ignores the URL and the base path stored in the passed in + * {@link FileLocator}. It is only triggered by absolute names in the locator's + * {@code fileName} component. + * /p + * + * @version $Id: $ + * @since 2.0 + */ +public class AbsoluteNameLocationStrategy implements FileLocationStrategy +{ +/** + * {@inheritDoc} This implementation constructs a {@code File} object from + * the locator's file name (if defined). If this results in an absolute file + * name pointing to an existing file, the corresponding URL is returned. + */ +public URL locate(FileSystem fileSystem, FileLocator locator) +{ +if (StringUtils.isNotEmpty(locator.getFileName())) +{ +File file = new File(locator.getFileName()); +if (file.isAbsolute() file.exists()) +{ +return FileLocatorUtils.convertFileToURL(file); +} +} + +return null; +} +} Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestAbsoluteNameLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestAbsoluteNameLocationStrategy.java?rev=1525398view=auto == --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestAbsoluteNameLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestAbsoluteNameLocationStrategy.java Sun Sep 22 17:48:59 2013 @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.io.File;
svn commit: r1525400 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/io/ test/java/org/apache/commons/configuration/io/
Author: oheger Date: Sun Sep 22 17:50:15 2013 New Revision: 1525400 URL: http://svn.apache.org/r1525400 Log: Added HomeDirectoryLocationStrategy. This FileLocationStrategy implementation searches for files in a configurable home directory. Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/HomeDirectoryLocationStrategy.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestHomeDirectoryLocationStrategy.java Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocatorUtils.java Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocatorUtils.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocatorUtils.java?rev=1525400r1=1525399r2=1525400view=diff == --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocatorUtils.java (original) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileLocatorUtils.java Sun Sep 22 17:50:15 2013 @@ -541,34 +541,46 @@ public final class FileLocatorUtils } else { -StringBuilder fName = new StringBuilder(); -fName.append(basePath); +file = new File(appendPath(basePath, fileName)); +} + +return file; +} -// My best friend. Paranoia. -if (!basePath.endsWith(File.separator)) -{ -fName.append(File.separator); -} - -// -// We have a relative path, and we have -// two possible forms here. If we have the -// ./ form then just strip that off first -// before continuing. -// -if (fileName.startsWith(. + File.separator)) -{ -fName.append(fileName.substring(2)); -} -else -{ -fName.append(fileName); -} +/** + * Extends a path by another component. The given extension is added to the + * already existing path adding a separator if necessary. + * + * @param path the path to be extended + * @param ext the extension of the path + * @return the extended path + */ +static String appendPath(String path, String ext) +{ +StringBuilder fName = new StringBuilder(); +fName.append(path); -file = new File(fName.toString()); +// My best friend. Paranoia. +if (!path.endsWith(File.separator)) +{ +fName.append(File.separator); } -return file; +// +// We have a relative path, and we have +// two possible forms here. If we have the +// ./ form then just strip that off first +// before continuing. +// +if (ext.startsWith(. + File.separator)) +{ +fName.append(ext.substring(2)); +} +else +{ +fName.append(ext); +} +return fName.toString(); } /** Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/HomeDirectoryLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/HomeDirectoryLocationStrategy.java?rev=1525400view=auto == --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/HomeDirectoryLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/HomeDirectoryLocationStrategy.java Sun Sep 22 17:50:15 2013 @@ -0,0 +1,172 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import java.io.File; +import java.net.URL; + +import org.apache.commons.lang3.StringUtils; + +/** + * p + * A specialized implementation of {@code
svn commit: r1525401 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/io/ClasspathLocationStrategy.java test/java/org/apache/commons/configuration/io/TestClassp
Author: oheger Date: Sun Sep 22 17:50:51 2013 New Revision: 1525401 URL: http://svn.apache.org/r1525401 Log: Added ClasspathLocationStrategy. This FileLocationStrategy implementation interprets a locator's file name as resource name and tries to locate it on the classpath. Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/ClasspathLocationStrategy.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestClasspathLocationStrategy.java Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/ClasspathLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/ClasspathLocationStrategy.java?rev=1525401view=auto == --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/ClasspathLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/ClasspathLocationStrategy.java Sun Sep 22 17:50:51 2013 @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import java.net.URL; + +import org.apache.commons.lang3.StringUtils; + +/** + * p + * A specialized {@code FileLocationStrategy} implementation which searches for + * files on the class path. + * /p + * p + * This strategy implementation ignores the URL and the base path components of + * the passed in {@link FileLocator}. It tries to look up the file name on both + * the class path and the system class path. + * /p + * + * @version $Id: $ + * @since 2.0 + */ +public class ClasspathLocationStrategy implements FileLocationStrategy +{ +/** + * {@inheritDoc} This implementation looks up the locator's file name as a + * resource on the class path. + */ +public URL locate(FileSystem fileSystem, FileLocator locator) +{ +return StringUtils.isEmpty(locator.getFileName()) ? null +: FileLocatorUtils.locateFromClasspath(locator.getFileName()); +} +} Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestClasspathLocationStrategy.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestClasspathLocationStrategy.java?rev=1525401view=auto == --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestClasspathLocationStrategy.java (added) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestClasspathLocationStrategy.java Sun Sep 22 17:50:51 2013 @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.io; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.net.URL; + +import org.apache.commons.configuration.ConfigurationAssert; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; + +/** + * Test class for {@code ClasspathLocationStrategy}. + * + * @version $Id: $ + */ +public class TestClasspathLocationStrategy +{ +/** Constant for a test file name. */ +private static final String FILE_NAME =
svn commit: r1525483 - /commons/proper/net/trunk/src/main/java/examples/mail/IMAPImportMbox.java
Author: sebb Date: Mon Sep 23 00:48:46 2013 New Revision: 1525483 URL: http://svn.apache.org/r1525483 Log: Use IMAP URL to simplify command line Add selector support Modified: commons/proper/net/trunk/src/main/java/examples/mail/IMAPImportMbox.java Modified: commons/proper/net/trunk/src/main/java/examples/mail/IMAPImportMbox.java URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/mail/IMAPImportMbox.java?rev=1525483r1=1525482r2=1525483view=diff == --- commons/proper/net/trunk/src/main/java/examples/mail/IMAPImportMbox.java (original) +++ commons/proper/net/trunk/src/main/java/examples/mail/IMAPImportMbox.java Mon Sep 23 00:48:46 2013 @@ -21,6 +21,10 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.BitSet; +import java.util.List; import org.apache.commons.net.imap.IMAPClient; import org.apache.commons.net.imap.IMAPSClient; @@ -29,8 +33,13 @@ import org.apache.commons.net.imap.IMAPS * This is an example program demonstrating how to use the IMAP[S]Client class. * This program connects to a IMAP[S] server and imports messages into the folder from an mbox file. * p - * Usage: IMAPMail imap[s] server hostname folder username password mboxfile [secure protocol, e.g. TLS] + * Usage: IMAPImportMbox imap[s]://user:password@host[:port]/folder/path mboxfile [selectors] * p + * An example selector might be: + * ul + * li1,2,3,7-10/li + * li-142986- : this is useful for retrieving messages by apmail number, which appears as From xyz-return-142986-apmail-.../li + * ul */ public final class IMAPImportMbox { @@ -39,33 +48,93 @@ public final class IMAPImportMbox public static void main(String[] args) throws IOException { -if (args.length 5) +if (args.length 2) { -System.err.println( -Usage: IMAPImportMbox imap server hostname folder username password mboxfile [TLS]); +System.err.println(Usage: IMAPImportMbox imap[s]://user:password@host[:port]/folder/path mboxfile [selectors]); +System.err.println(\tWhere: a selector is a list of numbers/number ranges - 1,2,3-10 - or a list of strings to match in the initial From line); System.exit(1); } -final String server = args[0]; -final String folder = args[1]; -final String username = args[2]; -final String password = args[3]; -final String file = args[4]; -final String proto = (args.length 5) ? args[5] : null; +final URI uri = URI.create(args[0]); +final String file = args[1]; final File mbox = new File(file); if (!mbox.isFile() || !mbox.canRead()) { throw new IOException(Cannot read mailbox file: + mbox); } -IMAPClient imap; +final String userInfo = uri.getUserInfo(); +if (userInfo == null) { +throw new IllegalArgumentException(Missing userInfo details); +} + +String []userpass = userInfo.split(:); +if (userpass.length != 2) { +throw new IllegalArgumentException(Invalid userInfo details: ' + userpass + '); +} + +String username = userpass[0]; +String password = userpass[1]; + +String path = uri.getPath(); +if (path == null || path.length() 1) { +throw new IllegalArgumentException(Invalid folderPath: ' + path + '); +} +String folder = path.substring(1); // skip the leading / + +ListString contains = new ArrayListString(); // list of strings to find +BitSet msgNums = new BitSet(); // list of message numbers + +for(int i = 2; i args.length; i++) { +String arg = args[i]; +if (arg.matches(\\d+(-\\d+)(,\\d+(-\\d+))*)) { // number,m-n +for(String entry :arg.split(,)) { +String []parts = entry.split(-); +if (parts.length == 2) { // m-n +int low = Integer.parseInt(parts[0]); +int high = Integer.parseInt(parts[1]); +for(int j=low; j = high; j++) { +msgNums.set(j); +} +} else { +msgNums.set(Integer.parseInt(entry)); +} +} +} else { +contains.add(arg); // not a number/number range +} +} + +final IMAPClient imap; -if (proto != null) { -System.out.println(Using secure protocol: + proto); -imap = new IMAPSClient(proto, true); // implicit +if (imaps.equalsIgnoreCase(uri.getScheme())) { +System.out.println(Using secure