Author: adamw Date: 2005-11-11 17:53:22 -0500 (Fri, 11 Nov 2005) New Revision: 1560 Added: trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/SlashNamesTest.java Modified: trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/AbstractResource.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnResource.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnContentManager.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnDirectory.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHeadNode.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHistoricNode.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectory.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectoryHelper.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNode.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNodeHelper.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewResourceHelper.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNode.java Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-29 : implementation Modified: trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/AbstractResource.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/AbstractResource.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/AbstractResource.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -92,4 +92,12 @@ * is the root directory. */ public String getName(); + + /** + * Gets the full name of this resource, that is, path to this resource + * relative to the content manager this node was read from. + * + * @return Full name of this resource. + */ + public String getFullName(); } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnResource.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnResource.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnResource.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -46,28 +46,22 @@ protected String fullPath; protected File file; protected String name; + protected String fullName; protected SvnContentManager svnCm; - public AbstractSvnResource(String id, String resFullPath, File file, String name, + public AbstractSvnResource(String id, String resFullPath, File file, SvnContentManager svnCm) { this.file = file; this.id = id; - this.name = name; this.svnCm = svnCm; - fullPath = resFullPath; + String[] pathParams = svnCm.getNamesFromPath(resFullPath); - // Compacting fullPath, that is, throwing out unnecessary /. - while (fullPath.contains("//")) - fullPath = fullPath.replace("//", "/"); + fullPath = pathParams[0]; + name = pathParams[1]; + fullName = pathParams[2]; - if (fullPath.startsWith("/")) - fullPath = fullPath.substring(1); - - if (fullPath.endsWith("/")) - fullPath = fullPath.substring(0, fullPath.length() - 1); - modifiedProperties = new HashMap<String, String>(); service = Tools.getService(); } @@ -115,6 +109,10 @@ return name; } + public String getFullName() { + return fullName; + } + protected boolean deleteResource() { return false; } @@ -154,26 +152,15 @@ return null; String parentPath; - String parentName; int lastSlash = fullPath.lastIndexOf('/'); if (lastSlash == -1) { // No / at all in the path - this resource must be a child of the // root directory. parentPath = ""; - parentName = ""; } else { // Getting the parent path. parentPath = fullPath.substring(0, lastSlash); - - // Getting the name from the parent's path. This is either the same - // as path, if the parent directory is a child of the root - // directory, or the last segment of parent's path. - int parentLastSlash = parentPath.lastIndexOf('/'); - if (parentLastSlash == -1) - parentName = parentPath; - else - parentName = parentPath.substring(parentLastSlash+1); } // Checking if the path that we constructed is valid (that is, not @@ -187,6 +174,6 @@ File parentFile = svnCm.getFileForPrefixedPath(parentPath); - return new SvnDirectory(id, parentPath, parentFile, parentName, svnCm); + return new SvnDirectory(id, parentPath, parentFile, svnCm); } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnContentManager.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnContentManager.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnContentManager.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -39,11 +39,13 @@ * <code>service</code> - service interface binding. */ private SvnService service; + private int prefixLength; public SvnContentManager(String id, String prefix) { super(id, prefix); service = Tools.getService(); + prefixLength = prefix.length(); } /** @@ -93,33 +95,50 @@ boolean checkPathChild(String path) { return path.startsWith(prefix) && (!path.equals(prefix)); } - - @Override - public Directory getRootDirectory() { - return getDirectory(""); - } - - private String getNameFromPath(String path) { + + /** + * From the given full file path, extractes a node's name and full name. + * Also, modifies the given path to a most compact form (removing any + * unnecessary / and spaces. + * @param path Path from which to extract the names. + * @return An array of strings, containing 3 elements: { compacted full + * file path, name of resource, full name of resource }. + */ + String[] getNamesFromPath(String path) { + // Compacting path, that is, throwing out unnecessary /. + while (path.contains("//")) + path = path.replace("//", "/"); + + if (path.startsWith("/")) + path = path.substring(1); + + if (path.endsWith("/")) + path = path.substring(0, path.length() - 1); + + // Constructing fullName - just getting rid of the prefix and possible + // / on the first position. + String fullName = path.trim().substring(prefixLength); + if (fullName.startsWith("/")) + fullName = fullName.substring(1); + + // Constructing name. String name; - path = path.trim(); - // Getting the index of last /. - int lastSlash = path.lastIndexOf('/'); + int lastSlash = fullName.lastIndexOf('/'); - // If the name ends with a /, getting the part before it. - if ((lastSlash == path.length()-1) && (lastSlash != -1)) { - path = path.substring(0, lastSlash); - lastSlash = path.lastIndexOf('/'); - } - if (lastSlash != -1) { - name = path.substring(lastSlash+1); + name = fullName.substring(lastSlash+1); } else - name = path; + name = fullName; - return name; + return new String[] { path, name, fullName }; } + + @Override + public Directory getRootDirectory() { + return getDirectory(""); + } @Override public Node getNode(String path) { @@ -129,7 +148,7 @@ throw new ResourceDoesNotExist(file.getAbsolutePath()); return new SvnHeadNode(id, getPrefixedPath(path), file, - getNameFromPath(path), this); + this); } @Override @@ -140,6 +159,6 @@ throw new ResourceDoesNotExist(file.getAbsolutePath()); return new SvnDirectory(id, getPrefixedPath(path), file, - getNameFromPath(path), this); + this); } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnDirectory.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnDirectory.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnDirectory.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -39,9 +39,9 @@ * @author Damon Sicore (da...@si...) */ public class SvnDirectory extends AbstractSvnResource implements Directory { - public SvnDirectory(String id, String fullPath, File file, String name, + public SvnDirectory(String id, String fullPath, File file, SvnContentManager svnCm) { - super(id, fullPath, file, name, svnCm); + super(id, fullPath, file, svnCm); } public NodeList getNodes() { @@ -65,7 +65,7 @@ for (String node : list) { String childFullPath = fullPath + '/' + node; ret.add(new SvnHeadNode(id, childFullPath, new File(service - .getFileSystemPath(id, childFullPath)), node, svnCm)); + .getFileSystemPath(id, childFullPath)), svnCm)); } } catch (SvnOperationFailed e) { throw new RepositoryException(e); @@ -96,7 +96,7 @@ for (String directory : list) { String childFullPath = fullPath + '/' + directory; ret.add(new SvnDirectory(id, childFullPath, new File(service - .getFileSystemPath(id, childFullPath)), directory, + .getFileSystemPath(id, childFullPath)), svnCm)); } } catch (SvnOperationFailed e) { @@ -106,37 +106,25 @@ return ret; } - private void checkName(String name) throws RepositoryException { - if (name.contains("/")) - throw new RepositoryException("A / found in the given name: " - + name); - } - public Node getNode(String name) throws RepositoryException, ResourceDoesNotExist { - checkName(name); - String reqFullPath = fullPath + "/" + name; File reqNode = svnCm.getFileForPrefixedPath(reqFullPath); if (!reqNode.isFile()) throw new ResourceDoesNotExist(reqNode.getAbsolutePath()); - return new SvnHeadNode(id, reqFullPath, reqNode, name, svnCm); + return new SvnHeadNode(id, reqFullPath, reqNode, svnCm); } public Directory getDirectory(String name) throws RepositoryException, ResourceDoesNotExist { - checkName(name); - String reqFullPath = fullPath + "/" + name; File reqDir = svnCm.getFileForPrefixedPath(reqFullPath); if (!reqDir.isDirectory()) throw new ResourceDoesNotExist(reqDir.getAbsolutePath()); - return new SvnDirectory(id, reqFullPath, reqDir, name, svnCm); + return new SvnDirectory(id, reqFullPath, reqDir, svnCm); } public Node newNode(String name) { - checkName(name); - String childFullPath = fullPath + '/' + name; try { @@ -148,16 +136,14 @@ if (newFile.exists()) throw new ResourceAlreadyExists(childFullPath); - return new SvnNewNodeHelper(id, childFullPath, newFile, name, - svnCm, this); + return new SvnNewNodeHelper(id, childFullPath, newFile, + svnCm, this, name); } catch (SvnOperationFailed e) { throw new RepositoryException(e); } } public Directory newDirectory(String name) throws RepositoryException { - checkName(name); - String childFullPath = fullPath + '/' + name; try { service.synchronizeWithWriteLock(id, childFullPath); @@ -169,8 +155,8 @@ throw new ResourceAlreadyExists(childFullPath); } - return new SvnNewDirectoryHelper(id, childFullPath, newDir, name, - svnCm, this); + return new SvnNewDirectoryHelper(id, childFullPath, newDir, + svnCm, this, name); } catch (SvnOperationFailed e) { throw new RepositoryException(e); } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHeadNode.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHeadNode.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHeadNode.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -48,9 +48,9 @@ return content; } - public SvnHeadNode(String id, String fullPath, File file, String name, + public SvnHeadNode(String id, String fullPath, File file, SvnContentManager svnCm) { - super(id, fullPath, file, name, svnCm); + super(id, fullPath, file, svnCm); content = null; } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHistoricNode.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHistoricNode.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHistoricNode.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -49,7 +49,7 @@ public SvnHistoricNode(String id, String fullPath, File file, String name, SvnContentManager svnCm, Date commitDate, String logMessage, long revisionAbsolute, int revisionRelative) { - super(id, fullPath, file, name, svnCm); + super(id, fullPath, file, svnCm); this.logMessage = logMessage; this.commitDate = commitDate; Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectory.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectory.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectory.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -35,9 +35,9 @@ * @author Damon Sicore (da...@si...) */ public class SvnNewDirectory extends SvnDirectory { - public SvnNewDirectory(String id, String fullPath, File file, String name, + public SvnNewDirectory(String id, String fullPath, File file, SvnContentManager svnCm) { - super(id, fullPath, file, name, svnCm); + super(id, fullPath, file, svnCm); } @Override Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectoryHelper.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectoryHelper.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectoryHelper.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -24,6 +24,7 @@ import java.io.File; import java.util.List; +import org.jboss.shotoku.AbstractResource; import org.jboss.shotoku.Directory; import org.jboss.shotoku.Node; import org.jboss.shotoku.NodeList; @@ -40,20 +41,18 @@ private Directory currentDirectory; public SvnNewDirectoryHelper(String id, String fullPath, File file, - String name, SvnContentManager svnCm, Directory parentDirectory) { - super(parentDirectory, name); - currentDirectory = new SvnNewDirectory(id, fullPath, file, name, svnCm); + SvnContentManager svnCm, Directory parentDirectory, + String requestedName) { + super(parentDirectory, requestedName); + currentDirectory = new SvnNewDirectory(id, fullPath, file, svnCm); + currentResource = currentDirectory; } - public void save(String logMessage) throws RepositoryException { - currentDirectory.save(logMessage); + protected AbstractResource getNormalResource() { currentDirectory = parentDirectory.getDirectory(name); + return currentDirectory; } - public void delete() throws RepositoryException { - currentDirectory.delete(); - } - public List<Directory> getDirectories() throws RepositoryException { return currentDirectory.getDirectories(); } @@ -63,14 +62,6 @@ return currentDirectory.getDirectory(name); } - public String getLogMessage() throws RepositoryException { - return currentDirectory.getLogMessage(); - } - - public String getName() { - return currentDirectory.getName(); - } - public Node getNode(String name) throws RepositoryException, ResourceDoesNotExist { return currentDirectory.getNode(name); @@ -79,15 +70,7 @@ public NodeList getNodes() throws RepositoryException { return currentDirectory.getNodes(); } - - public Directory getParent() throws RepositoryException { - return currentDirectory.getParent(); - } - - public String getProperty(String name) throws RepositoryException { - return currentDirectory.getProperty(name); - } - + public boolean hasIndex(String name) throws RepositoryException { return currentDirectory.hasIndex(name); } @@ -105,8 +88,4 @@ public void setIndex(String name, boolean index) throws RepositoryException { currentDirectory.setIndex(name, index); } - - public void setProperty(String name, String value) { - currentDirectory.setProperty(name, value); - } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNode.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNode.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNode.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -37,9 +37,9 @@ public class SvnNewNode extends SvnHeadNode { private NodeContent content; - public SvnNewNode(String id, String fullPath, File file, String name, + public SvnNewNode(String id, String fullPath, File file, SvnContentManager svnCm) { - super(id, fullPath, file, name, svnCm); + super(id, fullPath, file, svnCm); content = new NodeContent(); } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNodeHelper.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNodeHelper.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNodeHelper.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -26,6 +26,7 @@ import java.io.OutputStream; import java.util.Date; +import org.jboss.shotoku.AbstractResource; import org.jboss.shotoku.Directory; import org.jboss.shotoku.History; import org.jboss.shotoku.Node; @@ -38,25 +39,23 @@ public class SvnNewNodeHelper extends SvnNewResourceHelper implements Node { private Node currentNode; - public SvnNewNodeHelper(String id, String fullPath, File file, String name, - SvnContentManager svnCm, Directory parentDirectory) { - super(parentDirectory, name); - currentNode = new SvnNewNode(id, fullPath, file, name, svnCm); + public SvnNewNodeHelper(String id, String fullPath, File file, + SvnContentManager svnCm, Directory parentDirectory, + String requestedName) { + super(parentDirectory, requestedName); + currentNode = new SvnNewNode(id, fullPath, file, svnCm); + currentResource = currentNode; } - - public void save(String logMessage) throws RepositoryException { - currentNode.save(logMessage); + + protected AbstractResource getNormalResource() { currentNode = parentDirectory.getNode(name); + return currentNode; } public void copyToFile(String fileName) throws RepositoryException { currentNode.copyToFile(fileName); } - public void delete() throws RepositoryException { - currentNode.delete(); - } - public String getContent() throws RepositoryException { return currentNode.getContent(); } @@ -81,30 +80,14 @@ return currentNode.getLength(); } - public String getLogMessage() throws RepositoryException { - return currentNode.getLogMessage(); - } - public String getMimeType() { return currentNode.getMimeType(); } - public String getName() { - return currentNode.getName(); - } - public OutputStream getOutputStream() { return currentNode.getOutputStream(); } - public Directory getParent() throws RepositoryException { - return currentNode.getParent(); - } - - public String getProperty(String name) throws RepositoryException { - return currentNode.getProperty(name); - } - public int getRevisionNumber() throws RepositoryException { return currentNode.getRevisionNumber(); } @@ -121,10 +104,6 @@ currentNode.setContent(content); } - public void setProperty(String name, String value) { - currentNode.setProperty(name, value); - } - public Date getLastModificationDate() throws RepositoryException { return currentNode.getLastModificationDate(); } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewResourceHelper.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewResourceHelper.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewResourceHelper.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -21,7 +21,9 @@ */ package org.jboss.shotoku.svn; +import org.jboss.shotoku.AbstractResource; import org.jboss.shotoku.Directory; +import org.jboss.shotoku.exceptions.RepositoryException; /** * A base class for new resource helpers - their function is tu tunnel all @@ -32,12 +34,57 @@ * @author Adam Warski (ad...@as...) * @author Damon Sicore (da...@si...) */ -public abstract class SvnNewResourceHelper { +public abstract class SvnNewResourceHelper implements AbstractResource { protected Directory parentDirectory; protected String name; + protected AbstractResource currentResource; public SvnNewResourceHelper(Directory parentDirectory, String name) { this.parentDirectory = parentDirectory; this.name = name; } + + protected abstract AbstractResource getNormalResource(); + + public void save(String logMessage) throws RepositoryException { + String[] nameParts = name.split("[/]"); + Directory lastParent = parentDirectory; + for (int i=0; i<nameParts.length-1; i++) { + if (!"".equals(nameParts[i])) { + lastParent = lastParent.newDirectory(nameParts[i]); + lastParent.save(logMessage); + } + } + + currentResource.save(logMessage); + currentResource = getNormalResource(); + } + + public String getFullName() { + return currentResource.getFullName(); + } + + public void delete() throws RepositoryException { + currentResource.delete(); + } + + public String getLogMessage() throws RepositoryException { + return currentResource.getLogMessage(); + } + + public String getName() { + return currentResource.getName(); + } + + public Directory getParent() throws RepositoryException { + return currentResource.getParent(); + } + + public String getProperty(String name) throws RepositoryException { + return currentResource.getProperty(name); + } + + public void setProperty(String name, String value) { + currentResource.setProperty(name, value); + } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNode.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNode.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNode.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -45,9 +45,9 @@ SvnNode.class.getResourceAsStream("/mime-types.txt")); } - public SvnNode(String id, String fullPath, File file, String name, + public SvnNode(String id, String fullPath, File file, SvnContentManager svnCm) { - super(id, fullPath, file, name, svnCm); + super(id, fullPath, file, svnCm); } public History getHistory() { Added: trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/SlashNamesTest.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/SlashNamesTest.java 2005-11-11 16:00:04 UTC (rev 1559) +++ trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/SlashNamesTest.java 2005-11-11 22:53:22 UTC (rev 1560) @@ -0,0 +1,66 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.shotoku.test; + +import org.jboss.shotoku.Directory; +import org.jboss.shotoku.Node; + +/** + * @author Adam Warski (ad...@as...) + * @author Damon Sicore (da...@si...) + */ +public class SlashNamesTest extends ShotokuTest { + private final static String TEST_DIR = "slash-test-dir"; + private final static String TEST_NESTED_DIR = "a/b/c"; + private final static String TEST_NESTED_NODE = "h/j/k"; + private final static String TEST_CONTENT = "T"; + + public void setUp() { + cm.getRootDirectory().newDirectory(TEST_DIR).save(TEST_DIR); + } + + public void testNested() { + Directory base = cm.getDirectory(TEST_DIR); + Directory nested1 = base.newDirectory(TEST_NESTED_DIR); + Node nested2 = base.newNode(TEST_NESTED_NODE); + + assertTrue((TEST_DIR + "/" + TEST_NESTED_DIR).equals(nested1.getFullName())); + assertTrue((TEST_DIR + "/" + TEST_NESTED_NODE).equals(nested2.getFullName())); + + nested1.save(""); + + nested2.setContent(TEST_CONTENT); + nested2.save(""); + + // We should be able to get the directories and node. + base.getDirectory("a").getDirectory("b").getDirectory("c"); + base.getDirectory(TEST_NESTED_DIR); + + assertTrue(TEST_CONTENT.equals(base.getDirectory("h"). + getDirectory("j").getNode("k").getContent())); + assertTrue(TEST_CONTENT.equals(base.getNode(TEST_NESTED_NODE).getContent())); + } + + public void tearDown() { + cm.getDirectory(TEST_DIR).delete(); + } +} |