1:
30:
31: package ;
32:
33: import ;
34: import ;
35:
36: import ;
37: import ;
38: import ;
39: import ;
40: import ;
41: import ;
42: import ;
43:
44:
49: public class FileContentLocation extends FileContentEntity implements ContentLocation
50: {
51: public FileContentLocation(final ContentLocation parent, final File backend)
52: {
53: super(parent, backend);
54: }
55:
56: public FileContentLocation(final Repository repository, final File backend)
57: {
58: super(repository, backend);
59: }
60:
61: public ContentEntity[] listContents() throws ContentIOException
62: {
63: final File file = getBackend();
64: final File[] files = file.listFiles();
65: final ContentEntity[] entities = new ContentEntity[files.length];
66: for (int i = 0; i < files.length; i++)
67: {
68: final File child = files[i];
69: if (child.isDirectory())
70: {
71: entities[i] = new FileContentLocation(this, child);
72: }
73: else if (child.isFile())
74: {
75: entities[i] = new FileContentLocation(this, child);
76: }
77: }
78: return entities;
79: }
80:
81: public ContentEntity getEntry(final String name) throws ContentIOException
82: {
83: final File file = getBackend();
84: final File child = new File (file, name);
85: if (child.exists() == false)
86: {
87: throw new ContentIOException("Not found.");
88: }
89: try
90: {
91: if (IOUtils.getInstance().isSubDirectory(file, child))
92: {
93: throw new ContentIOException("Not sub-directory");
94: }
95: }
96: catch (IOException e)
97: {
98: throw new ContentIOException("IO Error.");
99: }
100:
101: if (child.isDirectory())
102: {
103: return new FileContentLocation(this, child);
104: }
105: else if (child.isFile())
106: {
107: return new FileContentItem(this, child);
108: }
109: else
110: {
111: throw new ContentIOException("Not File nor directory.");
112: }
113: }
114:
115: public ContentItem createItem(final String name) throws ContentCreationException
116: {
117: final File file = getBackend();
118: final File child = new File (file, name);
119: if (child.exists())
120: {
121: throw new ContentCreationException("File already exists.");
122: }
123: try
124: {
125: if (child.createNewFile() == false)
126: {
127: throw new ContentCreationException("Unable to create");
128: }
129: return new FileContentItem(this, child);
130: }
131: catch (IOException e)
132: {
133: throw new ContentCreationException("IOError while create");
134: }
135: }
136:
137: public ContentLocation createLocation(final String name)
138: throws ContentCreationException
139: {
140: final File file = getBackend();
141: final File child = new File (file, name);
142: if (child.exists())
143: {
144: throw new ContentCreationException("File already exists.");
145: }
146: if (child.mkdir() == false)
147: {
148: throw new ContentCreationException("Unable to create");
149: }
150: return new FileContentLocation(this, child);
151: }
152:
153: public boolean exists(final String name)
154: {
155: final File file = getBackend();
156: final File child = new File (file, name);
157: return (child.exists());
158: }
159: }