20 package net.sf.gridarta.plugin;
23 import java.io.IOException;
30 import nu.xom.Builder;
31 import nu.xom.Document;
32 import nu.xom.Element;
33 import nu.xom.ParsingException;
34 import org.apache.log4j.Category;
35 import org.apache.log4j.Logger;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
38 import org.xml.sax.SAXException;
39 import org.xml.sax.XMLReader;
40 import org.xml.sax.helpers.XMLReaderFactory;
68 public static <G extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>>
PluginModel<G, A, R> loadPlugins(@NotNull
final PluginParameterFactory<G, A, R> pluginParameterFactory, @NotNull
final PluginModelParser<G, A, R> pluginModelParser, @NotNull
final ErrorView errorView, @NotNull
final File pluginsDir) {
70 final File[]
files = pluginsDir.listFiles();
77 for (
final File pluginFile :
files) {
78 final String
name = pluginFile.getName();
79 if (!
name.startsWith(
".") && !
name.endsWith(
"~") && pluginFile.isFile()) {
83 if (
LOG.isDebugEnabled()) {
84 LOG.debug(
"storing with code " + plugin.
getCode());
90 }
catch (
final IOException | ParsingException | SAXException ex) {
95 if (
LOG.isInfoEnabled()) {
96 LOG.info(
"Loaded " + (pluginModel.
getPluginCount() - pluginCount) +
" plugins from '" + pluginsDir +
"'.");
101 public static <G extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>>
Plugin<G, A, R> loadXML(@NotNull
final PluginModelParser<G, A, R> pluginModelParser, @NotNull
final File file)
throws IOException, ParsingException, SAXException {
102 final XMLReader xmlReader = XMLReaderFactory.createXMLReader();
103 final Builder builder =
new Builder(xmlReader,
false);
104 final Document d = builder.build(file);
105 return loadXML(pluginModelParser, d, file);
109 private static <G extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>>
Plugin<G, A, R> loadXML(@NotNull
final PluginModelParser<G, A, R> pluginModelParser, @NotNull
final Document doc, @Nullable
final File file)
throws IOException {
110 final Element elt = doc.getRootElement();
112 throw new IOException(
"plugin file is empty");
114 if (!elt.getLocalName().equalsIgnoreCase(
"script")) {
115 throw new IOException(
"missing root element named \"script\"");
120 if (
LOG.isDebugEnabled()) {