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(final String name) throws ContentIOException
76: {
77: return (ContentEntity) entries.get(name);
78: }
79:
80:
89: public ContentItem createItem(final 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(final 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: if ("/".equals(this.contentId) == false)
112: {
113: try
114: {
115: final ZipEntry entry = new ZipEntry(contentId);
116: repository.writeDirectory(entry);
117: }
118: catch (IOException e)
119: {
120: throw new ContentCreationException("Failed to create directory.");
121: }
122: }
123: return item;
124: }
125:
126: public boolean exists(final String name)
127: {
128: return entries.containsKey(name);
129: }
130:
131: public String getName()
132: {
133: return name;
134: }
135:
136: public Object getContentId()
137: {
138: return contentId;
139: }
140:
141: public Object getAttribute(final String domain, final String key)
142: {
143: return null;
144: }
145:
146: public boolean setAttribute(final String domain, final String key, final Object value)
147: {
148: return false;
149: }
150:
151: public ContentLocation getParent()
152: {
153: return parent;
154: }
155:
156: public Repository getRepository()
157: {
158: return repository;
159: }
160:
161: public boolean delete()
162: {
163: return false;
164: }
165: }