20 package net.sf.gridarta.model.artifact;
22 import java.io.BufferedReader;
24 import java.io.FileInputStream;
25 import java.io.FilenameFilter;
26 import java.io.IOException;
27 import java.io.InputStreamReader;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.Collection;
31 import java.util.Collections;
32 import java.util.List;
43 import org.apache.log4j.Category;
44 import org.apache.log4j.Logger;
45 import org.jetbrains.annotations.NotNull;
46 import org.jetbrains.annotations.Nullable;
89 final File fullPath =
new File(dir,
name);
91 return fullPath.isDirectory() && !
name.equalsIgnoreCase(
"cvs") && !
name.equalsIgnoreCase(
".xvpics") && !
name.equalsIgnoreCase(
".svn") ||
name.toLowerCase().endsWith(
".art");
112 return Collections.unmodifiableCollection(
invObjects);
125 public void loadArchesFromArtifacts(@NotNull
final File f, @NotNull
final String panelName, @NotNull
final String folderName) {
128 if (
LOG.isInfoEnabled()) {
145 if (f.isDirectory()) {
147 if (traverse !=
null) {
148 Arrays.sort(traverse);
149 for (
final String entry : traverse) {
168 private void loadArtifact(@NotNull
final ErrorViewCollector errorViewCollector, @NotNull
final File f, @NotNull
final String archPath, @NotNull
final String panelName, @NotNull
final String folderName) {
170 try (FileInputStream fis =
new FileInputStream(f)) {
172 try (BufferedReader in =
new BufferedReader(isr)) {
173 loadArtifact(in, errorViewCollector, archPath, panelName, folderName);
177 }
catch (
final IOException ex) {
191 public void loadArtifact(@NotNull
final BufferedReader in, @NotNull
final ErrorViewCollector errorViewCollector, @NotNull
final String archPath, @NotNull
final String panelName, @NotNull
final String folderName)
throws IOException {
193 @Nullable String
name =
null;
194 @Nullable String defArchName =
null;
197 @Nullable String editorPath =
null;
199 final String thisLine2 = in.readLine();
200 if (thisLine2 ==
null) {
204 final String thisLine = thisLine2.trim();
206 if (!thisLine.startsWith(
"#") && !thisLine.isEmpty()) {
207 if (thisLine.startsWith(
"artifact ")) {
208 name = thisLine.substring(9);
209 }
else if (thisLine.startsWith(
"def_arch ")) {
210 defArchName = thisLine.substring(9);
211 }
else if (thisLine.startsWith(
"editor ")) {
212 final String
editor = thisLine.substring(7);
213 final int tIndex =
editor.indexOf(
':');
215 editorCode = Integer.parseInt(
editor);
217 editorPath =
editor.substring(tIndex + 1);
219 editorCode = Integer.parseInt(
editor.substring(0, tIndex));
221 }
else if (thisLine.startsWith(
"Object")) {
222 if (editorCode == -1) {
225 if (editorCode == 0 || editorCode == 2) {
228 final String objTitle = thisLine.length() > 7 ? thisLine.substring(7) :
"";
231 if (defArchName ==
null) {
233 }
else if (defArchName.isEmpty()) {
235 }
else if (
name ==
null) {
237 }
else if (
name.isEmpty()) {
242 if (editorCode != 0 && editorCode != 2) {
251 final String thisLine3 = in.readLine();
252 if (thisLine3 ==
null || thisLine3.equals(
"end")) {
258 errorViewCollector.addWarning(
ErrorViewCategory.
ARTIFACT_ENTRY_INVALID,
"line " + lineCount +
", Object '" + defArchName +
"' / '" +
name +
"' / '" + objTitle +
"' references undefined archetype '" + ex.getMessage() +
"'");