Changeset 3652
- Timestamp:
- 2003-01-06T15:41:05+13:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/LibraryServlet.java
r3599 r3652 3 3 import org.greenstone.gsdl3.core.*; 4 4 import org.greenstone.gsdl3.util.*; 5 5 import org.greenstone.gsdl3.action.PageAction; // used to get the default action 6 import org.w3c.dom.Document; 7 import org.w3c.dom.Element; 6 8 import java.io.*; 7 9 import javax.servlet.*; … … 30 32 * in the servlet params */ 31 33 protected final String DEFAULT_LANG = "en"; 34 /** container Document to create XML Nodes */ 35 protected Document doc_=null; 36 /** a converter class to parse XML and create Docs */ 37 protected XMLConverter converter_=null; 38 32 39 /** initialise the servlet 33 40 */ … … 74 81 recept_.configure(); 75 82 83 converter_ = new XMLConverter(); 84 doc_ = converter_.newDOM(); 85 76 86 } 77 87 … … 84 94 PrintWriter out = response.getWriter(); 85 95 86 // if the interface owns the default - keep this here, otherwise move 87 // it to receptionist 88 String lang = request.getParameter("l"); 96 String lang = request.getParameter(GSCGI.LANGUAGE_ARG); 89 97 if (lang==null || lang.equals("")) { 90 98 lang = default_lang_; // the default 91 99 } 100 String output = request.getParameter(GSCGI.OUTPUT_ARG); 101 if (output==null || output.equals("")) { 102 output = "html"; // uses html by default 103 } 104 92 105 // the request to the receptionist 93 String xml_request="<message><request lang='"+lang+"' type='action' output='html' action="; 94 95 String action = request.getParameter("a"); 106 Element xml_message = doc_.createElement(GSXML.MESSAGE_ELEM); 107 Element xml_request = doc_.createElement(GSXML.REQUEST_ELEM); 108 xml_message.appendChild(xml_request); 109 xml_request.setAttribute(GSXML.LANG_ATT, lang); 110 xml_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_CGI); 111 xml_request.setAttribute(GSXML.OUTPUT_ATT, output); 112 113 String action = request.getParameter(GSCGI.ACTION_ARG); 114 String subaction = request.getParameter(GSCGI.SUBACTION_ARG); 96 115 if (action==null || action.equals("")) { 97 // display the home page 98 // a=p&sa=home 99 xml_request +="'p' subaction='home'/>"; 100 } else { 101 String subaction = request.getParameter("sa"); 102 xml_request += "'"+action+"'"; 103 if (subaction != null) { 104 xml_request += " subaction='"+subaction+"'"; 105 } 106 xml_request += "><paramList>"; 107 Enumeration params = request.getParameterNames(); 108 while(params.hasMoreElements()) { 109 String name = (String)params.nextElement(); 110 if (!name.equals("a") && !name.equals("sa") && !name.equals("l")) { // these ones are in the header so leave out 111 String value=""; 112 String []values = request.getParameterValues(name); 113 value = values[0]; 114 if (values.length > 1) { 115 for (int i=1; i< values.length; i++) { 116 value += ","+values[i]; 117 } 116 // should we do all the following stuff if using default page? 117 // display the home page - the default page 118 action = "p"; 119 subaction = PageAction.HOME_PAGE; 120 xml_request.setAttribute(GSXML.ACTION_ATT, action); 121 xml_request.setAttribute(GSXML.SUBACTION_ATT, subaction); 122 123 Element xml_result = recept_.process(xml_message); 124 out.println(converter_.getString(xml_result)); 125 return; 126 } 127 128 xml_request.setAttribute(GSXML.ACTION_ATT, action); 129 if (subaction != null) { 130 xml_request.setAttribute(GSXML.SUBACTION_ATT, subaction); 131 } 132 Element xml_param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 133 xml_request.appendChild(xml_param_list); 134 Enumeration params = request.getParameterNames(); 135 while(params.hasMoreElements()) { 136 String name = (String)params.nextElement(); 137 if (!name.equals(GSCGI.ACTION_ARG) && !name.equals(GSCGI.SUBACTION_ARG) && !name.equals(GSCGI.LANGUAGE_ARG) && !name.equals(GSCGI.OUTPUT_ARG)) { // these ones are in the header so leave out 138 String value=""; 139 String []values = request.getParameterValues(name); 140 value = values[0]; 141 if (values.length > 1) { 142 for (int i=1; i< values.length; i++) { 143 value += ","+values[i]; 118 144 } 119 xml_request += "<param name='"+name+"' value='"+GSXML.xmlSafe(value)+"'/>";120 121 145 } 122 } 123 xml_request += "</paramList></request>"; 124 if (action.equals("a")&&subaction.equals("r")) { // applet action 125 response.setContentType("text/plain"); 146 Element param = doc_.createElement(GSXML.PARAM_ELEM); 147 param.setAttribute(GSXML.NAME_ATT, name); 148 param.setAttribute(GSXML.VALUE_ATT, GSXML.xmlSafe(value)); 149 xml_param_list.appendChild(param); 150 126 151 } 127 152 } 128 xml_request += "</message>";129 153 130 String result = recept_.process(xml_request); 131 132 out.println(result); 133 134 135 154 if (!output.equals("html")) { 155 response.setContentType("text/xml"); // for now use text 156 } 157 // hopefully can get rid of following 158 if (action.equals("a")&&subaction.equals("r")) { // applet action 159 response.setContentType("text/xml"); 160 } 161 162 Element xml_result = recept_.process(xml_message); 163 out.println(converter_.getString(xml_result)); 136 164 } 137 165 }
Note:
See TracChangeset
for help on using the changeset viewer.