source: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/PageAction.java@ 3467

Last change on this file since 3467 was 3467, checked in by kjdon, 22 years ago

the xml representation of cgi args now has two attributes 'action' and 'subaction', instead of the single 'info' attribute

  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1package org.greenstone.gsdl3.action;
2
3import org.greenstone.gsdl3.core.ModuleInterface;
4import org.greenstone.gsdl3.util.*;
5// XML classes
6import org.w3c.dom.Node;
7import org.w3c.dom.NodeList;
8import org.w3c.dom.Document;
9import org.w3c.dom.Element;
10
11import java.util.HashMap;
12import java.io.File;
13
14public class PageAction extends Action {
15
16 public String process (Element message) {
17
18 Element request = (Element)message.getElementsByTagName("request").item(0);
19 // the page name is the subaction
20 String page_name = request.getAttribute("subaction");
21
22 // create the return page tree
23 Element page = doc_.createElement("page");
24 page.setAttribute("lang", message.getAttribute("lang"));
25 // add the lang stuff from xml_in
26 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true));
27 // add the system stuff from xml_in
28 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true));
29
30 if (page_name.equals("")) {
31 // for now send an error. change to always display the home page?
32 return GSHTML.errorPage(" page action specified, but no page specified");
33 }
34 if (page_name.equals("home")) {
35 return homePage(page, request);
36 } else if (page_name.equals("about")) {
37 return aboutPage(page, request);
38 } else {
39 return GSHTML.errorPage("page: "+page_name+" not yet implemented");
40 }
41 }
42
43
44 protected String homePage(Element page, Element orig_message) {
45
46 // first, get the list of collections from mr
47
48 Element coll_list_message = doc_.createElement("message");
49 coll_list_message.setAttribute("lang", page.getAttribute("lang"));
50 Element coll_list_request = doc_.createElement("request");
51 coll_list_message.appendChild(coll_list_request);
52 coll_list_request.setAttribute("type", "describe");
53 //coll_list_request.setAttribute("info", "collectionList");
54
55 Element coll_list_response = (Element)mr_.process(coll_list_message);
56 if (coll_list_response==null) {
57 return GSHTML.errorPage("couldn't query the mr about collections");
58 }
59
60 // second, get the metadata for each collection
61 NodeList colls = coll_list_response.getElementsByTagName("collection");
62
63 Element metadata_message = doc_.createElement("message");
64 metadata_message.setAttribute("lang", page.getAttribute("lang"));
65 Element metadata_request = doc_.createElement("request");
66 metadata_message.appendChild(metadata_request);
67 metadata_request.setAttribute("type", "describe");
68 for (int i=0; i<colls.getLength(); i++) {
69 // get the metadata for each one
70 Element c = (Element)colls.item(i);
71 String name = c.getAttribute("name");
72
73 metadata_request.setAttribute("to", name); // overwrites the old value
74 Element metadata_response = (Element)mr_.process(metadata_message);
75 Element coll = (Element)metadata_response.getElementsByTagName("collection").item(0);
76 GSXML.mergeMetadataLists(c, coll); // add the metadata to the original response
77 }
78
79 //now the full response is in coll_list_response
80
81 // add it in to the page xml tree
82 page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_list_response, "response"), true));
83
84 String stylesheet = GSFile.stylesheetFile(config_, "home.xsl");
85 Document style_doc = converter_.getDOM(new File(stylesheet));
86 GSXSLT.absoluteIncludePaths(style_doc, config_);
87 //System.out.println("page=");
88 //System.out.println(converter_.getString(page));
89 return transformer_.transform(style_doc, page);
90
91
92 } // homePage
93
94 protected String aboutPage(Element page, Element request) {
95
96 // get the params out
97 HashMap params = GSXML.extractParams((Element)GSXML.getNodeByPath(request, "paramList"));
98 String coll_name = (String)params.get("c");
99 if (coll_name == null || coll_name.equals("")) {
100 coll_name = (String)params.get("sc"); // cluster name
101 }
102 if (coll_name == null || coll_name.equals("")) {
103 return GSHTML.errorPage("about page - need to specify coll name or cluster name");
104 }
105
106 Element coll_about_message = doc_.createElement("message");
107 coll_about_message.setAttribute("lang", page.getAttribute("lang"));
108
109 Element coll_about_request = doc_.createElement("request");
110 coll_about_message.appendChild(coll_about_request);
111 coll_about_request.setAttribute("type", "describe");
112 coll_about_request.setAttribute("to", coll_name);
113
114 Element coll_about_response = (Element)mr_.process(coll_about_message);
115
116 // System.out.println("coll response=");
117 //System.out.println(converter_.getString(coll_about_response));
118 // add the response to the page
119 page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_about_response, "response"), true));
120
121 // process using the stylesheet
122 String stylesheet = GSFile.stylesheetFile(config_, "about.xsl");
123 Document style_doc = converter_.getDOM(new File(stylesheet));
124 GSXSLT.absoluteIncludePaths(style_doc, config_);
125 return transformer_.transform(style_doc, page);
126
127
128 }
129}
Note: See TracBrowser for help on using the repository browser.