[3235] | 1 | /*
|
---|
[24236] | 2 | * Collection.java
|
---|
| 3 | * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
|
---|
| 4 | *
|
---|
| 5 | * This program is free software; you can redistribute it and/or modify
|
---|
| 6 | * it under the terms of the GNU General Public License as published by
|
---|
| 7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 8 | * (at your option) any later version.
|
---|
| 9 | *
|
---|
| 10 | * This program is distributed in the hope that it will be useful,
|
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | * GNU General Public License for more details.
|
---|
| 14 | *
|
---|
| 15 | * You should have received a copy of the GNU General Public License
|
---|
| 16 | * along with this program; if not, write to the Free Software
|
---|
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 18 | */
|
---|
[3222] | 19 | package org.greenstone.gsdl3.collection;
|
---|
| 20 |
|
---|
[25751] | 21 | import java.io.BufferedReader;
|
---|
| 22 | import java.io.BufferedWriter;
|
---|
| 23 | import java.io.File;
|
---|
| 24 | import java.io.FileReader;
|
---|
| 25 | import java.io.FileWriter;
|
---|
| 26 | import java.io.IOException;
|
---|
| 27 | import java.io.PrintWriter;
|
---|
| 28 | import java.io.StringWriter;
|
---|
| 29 | import java.util.ArrayList;
|
---|
| 30 | import java.util.HashMap;
|
---|
[3222] | 31 |
|
---|
[25751] | 32 | import org.apache.commons.lang3.StringUtils;
|
---|
| 33 | import org.apache.log4j.Logger;
|
---|
| 34 | import org.greenstone.gsdl3.core.ModuleInterface;
|
---|
[32985] | 35 | import org.greenstone.gsdl3.service.Authentication;
|
---|
[30838] | 36 | import org.greenstone.gsdl3.util.CustomClassLoader;
|
---|
[30670] | 37 | import org.greenstone.gsdl3.util.Dictionary;
|
---|
[25751] | 38 | import org.greenstone.gsdl3.util.GSFile;
|
---|
| 39 | import org.greenstone.gsdl3.util.GSXML;
|
---|
[27716] | 40 | import org.greenstone.gsdl3.util.GSXSLT;
|
---|
[25751] | 41 | import org.greenstone.gsdl3.util.OAIXML;
|
---|
[27716] | 42 | import org.greenstone.gsdl3.util.SimpleMacroResolver;
|
---|
[25751] | 43 | import org.greenstone.gsdl3.util.UserContext;
|
---|
[28966] | 44 | import org.greenstone.gsdl3.util.XMLConverter;
|
---|
[25751] | 45 | import org.greenstone.gsdl3.util.XMLTransformer;
|
---|
[24393] | 46 | import org.w3c.dom.Document;
|
---|
[25751] | 47 | import org.w3c.dom.Element;
|
---|
[24393] | 48 | import org.w3c.dom.Node;
|
---|
| 49 | import org.w3c.dom.NodeList;
|
---|
[3222] | 50 |
|
---|
| 51 | /**
|
---|
[24393] | 52 | * Represents a collection in Greenstone. A collection is an extension of a
|
---|
| 53 | * ServiceCluster - it has local data that the services use.
|
---|
| 54 | *
|
---|
[25727] | 55 | * @author Katherine Don
|
---|
[24236] | 56 | * @see ModuleInterface
|
---|
| 57 | */
|
---|
[24393] | 58 | public class Collection extends ServiceCluster
|
---|
| 59 | {
|
---|
[3222] | 60 |
|
---|
[24393] | 61 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.Collection.class.getName());
|
---|
[13123] | 62 |
|
---|
[27705] | 63 | /** is this collection being tidied and therefore can support realistic book view? */
|
---|
[24393] | 64 | protected boolean useBook = false;
|
---|
[27705] | 65 | /**
|
---|
| 66 | * is this collection public or private - public collections will
|
---|
| 67 | * appear on the home page, whereas private collections won't
|
---|
| 68 | */
|
---|
[24393] | 69 | protected boolean is_public = true;
|
---|
[26446] | 70 | /** collection type : mg, mgpp or lucene */
|
---|
| 71 | protected String col_type = "";
|
---|
| 72 | /** database type : gdbm, jdbm or sqlite */
|
---|
| 73 | protected String db_type = "";
|
---|
[28984] | 74 | /** time when this collection was built Used by RSS */
|
---|
[24393] | 75 | protected long lastmodified = 0;
|
---|
[31916] | 76 | /** earliestDatestamp of this collection. Used by RSS. No longer used as fallback by OAI */
|
---|
[28984] | 77 | protected long earliestDatestamp = 0;
|
---|
[23938] | 78 |
|
---|
[25092] | 79 | /** Stores the default accessibility of guest users */
|
---|
| 80 | protected boolean _publicAccess = true;
|
---|
| 81 | /** Stores the scope of any security rules (either collection or document) */
|
---|
| 82 | protected boolean _securityScopeCollection = true;
|
---|
[32985] | 83 | protected boolean _humanVerify = false;
|
---|
| 84 | protected boolean _useRecaptcha = false; // for human verify
|
---|
| 85 | protected String _siteKey = null; // for recaptcha
|
---|
| 86 | protected String _secretKey = null; // for recaptcha
|
---|
| 87 |
|
---|
[25092] | 88 | protected HashMap<String, ArrayList<Element>> _documentSets = new HashMap<String, ArrayList<Element>>();
|
---|
| 89 | protected ArrayList<HashMap<String, ArrayList<String>>> _securityExceptions = new ArrayList<HashMap<String, ArrayList<String>>>();
|
---|
| 90 |
|
---|
[24393] | 91 | protected XMLTransformer transformer = null;
|
---|
[24236] | 92 |
|
---|
[24393] | 93 | /** same as setClusterName */
|
---|
| 94 | public void setCollectionName(String name)
|
---|
| 95 | {
|
---|
| 96 | setClusterName(name);
|
---|
[3222] | 97 | }
|
---|
[24393] | 98 |
|
---|
| 99 | public Collection()
|
---|
| 100 | {
|
---|
| 101 | super();
|
---|
[28966] | 102 | this.description = this.desc_doc.createElement(GSXML.COLLECTION_ELEM);
|
---|
[4097] | 103 | }
|
---|
[14208] | 104 |
|
---|
[24393] | 105 | /**
|
---|
| 106 | * Configures the collection.
|
---|
| 107 | *
|
---|
| 108 | * gsdlHome and collectionName must be set before configure is called.
|
---|
| 109 | *
|
---|
| 110 | * the file buildcfg.xml is located in gsdlHome/collect/collectionName
|
---|
| 111 | * collection metadata is obtained, and services loaded.
|
---|
| 112 | *
|
---|
| 113 | * @return true/false on success/fail
|
---|
| 114 | */
|
---|
| 115 | public boolean configure()
|
---|
| 116 | {
|
---|
| 117 | if (this.site_home == null || this.cluster_name == null)
|
---|
| 118 | {
|
---|
| 119 | logger.error("Collection: site_home and collection_name must be set before configure called!");
|
---|
| 120 | return false;
|
---|
| 121 | }
|
---|
[30670] | 122 | // set up the class loader
|
---|
[30838] | 123 | this.class_loader = new CustomClassLoader(this.getClass().getClassLoader(), GSFile.collectionResourceDir(this.site_home, this.cluster_name));
|
---|
[27705] | 124 |
|
---|
[26446] | 125 | macro_resolver.addMacro("_httpcollection_", this.site_http_address + "/collect/" + this.cluster_name);
|
---|
[24236] | 126 |
|
---|
[24393] | 127 | Element coll_config_xml = loadCollConfigFile();
|
---|
[29164] | 128 | if (coll_config_xml == null) {
|
---|
| 129 | logger.error("Collection: couldn't configure collection: " + this.cluster_name + ", " + "Couldn't load collection config file");
|
---|
| 130 |
|
---|
| 131 | return false;
|
---|
| 132 | }
|
---|
[24393] | 133 | Element build_config_xml = loadBuildConfigFile();
|
---|
[24236] | 134 |
|
---|
[29164] | 135 | if (build_config_xml == null)
|
---|
[24393] | 136 | {
|
---|
[29164] | 137 | logger.error("Collection: couldn't configure collection: " + this.cluster_name + ", " + "Couldn't load build config file");
|
---|
| 138 |
|
---|
| 139 | return false;
|
---|
[24393] | 140 | }
|
---|
| 141 |
|
---|
[29164] | 142 | GSXSLT.modifyCollectionConfigForDebug(coll_config_xml);
|
---|
[24393] | 143 | // get the collection type attribute
|
---|
| 144 | Element search = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.SEARCH_ELEM);
|
---|
| 145 | if (search != null)
|
---|
| 146 | {
|
---|
| 147 | col_type = search.getAttribute(GSXML.TYPE_ATT);
|
---|
| 148 | }
|
---|
[30563] | 149 |
|
---|
[24393] | 150 | Element browse = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.INFODB_ELEM);
|
---|
| 151 | if (browse != null)
|
---|
| 152 | {
|
---|
| 153 | db_type = browse.getAttribute(GSXML.TYPE_ATT);
|
---|
| 154 | }
|
---|
| 155 | else
|
---|
| 156 | {
|
---|
| 157 | db_type = "gdbm"; //Default database type
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[26446] | 160 | this.description.setAttribute(GSXML.TYPE_ATT, col_type);
|
---|
| 161 | this.description.setAttribute(GSXML.DB_TYPE_ATT, db_type);
|
---|
[27705] | 162 |
|
---|
[25974] | 163 | _globalFormat = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.FORMAT_ELEM);
|
---|
[26446] | 164 | // process the metadata and display items and default library params
|
---|
| 165 | super.configureLocalData(coll_config_xml);
|
---|
| 166 | super.configureLocalData(build_config_xml);
|
---|
| 167 | // get extra collection specific stuff
|
---|
[24393] | 168 | findAndLoadInfo(coll_config_xml, build_config_xml);
|
---|
| 169 |
|
---|
[25092] | 170 | loadSecurityInformation(coll_config_xml);
|
---|
| 171 |
|
---|
[32475] | 172 | // do we have archives folder?
|
---|
| 173 | File archives_folder = new File(GSFile.collectionArchiveDir(this.site_home, this.cluster_name));
|
---|
| 174 | if (!archives_folder.exists()) {
|
---|
| 175 | this.description.setAttribute(GSXML.NO_ARCHIVES_ATT, "true");
|
---|
| 176 | }
|
---|
[24393] | 177 | // now do the services
|
---|
| 178 | configureServiceRacks(coll_config_xml, build_config_xml);
|
---|
| 179 |
|
---|
| 180 | return true;
|
---|
| 181 |
|
---|
[24221] | 182 | }
|
---|
[24393] | 183 |
|
---|
| 184 | public boolean useBook()
|
---|
| 185 | {
|
---|
| 186 | return useBook;
|
---|
[24221] | 187 | }
|
---|
[13860] | 188 |
|
---|
[24393] | 189 | public boolean isPublic()
|
---|
| 190 | {
|
---|
| 191 | return is_public;
|
---|
[24221] | 192 | }
|
---|
[24393] | 193 |
|
---|
[31916] | 194 | // Used by RSSRetrieve. No longer used by OAI Receptionist (as second fallback)
|
---|
[24393] | 195 | public long getLastmodified()
|
---|
| 196 | {
|
---|
| 197 | return lastmodified;
|
---|
[24236] | 198 | }
|
---|
[23938] | 199 |
|
---|
[31916] | 200 | // used by RSSRetrieve, no longer used as fallback by the OAIReceptionist
|
---|
[24393] | 201 | public long getEarliestDatestamp()
|
---|
| 202 | {
|
---|
| 203 | return earliestDatestamp;
|
---|
| 204 | }
|
---|
[24236] | 205 |
|
---|
[24393] | 206 | /**
|
---|
| 207 | * load in the collection config file into a DOM Element
|
---|
| 208 | */
|
---|
| 209 | protected Element loadCollConfigFile()
|
---|
| 210 | {
|
---|
[24236] | 211 |
|
---|
[24393] | 212 | File coll_config_file = new File(GSFile.collectionConfigFile(this.site_home, this.cluster_name));
|
---|
[24236] | 213 |
|
---|
[24393] | 214 | if (!coll_config_file.exists())
|
---|
| 215 | {
|
---|
| 216 | return null;
|
---|
[24221] | 217 | }
|
---|
[26446] | 218 | // get the xml
|
---|
[24393] | 219 | Document coll_config_doc = this.converter.getDOM(coll_config_file, CONFIG_ENCODING);
|
---|
| 220 | Element coll_config_elem = null;
|
---|
| 221 | if (coll_config_doc != null)
|
---|
| 222 | {
|
---|
| 223 | coll_config_elem = coll_config_doc.getDocumentElement();
|
---|
| 224 | }
|
---|
| 225 | return coll_config_elem;
|
---|
| 226 |
|
---|
[24221] | 227 | }
|
---|
[4097] | 228 |
|
---|
[24393] | 229 | /**
|
---|
| 230 | * load in the collection build config file into a DOM Element
|
---|
| 231 | */
|
---|
| 232 | protected Element loadBuildConfigFile()
|
---|
| 233 | {
|
---|
| 234 | File build_config_file = new File(GSFile.collectionBuildConfigFile(this.site_home, this.cluster_name));
|
---|
| 235 | if (!build_config_file.exists())
|
---|
| 236 | {
|
---|
| 237 | logger.error("Collection: couldn't configure collection: " + this.cluster_name + ", " + build_config_file + " does not exist");
|
---|
| 238 | return null;
|
---|
| 239 | }
|
---|
| 240 | Document build_config_doc = this.converter.getDOM(build_config_file, CONFIG_ENCODING);
|
---|
| 241 | Element build_config_elem = null;
|
---|
| 242 | if (build_config_doc != null)
|
---|
| 243 | {
|
---|
| 244 | build_config_elem = build_config_doc.getDocumentElement();
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | lastmodified = build_config_file.lastModified();
|
---|
| 248 |
|
---|
| 249 | return build_config_elem;
|
---|
[3847] | 250 | }
|
---|
[23938] | 251 |
|
---|
[24393] | 252 | /**
|
---|
| 253 | * find the metadata and display elems from the two config files and add it
|
---|
| 254 | * to the appropriate lists
|
---|
| 255 | */
|
---|
| 256 | protected boolean findAndLoadInfo(Element coll_config_xml, Element build_config_xml)
|
---|
| 257 | {
|
---|
[28984] | 258 | addMetadata("httpPath", this.site_http_address + "/collect/" + this.cluster_name);
|
---|
[24393] | 259 |
|
---|
| 260 |
|
---|
| 261 | //check whether the html are tidy or not
|
---|
| 262 | Element import_list = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.IMPORT_ELEM);
|
---|
| 263 | if (import_list != null)
|
---|
| 264 | {
|
---|
| 265 | Element plugin_list = (Element) GSXML.getChildByTagName(import_list, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER);
|
---|
[26446] | 266 | //addPlugins(plugin_list);
|
---|
[24393] | 267 | if (plugin_list != null)
|
---|
| 268 | {
|
---|
| 269 | Element plugin_elem = (Element) GSXML.getNamedElement(plugin_list, GSXML.PLUGIN_ELEM, GSXML.NAME_ATT, "HTMLPlugin");
|
---|
| 270 | if (plugin_elem != null)
|
---|
| 271 | {
|
---|
| 272 | //get the option
|
---|
| 273 | Element option_elem = (Element) GSXML.getNamedElement(plugin_elem, GSXML.PARAM_OPTION_ELEM, GSXML.NAME_ATT, "-use_realistic_book");
|
---|
| 274 | if (option_elem != null)
|
---|
| 275 | {
|
---|
| 276 | useBook = true;
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
[26446] | 281 | String tidy = (useBook == true ? "tidy" : "untidy");
|
---|
| 282 | addMetadata("tidyoption", tidy);
|
---|
[24393] | 283 |
|
---|
[28984] | 284 |
|
---|
[25466] | 285 | if (this.metadata_list != null)
|
---|
[24393] | 286 | {
|
---|
[28984] | 287 | // check whether we are public or not
|
---|
[25466] | 288 | Element meta_elem = (Element) GSXML.getNamedElement(this.metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, "public");
|
---|
[24393] | 289 | if (meta_elem != null)
|
---|
| 290 | {
|
---|
| 291 | String value = GSXML.getValue(meta_elem).toLowerCase().trim();
|
---|
| 292 | if (value.equals("false"))
|
---|
| 293 | {
|
---|
| 294 | is_public = false;
|
---|
| 295 | }
|
---|
| 296 | }
|
---|
[28984] | 297 | // earliest datestamp is the time the collection was created.
|
---|
| 298 | meta_elem = (Element) GSXML.getNamedElement(this.metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, OAIXML.EARLIEST_DATESTAMP);
|
---|
| 299 | if (meta_elem != null) {
|
---|
| 300 | String earliestDatestampStr = GSXML.getValue(meta_elem);
|
---|
| 301 | if (!earliestDatestampStr.equals("")) {
|
---|
| 302 | earliestDatestamp = Long.parseLong(earliestDatestampStr) * 1000; // stored in seconds, convert to milliseconds
|
---|
| 303 | }
|
---|
| 304 | }
|
---|
| 305 |
|
---|
[24393] | 306 | }
|
---|
| 307 | return true;
|
---|
[24221] | 308 | }
|
---|
[4097] | 309 |
|
---|
[25092] | 310 | protected void loadSecurityInformation(Element coll_config_xml)
|
---|
| 311 | {
|
---|
| 312 | Element securityBlock = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.SECURITY_ELEM);
|
---|
| 313 |
|
---|
[25647] | 314 | if (securityBlock == null)
|
---|
[25092] | 315 | {
|
---|
| 316 | return;
|
---|
| 317 | }
|
---|
[25647] | 318 |
|
---|
[29310] | 319 | String disabled = securityBlock.getAttribute(GSXML.DISABLED_ATT);
|
---|
| 320 | if (!disabled.equals("")) {
|
---|
| 321 | // security block has been disabled.
|
---|
| 322 | logger.warn("Security block has been disabled. Not implementing any security for collection "+this.cluster_name);
|
---|
| 323 | return;
|
---|
| 324 | }
|
---|
[25092] | 325 | String scope = securityBlock.getAttribute(GSXML.SCOPE_ATT);
|
---|
| 326 | String defaultAccess = securityBlock.getAttribute(GSXML.DEFAULT_ACCESS_ATT);
|
---|
| 327 |
|
---|
| 328 | if (defaultAccess.toLowerCase().equals("public"))
|
---|
| 329 | {
|
---|
| 330 | _publicAccess = true;
|
---|
| 331 | }
|
---|
| 332 | else if (defaultAccess.toLowerCase().equals("private"))
|
---|
| 333 | {
|
---|
| 334 | _publicAccess = false;
|
---|
| 335 | }
|
---|
| 336 | else
|
---|
| 337 | {
|
---|
[33113] | 338 | logger.warn("Default access for collection " + this.cluster_name + " is neither public nor private, assuming public");
|
---|
[25092] | 339 | }
|
---|
| 340 |
|
---|
[32985] | 341 | String humanVerify = securityBlock.getAttribute("humanVerify");
|
---|
| 342 | if (humanVerify.equals("true")) {
|
---|
| 343 | _humanVerify = true;
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | String useRecaptcha = securityBlock.getAttribute("useRecaptcha");
|
---|
| 347 | if (useRecaptcha.equals("true")) {
|
---|
| 348 |
|
---|
| 349 | Authentication authen_services =(Authentication) this.router.getModuleMap().get(Authentication.AUTHENTICATION_SERVICE);
|
---|
| 350 | if (authen_services != null) {
|
---|
| 351 | String siteKey = authen_services.getRecaptchaSiteKey();
|
---|
| 352 | String secretKey = authen_services.getRecaptchaSecretKey();
|
---|
| 353 |
|
---|
| 354 | if (siteKey != null && secretKey != null) {
|
---|
| 355 | _useRecaptcha = true;
|
---|
| 356 | _siteKey = siteKey;
|
---|
| 357 | _secretKey = secretKey;
|
---|
[32989] | 358 | } else {
|
---|
| 359 | logger.warn("use_recaptcha was set to true, but couldn't find recaptcha site and secret keys from the siteConfig Authentication service. Setting use_recaptcha to false!");
|
---|
[32990] | 360 | }
|
---|
[32985] | 361 | }
|
---|
| 362 | }
|
---|
[25092] | 363 | if (scope.toLowerCase().equals("collection"))
|
---|
| 364 | {
|
---|
| 365 | _securityScopeCollection = true;
|
---|
| 366 | }
|
---|
| 367 | else if (scope.toLowerCase().equals("documents") || scope.toLowerCase().equals("document"))
|
---|
| 368 | {
|
---|
| 369 | _securityScopeCollection = false;
|
---|
| 370 | }
|
---|
| 371 | else
|
---|
| 372 | {
|
---|
[33113] | 373 | logger.warn("Security scope is neither collection nor document, assuming collection");
|
---|
[25092] | 374 | }
|
---|
| 375 |
|
---|
| 376 | NodeList exceptions = GSXML.getChildrenByTagName(securityBlock, GSXML.EXCEPTION_ELEM);
|
---|
| 377 |
|
---|
| 378 | if (exceptions.getLength() > 0)
|
---|
| 379 | {
|
---|
| 380 | if (!_securityScopeCollection)
|
---|
| 381 | {
|
---|
| 382 | NodeList documentSetElems = GSXML.getChildrenByTagName(securityBlock, GSXML.DOCUMENT_SET_ELEM);
|
---|
| 383 | for (int i = 0; i < documentSetElems.getLength(); i++)
|
---|
| 384 | {
|
---|
| 385 | Element documentSet = (Element) documentSetElems.item(i);
|
---|
| 386 | String setName = documentSet.getAttribute(GSXML.NAME_ATT);
|
---|
| 387 | NodeList matchStatements = GSXML.getChildrenByTagName(documentSet, GSXML.MATCH_ELEM);
|
---|
| 388 | ArrayList<Element> matchStatementList = new ArrayList<Element>();
|
---|
| 389 | for (int j = 0; j < matchStatements.getLength(); j++)
|
---|
| 390 | {
|
---|
| 391 | matchStatementList.add((Element) matchStatements.item(j));
|
---|
| 392 | }
|
---|
| 393 | _documentSets.put(setName, matchStatementList);
|
---|
| 394 | }
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | for (int i = 0; i < exceptions.getLength(); i++)
|
---|
| 398 | {
|
---|
| 399 | HashMap<String, ArrayList<String>> securityException = new HashMap<String, ArrayList<String>>();
|
---|
| 400 | ArrayList<String> exceptionGroups = new ArrayList<String>();
|
---|
| 401 | ArrayList<String> exceptionSets = new ArrayList<String>();
|
---|
| 402 |
|
---|
| 403 | Element exception = (Element) exceptions.item(i);
|
---|
| 404 | NodeList groups = GSXML.getChildrenByTagName(exception, GSXML.GROUP_ELEM);
|
---|
| 405 | for (int j = 0; j < groups.getLength(); j++)
|
---|
| 406 | {
|
---|
| 407 | Element group = (Element) groups.item(j);
|
---|
| 408 | String groupName = group.getAttribute(GSXML.NAME_ATT);
|
---|
| 409 | exceptionGroups.add(groupName);
|
---|
| 410 | }
|
---|
| 411 | NodeList docSets = GSXML.getChildrenByTagName(exception, GSXML.DOCUMENT_SET_ELEM);
|
---|
| 412 | for (int j = 0; j < docSets.getLength(); j++)
|
---|
| 413 | {
|
---|
| 414 | Element docSet = (Element) docSets.item(j);
|
---|
| 415 | String docSetName = docSet.getAttribute(GSXML.NAME_ATT);
|
---|
| 416 | exceptionSets.add(docSetName);
|
---|
| 417 | }
|
---|
[29310] | 418 | if (_securityScopeCollection) {
|
---|
| 419 | // we don't add in any exceptions that have document sets
|
---|
| 420 | if (!exceptionSets.isEmpty()) {
|
---|
| 421 | continue;
|
---|
| 422 | }
|
---|
| 423 | }
|
---|
[25092] | 424 | securityException.put("groups", exceptionGroups);
|
---|
| 425 | securityException.put("sets", exceptionSets);
|
---|
| 426 | _securityExceptions.add(securityException);
|
---|
| 427 | }
|
---|
| 428 | }
|
---|
| 429 | }
|
---|
| 430 |
|
---|
[24393] | 431 | protected boolean configureServiceRacks(Element coll_config_xml, Element build_config_xml)
|
---|
| 432 | {
|
---|
| 433 | clearServices();
|
---|
| 434 | Element service_list = (Element) GSXML.getChildByTagName(build_config_xml, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER);
|
---|
[27705] | 435 | if (service_list != null)
|
---|
| 436 | {
|
---|
| 437 | configureServiceRackList(service_list, coll_config_xml);
|
---|
[26446] | 438 | }
|
---|
[24393] | 439 | // collection Config may also contain manually added service racks
|
---|
| 440 | service_list = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 441 | if (service_list != null)
|
---|
| 442 | {
|
---|
[27705] | 443 | configureServiceRackList(service_list, build_config_xml);
|
---|
[24393] | 444 | }
|
---|
| 445 | return true;
|
---|
| 446 | }
|
---|
[23489] | 447 |
|
---|
[24393] | 448 | /**
|
---|
| 449 | * do a configure on only part of the collection
|
---|
| 450 | */
|
---|
| 451 | protected boolean configureSubset(String subset)
|
---|
| 452 | {
|
---|
[24203] | 453 |
|
---|
[24393] | 454 | // need the coll config files
|
---|
| 455 | Element coll_config_elem = loadCollConfigFile();
|
---|
| 456 | Element build_config_elem = loadBuildConfigFile();
|
---|
| 457 | if (coll_config_elem == null || build_config_elem == null)
|
---|
| 458 | {
|
---|
| 459 | // wont be able to do any of the requests
|
---|
| 460 | return false;
|
---|
| 461 | }
|
---|
[23489] | 462 |
|
---|
[24393] | 463 | if (subset.equals(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER))
|
---|
| 464 | {
|
---|
| 465 | return configureServiceRacks(coll_config_elem, build_config_elem);
|
---|
| 466 | }
|
---|
[23489] | 467 |
|
---|
[28966] | 468 | if (subset.equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER) || subset.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER) || subset.equals(GSXML.LIBRARY_PARAM_ELEM+GSXML.LIST_MODIFIER))
|
---|
[24393] | 469 | {
|
---|
[27705] | 470 | configureLocalData(coll_config_elem);
|
---|
| 471 | configureLocalData(build_config_elem);
|
---|
[24393] | 472 | return findAndLoadInfo(coll_config_elem, build_config_elem);
|
---|
[23489] | 473 |
|
---|
[24393] | 474 | }
|
---|
[23489] | 475 |
|
---|
[24393] | 476 | logger.error("Collection: cant process system request, configure " + subset);
|
---|
| 477 | return false;
|
---|
| 478 | }
|
---|
[23489] | 479 |
|
---|
[24393] | 480 | /**
|
---|
| 481 | * handles requests made to the ServiceCluster itself
|
---|
| 482 | *
|
---|
| 483 | * @param req
|
---|
| 484 | * - the request Element- <request>
|
---|
| 485 | * @return the result Element - should be <response>
|
---|
| 486 | */
|
---|
[28966] | 487 | protected Element processMessage(Document result_doc, Element request)
|
---|
[24393] | 488 | {
|
---|
[27705] | 489 | String type = request.getAttribute(GSXML.TYPE_ATT);
|
---|
[24393] | 490 | if (type.equals(GSXML.REQUEST_TYPE_FORMAT_STRING))
|
---|
| 491 | {
|
---|
[28966] | 492 | return processFormatStringRequest(result_doc, request);
|
---|
[24393] | 493 | }
|
---|
[25092] | 494 | else if (type.equals(GSXML.REQUEST_TYPE_SECURITY))
|
---|
| 495 | {
|
---|
[28966] | 496 | return processSecurityRequest(result_doc, request);
|
---|
[25092] | 497 | }
|
---|
[25989] | 498 | else if (type.equals(GSXML.REQUEST_TYPE_FORMAT))
|
---|
| 499 | {
|
---|
[28966] | 500 |
|
---|
| 501 | Element response = result_doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
[27705] | 502 | response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
|
---|
| 503 | response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_FORMAT);
|
---|
| 504 | if (_globalFormat != null)
|
---|
[25989] | 505 | {
|
---|
[28966] | 506 | response.appendChild(result_doc.importNode(_globalFormat, true));
|
---|
[25989] | 507 | }
|
---|
[26446] | 508 | return response;
|
---|
[25989] | 509 | }
|
---|
[26446] | 510 | // unknown type
|
---|
[28966] | 511 | return super.processMessage(result_doc, request);
|
---|
[24393] | 512 |
|
---|
| 513 | }
|
---|
| 514 |
|
---|
[28966] | 515 | protected Element processSecurityRequest(Document result_doc, Element request)
|
---|
[27705] | 516 | {
|
---|
[28966] | 517 | Element response = result_doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
[27705] | 518 | response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
|
---|
| 519 | response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_SECURITY);
|
---|
[26446] | 520 |
|
---|
[32985] | 521 | if (_humanVerify) {
|
---|
| 522 | response.setAttribute("humanVerify", "true");
|
---|
| 523 | if (_useRecaptcha) {
|
---|
| 524 | response.setAttribute("siteKey", _siteKey);
|
---|
| 525 | response.setAttribute("secretKey", _secretKey);
|
---|
| 526 | }
|
---|
| 527 | }
|
---|
[27705] | 528 | String oid = request.getAttribute("oid");
|
---|
| 529 | if (oid.contains("."))
|
---|
| 530 | {
|
---|
| 531 | oid = oid.substring(0, oid.indexOf("."));
|
---|
| 532 | }
|
---|
| 533 |
|
---|
| 534 | ArrayList<String> groups = getPermittedGroups(oid);
|
---|
| 535 |
|
---|
[28966] | 536 | Element groupList = result_doc.createElement(GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER);
|
---|
[27705] | 537 | response.appendChild(groupList);
|
---|
| 538 |
|
---|
| 539 | for (String groupName : groups)
|
---|
| 540 | {
|
---|
[28966] | 541 | Element group = result_doc.createElement(GSXML.GROUP_ELEM);
|
---|
[27705] | 542 | groupList.appendChild(group);
|
---|
| 543 | group.setAttribute(GSXML.NAME_ATT, groupName);
|
---|
| 544 | }
|
---|
| 545 | return response;
|
---|
| 546 | }
|
---|
| 547 |
|
---|
[25092] | 548 | protected ArrayList<String> getPermittedGroups(String oid)
|
---|
| 549 | {
|
---|
| 550 | ArrayList<String> groups = new ArrayList<String>();
|
---|
[25647] | 551 |
|
---|
[25092] | 552 | if (_securityScopeCollection)
|
---|
| 553 | {
|
---|
| 554 | if (_publicAccess)
|
---|
| 555 | {
|
---|
| 556 | groups.add("");
|
---|
| 557 | }
|
---|
| 558 | else
|
---|
| 559 | {
|
---|
| 560 | for (HashMap<String, ArrayList<String>> exception : _securityExceptions)
|
---|
| 561 | {
|
---|
| 562 | for (String group : exception.get("groups"))
|
---|
| 563 | {
|
---|
| 564 | groups.add(group);
|
---|
| 565 | }
|
---|
| 566 | }
|
---|
| 567 | }
|
---|
| 568 | }
|
---|
| 569 | else
|
---|
| 570 | {
|
---|
[25647] | 571 | if (oid != null && !oid.equals(""))
|
---|
[25092] | 572 | {
|
---|
| 573 | boolean inSet = false;
|
---|
[29049] | 574 | for (HashMap<String, ArrayList<String>> exception : _securityExceptions) {
|
---|
| 575 |
|
---|
| 576 | ArrayList<String> exceptionSets = exception.get("sets");
|
---|
| 577 | if (exceptionSets.size() == 0) {
|
---|
| 578 | inSet = true;
|
---|
| 579 | for (String group : exception.get("groups"))
|
---|
| 580 | {
|
---|
| 581 | groups.add(group);
|
---|
| 582 | }
|
---|
| 583 | }
|
---|
| 584 | else {
|
---|
| 585 | for (String setName : exception.get("sets"))
|
---|
[25092] | 586 | {
|
---|
[29049] | 587 | if (documentIsInSet(oid, setName))
|
---|
| 588 | {
|
---|
| 589 | inSet = true;
|
---|
| 590 | for (String group : exception.get("groups"))
|
---|
[25092] | 591 | {
|
---|
[29049] | 592 | groups.add(group);
|
---|
[25092] | 593 | }
|
---|
[29049] | 594 | break;
|
---|
| 595 | }
|
---|
[25092] | 596 | }
|
---|
[29049] | 597 | }
|
---|
[25092] | 598 | }
|
---|
[29049] | 599 |
|
---|
| 600 |
|
---|
| 601 |
|
---|
[25647] | 602 | if (!inSet && _publicAccess)
|
---|
[29049] | 603 | {// our doc was not part of any exception, so it must be public
|
---|
[25092] | 604 | groups.add("");
|
---|
| 605 | }
|
---|
| 606 | }
|
---|
[29049] | 607 | else // if we are not doing a request with an oid, then free to access
|
---|
[25092] | 608 | {
|
---|
| 609 | groups.add("");
|
---|
| 610 | }
|
---|
| 611 | }
|
---|
| 612 |
|
---|
| 613 | return groups;
|
---|
| 614 | }
|
---|
| 615 |
|
---|
| 616 | protected boolean documentIsInSet(String oid, String setName)
|
---|
| 617 | {
|
---|
| 618 | ArrayList<Element> matchStatements = _documentSets.get(setName);
|
---|
| 619 | if (matchStatements == null || matchStatements.size() == 0)
|
---|
| 620 | {
|
---|
| 621 | return false;
|
---|
| 622 | }
|
---|
| 623 |
|
---|
| 624 | for (Element currentMatchStatement : matchStatements)
|
---|
| 625 | {
|
---|
| 626 | String fieldName = currentMatchStatement.getAttribute(GSXML.FIELD_ATT);
|
---|
| 627 | if (fieldName == null || fieldName.equals(""))
|
---|
| 628 | {
|
---|
| 629 | fieldName = "oid";
|
---|
| 630 | }
|
---|
| 631 |
|
---|
| 632 | String type = currentMatchStatement.getAttribute(GSXML.TYPE_ATT);
|
---|
| 633 | if (type == null || type.equals(""))
|
---|
| 634 | {
|
---|
| 635 | type = "match";
|
---|
| 636 | }
|
---|
| 637 |
|
---|
[33113] | 638 | //String fieldValue = "";
|
---|
| 639 | String[] fieldValues = null;
|
---|
[25092] | 640 | if (!fieldName.equals("oid"))
|
---|
| 641 | {
|
---|
[33113] | 642 | //fieldValue = getFieldValue(oid, fieldName);
|
---|
| 643 | fieldValues = getFieldValues(oid, fieldName);
|
---|
| 644 | if (fieldValues == null)
|
---|
[25092] | 645 | {
|
---|
| 646 | return false;
|
---|
| 647 | }
|
---|
| 648 | }
|
---|
| 649 | else
|
---|
| 650 | {
|
---|
[33113] | 651 | //fieldValue = oid;
|
---|
| 652 | //fieldValues = new String[0];
|
---|
| 653 | //fieldValues[0] = oid;
|
---|
| 654 | fieldValues = new String[]{oid}; // not allowed to do fieldValues = {oid}; after SEPARATE declaration.
|
---|
[25092] | 655 | }
|
---|
| 656 |
|
---|
| 657 | String matchValue = GSXML.getNodeText(currentMatchStatement);
|
---|
| 658 | if (type.equals("match"))
|
---|
[25647] | 659 | {
|
---|
[33113] | 660 |
|
---|
| 661 | for(int i = 0; i < fieldValues.length; i++) {
|
---|
| 662 | String fieldValue = fieldValues[i];
|
---|
[25647] | 663 | if (matchValue.equals(fieldValue))
|
---|
[25092] | 664 | {
|
---|
| 665 | return true;
|
---|
| 666 | }
|
---|
[33113] | 667 | }
|
---|
[25092] | 668 | }
|
---|
| 669 | else if (type.equals("regex"))
|
---|
| 670 | {
|
---|
[33113] | 671 | for(int i = 0; i < fieldValues.length; i++) {
|
---|
| 672 | String fieldValue = fieldValues[i];
|
---|
[25647] | 673 | if (fieldValue.matches(matchValue))
|
---|
[25092] | 674 | {
|
---|
| 675 | return true;
|
---|
| 676 | }
|
---|
[33113] | 677 | }
|
---|
[25092] | 678 | }
|
---|
| 679 | else
|
---|
| 680 | {
|
---|
| 681 | logger.warn("Unknown type of match specified in security block of collection " + this.cluster_name + ".");
|
---|
| 682 | }
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 | return false;
|
---|
| 686 | }
|
---|
| 687 |
|
---|
[33113] | 688 | protected String old_getFieldValue(String oid, String fieldName)
|
---|
[25092] | 689 | {
|
---|
[28966] | 690 | Document msg_doc = XMLConverter.newDOM();
|
---|
| 691 | Element metadataMessage = msg_doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
| 692 | Element metadataRequest = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_PROCESS, this.cluster_name + "/DocumentMetadataRetrieve", new UserContext());
|
---|
[25092] | 693 | metadataMessage.appendChild(metadataRequest);
|
---|
| 694 |
|
---|
[28966] | 695 | Element paramList = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
[25092] | 696 | metadataRequest.appendChild(paramList);
|
---|
[25647] | 697 |
|
---|
[28966] | 698 | Element param = msg_doc.createElement(GSXML.PARAM_ELEM);
|
---|
[25092] | 699 | paramList.appendChild(param);
|
---|
[25647] | 700 |
|
---|
[25092] | 701 | param.setAttribute(GSXML.NAME_ATT, "metadata");
|
---|
| 702 | param.setAttribute(GSXML.VALUE_ATT, fieldName);
|
---|
[25647] | 703 |
|
---|
[28966] | 704 | Element docList = msg_doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
[25092] | 705 | metadataRequest.appendChild(docList);
|
---|
[25647] | 706 |
|
---|
[28966] | 707 | Element doc = msg_doc.createElement(GSXML.DOC_NODE_ELEM);
|
---|
[25092] | 708 | docList.appendChild(doc);
|
---|
[25647] | 709 |
|
---|
[25092] | 710 | doc.setAttribute(GSXML.NODE_ID_ATT, oid);
|
---|
[25647] | 711 |
|
---|
[25092] | 712 | Element response = (Element) this.router.process(metadataMessage);
|
---|
| 713 | NodeList metadataElems = response.getElementsByTagName(GSXML.METADATA_ELEM);
|
---|
[25647] | 714 |
|
---|
| 715 | if (metadataElems.getLength() > 0)
|
---|
[25092] | 716 | {
|
---|
| 717 | Element metadata = (Element) metadataElems.item(0);
|
---|
| 718 | return GSXML.getNodeText(metadata);
|
---|
| 719 | }
|
---|
[25647] | 720 |
|
---|
[25092] | 721 | return null;
|
---|
| 722 | }
|
---|
[26446] | 723 |
|
---|
[33113] | 724 | protected String[] getFieldValues(String oid, String fieldName)
|
---|
| 725 | {
|
---|
| 726 | Document msg_doc = XMLConverter.newDOM();
|
---|
| 727 | Element metadataMessage = msg_doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
| 728 | Element metadataRequest = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_PROCESS, this.cluster_name + "/DocumentMetadataRetrieve", new UserContext());
|
---|
| 729 | metadataMessage.appendChild(metadataRequest);
|
---|
| 730 |
|
---|
| 731 | Element paramList = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 732 | metadataRequest.appendChild(paramList);
|
---|
| 733 |
|
---|
| 734 | Element param = msg_doc.createElement(GSXML.PARAM_ELEM);
|
---|
| 735 | paramList.appendChild(param);
|
---|
| 736 |
|
---|
| 737 | param.setAttribute(GSXML.NAME_ATT, "metadata");
|
---|
| 738 | param.setAttribute(GSXML.VALUE_ATT, fieldName);
|
---|
| 739 |
|
---|
| 740 | Element docList = msg_doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 741 | metadataRequest.appendChild(docList);
|
---|
| 742 |
|
---|
| 743 | Element doc = msg_doc.createElement(GSXML.DOC_NODE_ELEM);
|
---|
| 744 | docList.appendChild(doc);
|
---|
| 745 |
|
---|
| 746 | doc.setAttribute(GSXML.NODE_ID_ATT, oid);
|
---|
| 747 |
|
---|
| 748 | Element response = (Element) this.router.process(metadataMessage);
|
---|
| 749 | NodeList metadataElems = response.getElementsByTagName(GSXML.METADATA_ELEM);
|
---|
| 750 |
|
---|
| 751 | if (metadataElems.getLength() <= 0) {
|
---|
| 752 | return null;
|
---|
| 753 | }
|
---|
| 754 | // else
|
---|
| 755 | String[] fieldValues = new String[metadataElems.getLength()];
|
---|
| 756 | for(int i = 0; i < metadataElems.getLength(); i++)
|
---|
| 757 | {
|
---|
| 758 | Element metadata = (Element) metadataElems.item(i);
|
---|
| 759 | fieldValues[i] = GSXML.getNodeText(metadata);
|
---|
| 760 | }
|
---|
| 761 |
|
---|
| 762 | return fieldValues;
|
---|
| 763 |
|
---|
| 764 | }
|
---|
| 765 |
|
---|
[28966] | 766 | protected Element processFormatStringRequest(Document result_doc, Element request)
|
---|
[27705] | 767 | {
|
---|
[28966] | 768 | Element response = result_doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
[27705] | 769 | response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_FORMAT_STRING);
|
---|
| 770 | response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
|
---|
[26446] | 771 |
|
---|
[27705] | 772 | String subaction = request.getAttribute("subaction");
|
---|
| 773 | String service = request.getAttribute("service");
|
---|
[26446] | 774 |
|
---|
[27705] | 775 | String classifier = null;
|
---|
| 776 | if (service.equals("ClassifierBrowse"))
|
---|
| 777 | {
|
---|
| 778 | classifier = request.getAttribute("classifier");
|
---|
| 779 | }
|
---|
[26446] | 780 |
|
---|
[27705] | 781 | // check for version file
|
---|
| 782 | String directory = new File(GSFile.collectionConfigFile(this.site_home, this.cluster_name)).getParent() + File.separator;
|
---|
[26446] | 783 |
|
---|
[27705] | 784 | String version_filename = "";
|
---|
| 785 | if (service.equals("ClassifierBrowse"))
|
---|
| 786 | version_filename = directory + "browse_" + classifier + "_format_statement_version.txt";
|
---|
| 787 | else
|
---|
| 788 | version_filename = directory + "query_format_statement_version.txt";
|
---|
[26446] | 789 |
|
---|
[27705] | 790 | File version_file = new File(version_filename);
|
---|
[26446] | 791 |
|
---|
[27705] | 792 | if (subaction.equals("update"))
|
---|
| 793 | {
|
---|
| 794 | Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM);
|
---|
| 795 | //String format_string = GSXML.getNodeText(format_element);
|
---|
| 796 | Element format_statement = (Element) format_element.getFirstChild();
|
---|
[26446] | 797 |
|
---|
[27705] | 798 | String version_number = "1";
|
---|
| 799 | BufferedWriter writer;
|
---|
[26446] | 800 |
|
---|
[27705] | 801 | try
|
---|
| 802 | {
|
---|
[26446] | 803 |
|
---|
[27705] | 804 | if (version_file.exists())
|
---|
| 805 | {
|
---|
| 806 | // Read version
|
---|
| 807 | BufferedReader reader = new BufferedReader(new FileReader(version_filename));
|
---|
| 808 | version_number = reader.readLine();
|
---|
| 809 | int aInt = Integer.parseInt(version_number) + 1;
|
---|
| 810 | version_number = Integer.toString(aInt);
|
---|
| 811 | reader.close();
|
---|
| 812 | }
|
---|
| 813 | else
|
---|
| 814 | {
|
---|
| 815 | // Create
|
---|
| 816 | version_file.createNewFile();
|
---|
| 817 | writer = new BufferedWriter(new FileWriter(version_filename));
|
---|
| 818 | writer.write(version_number);
|
---|
| 819 | writer.close();
|
---|
| 820 | }
|
---|
[26446] | 821 |
|
---|
[27705] | 822 | // Write version file
|
---|
| 823 | String format_statement_filename = "";
|
---|
[26446] | 824 |
|
---|
[27705] | 825 | if (service.equals("ClassifierBrowse"))
|
---|
| 826 | format_statement_filename = directory + "browse_" + classifier + "_format_statement_v" + version_number + ".txt";
|
---|
| 827 | else
|
---|
| 828 | format_statement_filename = directory + "query_format_statement_v" + version_number + ".txt";
|
---|
[26446] | 829 |
|
---|
[27705] | 830 | // Write format statement
|
---|
| 831 | String format_string = this.converter.getString(format_statement); //GSXML.xmlNodeToString(format_statement);
|
---|
| 832 | writer = new BufferedWriter(new FileWriter(format_statement_filename));
|
---|
| 833 | writer.write(format_string);
|
---|
| 834 | writer.close();
|
---|
[26446] | 835 |
|
---|
[27705] | 836 | // Update version number
|
---|
| 837 | writer = new BufferedWriter(new FileWriter(version_filename));
|
---|
| 838 | writer.write(version_number);
|
---|
| 839 | writer.close();
|
---|
[26446] | 840 |
|
---|
[27705] | 841 | }
|
---|
| 842 | catch (IOException e)
|
---|
| 843 | {
|
---|
| 844 | logger.error("IO Exception " + e);
|
---|
| 845 | }
|
---|
| 846 | }
|
---|
[26446] | 847 |
|
---|
[27705] | 848 | if (subaction.equals("saveDocument"))
|
---|
| 849 | {
|
---|
| 850 | Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM);
|
---|
| 851 | //String format_string = GSXML.getNodeText(format_element);
|
---|
| 852 | // Get display tag
|
---|
| 853 | Element display_format = (Element) format_element.getFirstChild();
|
---|
[26446] | 854 |
|
---|
[27705] | 855 | String collection_config = directory + "collectionConfig.xml";
|
---|
| 856 | Document config = this.converter.getDOM(new File(collection_config), "UTF-8");
|
---|
[26446] | 857 |
|
---|
[27705] | 858 | Node current_node = GSXML.getChildByTagName(config, "CollectionConfig");
|
---|
[26446] | 859 |
|
---|
[27705] | 860 | // Get display child
|
---|
| 861 | if (GSXML.getChildByTagName(current_node, "display") == null)
|
---|
| 862 | {
|
---|
| 863 | // well then create a format tag
|
---|
| 864 | Element display_tag = config.createElement("display");
|
---|
| 865 | current_node = (Node) current_node.appendChild(display_tag);
|
---|
| 866 | }
|
---|
| 867 | else
|
---|
| 868 | {
|
---|
| 869 | current_node = GSXML.getChildByTagName(current_node, "display");
|
---|
| 870 | }
|
---|
[26446] | 871 |
|
---|
[27705] | 872 | if (GSXML.getChildByTagName(current_node, "format") == null)
|
---|
| 873 | {
|
---|
| 874 | // well then create a format tag
|
---|
| 875 | Element format_tag = config.createElement("format");
|
---|
| 876 | current_node.appendChild(format_tag);
|
---|
| 877 | }
|
---|
[26446] | 878 |
|
---|
[27705] | 879 | current_node.replaceChild(config.importNode(display_format, true), GSXML.getChildByTagName(current_node, "format"));
|
---|
[26446] | 880 |
|
---|
[27705] | 881 | String new_config = this.converter.getString(config);
|
---|
[26446] | 882 |
|
---|
[27705] | 883 | new_config = StringUtils.replace(new_config, "<", "<");
|
---|
| 884 | new_config = StringUtils.replace(new_config, ">", ">");
|
---|
| 885 | new_config = StringUtils.replace(new_config, """, "\"");
|
---|
[26446] | 886 |
|
---|
[27705] | 887 | try
|
---|
| 888 | {
|
---|
| 889 | // Write to file (not original! for now)
|
---|
| 890 | BufferedWriter writer = new BufferedWriter(new FileWriter(collection_config + ".new"));
|
---|
| 891 | writer.write(new_config);
|
---|
| 892 | writer.close();
|
---|
| 893 | }
|
---|
| 894 | catch (IOException e)
|
---|
| 895 | {
|
---|
| 896 | logger.error("IO Exception " + e);
|
---|
| 897 | }
|
---|
| 898 | }
|
---|
[26446] | 899 |
|
---|
[27705] | 900 | if (subaction.equals("save"))
|
---|
| 901 | {
|
---|
| 902 | Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM);
|
---|
| 903 | Element format_statement = (Element) format_element.getFirstChild();
|
---|
[26446] | 904 |
|
---|
[27705] | 905 | try
|
---|
| 906 | {
|
---|
| 907 | // open collectionConfig.xml and read in to w3 Document
|
---|
| 908 | String collection_config = directory + "collectionConfig.xml";
|
---|
| 909 | Document config = this.converter.getDOM(new File(collection_config), "UTF-8");
|
---|
[26446] | 910 |
|
---|
[27705] | 911 | //String tag_name = "";
|
---|
| 912 | int k;
|
---|
| 913 | int index;
|
---|
| 914 | Element elem;
|
---|
| 915 | Node current_node = GSXML.getChildByTagName(config, "CollectionConfig");
|
---|
| 916 | NodeList current_node_list;
|
---|
[26446] | 917 |
|
---|
[27705] | 918 | if (service.equals("ClassifierBrowse"))
|
---|
| 919 | {
|
---|
| 920 | //tag_name = "browse";
|
---|
| 921 | // if CLX then need to look in <classifier> X then <format>
|
---|
| 922 | // default is <browse><format>
|
---|
[26446] | 923 |
|
---|
[27705] | 924 | current_node = GSXML.getChildByTagName(current_node, "browse");
|
---|
[26446] | 925 |
|
---|
[27705] | 926 | // find CLX
|
---|
| 927 | if (classifier != null)
|
---|
| 928 | {
|
---|
| 929 | current_node_list = GSXML.getChildrenByTagName(current_node, "classifier");
|
---|
| 930 | index = Integer.parseInt(classifier.substring(2)) - 1;
|
---|
[26446] | 931 |
|
---|
[27705] | 932 | // index should be given by X-1
|
---|
| 933 | current_node = current_node_list.item(index);
|
---|
| 934 | // what if classifier does not have a format tag?
|
---|
| 935 | if (GSXML.getChildByTagName(current_node, "format") == null)
|
---|
| 936 | {
|
---|
| 937 | // well then create a format tag
|
---|
| 938 | Element format_tag = config.createElement("format");
|
---|
| 939 | current_node.appendChild(format_tag);
|
---|
| 940 | }
|
---|
| 941 | }
|
---|
| 942 | else
|
---|
| 943 | {
|
---|
| 944 | // To support all classifiers, set classifier to null? There is the chance here that the format tag does not exist
|
---|
| 945 | if (GSXML.getChildByTagName(current_node, "format") == null)
|
---|
| 946 | {
|
---|
| 947 | // well then create a format tag
|
---|
| 948 | Element format_tag = config.createElement("format");
|
---|
| 949 | current_node.appendChild(format_tag);
|
---|
| 950 | }
|
---|
| 951 | }
|
---|
| 952 | }
|
---|
| 953 | else if (service.equals("AllClassifierBrowse"))
|
---|
| 954 | {
|
---|
| 955 | current_node = GSXML.getChildByTagName(current_node, "browse");
|
---|
| 956 | if (GSXML.getChildByTagName(current_node, "format") == null)
|
---|
| 957 | {
|
---|
| 958 | // well then create a format tag
|
---|
| 959 | Element format_tag = config.createElement("format");
|
---|
| 960 | current_node.appendChild(format_tag);
|
---|
| 961 | }
|
---|
| 962 | }
|
---|
| 963 | else
|
---|
| 964 | {
|
---|
| 965 | // look in <format> with no attributes
|
---|
| 966 | current_node_list = GSXML.getChildrenByTagName(current_node, "search");
|
---|
| 967 | for (k = 0; k < current_node_list.getLength(); k++)
|
---|
| 968 | {
|
---|
| 969 | current_node = current_node_list.item(k);
|
---|
| 970 | // if current_node has no attributes then break
|
---|
| 971 | elem = (Element) current_node;
|
---|
| 972 | if (elem.hasAttribute("name") == false)
|
---|
| 973 | break;
|
---|
| 974 | }
|
---|
| 975 | }
|
---|
[26446] | 976 |
|
---|
[27705] | 977 | current_node.replaceChild(config.importNode(format_statement, true), GSXML.getChildByTagName(current_node, "format"));
|
---|
[26446] | 978 |
|
---|
[27705] | 979 | // Now convert config document to string for writing to file
|
---|
| 980 | String new_config = this.converter.getString(config);
|
---|
[26446] | 981 |
|
---|
[27705] | 982 | new_config = StringUtils.replace(new_config, "<", "<");
|
---|
| 983 | new_config = StringUtils.replace(new_config, ">", ">");
|
---|
| 984 | new_config = StringUtils.replace(new_config, """, "\"");
|
---|
[26446] | 985 |
|
---|
[27705] | 986 | // Write to file (not original! for now)
|
---|
| 987 | BufferedWriter writer = new BufferedWriter(new FileWriter(collection_config + ".new"));
|
---|
| 988 | writer.write(new_config);
|
---|
| 989 | writer.close();
|
---|
[26446] | 990 |
|
---|
[27705] | 991 | }
|
---|
| 992 | catch (Exception ex)
|
---|
| 993 | {
|
---|
| 994 | logger.error("There was an exception " + ex);
|
---|
[26446] | 995 |
|
---|
[27705] | 996 | StringWriter sw = new StringWriter();
|
---|
| 997 | PrintWriter pw = new PrintWriter(sw, true);
|
---|
| 998 | ex.printStackTrace(pw);
|
---|
| 999 | pw.flush();
|
---|
| 1000 | sw.flush();
|
---|
| 1001 | logger.error(sw.toString());
|
---|
| 1002 | }
|
---|
[26446] | 1003 |
|
---|
[27705] | 1004 | }
|
---|
| 1005 |
|
---|
| 1006 | return response;
|
---|
| 1007 | }
|
---|
[30670] | 1008 |
|
---|
| 1009 |
|
---|
[24393] | 1010 | }
|
---|