1 17 package org.alfresco.repo.content; 18 19 import java.util.Calendar ; 20 import java.util.GregorianCalendar ; 21 import java.util.Set ; 22 23 import org.alfresco.error.AlfrescoRuntimeException; 24 import org.alfresco.service.cmr.repository.ContentIOException; 25 import org.alfresco.service.cmr.repository.ContentReader; 26 import org.alfresco.util.GUID; 27 28 38 public abstract class AbstractContentStore implements ContentStore 39 { 40 44 public boolean exists(String contentUrl) throws ContentIOException 45 { 46 ContentReader reader = getReader(contentUrl); 47 return reader.exists(); 48 } 49 50 56 public static String createNewUrl() 57 { 58 Calendar calendar = new GregorianCalendar (); 59 int year = calendar.get(Calendar.YEAR); 60 int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); 62 int hour = calendar.get(Calendar.HOUR_OF_DAY); 63 StringBuilder sb = new StringBuilder (20); 65 sb.append(STORE_PROTOCOL) 66 .append(year).append('/') 67 .append(month).append('/') 68 .append(day).append('/') 69 .append(hour).append('/') 70 .append(GUID.generate()).append(".bin"); 71 String newContentUrl = sb.toString(); 72 return newContentUrl; 74 } 75 76 89 public static String getRelativePart(String contentUrl) throws RuntimeException 90 { 91 int index = 0; 92 if (contentUrl.startsWith(STORE_PROTOCOL)) 93 { 94 index = 8; 95 } 96 else if (contentUrl.startsWith("file://")) 97 { 98 index = 7; 99 } 100 else 101 { 102 throw new AlfrescoRuntimeException( 103 "All content URLs must start with " + STORE_PROTOCOL + ": \n" + 104 " the invalid url is: " + contentUrl); 105 } 106 107 String path = contentUrl.substring(index); 109 if (path.length() < 10) 111 { 112 throw new AlfrescoRuntimeException( 113 "The content URL is invalid: \n" + 114 " content url: " + contentUrl); 115 } 116 return path; 117 } 118 119 public final Set <String > getUrls() throws ContentIOException 120 { 121 return getUrls(null, null); 122 } 123 } 124 | Popular Tags |