You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by eg...@apache.org on 2003/09/30 11:08:05 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/publication DefaultDocumentIdToPathMapper.java
egli 2003/09/30 02:08:05
Modified: src/java/org/apache/lenya/cms/publication
DefaultDocumentIdToPathMapper.java
Log:
The DefaultDocumentIdToPathMapper now also implements the
PathToDocumentIdMapper interface, i.e. it can be used to query for a
document-id given a file, an area and a publication.
Revision Changes Path
1.14 +43 -10 cocoon-lenya/src/java/org/apache/lenya/cms/publication/DefaultDocumentIdToPathMapper.java
Index: DefaultDocumentIdToPathMapper.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/DefaultDocumentIdToPathMapper.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DefaultDocumentIdToPathMapper.java 4 Sep 2003 17:04:01 -0000 1.13
+++ DefaultDocumentIdToPathMapper.java 30 Sep 2003 09:08:05 -0000 1.14
@@ -62,21 +62,32 @@
*
*
*/
-public class DefaultDocumentIdToPathMapper implements DocumentIdToPathMapper {
+public class DefaultDocumentIdToPathMapper
+ implements DocumentIdToPathMapper, PathToDocumentIdMapper {
/**
* @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getFile(org.apache.lenya.cms.publication.Publication, java.lang.String, java.lang.String, java.lang.String)
*/
- public File getFile(Publication publication, String area, String documentId, String language) {
- File file = new File(getDirectory(publication, area, documentId), getFilename(language));
+ public File getFile(
+ Publication publication,
+ String area,
+ String documentId,
+ String language) {
+ File file =
+ new File(
+ getDirectory(publication, area, documentId),
+ getFilename(language));
return file;
}
- /**
- * (non-Javadoc)
- * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getDirectory(org.apache.lenya.cms.publication.Publication, java.lang.String, java.lang.String)
- */
- public File getDirectory(Publication publication, String area, String documentId) {
+ /**
+ * (non-Javadoc)
+ * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getDirectory(org.apache.lenya.cms.publication.Publication, java.lang.String, java.lang.String)
+ */
+ public File getDirectory(
+ Publication publication,
+ String area,
+ String documentId) {
assert documentId.startsWith("/");
// remove leading slash
documentId = documentId.substring(1);
@@ -116,5 +127,27 @@
}
return "index" + languageSuffix + ".xml";
}
-
+
+ public String getDocumentId(
+ Publication publication,
+ String area,
+ File file)
+ throws DocumentDoesNotExistException {
+
+ String fileName = file.getAbsolutePath();
+ String contentDirName =
+ publication.getContentDirectory(area).getAbsolutePath();
+ if (fileName.startsWith(contentDirName)) {
+ // trim everything up to the documentId
+ String relativeFileName =
+ fileName.substring(contentDirName.length());
+ // trim everything after the documentId
+ return relativeFileName.substring(
+ 0,
+ relativeFileName.lastIndexOf("/"));
+ } else {
+ throw new DocumentDoesNotExistException(
+ "No document associated with file" + fileName);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org