1:
30:
31: package ;
32:
33: import ;
34: import ;
35: import ;
36:
37: import ;
38: import ;
39: import ;
40: import ;
41: import ;
42: import ;
43: import ;
44:
45:
50: public class ZipContentLocation implements ContentLocation
51: {
52: private HashMap entries;
53: private String name;
54: private String contentId;
55: private ContentLocation parent;
56: private ZipRepository repository;
57:
58: public ZipContentLocation(final ZipRepository repository,
59: final ContentLocation parent,
60: final String name)
61: {
62: this.repository = repository;
63: this.parent = parent;
64: this.name = name;
65: this.entries = new HashMap();
66: this.contentId = RepositoryUtilities.buildName(this, "/") + "/";
67: }
68:
69: public ContentEntity[] listContents() throws ContentIOException
70: {
71: return (ContentEntity[]) entries.values().toArray
72: (new ContentEntity[entries.size()]);
73: }
74:
75: public ContentEntity getEntry(String name) throws ContentIOException
76: {
77: return (ContentEntity) entries.get(name);
78: }
79:
80:
89: public ContentItem createItem(String name) throws ContentCreationException
90: {
91: if (entries.containsKey(name))
92: {
93: throw new ContentCreationException("Entry already exists");
94: }
95:
96: final ZipContentItem item = new ZipContentItem(name, repository, this);
97: entries.put (name, item);
98: return item;
99: }
100:
101: public ContentLocation createLocation(String name)
102: throws ContentCreationException
103: {
104: if (entries.containsKey(name))
105: {
106: throw new ContentCreationException("Entry already exists");
107: }
108:
109: final ZipContentLocation item = new ZipContentLocation(repository, this, name);
110: entries.put (name, item);
111:
112: try
113: {
114: final ZipEntry entry = new ZipEntry(contentId);
115: repository.writeDirectory(entry);
116: return item;
117: }
118: catch (IOException e)
119: {
120: throw new ContentCreationException("Failed to create directory.");
121: }
122: }
123:
124: public boolean exists(final String name)
125: {
126: return entries.containsKey(name);
127: }
128:
129: public String getName()
130: {
131: return name;
132: }
133:
134: public Object getContentId()
135: {
136: return contentId;
137: }
138:
139: public Object getAttribute(String domain, String key)
140: {
141: return null;
142: }
143:
144: public boolean setAttribute(String domain, String key, Object value)
145: {
146: return false;
147: }
148:
149: public ContentLocation getParent()
150: {
151: return parent;
152: }
153:
154: public Repository getRepository()
155: {
156: return repository;
157: }
158:
159: public boolean delete()
160: {
161: return false;
162: }
163: }