source: gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/core/IIIFMessageRouter.java@ 32883

Last change on this file since 32883 was 32883, checked in by davidb, 5 years ago

Code tidy up

File size: 5.0 KB
Line 
1/*
2 * IIIFMessageRouter.java
3 * Copyright (C) 2018 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 */
19package org.greenstone.gsdl3.core;
20
21import java.io.File;
22import java.net.Authenticator;
23import java.net.PasswordAuthentication;
24import java.util.HashMap;
25import java.util.Map;
26import java.util.Iterator;
27
28import org.apache.commons.lang3.StringUtils;
29import org.apache.log4j.Logger;
30import org.greenstone.gsdl3.collection.IIIFCollection;
31import org.greenstone.gsdl3.collection.ServiceCluster;
32import org.greenstone.gsdl3.comms.Communicator;
33import org.greenstone.gsdl3.comms.SOAPCommunicator;
34import org.greenstone.gsdl3.service.ServiceRack;
35import org.greenstone.gsdl3.util.GSFile;
36import org.greenstone.gsdl3.util.GSPath;
37import org.greenstone.gsdl3.util.GSXML;
38import org.greenstone.gsdl3.util.IIIFXML;
39import org.greenstone.gsdl3.util.UserContext;
40import org.greenstone.gsdl3.util.XMLConverter;
41import org.greenstone.util.GlobalProperties;
42import org.w3c.dom.Document;
43import org.w3c.dom.Element;
44import org.w3c.dom.Node;
45import org.w3c.dom.NodeList;
46
47/**
48 * The hub of a Greenstone IIIF image server/bridge.
49 *
50 * A simplified version of MessageRouter for IIIFServerBridge. Only loads up collections that have IIIF services.
51 */
52public class IIIFMessageRouter extends MessageRouter
53{
54
55 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.IIIFMessageRouter.class.getName());
56
57 public Element iiif_config = null;
58 //***************************************************************
59 // public methods
60 //***************************************************************
61
62 /** constructor */
63 public IIIFMessageRouter()
64 {
65 }
66
67 /**
68 * read thru own site config file - create services and connect to sites
69 */
70 protected boolean configureLocalSite()
71 {
72
73 // this may be a reconfigure, so clean up the old moduleMap
74 cleanUpModuleMapEntire();
75
76 // ****
77 // for iiif, we don't do anything with the site config
78 // file. But we'll read it in and keep it in case need
79 // it later
80 File configFile = new File(GSFile.siteConfigFile(this.site_home));
81
82 if (!configFile.exists())
83 {
84 logger.error(" site config file: " + configFile.getPath() + " not found!");
85 return false;
86 }
87
88 Document config_doc = XMLConverter.getDOM(configFile);
89 if (config_doc == null)
90 {
91 logger.error(" couldn't parse site config file: " + configFile.getPath());
92 return false;
93 }
94
95 this.config_info = config_doc.getDocumentElement();
96
97 // this is the receptionist's IFFFConfig.xml.
98 // Need to rethink how the MR gets this this if we
99 // ever talk to remote site, and whether it should be
100 // using it anyway
101 this.iiif_config = IIIFXML.getIIIFConfigXML();
102 if (this.iiif_config == null)
103 {
104 logger.error("Couldn't load in IIIFConfig.xml");
105 return false;
106 }
107 Document doc = XMLConverter.newDOM();
108 // load up the collections
109 this.collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
110 configureCollections();
111
112 return true;
113
114 }
115
116
117 /**
118 * creates and configures a new collection if this is done for a
119 * reconfigure, the collection should be deactivated first.
120 *
121 * @param col_name
122 * the name of the collection
123 * @return true if collection created ok
124 */
125 protected boolean activateCollectionByName(String col_name)
126 {
127
128 logger.info("Activating collection: " + col_name + ".");
129 Document doc = this.collection_list.getOwnerDocument();
130 // use our special IIIFCollection - this will only load in IIIF services
131 IIIFCollection c = new IIIFCollection();
132
133 c.setCollectionName(col_name);
134 c.setSiteHome(this.site_home);
135 c.setSiteAddress(this.site_http_address);
136 c.setMessageRouter(this);
137 if (!c.configure()) {
138 logger.error("Couldn't configure collection: " + col_name + ".");
139 return false;
140 }
141
142 logger.info("have just configured collection " + col_name);
143 if (!c.hasIIIF()) {
144 logger.info ("collection "+col_name+" has no IIIF services. Not keeping it loaded");
145 return false;
146 }
147 if (!c.configureIIIF(this.iiif_config)) {
148 logger.info("couldn't configure the collection : "+col_name +" with the iiif config info");
149 return false;
150 }
151 // add to list of collections
152 this.module_map.put(col_name, c);
153 Element e = doc.createElement(GSXML.COLLECTION_ELEM);
154 e.setAttribute(GSXML.NAME_ATT, col_name);
155
156 this.collection_list.appendChild(e);
157 return true;
158
159 }
160}
Note: See TracBrowser for help on using the repository browser.