1 5 6 package org.exoplatform.services.jcr.impl.storage.filesystem.nodedata; 7 8 9 import javax.jcr.ItemExistsException; 10 import javax.jcr.PathNotFoundException; 11 import javax.jcr.RepositoryException; 12 import org.exoplatform.services.jcr.core.NodeData; 13 import org.exoplatform.services.jcr.util.PathUtil; 14 import java.io.File ; 15 import java.io.IOException ; 16 17 23 24 public class NodeContainerResolver { 25 26 public static final String DOCVIEW_EXT = ".rdv"; 28 29 public NodeContainer resolve(File rootFile, String jcrPath) throws PathNotFoundException, 30 RepositoryException, IOException { 31 33 int depth = PathUtil.getDepth(jcrPath); 34 int i = 0; 35 File container = null; 36 String parentType = "nt:folder"; 38 String ancestor = null; 39 40 41 for (; i <= depth; i++) { 42 ancestor = PathUtil.getAncestorPath(jcrPath, i); 43 container = new File (rootFile.getCanonicalPath() + ancestor); 44 45 if (container.exists()) { 46 if (container.isDirectory()) { 47 parentType = "nt:folder"; 48 } else { 49 if (container.getName().toLowerCase().endsWith(DOCVIEW_EXT)) 50 parentType = "exo:jcrdocfile"; 51 else 52 parentType = "nt:file"; 53 } 54 break; 55 } 56 } 57 58 60 if (parentType == null) 61 throw new PathNotFoundException("File for the <" + jcrPath + "> not found!"); 62 63 if (parentType.equals("nt:file")) 64 return new FileNodeContainer(ancestor, container); 65 else if (parentType.equals("nt:folder")) 66 return new FolderNodeContainer(ancestor, container); 67 else if (parentType.equals("exo:jcrdocfile")) 68 return new DocViewNodeContainer(ancestor, container.getCanonicalPath()); 69 70 throw new RepositoryException("Unresolved node <" + jcrPath + ">!"); 71 72 } 73 74 public NodeContainer create(File rootFile, NodeData node) throws PathNotFoundException, 75 RepositoryException, IOException , ItemExistsException { 76 77 String nodeType = node.getPrimaryNodeType().getName(); 79 String jcrPath = node.getPath(); 80 81 System.out.println("Resolver create ---" + jcrPath + " " + nodeType + " " + rootFile.getCanonicalPath() + jcrPath); 82 83 if (isFile(nodeType)) { 84 File file = new File (rootFile.getCanonicalPath() + jcrPath); 85 if (file.exists()) 86 throw new ItemExistsException("File for <" + jcrPath + "> already exists!"); 87 88 if ("nt:folder".equals(nodeType)) { 89 file.mkdir(); 90 } else { 91 file.createNewFile(); 92 } 93 } 94 else if(!"nt:content".equals(nodeType)) 95 throw new RepositoryException("FS container can't create node of type <" + nodeType + ">!"); 96 97 return resolve(rootFile, jcrPath); 98 } 99 100 private boolean isFile(String type) { 101 102 return type.equals("nt:file") || 103 type.equals("nt:folder") || 104 type.equals("exo:jcrdocfile"); 105 } 106 107 108 } 109 | Popular Tags |