示例#1
0
 public void createFolder(PackageName packageName) {
   try {
     MDSSession mdsSession = getMdsSession();
     PTransaction transaction = getpTransaction(mdsSession);
     transaction.createPackage(packageName);
     mdsSession.flushChanges();
   } catch (Exception e) {
     throw new IllegalArgumentException("Could not create Folder ! " + e.getMessage());
   }
 }
示例#2
0
 public void createFile(String path, String content) {
   try {
     MDSSession session = getMdsSession();
     PTransaction transaction = getpTransaction(session);
     DocumentName mdsDocumentName = DocumentName.create(path);
     InputSource is = new InputSource(new StringReader(content));
     transaction.createDocument(mdsDocumentName, is);
     session.flushChanges();
   } catch (Exception e) {
     throw new IllegalArgumentException("Could not add new file ", e);
   }
 }
示例#3
0
 public void updateFile(DocumentName documentName, String content) {
   try {
     MDSSession session = getMdsSession();
     PTransaction transaction = getpTransaction(session);
     PManager pManager = storeInitializer.getMDSInstance().getPersistenceManager();
     PContext pContext = session.getPContext();
     PDocument pdocument = pManager.getDocument(pContext, documentName);
     InputSource is = new InputSource(new StringReader(content));
     transaction.saveDocument(pdocument, true, is);
     session.flushChanges();
   } catch (Exception e) {
     throw new IllegalArgumentException("Could not edit file ", e);
   }
 }
示例#4
0
 private PDocument getPDocument(DocumentName documentName, Long key) {
   try {
     MDSInstance instance = storeInitializer.getMDSInstance();
     MDSSession session = createSession(instance);
     PManager pManager = instance.getPersistenceManager();
     PContext pContext = session.getPContext();
     if (key > 0) {
       return pManager.getVersionSupport().getDocument(pContext, documentName, key);
     } else {
       return pManager.getDocument(pContext, documentName);
     }
   } catch (MDSAccessException e) {
     throw new IllegalArgumentException("Could not read ", e);
   }
 }
示例#5
0
 public void deleteFile(ResourceName path) {
   try {
     MDSSession session = getMdsSession();
     PTransaction transaction = getpTransaction(session);
     PManager pManager = storeInitializer.getMDSInstance().getPersistenceManager();
     PContext pContext = session.getPContext();
     if (path instanceof PackageName) {
       PPackage ppackage = pManager.getPackage(pContext, (PackageName) path);
       transaction.deletePackage(ppackage, true);
     } else {
       PDocument pdocument = pManager.getDocument(pContext, (DocumentName) path);
       transaction.deleteDocument(pdocument, true);
     }
     session.flushChanges();
   } catch (Exception e) {
     throw new IllegalArgumentException("Could not remove file ", e);
   }
 }
示例#6
0
 public boolean isAvailable(ResourceName documentName) {
   try {
     MDSSession session = getMdsSession();
     PManager pManager = storeInitializer.getMDSInstance().getPersistenceManager();
     PContext pContext = session.getPContext();
     if (documentName instanceof PackageName) {
       PPackage ppackage = pManager.getPackage(pContext, (PackageName) documentName);
       if (ppackage == null) return false;
     } else {
       PDocument pdocument = pManager.getDocument(pContext, (DocumentName) documentName);
       if (pdocument == null) return false;
     }
   } catch (InvalidNamespaceException e) {
     return false;
   } catch (MDSAccessException e) {
     return false;
   }
   return true;
 }
示例#7
0
 private PDocument getpDocument(DocumentName documentName) throws MDSAccessException {
   MDSSession session = getMdsSession();
   PManager pManager = storeInitializer.getMDSInstance().getPersistenceManager();
   PContext pContext = session.getPContext();
   return pManager.getDocument(pContext, documentName);
 }
示例#8
0
 private PTransaction getpTransaction(MDSSession session) {
   return session.getPTransaction();
 }