[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;
|
---|
[8601] | 32 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
| 33 | import org.w3c.dom.*;
|
---|
| 34 |
|
---|
| 35 | /** 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. */
|
---|
| 36 | public class Plugin
|
---|
[12247] | 37 | extends ArgumentContainer {
|
---|
| 38 | private boolean does_explode_metadata_databases = false;
|
---|
| 39 |
|
---|
[8601] | 40 | /** 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)
|
---|
| 41 | */
|
---|
| 42 | public Plugin() {
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public Plugin(Element element, Plugin base_plugin) {
|
---|
[12247] | 46 | super(element, base_plugin);
|
---|
[8601] | 47 | }
|
---|
| 48 |
|
---|
| 49 | /** Method to compare two plugins for ordering.
|
---|
[12247] | 50 | * We override the base method cos we compare by plugin name rather than toString()
|
---|
[8601] | 51 | */
|
---|
| 52 | public int compareTo(Object object) {
|
---|
| 53 | if(object instanceof Plugin) {
|
---|
| 54 | return name.compareTo(((Plugin)object).getName());
|
---|
| 55 | }
|
---|
| 56 | return -1;
|
---|
| 57 | }
|
---|
[12247] | 58 |
|
---|
[8601] | 59 | /** The assigned plugin constructor.
|
---|
| 60 | * @param element the DOM Element this plugin is based upon
|
---|
| 61 | */
|
---|
| 62 | public DOMProxyListEntry create(Element element) {
|
---|
| 63 | String plugin_name = element.getAttribute(StaticStrings.TYPE_ATTRIBUTE);
|
---|
| 64 | // Determine the base plugin from the plugin name
|
---|
| 65 | Plugin base_plugin = CollectionDesignManager.plugin_manager.getBasePlugin(plugin_name);
|
---|
| 66 | Plugin plugin = new Plugin(element, base_plugin);
|
---|
[12247] | 67 | if (base_plugin == null) {
|
---|
| 68 | plugin.setAssigned(false);
|
---|
| 69 | }
|
---|
[8601] | 70 | base_plugin = null;
|
---|
| 71 | plugin_name = null;
|
---|
| 72 | return plugin;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[8607] | 75 |
|
---|
[8768] | 76 | /** Checks whether the plugin this instance is based on processes metadata databases that can be exploded. */
|
---|
| 77 | public boolean doesExplodeMetadataDatabases()
|
---|
| 78 | {
|
---|
[9126] | 79 | Plugin base_plugin = CollectionDesignManager.plugin_manager.getBasePlugin(getName());
|
---|
| 80 | if (base_plugin == null) {
|
---|
| 81 | return false;
|
---|
| 82 | }
|
---|
| 83 | return base_plugin.does_explode_metadata_databases;
|
---|
[8768] | 84 | }
|
---|
| 85 |
|
---|
| 86 |
|
---|
[11378] | 87 | /** Checks whether this plugin instance will process the specified file (given its block_exp). */
|
---|
| 88 | public boolean doesBlockFile(File file)
|
---|
| 89 | {
|
---|
| 90 | // Check the filename against the plugin's block_exp value
|
---|
[12247] | 91 | //ArrayList arguments = getArguments(true, true);
|
---|
| 92 | ArrayList arguments = getArguments();
|
---|
[11378] | 93 | for (int i = 0; i < arguments.size(); i++) {
|
---|
| 94 | Argument argument = (Argument) arguments.get(i);
|
---|
| 95 | if (argument.getName().equals("block_exp")) {
|
---|
| 96 | // Try the assigned value first, for when the user has manually set the value
|
---|
| 97 | String regular_expression = argument.getValue();
|
---|
| 98 | if (regular_expression == null || regular_expression.equals("")) {
|
---|
| 99 | // Not set, so use the default value
|
---|
| 100 | regular_expression = argument.getDefaultValue();
|
---|
| 101 | if (regular_expression.equals("")) {
|
---|
| 102 | continue;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | // The $ at the end doesn't seem to work in Java, so need to add ".*" at the start
|
---|
| 107 | if (regular_expression.startsWith("(?i)")) {
|
---|
| 108 | // Don't mess up case-insensitive matching though
|
---|
| 109 | regular_expression = "(?i)" + ".*" + regular_expression.substring("(?i)".length());
|
---|
| 110 | }
|
---|
| 111 | else {
|
---|
| 112 | regular_expression = ".*" + regular_expression;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | // If the filename matches the regular expression, this plugin will deal with the file in some way
|
---|
| 116 | if (file.getName().matches(regular_expression)) {
|
---|
| 117 | return true;
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | // This plugin will (probably) not deal with the specified file
|
---|
| 123 | return false;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 |
|
---|
[9020] | 127 | /** Checks whether this plugin instance will process the specified file (given its process_exp). */
|
---|
[8607] | 128 | public boolean doesProcessFile(File file)
|
---|
| 129 | {
|
---|
[9020] | 130 | // Check the filename against the plugin's process_exp value
|
---|
[12247] | 131 | //ArrayList arguments = getArguments(true, true);
|
---|
| 132 | ArrayList arguments = getArguments();
|
---|
[8607] | 133 | for (int i = 0; i < arguments.size(); i++) {
|
---|
| 134 | Argument argument = (Argument) arguments.get(i);
|
---|
[9020] | 135 | if (argument.getName().equals("process_exp")) {
|
---|
[8607] | 136 | // Try the assigned value first, for when the user has manually set the value
|
---|
| 137 | String regular_expression = argument.getValue();
|
---|
| 138 | if (regular_expression == null || regular_expression.equals("")) {
|
---|
| 139 | // Not set, so use the default value
|
---|
| 140 | regular_expression = argument.getDefaultValue();
|
---|
| 141 | if (regular_expression.equals("")) {
|
---|
| 142 | continue;
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | // The $ at the end doesn't seem to work in Java, so need to add ".*" at the start
|
---|
| 147 | if (regular_expression.startsWith("(?i)")) {
|
---|
| 148 | // Don't mess up case-insensitive matching though
|
---|
| 149 | regular_expression = "(?i)" + ".*" + regular_expression.substring("(?i)".length());
|
---|
| 150 | }
|
---|
| 151 | else {
|
---|
| 152 | regular_expression = ".*" + regular_expression;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | // If the filename matches the regular expression, this plugin will deal with the file in some way
|
---|
| 156 | if (file.getName().matches(regular_expression)) {
|
---|
| 157 | return true;
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 |
|
---|
[8768] | 162 | // This plugin will (probably) not deal with the specified file
|
---|
[8607] | 163 | return false;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
[8601] | 166 | public boolean isSeparator() {
|
---|
| 167 | return (element != null && element.getAttribute(StaticStrings.SEPARATOR_ATTRIBUTE).equals(StaticStrings.TRUE_STR));
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[8768] | 170 | public void setDoesExplodeMetadataDatabases(boolean does_explode_metadata_databases) {
|
---|
| 171 | this.does_explode_metadata_databases = does_explode_metadata_databases;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
[8601] | 174 | }
|
---|