source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/Page.java@ 22085

Last change on this file since 22085 was 22085, checked in by sjm84, 14 years ago

Created a util package from classes that could be useful outside of their original packages

File size: 3.9 KB
Line 
1package org.greenstone.gsdl3.core;
2
3import java.io.File;
4import java.util.HashMap;
5
6import org.greenstone.util.GlobalProperties;
7import org.greenstone.gsdl3.util.*;
8import org.w3c.dom.*;
9
10public class Page {
11
12 private Element page ;
13 private Element pageRequest ;
14 private Element pageResponse ;
15
16 private Document siteUi ;
17 private Document collectUi ;
18 private Document siteMetadata ;
19 private Document collectMetadata ;
20
21 private Receptionist receptionist ;
22
23 public Page(Element page, Receptionist receptionist) {
24 try {
25 this.page = page ;
26 this.receptionist = receptionist ;
27
28 pageRequest = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM);
29 pageResponse = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM);
30
31 String siteHome = GSFile.siteHome(GlobalProperties.getGSDL3Home(), getSite()) ;
32 String collection = getCollection() ;
33
34 File siteUiFile = new File(siteHome + File.separatorChar + "ui" + File.separatorChar + "ui.xml") ;
35 //System.out.println("siteUi: " + siteUiFile.getAbsolutePath()) ;
36 siteUi = receptionist.converter.getDOM(siteUiFile, "utf-8");
37 if (siteUi == null) {
38 System.out.println(" could not parse site level ui file: " + siteUiFile.getPath());
39 }
40
41 File siteMetadataFile = new File(siteHome + File.separatorChar + "metadata.xml") ;
42 //System.out.println("siteMetadata: " + siteMetadataFile.getAbsolutePath()) ;
43 siteMetadata = receptionist.converter.getDOM(siteMetadataFile, "utf-8");
44 if (siteMetadata == null) {
45 System.out.println(" could not parse site level metadata file: " + siteMetadataFile.getPath());
46 }
47
48 if (!collection.equals("")) {
49 File collectUiFile = new File(GSFile.collectionBaseDir(siteHome, collection) + File.separatorChar + "ui" + File.separatorChar + "ui.xml") ;
50 collectUi = receptionist.converter.getDOM(collectUiFile, "utf-8");
51 if (collectUi == null) {
52 System.out.println(" could not parse collect level ui file: " + collectUiFile.getPath());
53 }
54
55 File collectMetadataFile = new File(GSFile.collectionBaseDir(siteHome, collection) + File.separatorChar + "metadata.xml") ;
56 collectMetadata = receptionist.converter.getDOM(collectMetadataFile, "utf-8");
57 if (collectMetadata == null) {
58 System.out.println(" could not parse collect level metadata file: " + collectMetadataFile.getPath());
59 }
60 }
61 } catch (Exception e) {
62 e.printStackTrace() ;
63 }
64 }
65
66 public Element getPage() {
67 return page ;
68 }
69
70 public Element getPageRequest() {
71 return pageRequest ;
72 }
73
74 public Element getPageResponse() {
75 return pageResponse ;
76 }
77
78 public String getAction() {
79 return pageRequest.getAttribute("action") ;
80 }
81
82 public String getSubaction() {
83 return pageRequest.getAttribute("subaction") ;
84 }
85
86 public String getSiteHome() {
87 return GSFile.siteHome(GlobalProperties.getGSDL3Home(), getSite()) ;
88 }
89
90 public String getCollectionHome() {
91 String collection = this.getCollection() ;
92 if (!collection.equals(""))
93 return GSFile.collectionBaseDir(getSiteHome(), collection) ;
94 else
95 return null ;
96 }
97
98 public Document getSiteUi() {
99 return siteUi ;
100 }
101
102 public Document getCollectUi() {
103 return collectUi ;
104 }
105
106 public Document getSiteMetadata() {
107 return siteMetadata ;
108 }
109
110 public Document getCollectMetadata() {
111 return collectMetadata ;
112 }
113
114 public String getLanguage() {
115 String lang = pageRequest.getAttribute(GSXML.LANG_ATT);
116 return lang ;
117 }
118
119 public String getSite() {
120 return (String) receptionist.config_params.get(GSConstants.SITE_NAME) ;
121 }
122
123 public String getCollection() {
124 String collection = "" ;
125 Element request = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM);
126
127 Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
128 if (cgi_param_list != null) {
129 HashMap params = GSXML.extractParams(cgi_param_list, false);
130 collection = (String)params.get(GSParams.COLLECTION);
131 if (collection == null) collection = "";
132 }
133 return collection ;
134 }
135}
Note: See TracBrowser for help on using the repository browser.