- Timestamp:
- 2008-07-17T23:28:27+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/trunk/src/java/org/greenstone/gsdl3/core/SkinnedReceptionist.java
r16374 r16446 1 1 package org.greenstone.gsdl3.core; 2 2 3 import java.util.* 4 import java.io.* 3 import java.util.*; 4 import java.io.*; 5 5 6 6 import org.w3c.dom.NodeList; … … 11 11 import org.greenstone.gsdl3.util.*; 12 12 13 import javax.xml.xpath.* 13 import javax.xml.xpath.*; 14 14 15 15 public class SkinnedReceptionist extends NZDLReceptionist { 16 16 17 /** a transformer class to transform xml using xslt */ 18 protected XMLTransformer transformer=null; 19 20 public SkinnedReceptionist() { 21 super(); 22 System.out.println("Skinned Receptionist created") ; 23 //this.xslt_map = new HashMap(); 24 this.transformer = new XMLTransformer(); 25 } 26 27 protected Node postProcessPage(Element p) { 28 try { 29 //Avoid the duplicate attribute in the namespaces declaration of the generated html file 30 //String NAMESPACE_URI = "http://www.greenstone.org/greenstone3/schema/gsf"; 31 //String NAMESPACE_PREFIX = "gsf"; 32 //p.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + NAMESPACE_PREFIX, NAMESPACE_URI); 33 34 35 Page page = new Page(p, this) ; 36 Skin skin = new Skin(page, this) ; 37 38 addExtraInfo(p) ; 39 addCssFiles(page, skin) ; 40 addJsFiles(page, skin) ; 41 addUiElements(page) ; 42 addMetadataElements(page) ; 43 44 String output = page.getPageRequest().getAttribute(GSXML.OUTPUT_ATT); 45 46 // might need to add some data to the page 47 //addExtraInfo(page); 48 49 50 System.out.println("action = " + page.getAction()) ; 51 // if we are displaying a document, specify an attribute for weither a cover image exists. 52 if (page.getAction().equals("d")) { 53 54 System.out.println("doing the document thing") ; 55 56 Element document = (Element)p.getElementsByTagName("document").item(0) ; 57 Element metadataList = (Element)GSXML.getChildByTagName(document, "metadataList") ; 58 String archiveDir = "" ; 59 NodeList metadata = metadataList.getChildNodes() ; 60 for (int i=0 ; i<metadata.getLength() ; i++) { 61 Element m = (Element) metadata.item(i) ; 62 if (m.getAttribute("name").equals("archivedir")) 63 archiveDir = GSXML.getNodeText(m) ; 64 } 65 66 String coverImage_path = page.getCollectionHome() 67 + File.separatorChar + "index" 68 + File.separatorChar + "assoc" 69 + File.separatorChar + archiveDir 70 + File.separatorChar + "cover.jpg" ; 71 72 document.setAttribute("coverImage", coverImage_path) ; 73 74 File coverImage = new File(coverImage_path) ; 75 document.setAttribute("hasCoverImage", String.valueOf(coverImage.canRead())) ; 76 } 77 78 79 Node np = null; 80 try { 81 if (skin != null && !output.equals("xml")) { 82 np = skin.transformPage(page); 83 } 84 else { 85 np = p; 86 } 87 } catch (Exception e) { 88 e.printStackTrace() ; 89 } 90 91 92 93 return np ; 94 } catch (Exception e) { 95 e.printStackTrace() ; 96 return doc.createElement("page") ; 97 } 98 } 99 100 /** overwrite this to add any extra info that might be needed in the page before transformation */ 101 protected void addExtraInfo(Element page) { 102 103 //logger.debug("the page before adding extra info is"); 104 //logger.debug(this.converter.getPrettyString(page)); 105 106 super.addExtraInfo(page); 107 108 // this gets the collection info 109 Element page_response = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM); 110 Element page_request = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM); 111 Element collection_info = (Element)GSXML.getChildByTagName(page_response, GSXML.COLLECTION_ELEM); 112 if (collection_info== null) { 113 return; 114 } 115 116 String collection = collection_info.getAttribute("name"); // should we take this from the request instead?? 117 // look through services and see if classifier one is present - need to 118 // get the list of classifiers 119 Element service_list = (Element)GSXML.getChildByTagName(collection_info, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER); 120 if (service_list == null) { 121 // something weird has gone wrong 122 return; 123 } 124 125 Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 126 String lang = page.getAttribute(GSXML.LANG_ATT); 127 128 boolean do_classifier = false; 129 boolean do_query = false; 130 Element classifier_service = GSXML.getNamedElement(service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "ClassifierBrowse"); 131 Element query_service = GSXML.getNamedElement(service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "TextQuery"); 132 if (classifier_service != null) { 133 do_classifier = true; 134 // find the list of classifiers 135 136 String to = GSPath.appendLink(collection, "ClassifierBrowse"); 137 Element info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, ""); 138 info_message.appendChild(info_request); 139 } 140 141 String action = page_request.getAttribute(GSXML.ACTION_ATT); 142 String subaction = page_request.getAttribute(GSXML.SUBACTION_ATT); 143 144 if (query_service != null && action.equals("p") && subaction.equals("about")) { 145 do_query = true; 146 // get the full description 147 String to = GSPath.appendLink(collection, "TextQuery"); 148 Element query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, ""); 149 info_message.appendChild(query_request); 150 151 } 152 153 Element info_resp_message = (Element) this.mr.process(info_message); 154 Element info_response = (Element) GSXML.getChildByTagName(info_resp_message, GSXML.RESPONSE_ELEM); 155 // String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.SERVICE_ELEM); 156 if (do_classifier) { 157 Element classifier_service_info = (Element)GSXML.getNamedElement(info_response, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "CLassifierBrowse"); 158 if (classifier_service_info != null) { 159 service_list.replaceChild(this.doc.importNode(classifier_service_info, true), classifier_service); 160 } 161 } 162 if (do_query) { 163 Element query_service_info = (Element)GSXML.getNamedElement(info_response, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "TextQuery"); 164 if (query_service_info != null) { 165 service_list.replaceChild(this.doc.importNode(query_service_info, true), query_service); 166 } 167 } 168 //logger.debug("the final page before transforming is"); 169 //logger.debug(this.converter.getPrettyString(page)); 170 return; 171 } 172 173 protected void addCssFiles(Page page, Skin skin) { 174 175 Element cssFileList = doc.createElement("cssFileList") ; 176 177 // get skin level files 178 if (skin != null) { 179 File dir = new File(skin.rootDirectory.getPath() + File.separatorChar + "css") ; 180 if (dir.isDirectory()) { 181 File[] files = dir.listFiles() ; 182 183 for (int fi=0, fn=files.length ; fi<fn ; fi++) { 184 if (files[fi].getName().endsWith(".css")) { 185 Element cssFile = doc.createElement("cssFile") ; 186 String path = files[fi].getPath() ; 187 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()) ; 188 //changes to a correct path in case GS3 runs on Windows 189 path = path.replace( '\\', '/' ); 190 cssFile.setAttribute("path", path) ; 191 cssFileList.appendChild(cssFile) ; 192 } 193 } 194 } 17 /** a transformer class to transform xml using xslt */ 18 protected XMLTransformer transformer=null; 19 20 public SkinnedReceptionist() { 21 super(); 22 System.out.println("Skinned Receptionist created"); 23 //this.xslt_map = new HashMap(); 24 this.transformer = new XMLTransformer(); 25 } 26 27 protected Node postProcessPage(Element p) { 28 try { 29 //Avoid the duplicate attribute in the namespaces declaration of the generated html file 30 //String NAMESPACE_URI = "http://www.greenstone.org/greenstone3/schema/gsf"; 31 //String NAMESPACE_PREFIX = "gsf"; 32 //p.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + NAMESPACE_PREFIX, NAMESPACE_URI); 33 34 35 Page page = new Page(p, this); 36 Skin skin = new Skin(page, this); 37 38 addExtraInfo(p); 39 addCssFiles(page, skin); 40 addJsFiles(page, skin); 41 addUiElements(page); 42 addMetadataElements(page); 43 44 String output = page.getPageRequest().getAttribute(GSXML.OUTPUT_ATT); 45 46 // might need to add some data to the page 47 //addExtraInfo(page); 48 49 50 System.out.println("action = " + page.getAction()); 51 // if we are displaying a document, specify an attribute for weither a cover image exists. 52 if (page.getAction().equals("d")) { 53 54 System.out.println("doing the document thing"); 55 56 Element document = (Element)p.getElementsByTagName("document").item(0); 57 Element metadataList = (Element)GSXML.getChildByTagName(document, "metadataList"); 58 String archiveDir = ""; 59 NodeList metadata = metadataList.getChildNodes(); 60 for (int i=0; i<metadata.getLength(); i++) { 61 Element m = (Element) metadata.item(i); 62 if (m.getAttribute("name").equals("archivedir")) 63 archiveDir = GSXML.getNodeText(m); 64 } 65 66 String coverImage_path = page.getCollectionHome() 67 + File.separatorChar + "index" 68 + File.separatorChar + "assoc" 69 + File.separatorChar + archiveDir 70 + File.separatorChar + "cover.jpg"; 71 72 document.setAttribute("coverImage", coverImage_path); 73 74 File coverImage = new File(coverImage_path); 75 document.setAttribute("hasCoverImage", String.valueOf(coverImage.canRead())); 76 } 77 78 79 Node np = null; 80 try { 81 82 if (skin != null && !output.equals("xml")) { 83 System.err.println("Away to to skin transformPage"); 84 np = skin.transformPage(page); 85 System.err.println("done"); 86 87 88 } 89 else { 90 np = p; 91 } 92 } catch (Exception e) { 93 e.printStackTrace(); 94 } 95 96 97 98 return np; 99 } catch (Exception e) { 100 e.printStackTrace(); 101 return doc.createElement("page"); 102 } 103 } 104 105 /** overwrite this to add any extra info that might be needed in the page before transformation */ 106 protected void addExtraInfo(Element page) { 107 108 //logger.debug("the page before adding extra info is"); 109 //logger.debug(this.converter.getPrettyString(page)); 110 111 super.addExtraInfo(page); 112 113 // this gets the collection info 114 Element page_response = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM); 115 Element page_request = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM); 116 Element collection_info = (Element)GSXML.getChildByTagName(page_response, GSXML.COLLECTION_ELEM); 117 if (collection_info== null) { 118 return; 119 } 120 121 String collection = collection_info.getAttribute("name"); // should we take this from the request instead?? 122 // look through services and see if classifier one is present - need to 123 // get the list of classifiers 124 Element service_list = (Element)GSXML.getChildByTagName(collection_info, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER); 125 if (service_list == null) { 126 // something weird has gone wrong 127 return; 128 } 129 130 Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 131 String lang = page.getAttribute(GSXML.LANG_ATT); 132 133 boolean do_classifier = false; 134 boolean do_query = false; 135 Element classifier_service = GSXML.getNamedElement(service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "ClassifierBrowse"); 136 Element query_service = GSXML.getNamedElement(service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "TextQuery"); 137 if (classifier_service != null) { 138 do_classifier = true; 139 // find the list of classifiers 140 141 String to = GSPath.appendLink(collection, "ClassifierBrowse"); 142 Element info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, ""); 143 info_message.appendChild(info_request); 144 } 145 146 String action = page_request.getAttribute(GSXML.ACTION_ATT); 147 String subaction = page_request.getAttribute(GSXML.SUBACTION_ATT); 148 149 if (query_service != null && action.equals("p") && subaction.equals("about")) { 150 do_query = true; 151 // get the full description 152 String to = GSPath.appendLink(collection, "TextQuery"); 153 Element query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, ""); 154 info_message.appendChild(query_request); 155 156 } 157 158 Element info_resp_message = (Element) this.mr.process(info_message); 159 Element info_response = (Element) GSXML.getChildByTagName(info_resp_message, GSXML.RESPONSE_ELEM); 160 // String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.SERVICE_ELEM); 161 if (do_classifier) { 162 Element classifier_service_info = (Element)GSXML.getNamedElement(info_response, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "CLassifierBrowse"); 163 if (classifier_service_info != null) { 164 service_list.replaceChild(this.doc.importNode(classifier_service_info, true), classifier_service); 165 } 166 } 167 if (do_query) { 168 Element query_service_info = (Element)GSXML.getNamedElement(info_response, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "TextQuery"); 169 if (query_service_info != null) { 170 service_list.replaceChild(this.doc.importNode(query_service_info, true), query_service); 171 } 172 } 173 //logger.debug("the final page before transforming is"); 174 //logger.debug(this.converter.getPrettyString(page)); 175 return; 176 } 177 178 protected void addCssFiles(Page page, Skin skin) { 179 180 Element cssFileList = doc.createElement("cssFileList"); 181 182 // get skin level files 183 if (skin != null) { 184 File dir = new File(skin.rootDirectory.getPath() + File.separatorChar + "css"); 185 if (dir.isDirectory()) { 186 File[] files = dir.listFiles(); 187 188 for (int fi=0, fn=files.length; fi<fn; fi++) { 189 if (files[fi].getName().endsWith(".css")) { 190 Element cssFile = doc.createElement("cssFile"); 191 String path = files[fi].getPath(); 192 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()); 193 //changes to a correct path in case GS3 runs on Windows 194 path = path.replace( '\\', '/' ); 195 cssFile.setAttribute("path", path); 196 cssFileList.appendChild(cssFile); 197 } 198 } 199 } 200 } 201 202 // get site level files 203 String site_home = page.getSiteHome(); 204 File dir = new File(site_home + File.separatorChar + "ui" + File.separatorChar + "css"); 205 if (dir.isDirectory()) { 206 File[] files = dir.listFiles(); 207 for (int fi=0, fn=files.length; fi<fn; fi++) { 208 if (files[fi].getName().endsWith(".css")) { 209 Element cssFile = doc.createElement("cssFile"); 210 String path = files[fi].getPath(); 211 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()); 212 //changes to a correct path in case GS3 runs on Windows 213 path = path.replace( '\\', '/' ); 214 cssFile.setAttribute("path", path); 215 cssFileList.appendChild(cssFile); 216 } 217 } 218 } 219 220 // get collect level files 221 String collect_home = page.getCollectionHome(); 222 if (collect_home != "") { 223 dir = new File(collect_home + File.separatorChar + "ui" + File.separatorChar + "css"); 224 if (dir.isDirectory()) { 225 File[] files = dir.listFiles(); 226 for (int fi=0, fn=files.length; fi<fn; fi++) { 227 if (files[fi].getName().endsWith(".css")) { 228 Element cssFile = doc.createElement("cssFile"); 229 String path = files[fi].getPath(); 230 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()); 231 //changes to a correct path in case GS3 runs on Windows 232 path = path.replace( '\\', '/' ); 233 cssFile.setAttribute("path", path); 234 cssFileList.appendChild(cssFile); 235 } 236 } 237 } 238 } 239 240 page.getPageResponse().appendChild(cssFileList); 241 } 242 243 protected void addJsFiles(Page page, Skin skin) { 244 245 Element jsFileList = doc.createElement("jsFileList"); 246 247 // get skin level files 248 if (skin != null) { 249 File dir = new File(skin.rootDirectory.getPath() + File.separatorChar + "js"); 250 if (dir.isDirectory()) { 251 File[] files = dir.listFiles(); 252 253 for (int fi=0, fn=files.length; fi<fn; fi++) { 254 if (files[fi].getName().endsWith(".js")) { 255 Element jsFile = doc.createElement("jsFile"); 256 String path = files[fi].getPath(); 257 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()); 258 //changes to a correct path in case GS3 runs on Windows 259 path = path.replace( '\\', '/' ); 260 jsFile.setAttribute("path", path); 261 jsFileList.appendChild(jsFile); 262 } 263 } 264 } 265 } 266 267 // get site level files 268 String site_home = page.getSiteHome(); 269 File dir = new File(site_home + File.separatorChar + "ui" + File.separatorChar + "js"); 270 if (dir.isDirectory()) { 271 File[] files = dir.listFiles(); 272 for (int fi=0, fn=files.length; fi<fn; fi++) { 273 if (files[fi].getName().endsWith(".js")) { 274 Element jsFile = doc.createElement("jsFile"); 275 String path = files[fi].getPath(); 276 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()); 277 //changes to a correct path in case GS3 runs on Windows 278 path = path.replace( '\\', '/' ); 279 jsFile.setAttribute("path", path); 280 jsFileList.appendChild(jsFile); 281 } 282 } 283 } 284 285 // get collect level files 286 String collect_home = page.getCollectionHome(); 287 if (collect_home != "") { 288 dir = new File(collect_home + File.separatorChar + "ui" + File.separatorChar + "js"); 289 if (dir.isDirectory()) { 290 File[] files = dir.listFiles(); 291 for (int fi=0, fn=files.length; fi<fn; fi++) { 292 if (files[fi].getName().endsWith(".js")) { 293 Element jsFile = doc.createElement("jsFile"); 294 String path = files[fi].getPath(); 295 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()); 296 //changes to a correct path in case GS3 runs on Windows 297 path = path.replace( '\\', '/' ); 298 jsFile.setAttribute("path", path); 299 jsFileList.appendChild(jsFile); 300 } 301 } 302 } 303 } 304 305 page.getPageResponse().appendChild(jsFileList); 306 } 307 308 protected void addUiElements(Page page) { 309 310 Document siteUi = page.getSiteUi(); 311 Document collectUi = page.getCollectUi(); 312 String lang = page.getLanguage(); 313 314 HashMap elements = getRelevantElements("uiItem", lang, siteUi, collectUi); 315 Element xmlElements = doc.createElement("uiItemList"); 316 317 Iterator i = elements.values().iterator(); 318 while (i.hasNext()) { 319 Element element = (Element)i.next(); 320 321 // doc.adoptNode(element); // Java 1.5 (DOM Level 3) 322 // xmlElements.appendChild(element); 323 324 // Java 1.4 equivalent 325 Node doc_owned_node = doc.importNode(element,true); 326 // Should also remove element from its original parent, as adopt does? 327 // element.getParentNode().removeChild(element); 328 329 330 xmlElements.appendChild(doc_owned_node); 331 332 333 } 334 335 page.getPageResponse().appendChild(xmlElements); 336 } 337 338 protected void addMetadataElements(Page page) { 339 Document siteMetadata = page.getSiteMetadata(); 340 Document collectMetadata = page.getCollectMetadata(); 341 String lang = page.getLanguage(); 342 343 HashMap elements = getRelevantElements("metadataItem", lang, siteMetadata, collectMetadata); 344 Element xmlElements = doc.createElement("metadataList"); 345 346 Iterator i = elements.values().iterator(); 347 while (i.hasNext()) { 348 Element element = (Element)i.next(); 349 350 // doc.adoptNode(element); // Java 1.5 (DOM Level 3) 351 // xmlElements.appendChild(element); 352 353 // Java 1.4 equivalent 354 Node doc_owned_node = doc.importNode(element,true); 355 // Should also remove element from its original parent, as adopt does? 356 // element.getParentNode().removeChild(element); 357 358 xmlElements.appendChild(doc_owned_node); 359 } 360 361 page.getPageResponse().appendChild(xmlElements); 362 } 363 364 protected Node transformPage(Element page) { 365 return super.transformPage(page); 366 } 367 368 private HashMap getRelevantElements(String tagName, String lang, Document siteLevel, Document collectLevel) { 369 370 HashMap elements = new HashMap(); 371 372 // get all relevant elements from collect level 373 if (collectLevel != null) { 374 375 NodeList xmlElements = collectLevel.getElementsByTagName(tagName); 376 for (int di = 0, dn = xmlElements.getLength(); di < dn; di++) { 377 378 Element xmlElement = (Element)xmlElements.item(di); 379 380 // only include elements that are language independent or are the correct language, and do not specify inherit=true 381 if ((xmlElement.getAttribute("lang").equals("") || xmlElement.getAttribute("lang").equalsIgnoreCase(lang)) && !xmlElement.getAttribute("inherit").equalsIgnoreCase("true")) { 382 String name = xmlElement.getAttribute("name"); 383 //System.out.println(name + " found and added at collect level"); 384 elements.put(name, xmlElement); 195 385 } 196 197 // get site level files 198 String site_home = page.getSiteHome() ; 199 File dir = new File(site_home + File.separatorChar + "ui" + File.separatorChar + "css") ; 200 if (dir.isDirectory()) { 201 File[] files = dir.listFiles() ; 202 for (int fi=0, fn=files.length ; fi<fn ; fi++) { 203 if (files[fi].getName().endsWith(".css")) { 204 Element cssFile = doc.createElement("cssFile") ; 205 String path = files[fi].getPath() ; 206 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()) ; 207 //changes to a correct path in case GS3 runs on Windows 208 path = path.replace( '\\', '/' ); 209 cssFile.setAttribute("path", path) ; 210 cssFileList.appendChild(cssFile) ; 211 } 212 } 213 } 214 215 // get collect level files 216 String collect_home = page.getCollectionHome() ; 217 if (collect_home != "") { 218 dir = new File(collect_home + File.separatorChar + "ui" + File.separatorChar + "css") ; 219 if (dir.isDirectory()) { 220 File[] files = dir.listFiles() ; 221 for (int fi=0, fn=files.length ; fi<fn ; fi++) { 222 if (files[fi].getName().endsWith(".css")) { 223 Element cssFile = doc.createElement("cssFile") ; 224 String path = files[fi].getPath() ; 225 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()) ; 226 //changes to a correct path in case GS3 runs on Windows 227 path = path.replace( '\\', '/' ); 228 cssFile.setAttribute("path", path) ; 229 cssFileList.appendChild(cssFile) ; 230 } 231 } 232 } 233 } 234 235 page.getPageResponse().appendChild(cssFileList) ; 236 } 237 238 protected void addJsFiles(Page page, Skin skin) { 239 240 Element jsFileList = doc.createElement("jsFileList") ; 241 242 // get skin level files 243 if (skin != null) { 244 File dir = new File(skin.rootDirectory.getPath() + File.separatorChar + "js") ; 245 if (dir.isDirectory()) { 246 File[] files = dir.listFiles() ; 247 248 for (int fi=0, fn=files.length ; fi<fn ; fi++) { 249 if (files[fi].getName().endsWith(".js")) { 250 Element jsFile = doc.createElement("jsFile") ; 251 String path = files[fi].getPath() ; 252 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()) ; 253 //changes to a correct path in case GS3 runs on Windows 254 path = path.replace( '\\', '/' ); 255 jsFile.setAttribute("path", path) ; 256 jsFileList.appendChild(jsFile) ; 257 } 258 } 259 } 260 } 261 262 // get site level files 263 String site_home = page.getSiteHome() ; 264 File dir = new File(site_home + File.separatorChar + "ui" + File.separatorChar + "js") ; 265 if (dir.isDirectory()) { 266 File[] files = dir.listFiles() ; 267 for (int fi=0, fn=files.length ; fi<fn ; fi++) { 268 if (files[fi].getName().endsWith(".js")) { 269 Element jsFile = doc.createElement("jsFile") ; 270 String path = files[fi].getPath() ; 271 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()) ; 272 //changes to a correct path in case GS3 runs on Windows 273 path = path.replace( '\\', '/' ); 274 jsFile.setAttribute("path", path) ; 275 jsFileList.appendChild(jsFile) ; 276 } 277 } 278 } 279 280 // get collect level files 281 String collect_home = page.getCollectionHome() ; 282 if (collect_home != "") { 283 dir = new File(collect_home + File.separatorChar + "ui" + File.separatorChar + "js") ; 284 if (dir.isDirectory()) { 285 File[] files = dir.listFiles() ; 286 for (int fi=0, fn=files.length ; fi<fn ; fi++) { 287 if (files[fi].getName().endsWith(".js")) { 288 Element jsFile = doc.createElement("jsFile") ; 289 String path = files[fi].getPath() ; 290 path = "." + path.substring(GlobalProperties.getGSDL3Home().length()) ; 291 //changes to a correct path in case GS3 runs on Windows 292 path = path.replace( '\\', '/' ); 293 jsFile.setAttribute("path", path) ; 294 jsFileList.appendChild(jsFile) ; 295 } 296 } 297 } 298 } 299 300 page.getPageResponse().appendChild(jsFileList) ; 301 } 302 303 protected void addUiElements(Page page) { 304 305 Document siteUi = page.getSiteUi() ; 306 Document collectUi = page.getCollectUi() ; 307 String lang = page.getLanguage() ; 308 309 HashMap<String, Element> elements = getRelevantElements("uiItem", lang, siteUi, collectUi) ; 310 Element xmlElements = doc.createElement("uiItemList") ; 311 312 Iterator<Element> i = elements.values().iterator() ; 313 while (i.hasNext()) { 314 Element element = i.next() ; 315 316 doc.adoptNode(element) ; 317 xmlElements.appendChild(element) ; 318 319 320 } 321 322 page.getPageResponse().appendChild(xmlElements) ; 323 } 324 325 protected void addMetadataElements(Page page) { 326 Document siteMetadata = page.getSiteMetadata() ; 327 Document collectMetadata = page.getCollectMetadata() ; 328 String lang = page.getLanguage() ; 329 330 HashMap<String, Element> elements = getRelevantElements("metadataItem", lang, siteMetadata, collectMetadata) ; 331 Element xmlElements = doc.createElement("metadataList") ; 332 333 Iterator<Element> i = elements.values().iterator() ; 334 while (i.hasNext()) { 335 Element element = i.next() ; 336 doc.adoptNode(element) ; 337 xmlElements.appendChild(element) ; 338 } 339 340 page.getPageResponse().appendChild(xmlElements) ; 341 } 342 343 protected Node transformPage(Element page) { 344 return super.transformPage(page) ; 345 } 346 347 private HashMap getRelevantElements(String tagName, String lang, Document siteLevel, Document collectLevel) { 348 349 HashMap elements = new HashMap<String, Element>() ; 350 351 // get all relevant elements from collect level 352 if (collectLevel != null) { 353 354 NodeList xmlElements = collectLevel.getElementsByTagName(tagName) ; 355 for (int di = 0, dn = xmlElements.getLength() ; di < dn ; di++) { 356 357 Element xmlElement = (Element)xmlElements.item(di) ; 358 359 // only include elements that are language independent or are the correct language, and do not specify inherit=true 360 if ((xmlElement.getAttribute("lang").equals("") || xmlElement.getAttribute("lang").equalsIgnoreCase(lang)) && !xmlElement.getAttribute("inherit").equalsIgnoreCase("true")) { 361 String name = xmlElement.getAttribute("name") ; 362 //System.out.println(name + " found and added at collect level") ; 363 elements.put(name, xmlElement) ; 364 } 365 } 366 } 367 368 // get all elements from site level 369 if (siteLevel != null) { 370 371 //System.out.println("getting all " + tagName + "'s (" + lang + ") from " + converter.getPrettyString(siteLevel)) ; 372 373 NodeList xmlElements = siteLevel.getElementsByTagName(tagName) ; 374 for (int di = 0, dn = xmlElements.getLength() ; di < dn ; di++) { 375 376 Element xmlElement = (Element)xmlElements.item(di) ; 377 378 // only include elements that are language independent or are the correct language, and which havent already been specified at collect level 379 if (xmlElement.getAttribute("lang").equals("") || xmlElement.getAttribute("lang").equalsIgnoreCase(lang)) { 380 String name = xmlElement.getAttribute("name") ; 381 //System.out.println(name + " found at site level") ; 386 } 387 } 388 389 // get all elements from site level 390 if (siteLevel != null) { 391 392 //System.out.println("getting all " + tagName + "'s (" + lang + ") from " + converter.getPrettyString(siteLevel)); 393 394 NodeList xmlElements = siteLevel.getElementsByTagName(tagName); 395 for (int di = 0, dn = xmlElements.getLength(); di < dn; di++) { 396 397 Element xmlElement = (Element)xmlElements.item(di); 398 399 // only include elements that are language independent or are the correct language, and which havent already been specified at collect level 400 if (xmlElement.getAttribute("lang").equals("") || xmlElement.getAttribute("lang").equalsIgnoreCase(lang)) { 401 String name = xmlElement.getAttribute("name"); 402 //System.out.println(name + " found at site level"); 382 403 383 if (!elements.containsKey(name)) { 384 elements.put(name, xmlElement) ; 385 //System.out.println(name + " added at site level") ; 386 } 387 } 388 } 389 } 390 391 return elements ; 392 } 393 394 395 396 397 404 if (!elements.containsKey(name)) { 405 elements.put(name, xmlElement); 406 //System.out.println(name + " added at site level"); 407 } 408 } 409 } 410 } 411 412 return elements; 413 } 414 415 398 416 }
Note:
See TracChangeset
for help on using the changeset viewer.