[8601] | 1 | /**
|
---|
| 2 | *#########################################################################
|
---|
| 3 | *
|
---|
| 4 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
| 5 | * library suite from the New Zealand Digital Library Project at the
|
---|
| 6 | * University of Waikato, New Zealand.
|
---|
| 7 | *
|
---|
| 8 | * Author: John Thompson, Greenstone Digital Library, University of Waikato
|
---|
| 9 | *
|
---|
| 10 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or modify
|
---|
| 13 | * it under the terms of the GNU General Public License as published by
|
---|
| 14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | * (at your option) any later version.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful,
|
---|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | * GNU General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, write to the Free Software
|
---|
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | *########################################################################
|
---|
| 26 | */
|
---|
| 27 | package org.greenstone.gatherer.cdm;
|
---|
| 28 |
|
---|
| 29 | import java.io.*;
|
---|
| 30 | import java.util.*;
|
---|
[9302] | 31 | import org.greenstone.gatherer.DebugStream;
|
---|
[12642] | 32 | import org.greenstone.gatherer.greenstone.Plugins;
|
---|
[8601] | 33 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
| 34 | import org.w3c.dom.*;
|
---|
| 35 |
|
---|
[12631] | 36 |
|
---|
[8601] | 37 | /** This class is responsible for storing information from a parsed pluginfo call in such a way that it allows easy access to parsed details for the purposes of user design and specification of plugins. */
|
---|
| 38 | public class Plugin
|
---|
[12631] | 39 | extends ArgumentContainer
|
---|
| 40 | {
|
---|
| 41 | private String default_block_expression = "";
|
---|
| 42 | private String default_process_expression = "";
|
---|
[12247] | 43 | private boolean does_explode_metadata_databases = false;
|
---|
[15108] | 44 | private boolean does_replace_srcdocs_with_html = false; // to work with replace_srcdoc_with_html.pl
|
---|
[13177] | 45 | private boolean loading_options_failed = false;
|
---|
[12631] | 46 |
|
---|
[8601] | 47 | /** Constructor used in DOMProxyListModel initializations, and Library Level. Used for Base plugins (those in the list of available plugins, not ones that are in the DOMProxyList)
|
---|
| 48 | */
|
---|
| 49 | public Plugin() {
|
---|
| 50 | }
|
---|
[12631] | 51 |
|
---|
[8601] | 52 |
|
---|
| 53 | public Plugin(Element element, Plugin base_plugin) {
|
---|
[12247] | 54 | super(element, base_plugin);
|
---|
[8601] | 55 | }
|
---|
| 56 |
|
---|
[12631] | 57 |
|
---|
[8601] | 58 | /** Method to compare two plugins for ordering.
|
---|
[12247] | 59 | * We override the base method cos we compare by plugin name rather than toString()
|
---|
[8601] | 60 | */
|
---|
| 61 | public int compareTo(Object object) {
|
---|
| 62 | if(object instanceof Plugin) {
|
---|
| 63 | return name.compareTo(((Plugin)object).getName());
|
---|
| 64 | }
|
---|
| 65 | return -1;
|
---|
| 66 | }
|
---|
[12631] | 67 |
|
---|
[12247] | 68 |
|
---|
[8601] | 69 | /** The assigned plugin constructor.
|
---|
| 70 | * @param element the DOM Element this plugin is based upon
|
---|
| 71 | */
|
---|
| 72 | public DOMProxyListEntry create(Element element) {
|
---|
| 73 | String plugin_name = element.getAttribute(StaticStrings.TYPE_ATTRIBUTE);
|
---|
| 74 | // Determine the base plugin from the plugin name
|
---|
[12642] | 75 | Plugin base_plugin = Plugins.getPlugin(plugin_name, true);
|
---|
[8601] | 76 | Plugin plugin = new Plugin(element, base_plugin);
|
---|
[12247] | 77 | if (base_plugin == null) {
|
---|
| 78 | plugin.setAssigned(false);
|
---|
| 79 | }
|
---|
[8601] | 80 | base_plugin = null;
|
---|
| 81 | plugin_name = null;
|
---|
| 82 | return plugin;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[8607] | 85 |
|
---|
[13177] | 86 | public boolean didLoadingOptionsFail()
|
---|
| 87 | {
|
---|
| 88 | return loading_options_failed;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 |
|
---|
[8768] | 92 | /** Checks whether the plugin this instance is based on processes metadata databases that can be exploded. */
|
---|
| 93 | public boolean doesExplodeMetadataDatabases()
|
---|
| 94 | {
|
---|
[12642] | 95 | Plugin base_plugin = Plugins.getPlugin(getName(), false);
|
---|
[9126] | 96 | if (base_plugin == null) {
|
---|
| 97 | return false;
|
---|
| 98 | }
|
---|
| 99 | return base_plugin.does_explode_metadata_databases;
|
---|
[8768] | 100 | }
|
---|
| 101 |
|
---|
[15108] | 102 | /** Checks whether the plugin this instance is based on processes source documents that can be replaced with their Greenstone generated html variants.
|
---|
| 103 | * This method works with replace_srcdoc_with_html.pl */
|
---|
| 104 | public boolean doesReplaceSrcDocsWithHtml()
|
---|
| 105 | {
|
---|
| 106 | //return does_replace_srcdocs_with_html;
|
---|
| 107 | Plugin base_plugin = Plugins.getPlugin(getName(), false);
|
---|
| 108 | if (base_plugin == null) {
|
---|
| 109 | return false;
|
---|
| 110 | }
|
---|
| 111 | return base_plugin.does_replace_srcdocs_with_html;
|
---|
| 112 | }
|
---|
[8768] | 113 |
|
---|
[11378] | 114 | /** Checks whether this plugin instance will process the specified file (given its block_exp). */
|
---|
| 115 | public boolean doesBlockFile(File file)
|
---|
| 116 | {
|
---|
| 117 | // Check the filename against the plugin's block_exp value
|
---|
[12247] | 118 | ArrayList arguments = getArguments();
|
---|
[11378] | 119 | for (int i = 0; i < arguments.size(); i++) {
|
---|
| 120 | Argument argument = (Argument) arguments.get(i);
|
---|
| 121 | if (argument.getName().equals("block_exp")) {
|
---|
| 122 | // Try the assigned value first, for when the user has manually set the value
|
---|
| 123 | String regular_expression = argument.getValue();
|
---|
| 124 | if (regular_expression == null || regular_expression.equals("")) {
|
---|
| 125 | // Not set, so use the default value
|
---|
| 126 | regular_expression = argument.getDefaultValue();
|
---|
| 127 | if (regular_expression.equals("")) {
|
---|
| 128 | continue;
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[12631] | 132 | if (doesFileMatchRegularExpression(file, regular_expression)) {
|
---|
[11378] | 133 | return true;
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[12631] | 138 | // Try the plugin's default block expression
|
---|
| 139 | if (!default_block_expression.equals("") && doesFileMatchRegularExpression(file, default_block_expression)) {
|
---|
| 140 | return true;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[11378] | 143 | // This plugin will (probably) not deal with the specified file
|
---|
| 144 | return false;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 |
|
---|
[9020] | 148 | /** Checks whether this plugin instance will process the specified file (given its process_exp). */
|
---|
[8607] | 149 | public boolean doesProcessFile(File file)
|
---|
| 150 | {
|
---|
[9020] | 151 | // Check the filename against the plugin's process_exp value
|
---|
[12247] | 152 | ArrayList arguments = getArguments();
|
---|
[8607] | 153 | for (int i = 0; i < arguments.size(); i++) {
|
---|
| 154 | Argument argument = (Argument) arguments.get(i);
|
---|
[9020] | 155 | if (argument.getName().equals("process_exp")) {
|
---|
[8607] | 156 | // Try the assigned value first, for when the user has manually set the value
|
---|
| 157 | String regular_expression = argument.getValue();
|
---|
| 158 | if (regular_expression == null || regular_expression.equals("")) {
|
---|
| 159 | // Not set, so use the default value
|
---|
| 160 | regular_expression = argument.getDefaultValue();
|
---|
| 161 | if (regular_expression.equals("")) {
|
---|
| 162 | continue;
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 |
|
---|
[12631] | 166 | if (doesFileMatchRegularExpression(file, regular_expression)) {
|
---|
[8607] | 167 | return true;
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[12631] | 172 | // Try the plugin's default process expression
|
---|
| 173 | if (!default_process_expression.equals("") && doesFileMatchRegularExpression(file, default_process_expression)) {
|
---|
| 174 | return true;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[8768] | 177 | // This plugin will (probably) not deal with the specified file
|
---|
[8607] | 178 | return false;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
[12631] | 181 |
|
---|
| 182 | private boolean doesFileMatchRegularExpression(File file, String regular_expression)
|
---|
| 183 | {
|
---|
| 184 | // The $ at the end doesn't seem to work in Java, so need to add ".*" at the start
|
---|
| 185 | if (regular_expression.startsWith("(?i)")) {
|
---|
| 186 | // Don't mess up case-insensitive matching though
|
---|
| 187 | regular_expression = "(?i)" + ".*" + regular_expression.substring("(?i)".length());
|
---|
| 188 | }
|
---|
| 189 | else {
|
---|
| 190 | regular_expression = ".*" + regular_expression;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | // If the filename matches the regular expression, this plugin will deal with the file in some way
|
---|
| 194 | if (file.getName().matches(regular_expression)) {
|
---|
| 195 | return true;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | return false;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 |
|
---|
[8601] | 202 | public boolean isSeparator() {
|
---|
| 203 | return (element != null && element.getAttribute(StaticStrings.SEPARATOR_ATTRIBUTE).equals(StaticStrings.TRUE_STR));
|
---|
| 204 | }
|
---|
| 205 |
|
---|
[12631] | 206 |
|
---|
| 207 | public void setDefaultBlockExpression(String default_block_expression)
|
---|
| 208 | {
|
---|
| 209 | this.default_block_expression = default_block_expression;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | public void setDefaultProcessExpression(String default_process_expression)
|
---|
| 214 | {
|
---|
| 215 | this.default_process_expression = default_process_expression;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 |
|
---|
| 219 | public void setDoesExplodeMetadataDatabases(boolean does_explode_metadata_databases)
|
---|
| 220 | {
|
---|
[8768] | 221 | this.does_explode_metadata_databases = does_explode_metadata_databases;
|
---|
| 222 | }
|
---|
[13177] | 223 |
|
---|
[15108] | 224 | // To work with replace_srcdoc_with_html.pl
|
---|
| 225 | public void setDoesReplaceSrcDocsWithHtml(boolean does_replace_srcdocs_with_html)
|
---|
| 226 | {
|
---|
| 227 | this.does_replace_srcdocs_with_html = does_replace_srcdocs_with_html;
|
---|
| 228 | }
|
---|
[13177] | 229 |
|
---|
| 230 | public void setLoadingOptionsFailed()
|
---|
| 231 | {
|
---|
| 232 | this.loading_options_failed = true;
|
---|
| 233 | }
|
---|
[8601] | 234 | }
|
---|