You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jo...@apache.org on 2007/03/12 23:49:38 UTC
svn commit: r517444 - in /cocoon/branches/BRANCH_2_1_X/src:
java/org/apache/cocoon/components/source/impl/
test/org/apache/cocoon/components/source/impl/
Author: joerg
Date: Mon Mar 12 15:49:37 2007
New Revision: 517444
URL: http://svn.apache.org/viewvc?view=rev&rev=517444
Log:
COCOON-2022: fix URI handling in ZipSource
Added:
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/source/impl/ZipSourceTestCase.java (with props)
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/source/impl/ZipSourceTestCase.xtest
Modified:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/ZipSource.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/ZipSourceFactory.java
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/ZipSource.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/ZipSource.java?view=diff&rev=517444&r1=517443&r2=517444
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/ZipSource.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/ZipSource.java Mon Mar 12 15:49:37 2007
@@ -43,7 +43,6 @@
private Source archive;
private String filePath;
-
public ZipSource(String protocol, Source archive, String filePath) {
this.protocol = protocol;
this.archive = archive;
@@ -91,14 +90,12 @@
}
}
- public InputStream getInputStream()
- throws IOException, SourceNotFoundException {
-
+ public InputStream getInputStream() throws IOException, SourceNotFoundException {
ZipInputStream zipStream = new ZipInputStream(this.archive.getInputStream());
try {
ZipEntry entry = findEntry(zipStream);
if (entry == null) {
- throw new SourceNotFoundException("File " + filePath + " is not found in the archive " +
+ throw new SourceNotFoundException("File " + this.filePath + " is not found in the archive " +
this.archive.getURI());
}
@@ -125,7 +122,7 @@
}
public String getURI() {
- return this.protocol + this.archive.getURI() + "!/" + this.filePath;
+ return this.protocol + ":" + this.archive.getURI() + "!/" + this.filePath;
}
public String getScheme() {
@@ -171,4 +168,5 @@
public long getLastModified() {
return this.archive.getLastModified();
}
+
}
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/ZipSourceFactory.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/ZipSourceFactory.java?view=diff&rev=517444&r1=517443&r2=517444
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/ZipSourceFactory.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/ZipSourceFactory.java Mon Mar 12 15:49:37 2007
@@ -53,14 +53,11 @@
private ServiceManager manager;
-
public void service(ServiceManager manager) throws ServiceException {
this.manager = manager;
}
-
- public Source getSource(String location, Map parameters)
- throws IOException, MalformedURLException {
+ public Source getSource(String location, Map parameters) throws IOException, MalformedURLException {
// Checks URL syntax
int protocolEnd = location.indexOf(":");
if (protocolEnd == -1) {
@@ -73,7 +70,7 @@
}
// Get protocol. Protocol is configurable via cocoon.xconf
- final String protocol = location.substring(0, protocolEnd - 1);
+ final String protocol = location.substring(0, protocolEnd);
// Get archive URL
final String archiveURL = location.substring(protocolEnd + 1, archiveEnd);
@@ -108,4 +105,5 @@
this.manager.release(resolver);
}
}
+
}
Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/source/impl/ZipSourceTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/source/impl/ZipSourceTestCase.java?view=auto&rev=517444
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/source/impl/ZipSourceTestCase.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/source/impl/ZipSourceTestCase.java Mon Mar 12 15:49:37 2007
@@ -0,0 +1,31 @@
+package org.apache.cocoon.components.source.impl;
+
+import org.apache.avalon.framework.service.ServiceException;
+
+import org.apache.cocoon.core.container.ContainerTestCase;
+
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceResolver;
+
+public class ZipSourceTestCase extends ContainerTestCase {
+
+ public void testURIHandling() throws Exception {
+ String zipSourceUri = "zip:file://test.zip!/test.xml";
+ Source zipSource;
+ SourceResolver resolver = null;
+ try {
+ resolver = (SourceResolver) getManager().lookup(SourceResolver.ROLE);
+ zipSource = resolver.resolveURI(zipSourceUri);
+ } catch (ServiceException se) {
+ throw new SourceException("SourceResolver is not available.", se);
+ } finally {
+ getManager().release(resolver);
+ }
+ assertTrue("Resolved Source is not an instance of ZipSource.",
+ zipSource instanceof ZipSource);
+ assertEquals("Scheme/protocol is wrong.", "zip", zipSource.getScheme());
+ assertEquals("Uri is wrong.", zipSourceUri, zipSource.getURI());
+ }
+
+}
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/source/impl/ZipSourceTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/source/impl/ZipSourceTestCase.xtest
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/source/impl/ZipSourceTestCase.xtest?view=auto&rev=517444
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/source/impl/ZipSourceTestCase.xtest (added)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/source/impl/ZipSourceTestCase.xtest Mon Mar 12 15:49:37 2007
@@ -0,0 +1,39 @@
+<?xml version="1.0" ?>
+<!--
+ 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.
+-->
+<testcase>
+ <roles>
+ <role name="org.apache.excalibur.source.SourceFactorySelector"
+ shorthand="source-factories"
+ default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
+
+ <role name="org.apache.excalibur.source.SourceResolver"
+ shorthand="source-resolver"
+ default-class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
+ </roles>
+
+ <components>
+ <source-factories>
+ <component-instance class="org.apache.excalibur.source.impl.ResourceSourceFactory" name="resource"/>
+ <component-instance class="org.apache.cocoon.components.source.impl.ZipSourceFactory" name="zip"/>
+ <component-instance class="org.apache.excalibur.source.impl.URLSourceFactory" name="*"/>
+ </source-factories>
+
+ <source-resolver class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
+ </components>
+
+</testcase>