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