1 6 7 package org.exoplatform.services.jcr.impl.storage.filesystem; 8 9 10 import org.apache.commons.logging.Log; 11 12 import java.io.File ; 13 14 15 import java.util.List ; 16 import javax.jcr.query.QueryResult; 17 import javax.jcr.query.Query; 18 import java.util.ArrayList ; 19 20 21 import java.io.IOException ; 22 23 24 import javax.jcr.*; 25 26 import org.apache.commons.codec.binary.Base64; 27 import org.exoplatform.services.jcr.core.NodeChange; 28 import org.exoplatform.services.jcr.core.NodeData; 29 import org.exoplatform.services.jcr.impl.core.NodeImpl; 30 import org.exoplatform.services.jcr.impl.core.PropertyImpl; 31 import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl; 32 import org.exoplatform.services.jcr.impl.storage.filesystem.nodedata.NodeContainer; 33 import org.exoplatform.services.jcr.impl.storage.filesystem.nodedata.NodeContainerResolver; 34 import org.exoplatform.services.jcr.storage.Container; 35 import org.exoplatform.services.jcr.storage.WorkspaceContainer; 36 import org.exoplatform.services.log.LogUtil; 37 38 39 54 public class SimpleFsContainerImpl implements WorkspaceContainer { 55 56 private static long id = System.currentTimeMillis(); 57 private static NodeContainerResolver resolver = new NodeContainerResolver(); 58 private Log log; 59 private File rootFile; 60 private NodeImpl rootNode; 61 private String name; 62 63 64 public SimpleFsContainerImpl(String name, String rootPath) throws RepositoryException { 65 log = LogUtil.getLog("org.exoplatform.services.jcr"); 66 rootFile = new File (rootPath); 67 if (!rootFile.exists()) 68 rootFile.mkdirs(); 69 70 String rootType = "nt:folder"; 71 if (!rootFile.isDirectory()) 72 rootType = "nt:file"; 73 if (!rootFile.exists()) 74 throw new RepositoryException("SimpleFsContainerImpl could not be created. File or folder '" + rootFile + "' not found."); 75 ArrayList props = new ArrayList (); 76 props.add(new PropertyImpl("/jcr:primaryType", new StringValue(rootType), PropertyType.STRING)); 77 rootNode = new NodeImpl(ROOT_PATH, props); 78 } 80 81 82 public String getName() { 83 return name; 84 } 85 86 public File getRootFile() { 87 return rootFile; 88 } 89 90 public NodeData getRootNode() { 91 return rootNode; 92 } 93 94 public NodeData getNodeByPath(String absPath) { 95 try { 96 NodeContainer container = resolver.resolve(rootFile, absPath); 97 98 return container.getNodeByPath(container.parseRelPath(absPath)); 100 } catch (Exception e) { 101 log.debug("GetNodeByPath throws exception " + e.getMessage()); 102 e.printStackTrace(); 103 return null; 104 } 105 } 106 114 public List getChildren(String path) { 115 try { 116 NodeContainer container = resolver.resolve(rootFile, path); 117 return container.getChildren(container.parseRelPath(path)); 118 } catch (Exception e) { 119 log.debug("SimpleFSContainer.GetChildren() throws exception " + e.getMessage()); 120 e.printStackTrace(); 121 return null; 122 } 123 } 124 125 public QueryResult getQueryResult(Query query) { 126 return null; 127 } 128 129 synchronized public void add(Node node) throws ItemExistsException, RepositoryException { 130 try { 131 NodeContainer container = resolver.create(rootFile, (NodeData)node); 132 log.debug("SFS Container add -->" + container); 133 container.add(node); 134 } catch (IOException e) { 135 throw new RepositoryException("SimpleFsContainerImpl.add() failed. Reason:" + e); 136 } catch (PathNotFoundException e) { 137 throw new RepositoryException("SimpleFsContainerImpl.add() failed. Reason:" + e); 138 } 139 } 140 141 synchronized public void update(Node node) throws RepositoryException { 142 try { 143 NodeContainer container = resolver.resolve(rootFile, node.getPath()); 144 container.update(node); 145 } catch (Exception e) { 146 log.debug("Update Node throws exception " + e.getMessage()); 147 } 148 } 149 150 synchronized public void delete(String absPath) { 151 try { 152 NodeContainer container = resolver.resolve(rootFile, absPath); 153 log.debug("FS Container delete node:" + absPath); 154 container.delete(absPath); 155 } catch (Exception e) { 156 log.debug("DelNode throws exception " + e.getMessage()); 157 } 158 } 159 160 161 } 162 | Popular Tags |