Author: reinhard Date: Sun Oct 10 05:01:35 2004 New Revision: 54246 Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DefaultRepository.java cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java Log: over designed (merging Block with RemoteBlock) (RemoteBlock* to be renamed to Block* later)
Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DefaultRepository.java ============================================================================== --- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DefaultRepository.java (original) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/DefaultRepository.java Sun Oct 10 05:01:35 2004 @@ -56,7 +56,7 @@ Locator locator = (Locator) locatorsIterator.next(); RemoteBlock remoteBlock = null; try { - remoteBlock = locator.getBlock(blockId); + remoteBlock = locator.getRemoteBlock(blockId); if(remoteBlock != null) { tempLocators.add(remoteBlock); } Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java ============================================================================== --- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java (original) +++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/FilesystemLocator.java Sun Oct 10 05:01:35 2004 @@ -50,8 +50,30 @@ } return null; } + + public InputStream getBlockAsStream(String blockUri) throws Exception { + return new FileInputStream(getBlockAsFile(blockUri)); + } - public RemoteBlock getBlock(String blockUri) throws Exception { + protected InputStream getBlockDescriptorAsStream(String blockUri) throws Exception { + + File cobFile = getBlockAsFile(blockUri); + if(cobFile == null) { + return null; + } + + // read the descriptor from the ZIP file + InputStream descriptorInputStream = null; + try { + descriptorInputStream = LocatorUtils.getDescriptorInputStream(new ZipInputStream(new FileInputStream(cobFile))); + } catch (Exception e) { + throw new Exception("Can't read block from " + cobFile.getAbsolutePath()); + } + + return descriptorInputStream; + } + + protected File getBlockAsFile(String blockUri) throws Exception { // strip schema to get the path if(!LocatorUtils.checkUri(blockUri)) { throw new IllegalArgumentException("Can't find the requested block " + blockUri + @@ -60,7 +82,7 @@ File cobFile = null; try { - cobFile = LocatorUtils.getCobAsFile(this.basedir, blockUri.substring("http:/".length())); + cobFile = LocatorUtils.getBlockAsFile(this.basedir, blockUri.substring("http:/".length())); } catch(FileNotFoundException fnfe) { String cobFilePath = null; if(cobFile != null) { @@ -70,39 +92,28 @@ return null; } } - - // read the descriptor from the ZIP file - InputStream descriptorInputStream = null; - try { - descriptorInputStream = LocatorUtils.getDescriptorInputStream(new ZipInputStream(new FileInputStream(cobFile))); - } catch (Exception e) { - throw new Exception("Can't read block from " + cobFile.getAbsolutePath()); - } - + return cobFile; + } + + public RemoteBlock getRemoteBlock(String blockUri) throws Exception { // get the RemoteBlock from the factory - RemoteBlock remoteBlock = null; - try { - remoteBlock = RemoteBlockFactory.getRemoteBlock(descriptorInputStream, this); - } catch (Exception e) { - throw new Exception("Can't read block descriptor from " + - cobFile.getAbsolutePath() + "; " + e.getMessage()); + InputStream descriptorInputStream = getBlockDescriptorAsStream(blockUri); + if(descriptorInputStream == null) { + return null; } - - return remoteBlock; - } + return RemoteBlockFactory.getRemoteBlock(descriptorInputStream, this); + } public RemoteBlock[] browse() { return null; } - - public RemoteBlock[] lookupBlock(String blockId) { - return null; - } public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Filesystemlocator: basedir = " + this.basedir); return sb.toString(); } + + } Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java ============================================================================== --- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java (original) +++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/DefaultRepositoryTest.java Sun Oct 10 05:01:35 2004 @@ -136,7 +136,7 @@ control1.setReturnValue(name, MockControl.ZERO_OR_MORE); try { for(int i = 0; i < allAvailableBlocks.length; i++) { - locator.getBlock(allAvailableBlocks[i]); + locator.getRemoteBlock(allAvailableBlocks[i]); if(hasItem(locatorBlocks, allAvailableBlocks[i])) { control1.setReturnValue(remoteBlock, MockControl.ZERO_OR_MORE); } Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java ============================================================================== --- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java (original) +++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/FilesystemLocatorTest.java Sun Oct 10 05:01:35 2004 @@ -54,7 +54,7 @@ // get the block that should be available and test its data RemoteBlock remoteBlock = null; try { - remoteBlock = filesystemLocator.getBlock(Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKID); + remoteBlock = filesystemLocator.getRemoteBlock(Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKID); } catch(Exception e) { // test fails because this should work (maybe a problem with the mapping) throw e; @@ -85,7 +85,7 @@ // try to get an unavailable block RemoteBlock remoteBlock = null; try { - remoteBlock = filesystemLocator.getBlock(Constants.AVAILABLE_INVALID_SAMPLE_BLOCKID); + remoteBlock = filesystemLocator.getRemoteBlock(Constants.AVAILABLE_INVALID_SAMPLE_BLOCKID); } catch (Exception e) { fail("The block URI is valid but at this place there is no block. This returns null and doesn't raise an exception."); } @@ -148,7 +148,7 @@ public final void testFileLookupWithNullArguments() { try { - File x = LocatorUtils.getCobAsFile(null, null); + File x = LocatorUtils.getBlockAsFile(null, null); fail("If null arguments are passed, an exception has to be thrown."); } catch(FileNotFoundException fnfe) { fail("Wrong exception thrown!"); @@ -161,7 +161,7 @@ try { File cobFile = new File(Constants.VALID_LOCATION_1 + Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKPATH + "/" + Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKFILE); - File resultFile = LocatorUtils.getCobAsFile(new File(Constants.VALID_LOCATION_1), Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKPATH); + File resultFile = LocatorUtils.getBlockAsFile(new File(Constants.VALID_LOCATION_1), Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKPATH); assertEquals(cobFile.getAbsolutePath(), resultFile.getAbsolutePath()); } catch(FileNotFoundException fnfe) { fail("The block " + Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKPATH + " should be found in repository " + Constants.VALID_LOCATION_1); @@ -171,14 +171,14 @@ public final void testUnavailableFileLookups() { // unavailable block try { - File x = LocatorUtils.getCobAsFile(new File(Constants.VALID_LOCATION_1), Constants.AVAILABLE_INVALID_SAMPLE_BLOCKID); + File x = LocatorUtils.getBlockAsFile(new File(Constants.VALID_LOCATION_1), Constants.AVAILABLE_INVALID_SAMPLE_BLOCKID); fail("If a block isn't found in a valid repository, a FileNotFoundException has to be thrown"); } catch(FileNotFoundException fnfe) { // test passed } // unavailable repository try { - File x = LocatorUtils.getCobAsFile(new File(Constants.INVALID_LOCATION), Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKPATH); + File x = LocatorUtils.getBlockAsFile(new File(Constants.INVALID_LOCATION), Constants.AVAILABLE_VALID_WEBMAIL1343_BLOCKPATH); fail("A non-existing repository can't return blocks!"); } catch(FileNotFoundException fnfe) { // test passed