1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.connector.filesystem;
25
26 import java.io.File;
27 import java.util.Collection;
28 import java.util.Map;
29 import java.util.Set;
30 import org.modeshape.graph.ExecutionContext;
31 import org.modeshape.graph.Location;
32 import org.modeshape.graph.connector.RepositorySourceException;
33 import org.modeshape.graph.property.Name;
34 import org.modeshape.graph.property.Property;
35 import org.modeshape.graph.property.ValueFactory;
36
37
38
39
40
41 public class ThrowProperties extends BasePropertiesFactory {
42
43 private static final long serialVersionUID = 1L;
44
45
46
47
48 public ThrowProperties() {
49 }
50
51
52
53
54
55
56
57 @Override
58 public Collection<Property> getDirectoryProperties( ExecutionContext context,
59 Location location,
60 File directory ) {
61 return NO_PROPERTIES_COLLECTION;
62 }
63
64
65
66
67
68
69
70 @Override
71 public Collection<Property> getFileProperties( ExecutionContext context,
72 Location location,
73 File file ) {
74 return NO_PROPERTIES_COLLECTION;
75 }
76
77
78
79
80
81
82
83 @Override
84 public Collection<Property> getResourceProperties( ExecutionContext context,
85 Location location,
86 File file,
87 String mimeType ) {
88 return NO_PROPERTIES_COLLECTION;
89 }
90
91
92
93
94
95
96
97 @Override
98 public Set<Name> recordDirectoryProperties( ExecutionContext context,
99 String sourceName,
100 Location location,
101 File file,
102 Map<Name, Property> properties ) throws RepositorySourceException {
103 int numProperties = properties.size();
104 if (numProperties != 0) {
105 ValueFactory<String> strings = context.getValueFactories().getStringFactory();
106 StringBuilder names = new StringBuilder();
107 boolean first = true;
108 for (Property property : properties.values()) {
109 if (STANDARD_PROPERTIES_FOR_FILE_OR_FOLDER.contains(property.getName())) continue;
110 if (first) first = false;
111 else names.append(",");
112 String name = strings.create(property.getName());
113 names.append(name);
114 }
115 String msg = null;
116 if (properties.size() == 1) {
117 msg = FileSystemI18n.couldNotStoreProperties.text(names, file.getPath(), sourceName);
118 } else {
119 msg = FileSystemI18n.couldNotStoreProperty.text(names, file.getPath(), sourceName);
120 }
121 throw new RepositorySourceException(sourceName, msg);
122 }
123 return NO_NAMES;
124 }
125
126
127
128
129
130
131
132 @Override
133 public Set<Name> recordFileProperties( ExecutionContext context,
134 String sourceName,
135 Location location,
136 File file,
137 Map<Name, Property> properties ) throws RepositorySourceException {
138 int numProperties = properties.size();
139 if (numProperties != 0) {
140 ValueFactory<String> strings = context.getValueFactories().getStringFactory();
141 StringBuilder names = new StringBuilder();
142 boolean first = true;
143 for (Property property : properties.values()) {
144 if (STANDARD_PROPERTIES_FOR_FILE_OR_FOLDER.contains(property.getName())) continue;
145 if (first) first = false;
146 else names.append(",");
147 String name = strings.create(property.getName());
148 names.append(name);
149 }
150 String msg = null;
151 if (properties.size() == 1) {
152 msg = FileSystemI18n.couldNotStoreProperties.text(names, file.getPath(), sourceName);
153 } else {
154 msg = FileSystemI18n.couldNotStoreProperty.text(names, file.getPath(), sourceName);
155 }
156 throw new RepositorySourceException(sourceName, msg);
157 }
158 return NO_NAMES;
159 }
160
161
162
163
164
165
166
167 @Override
168 public Set<Name> recordResourceProperties( ExecutionContext context,
169 String sourceName,
170 Location location,
171 File file,
172 Map<Name, Property> properties ) throws RepositorySourceException {
173 int numProperties = properties.size();
174 if (numProperties != 0) {
175 ValueFactory<String> strings = context.getValueFactories().getStringFactory();
176 StringBuilder names = new StringBuilder();
177 boolean first = true;
178 for (Property property : properties.values()) {
179 if (STANDARD_PROPERTIES_FOR_CONTENT.contains(property.getName())) continue;
180 if (first) first = false;
181 else names.append(",");
182 String name = strings.create(property.getName());
183 names.append(name);
184 }
185 String msg = null;
186 if (properties.size() == 1) {
187 msg = FileSystemI18n.couldNotStoreProperties.text(names, file.getPath(), sourceName);
188 } else {
189 msg = FileSystemI18n.couldNotStoreProperty.text(names, file.getPath(), sourceName);
190 }
191 throw new RepositorySourceException(sourceName, msg);
192 }
193 return NO_NAMES;
194 }
195 }