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

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

modified

  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 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;
12public class PageAction extends Action {
13
14 public String process (Element message) {
15
16 Element request = (Element)message.getElementsByTagName("request").item(0);
17 String info = request.getAttribute("info");
18 // remove the page/ bit
19 info = GSPath.removeFirstLink(info);
20 String page_name = GSPath.getFirstLink(info);
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 System.out.println("the initial xml response is");
61 System.out.println(converter_.getString(coll_list_response));
62
63 // second, get the metadata for each collection
64 NodeList colls = coll_list_response.getElementsByTagName("collection");
65
66 Element metadata_message = doc_.createElement("message");
67 metadata_message.setAttribute("lang", page.getAttribute("lang"));
68 Element metadata_request = doc_.createElement("request");
69 metadata_message.appendChild(metadata_request);
70 metadata_request.setAttribute("type", "describe");
71 for (int i=0; i<colls.getLength(); i++) {
72 // get the metadata for each one
73 Element c = (Element)colls.item(i);
74 String name = c.getAttribute("name");
75
76 metadata_request.setAttribute("to", name); // overwrites the old value
77 Element metadata_response = (Element)mr_.process(metadata_message);
78 Element coll = (Element)metadata_response.getElementsByTagName("collection").item(0);
79 GSXML.mergeMetadataLists(c, coll); // add the metadata to the original response
80 }
81
82 System.out.println("the second xml response is");
83 System.out.println(converter_.getString(coll_list_response));
84
85 //now the full response is in coll_list_response
86
87 // add it in to the page xml tree
88 page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_list_response, "response"), true));
89
90 String stylesheet = GSFile.stylesheetPath(config_, "home.xsl");
91 String transformed_result = transformer_.transform(stylesheet,
92 page);
93 return transformed_result;
94
95 } // homePage
96
97 protected String aboutPage(Element page, Element request) {
98
99 // get the params out
100 HashMap params = GSXML.extractParams((Element)GSXML.getNodeByPath(request, "paramList"));
101 String coll_name = (String)params.get("c");
102
103 Element coll_about_message = doc_.createElement("message");
104 coll_about_message.setAttribute("lang", page.getAttribute("lang"));
105
106 Element coll_about_request = doc_.createElement("request");
107 coll_about_message.appendChild(coll_about_request);
108 coll_about_request.setAttribute("type", "describe");
109 coll_about_request.setAttribute("to", coll_name);
110
111 Element coll_about_response = (Element)mr_.process(coll_about_message);
112
113
114 // add the response to the page
115 page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_about_response, "response"), true));
116
117 // process using the stylesheet
118 String stylesheet = GSFile.stylesheetPath(config_, "about.xsl");
119
120 //System.out.println("response="+converter_.getString(page));
121 String transformed_result = transformer_.transform(stylesheet,
122 page);
123 return transformed_result;
124
125
126 }
127}
Note: See TracBrowser for help on using the repository browser.