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