1 17 18 19 20 package org.apache.lenya.cms.publication; 21 22 27 public class UniqueDocumentId { 28 29 35 public String computeUniqueDocumentId( 36 Publication publication, 37 String area, 38 String documentid) { 39 SiteTree tree; 40 try { 41 tree = publication.getTree(area); 42 SiteTreeNode node = tree.getNode(documentid); 43 String suffix = null; 44 int version = 0; 45 String idwithoutsuffix = null; 46 47 if (node != null) { 48 int n = documentid.lastIndexOf("/"); 49 String lastToken = ""; 50 String substring = documentid; 51 if ((n < documentid.length()) && (n > 0)) { 52 lastToken = documentid.substring(n); 53 substring = documentid.substring(0, n); 54 } 55 56 int l = lastToken.length(); 57 int index = lastToken.lastIndexOf("-"); 58 if (0 < index && index < l) { 59 suffix = lastToken.substring(index + 1); 60 idwithoutsuffix = substring + lastToken.substring(0, index); 61 version = Integer.parseInt(suffix); 62 } else { 63 idwithoutsuffix = substring + lastToken; 64 } 65 66 while (node != null) { 67 version = version + 1; 68 suffix = (new Integer (version)).toString(); 69 documentid = idwithoutsuffix + "-" + suffix; 70 node = tree.getNode(documentid); 71 } 72 } 73 } catch (SiteTreeException e) { 74 e.printStackTrace(); 75 } 76 77 return documentid; 78 } 79 } 80 | Popular Tags |