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;
91 public boolean accept(
final File dir,
final String name) {
92 final File fullPath =
new File(dir, name);
94 return fullPath.isDirectory() && !name.equalsIgnoreCase(
"cvs") && !name.equalsIgnoreCase(
".xvpics") && !name.equalsIgnoreCase(
".svn") || name.toLowerCase().endsWith(
".art");
117 return Collections.unmodifiableCollection(
invObjects);
130 public void loadArchesFromArtifacts(@NotNull
final File f, @NotNull
final String panelName, @NotNull
final String folderName) {
133 if (
LOG.isInfoEnabled()) {
150 if (f.isDirectory()) {
152 if (traverse !=
null) {
153 Arrays.sort(traverse);
154 for (
final String entry : traverse) {
173 private void loadArtifact(@NotNull
final ErrorViewCollector errorViewCollector, @NotNull
final File f, @NotNull
final String archPath, @NotNull
final String panelName, @NotNull
final String folderName) {
175 try (FileInputStream fis =
new FileInputStream(f)) {
177 try (BufferedReader in =
new BufferedReader(isr)) {
178 loadArtifact(in, errorViewCollector, archPath, panelName, folderName);
182 }
catch (
final IOException ex) {
196 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 {
198 @Nullable String name =
null;
199 @Nullable String defArchName =
null;
202 @Nullable String editorPath =
null;
204 final String thisLine2 = in.readLine();
205 if (thisLine2 ==
null) {
209 final String thisLine = thisLine2.trim();
211 if (!thisLine.startsWith(
"#") && !thisLine.isEmpty()) {
212 if (thisLine.startsWith(
"artifact ")) {
213 name = thisLine.substring(9);
214 }
else if (thisLine.startsWith(
"def_arch ")) {
215 defArchName = thisLine.substring(9);
216 }
else if (thisLine.startsWith(
"editor ")) {
217 final String editor = thisLine.substring(7);
218 final int tIndex = editor.indexOf(
':');
220 editorCode = Integer.parseInt(editor);
222 editorPath = editor.substring(tIndex + 1);
224 editorCode = Integer.parseInt(editor.substring(0, tIndex));
226 }
else if (thisLine.startsWith(
"Object")) {
227 if (editorCode == -1) {
230 if (editorCode == 0 || editorCode == 2) {
233 final String objTitle = thisLine.length() > 7 ? thisLine.substring(7) :
"";
236 if (defArchName ==
null) {
238 }
else if (defArchName.isEmpty()) {
240 }
else if (name ==
null) {
242 }
else if (name.isEmpty()) {
247 if (editorCode != 0 && editorCode != 2) {
256 final String thisLine3 = in.readLine();
257 if (thisLine3 ==
null || thisLine3.equals(
"end")) {
263 errorViewCollector.addWarning(
ErrorViewCategory.
ARTIFACT_ENTRY_INVALID,
"line " + lineCount +
", Object '" + defArchName +
"' / '" + name +
"' / '" + objTitle +
"' references undefined archetype '" + ex.getMessage() +
"'");