Changeset 27617 for main


Ignore:
Timestamp:
06/13/13 13:13:46 (8 years ago)
Author:
sjm84
Message:

Various improvements and fixes mostly to do with adding depositor functionality

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryCommandline.java

    r26497 r27617  
    6464    {
    6565
    66         HashMap<String, Comparable> config_params = new HashMap<String, Comparable>();
     66        HashMap<String, Object> config_params = new HashMap<String, Object>();
    6767        //config_params.put(GSConstants.GSDL3_HOME, gsdl_home);
    6868        config_params.put(GSConstants.SITE_NAME, site_name);
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r27074 r27617  
    11package org.greenstone.gsdl3;
    22
     3import java.io.File;
     4import java.io.FileInputStream;
     5import java.io.FileOutputStream;
    36import java.io.IOException;
    47import java.io.PrintWriter;
    58import java.io.Serializable;
    69import java.lang.reflect.Type;
     10import java.nio.channels.FileChannel;
    711import java.util.ArrayList;
     12import java.util.Collection;
    813import java.util.Enumeration;
    914import java.util.HashMap;
     
    2126import javax.servlet.http.HttpSessionBindingEvent;
    2227import javax.servlet.http.HttpSessionBindingListener;
    23 
     28import javax.servlet.http.Part;
     29
     30import org.apache.commons.fileupload.FileItem;
     31import org.apache.commons.fileupload.disk.DiskFileItemFactory;
     32import org.apache.commons.fileupload.servlet.ServletFileUpload;
    2433import org.apache.commons.lang3.StringUtils;
    2534import org.apache.log4j.Logger;
     
    3645import org.greenstone.gsdl3.util.UserContext;
    3746import org.greenstone.gsdl3.util.XMLConverter;
     47import org.greenstone.util.GlobalProperties;
    3848import org.json.JSONObject;
    3949import org.w3c.dom.Document;
     
    169179        }
    170180
    171         HashMap<String, Comparable> config_params = new HashMap<String, Comparable>();
     181        HashMap<String, Object> config_params = new HashMap<String, Object>();
    172182
    173183        config_params.put(GSConstants.LIBRARY_NAME, library_name);
     
    315325    public class UserSessionCache implements HttpSessionBindingListener
    316326    {
    317 
    318327        String session_id = "";
    319328
     
    368377    }
    369378
    370     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
     379    public void doGetOrPost(HttpServletRequest request, HttpServletResponse response, Map<String, String[]> queryMap) throws ServletException, IOException
    371380    {
    372381        logUsageInfo(request);
    373382
    374         Map<String, String[]> queryMap = request.getParameterMap();
    375383        if (queryMap != null)
    376384        {
     
    380388            String rl = null;
    381389            String el = null;
     390
    382391            while (queryIter.hasNext())
    383392            {
     
    437446        PrintWriter out = response.getWriter();
    438447
    439         String lang = request.getParameter(GSParams.LANGUAGE);
     448        String lang = getFirstParam(GSParams.LANGUAGE, queryMap);
    440449        if (lang == null || lang.equals(""))
    441450        {
     
    454463        if (request.getAuthType() != null)
    455464        {
     465            //Get the username
     466            userContext.setUsername(request.getUserPrincipal().getName());
     467
    456468            //Get the groups for the user
    457469            Element acquireGroupMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
     
    461473            Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    462474            acquireGroupRequest.appendChild(paramList);
    463             paramList.appendChild(GSXML.createParameter(this.doc, "username", request.getUserPrincipal().getName()));
     475            paramList.appendChild(GSXML.createParameter(this.doc, GSXML.USERNAME_ATT, request.getUserPrincipal().getName()));
    464476
    465477            Element aquireGroupsResponseMessage = (Element) this.recept.process(acquireGroupMessage);
     
    478490        session.setAttribute(GSParams.LANGUAGE, lang);
    479491
    480         String output = request.getParameter(GSParams.OUTPUT);
     492        String output = getFirstParam(GSParams.OUTPUT, queryMap);
    481493        if (output == null || output.equals(""))
    482494        {
     
    517529        xml_message.appendChild(xml_request);
    518530
    519         String action = request.getParameter(GSParams.ACTION);
    520         String subaction = request.getParameter(GSParams.SUBACTION);
    521         String collection = request.getParameter(GSParams.COLLECTION);
    522         String document = request.getParameter(GSParams.DOCUMENT);
    523         String service = request.getParameter(GSParams.SERVICE);
     531        String action = getFirstParam(GSParams.ACTION, queryMap);
     532        String subaction = getFirstParam(GSParams.SUBACTION, queryMap);
     533        String collection = getFirstParam(GSParams.COLLECTION, queryMap);
     534        String document = getFirstParam(GSParams.DOCUMENT, queryMap);
     535        String service = getFirstParam(GSParams.SERVICE, queryMap);
    524536
    525537        // We clean up the cache session_ids_table if system
     
    536548            // collection param is in the sc parameter.
    537549            // don't like the fact that it is hard coded here
    538             String coll = request.getParameter(GSParams.SYSTEM_CLUSTER);
     550            String coll = getFirstParam(GSParams.SYSTEM_CLUSTER, queryMap);
    539551            if (coll != null && !coll.equals(""))
    540552            {
     
    547559                if (subaction.equals("a") || subaction.equals("d"))
    548560                {
    549                     String module_name = request.getParameter("sn");
     561                    String module_name = getFirstParam("sn", queryMap);
    550562                    if (module_name != null && !module_name.equals(""))
    551563                    {
     
    655667
    656668                    String value = "";
    657                     String[] values = request.getParameterValues(name);
     669                    String[] values = queryMap.get(name);
    658670                    value = values[0];
    659671                    if (values.length > 1)
     
    722734
    723735        //Add custom HTTP headers if requested
    724         String httpHeadersParam = request.getParameter(GSParams.HTTP_HEADER_FIELDS);
     736        String httpHeadersParam = getFirstParam(GSParams.HTTP_HEADER_FIELDS, queryMap);
    725737        if (httpHeadersParam != null && httpHeadersParam.length() > 0)
    726738        {
     
    768780        xml_request.setAttribute("fullURL", fullURL.replace("&", "&amp;"));
    769781
    770         if (!runSecurityChecks(request, xml_request, userContext, out, baseURL, collection, document))
     782        if (!runSecurityChecks(request, xml_request, userContext, out, baseURL, collection, document, queryMap))
    771783        {
    772784            return;
     
    798810
    799811        displaySize(session_ids_table);
    800 
     812    }
     813
     814    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
     815    {
     816        doGetOrPost(request, response, request.getParameterMap());
    801817    } //end of doGet(HttpServletRequest, HttpServletResponse)
    802818
    803     private boolean runSecurityChecks(HttpServletRequest request, Element xml_request, UserContext userContext, PrintWriter out, String baseURL, String collection, String document) throws ServletException
     819    private boolean runSecurityChecks(HttpServletRequest request, Element xml_request, UserContext userContext, PrintWriter out, String baseURL, String collection, String document, Map<String, String[]> queryMap) throws ServletException
    804820    {
    805821        //Check if we need to login or logout
    806         Map<String, String[]> params = request.getParameterMap();
    807         String[] username = params.get("username");
    808         String[] password = params.get("password");
    809         String[] logout = params.get("logout");
     822        String username = getFirstParam("username", queryMap);
     823        String password = getFirstParam("password", queryMap);
     824        String logout = getFirstParam("logout", queryMap);
    810825
    811826        if (logout != null)
     
    822837            }
    823838
     839            //This try/catch block catches when the login request fails (e.g. The user enters an incorrect password).
    824840            try
    825841            {
    826                 password[0] = Authentication.hashPassword(password[0]);
    827                 request.login(username[0], password[0]);
     842                //Try a global login first
     843                password = Authentication.hashPassword(password);
     844                request.login(username, password);
    828845            }
    829846            catch (Exception ex)
    830847            {
    831                 //The user entered in either the wrong username or the wrong password
    832                 Element loginPageMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
    833                 Element loginPageRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", userContext);
    834                 loginPageRequest.setAttribute(GSXML.ACTION_ATT, "p");
    835                 loginPageRequest.setAttribute(GSXML.SUBACTION_ATT, "login");
    836                 loginPageRequest.setAttribute(GSXML.OUTPUT_ATT, "html");
    837                 loginPageRequest.setAttribute(GSXML.BASE_URL, baseURL);
    838                 loginPageMessage.appendChild(loginPageRequest);
    839 
    840                 Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    841                 loginPageRequest.appendChild(paramList);
    842 
    843                 Element messageParam = this.doc.createElement(GSXML.PARAM_ELEM);
    844                 messageParam.setAttribute(GSXML.NAME_ATT, "loginMessage");
    845                 messageParam.setAttribute(GSXML.VALUE_ATT, "Either your username or password was incorrect, please try again.");
    846                 paramList.appendChild(messageParam);
    847 
    848                 Element urlParam = this.doc.createElement(GSXML.PARAM_ELEM);
    849                 urlParam.setAttribute(GSXML.NAME_ATT, "redirectURL");
    850                 String queryString = "";
    851                 if (request.getQueryString() != null)
    852                 {
    853                     queryString = "?" + request.getQueryString().replace("&", "&amp;");
    854                 }
    855                 urlParam.setAttribute(GSXML.VALUE_ATT, this.getServletName() + queryString);
    856                 paramList.appendChild(urlParam);
    857 
    858                 Node loginPageResponse = this.recept.process(loginPageMessage);
    859                 out.println(this.converter.getPrettyString(loginPageResponse));
    860 
    861                 return false;
    862             }
    863         }
    864 
    865         //If a user is logged in
    866         if (request.getAuthType() != null)
    867         {
    868             Element userInformation = this.doc.createElement(GSXML.USER_INFORMATION_ELEM);
    869             userInformation.setAttribute("username", request.getUserPrincipal().getName());
    870 
    871             Element userInfoMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
    872             Element userInfoRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SECURITY, "GetUserInformation", userContext);
    873             userInfoMessage.appendChild(userInfoRequest);
    874 
    875             Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    876             userInfoRequest.appendChild(paramList);
    877 
    878             Element param = this.doc.createElement(GSXML.PARAM_ELEM);
    879             param.setAttribute(GSXML.NAME_ATT, GSXML.USERNAME_ATT);
    880             param.setAttribute(GSXML.VALUE_ATT, request.getUserPrincipal().getName());
    881             paramList.appendChild(param);
    882 
    883             Element userInformationResponse = (Element) GSXML.getChildByTagName(this.recept.process(userInfoMessage), GSXML.RESPONSE_ELEM);
    884             Element responseParamList = (Element) GSXML.getChildByTagName(userInformationResponse, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    885             if (responseParamList == null)
    886             {
    887                 logger.error("Can't get the groups for user " + request.getUserPrincipal().getName());
    888             }
    889             else
    890             {
    891                 HashMap<String, Serializable> responseParams = GSXML.extractParams(responseParamList, true);
    892                 String groups = (String) responseParams.get(GSXML.GROUPS_ATT);
    893 
    894                 userInformation.setAttribute(GSXML.GROUPS_ATT, groups);
    895                 xml_request.appendChild(userInformation);
    896             }
    897         }
    898 
    899         //If we are in a collection-related page then make sure this user is allowed to access it
    900         if (collection != null && !collection.equals(""))
    901         {
    902             //Get the security info for this collection
    903             Element securityMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
    904             Element securityRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SECURITY, collection, userContext);
    905             securityMessage.appendChild(securityRequest);
    906             if (document != null && !document.equals(""))
    907             {
    908                 securityRequest.setAttribute(GSXML.NODE_OID, document);
    909             }
    910 
    911             Element securityResponse = (Element) GSXML.getChildByTagName(this.recept.process(securityMessage), GSXML.RESPONSE_ELEM);
    912             if (securityResponse == null)
    913             {
    914                 return false;
    915             }
    916 
    917             ArrayList<String> groups = GSXML.getGroupsFromSecurityResponse(securityResponse);
    918 
    919             //If guests are not allowed to access this page then check to see if the user is in a group that is allowed to access the page
    920             if (!groups.contains(""))
    921             {
    922                 boolean found = false;
    923                 for (String group : groups)
    924                 {
    925                     if (request.isUserInRole(group))
    926                     {
    927                         found = true;
    928                         break;
    929                     }
    930                 }
    931 
    932                 //The current user is not allowed to access the page so produce a login page
    933                 if (!found)
    934                 {
     848                try
     849                {
     850                    //If the global login fails then try a site-level login
     851                    String siteName = (String) this.recept.getConfigParams().get(GSConstants.SITE_NAME);
     852                    request.login(siteName + "-" + username, password);
     853                }
     854                catch (Exception exc)
     855                {
     856                    //The user entered in either the wrong username or the wrong password
    935857                    Element loginPageMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
    936858                    Element loginPageRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", userContext);
     
    946868                    Element messageParam = this.doc.createElement(GSXML.PARAM_ELEM);
    947869                    messageParam.setAttribute(GSXML.NAME_ATT, "loginMessage");
     870                    messageParam.setAttribute(GSXML.VALUE_ATT, "Either your username or password was incorrect, please try again.");
     871                    paramList.appendChild(messageParam);
     872
     873                    Element urlParam = this.doc.createElement(GSXML.PARAM_ELEM);
     874                    urlParam.setAttribute(GSXML.NAME_ATT, "redirectURL");
     875                    String queryString = "";
     876                    if (request.getQueryString() != null)
     877                    {
     878                        queryString = "?" + request.getQueryString().replace("&", "&amp;");
     879                    }
     880                    urlParam.setAttribute(GSXML.VALUE_ATT, this.getServletName() + queryString);
     881                    paramList.appendChild(urlParam);
     882
     883                    Node loginPageResponse = this.recept.process(loginPageMessage);
     884                    out.println(this.converter.getPrettyString(loginPageResponse));
     885
     886                    return false;
     887                }
     888            }
     889        }
     890
     891        //If a user is logged in
     892        if (request.getAuthType() != null)
     893        {
     894            Element userInformation = this.doc.createElement(GSXML.USER_INFORMATION_ELEM);
     895            userInformation.setAttribute(GSXML.USERNAME_ATT, request.getUserPrincipal().getName());
     896
     897            Element userInfoMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
     898            Element userInfoRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SECURITY, "GetUserInformation", userContext);
     899            userInfoMessage.appendChild(userInfoRequest);
     900
     901            Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     902            userInfoRequest.appendChild(paramList);
     903
     904            Element param = this.doc.createElement(GSXML.PARAM_ELEM);
     905            param.setAttribute(GSXML.NAME_ATT, GSXML.USERNAME_ATT);
     906            param.setAttribute(GSXML.VALUE_ATT, request.getUserPrincipal().getName());
     907            paramList.appendChild(param);
     908
     909            Element userInformationResponse = (Element) GSXML.getChildByTagName(this.recept.process(userInfoMessage), GSXML.RESPONSE_ELEM);
     910            Element responseParamList = (Element) GSXML.getChildByTagName(userInformationResponse, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     911            if (responseParamList == null)
     912            {
     913                logger.error("Can't get the groups for user " + request.getUserPrincipal().getName());
     914            }
     915            else
     916            {
     917                HashMap<String, Serializable> responseParams = GSXML.extractParams(responseParamList, true);
     918                String groups = (String) responseParams.get(GSXML.GROUPS_ATT);
     919
     920                userInformation.setAttribute(GSXML.GROUPS_ATT, groups);
     921                xml_request.appendChild(userInformation);
     922            }
     923        }
     924
     925        //If we are in a collection-related page then make sure this user is allowed to access it
     926        if (collection != null && !collection.equals(""))
     927        {
     928            //Get the security info for this collection
     929            Element securityMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
     930            Element securityRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SECURITY, collection, userContext);
     931            securityMessage.appendChild(securityRequest);
     932            if (document != null && !document.equals(""))
     933            {
     934                securityRequest.setAttribute(GSXML.NODE_OID, document);
     935            }
     936
     937            Element securityResponse = (Element) GSXML.getChildByTagName(this.recept.process(securityMessage), GSXML.RESPONSE_ELEM);
     938            if (securityResponse == null)
     939            {
     940                return false;
     941            }
     942
     943            ArrayList<String> groups = GSXML.getGroupsFromSecurityResponse(securityResponse);
     944
     945            //If guests are not allowed to access this page then check to see if the user is in a group that is allowed to access the page
     946            if (!groups.contains(""))
     947            {
     948                boolean found = false;
     949                for (String group : groups)
     950                {
     951                    if (request.isUserInRole(group))
     952                    {
     953                        found = true;
     954                        break;
     955                    }
     956                }
     957
     958                //The current user is not allowed to access the page so produce a login page
     959                if (!found)
     960                {
     961                    Element loginPageMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
     962                    Element loginPageRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", userContext);
     963                    loginPageRequest.setAttribute(GSXML.ACTION_ATT, "p");
     964                    loginPageRequest.setAttribute(GSXML.SUBACTION_ATT, "login");
     965                    loginPageRequest.setAttribute(GSXML.OUTPUT_ATT, "html");
     966                    loginPageRequest.setAttribute(GSXML.BASE_URL, baseURL);
     967                    loginPageMessage.appendChild(loginPageRequest);
     968
     969                    Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     970                    loginPageRequest.appendChild(paramList);
     971
     972                    Element messageParam = this.doc.createElement(GSXML.PARAM_ELEM);
     973                    messageParam.setAttribute(GSXML.NAME_ATT, "loginMessage");
    948974                    if (request.getAuthType() == null)
    949975                    {
     
    10201046    protected void encodeURLs(Node dataNode, HttpServletResponse response)
    10211047    {
    1022 
    10231048        if (dataNode == null)
    10241049        {
     
    10871112    }
    10881113
     1114    protected String getFirstParam(String name, Map<String, String[]> map)
     1115    {
     1116        String[] val = map.get(name);
     1117        if (val == null || val.length == 0)
     1118        {
     1119            return null;
     1120        }
     1121
     1122        return val[0];
     1123    }
     1124
    10891125    synchronized protected int getNextUserId()
    10901126    {
     
    10951131    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    10961132    {
    1097         doGet(request, response);
     1133        //Check if we need to process a file upload
     1134        if (ServletFileUpload.isMultipartContent(request))
     1135        {
     1136            DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
     1137
     1138            int sizeLimit = System.getProperties().containsKey("servlet.upload.filesize.limit") ? Integer.parseInt(System.getProperty("servlet.upload.filesize.limit")) : 100 * 1024 * 1024;
     1139
     1140            File tempDir = new File(GlobalProperties.getGSDL3Home() + File.separator + "tmp");
     1141            if (!tempDir.exists())
     1142            {
     1143                tempDir.mkdirs();
     1144            }
     1145
     1146            //We want all files to be stored on disk (hence the 0)
     1147            fileItemFactory.setSizeThreshold(0);
     1148            fileItemFactory.setRepository(tempDir);
     1149
     1150            ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);
     1151            uploadHandler.setFileSizeMax(sizeLimit);
     1152
     1153            HashMap<String, String[]> queryMap = new HashMap<String, String[]>();
     1154            try
     1155            {
     1156                List items = uploadHandler.parseRequest(request);
     1157                Iterator iter = items.iterator();
     1158                while (iter.hasNext())
     1159                {
     1160                    FileItem current = (FileItem) iter.next();
     1161                    if (current.isFormField())
     1162                    {
     1163                        queryMap.put(current.getFieldName(), new String[] { current.getString() });
     1164                    }
     1165                    else if (current.getName() != null && !current.getName().equals(""))
     1166                    {
     1167                        File file = new File(tempDir, current.getName());
     1168                        current.write(file);
     1169                    }
     1170                }
     1171            }
     1172            catch (Exception e)
     1173            {
     1174                e.printStackTrace();
     1175            }
     1176
     1177            doGetOrPost(request, response, queryMap);
     1178        }
     1179        else
     1180        {
     1181            doGetOrPost(request, response, request.getParameterMap());
     1182        }
    10981183    }
    10991184}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/Action.java

    r27144 r27617  
    2323
    2424    /** the system set up variables */
    25     protected HashMap<String, Comparable> config_params = null;
     25    protected HashMap<String, Object> config_params = null;
    2626    /** container Document to create XML Nodes */
    2727    protected Document doc = null;
     
    4343
    4444    /** the config variables must be set before configure is called */
    45     public void setConfigParams(HashMap<String, Comparable> params)
     45    public void setConfigParams(HashMap<String, Object> params)
    4646    {
    4747        this.config_params = params;
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/PageAction.java

    r27143 r27617  
    11package org.greenstone.gsdl3.action;
    22
     3import java.io.Serializable;
     4import java.util.HashMap;
     5
     6import org.apache.log4j.Logger;
     7import org.greenstone.gsdl3.util.GSParams;
     8import org.greenstone.gsdl3.util.GSPath;
     9import org.greenstone.gsdl3.util.GSXML;
     10import org.greenstone.gsdl3.util.UserContext;
    311import org.greenstone.util.GlobalProperties;
    4 import org.greenstone.gsdl3.core.ModuleInterface;
    5 import org.greenstone.gsdl3.util.*;
    6 //XML classes
     12import org.w3c.dom.Element;
    713import org.w3c.dom.Node;
    814import org.w3c.dom.NodeList;
    9 import org.w3c.dom.Document;
    10 import org.w3c.dom.Element;
    11 
    12 import java.util.HashMap;
    13 import java.io.File;
    14 import java.io.Serializable;
    15 
    16 import org.apache.log4j.*;
    1715
    1816public class PageAction extends Action
     
    3129        Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    3230        String collection = "";
    33         if(paramList != null)
     31        if (paramList != null)
    3432        {
    3533            HashMap<String, Serializable> params = GSXML.extractParams(paramList, false);
     
    6563        else
    6664        { // unknown page
    67 
    68             logger.error("unknown page specified!");
    6965            response = unknownPage(request);
    7066        }
     
    8480        result.appendChild(this.doc.importNode(response, true));
    8581        logger.debug("page action result: " + this.converter.getPrettyString(result));
     82
    8683        return result;
    8784    }
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/Receptionist.java

    r26055 r27617  
    3131
    3232    /** the set up variables */
    33     protected HashMap<String, Comparable> config_params = null;
     33    protected HashMap<String, Object> config_params = null;
    3434    /** container Document to create XML Nodes */
    3535    protected Document doc = null;
     
    7171    }
    7272
    73     public void setConfigParams(HashMap<String, Comparable> params)
     73    public void setConfigParams(HashMap<String, Object> params)
    7474    {
    7575        this.config_params = params;
    7676    }
    7777
    78     public HashMap<String, Comparable> getConfigParams()
     78    public HashMap<String, Object> getConfigParams()
    7979    {
    8080        return this.config_params;
     
    316316            }
    317317            base_interfaces.add(base_interface);
     318            this.config_params.put(GSConstants.BASE_INTERFACES, base_interfaces);
    318319            // now see if this has a base interface
    319320            Document config_doc = this.converter.getDOM(base_interface_config_file);
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java

    r27127 r27617  
    318318                //Add the names from this file
    319319                ArrayList<String> currentNames = metaNames.get(currentFileTemp.getAbsolutePath());
     320                if (currentNames == null)
     321                {
     322                    continue;
     323                }
     324
    320325                fullNameList.addAll(currentNames);
    321326
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java

    r27316 r27617  
    2121import java.sql.Connection;
    2222import java.sql.DriverManager;
     23import java.sql.PreparedStatement;
    2324import java.sql.ResultSet;
    2425import java.sql.SQLException;
     
    3637    static final String USERS = "users";
    3738    static final String ROLES = "roles";
     39    static final String DATA = "data";
    3840    private Connection conn = null;
    3941    private Statement state = null;
     
    142144            state.execute("create table users (username varchar(40) not null, password varchar(40) not null, accountstatus varchar(10), comment varchar(100), email varchar(40), primary key(username))");
    143145            state.execute("create table roles (username varchar(40) not null, role varchar(40) not null, primary key (username, role))");
     146            state.execute("create table data (username varchar(40) not null, name varchar(128) not null, value clob, primary key (username, name))");
    144147            state.execute("insert into " + USERS + " values ('admin', '" + Authentication.hashPassword("admin") + "', 'true', 'change the password for this account as soon as possible', '')");
    145148            state.execute("insert into " + ROLES + " values ('admin', 'administrator')");
     
    174177        for (HashMap<String, String> user : users)
    175178        {
    176             ResultSet gs = state.executeQuery("SELECT role FROM roles WHERE username = '" + user.get("username") + "'");
     179            ResultSet gs = state.executeQuery("SELECT role FROM " + ROLES + " WHERE username = '" + user.get("username") + "'");
    177180            String group = "";
    178181            while (gs.next())
     
    196199            return userQueryResult;
    197200        }
     201    }
     202
     203    public boolean addUserData(String username, String name, String value)
     204    {
     205        //Check if we already have a value under this name
     206        boolean found = false;
     207        try
     208        {
     209            ResultSet rs = state.executeQuery("SELECT * FROM " + DATA + " WHERE username='" + username + "' AND name='" + name + "'");
     210            if (rs.next())
     211            {
     212                found = true;
     213            }
     214            else
     215            {
     216                found = false;
     217            }
     218        }
     219        catch (Exception ex)
     220        {
     221            System.out.println("exception thrown:");
     222            if (ex instanceof SQLException)
     223            {
     224                printSQLError((SQLException) ex);
     225            }
     226            else
     227            {
     228                ex.printStackTrace();
     229            }
     230            closeDatabase();
     231            System.out.println("Error:" + ex.getMessage());
     232            return false;
     233        }
     234
     235        try
     236        {
     237            if (!found)
     238            {
     239                PreparedStatement stmt = null;
     240                stmt = conn.prepareStatement("INSERT INTO " + DATA + " VALUES (?, ?, ?)");
     241                stmt.setString(1, username);
     242                stmt.setString(2, name);
     243                stmt.setString(3, value);
     244                stmt.executeUpdate();
     245            }
     246            else
     247            {
     248                PreparedStatement stmt = null;
     249                stmt = conn.prepareStatement("UPDATE " + DATA + " SET value=? WHERE username=? AND name=?");
     250                stmt.setString(1, value);
     251                stmt.setString(2, username);
     252                stmt.setString(3, name);
     253                stmt.executeUpdate();
     254            }
     255        }
     256        catch (Exception ex)
     257        {
     258            System.out.println("exception thrown:");
     259            if (ex instanceof SQLException)
     260            {
     261                printSQLError((SQLException) ex);
     262            }
     263            else
     264            {
     265                ex.printStackTrace();
     266            }
     267            closeDatabase();
     268            System.out.println("Error:" + ex.getMessage());
     269            return false;
     270        }
     271        return true;
     272    }
     273
     274    public String getUserData(String username, String name)
     275    {
     276        try
     277        {
     278            ResultSet rs = state.executeQuery("SELECT * FROM " + DATA + " WHERE username='" + username + "' AND name='" + name + "'");
     279            if (rs.next())
     280            {
     281                return rs.getString("value");
     282            }
     283        }
     284        catch (Exception ex)
     285        {
     286            System.out.println("exception thrown:");
     287            if (ex instanceof SQLException)
     288            {
     289                printSQLError((SQLException) ex);
     290            }
     291            else
     292            {
     293                ex.printStackTrace();
     294            }
     295            closeDatabase();
     296            System.out.println("Error:" + ex.getMessage());
     297        }
     298        return null;
    198299    }
    199300
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSConstants.java

    r25805 r27617  
    2020
    2121/** these constants are used for servlet args, and config variables */
    22 public class GSConstants {
     22public class GSConstants
     23{
     24    public static final String GSDL3_HOME = "gsdl3_home";
     25    public static final String INTERFACE_NAME = "interface_name";
     26    public static final String SITE_NAME = "site_name";
     27    public static final String LIBRARY_NAME = "library_name";
     28    public static final String BASE_INTERFACES = "base_interfaces";
     29    public static final String DEFAULT_LANG = "default_lang";
     30    public static final String ALLOW_CLIENT_SIDE_XSLT = "allow_client_side_xslt";
     31    public static final String CLIENT_SIDE_XSLT_INTERFACE_SUFFIX = "-client-xslt";
    2332
    24     public static final String GSDL3_HOME = "gsdl3_home";
    25     public static final String INTERFACE_NAME = "interface_name";
    26     public static final String SITE_NAME = "site_name";
    27     public static final String LIBRARY_NAME = "library_name";
    28     public static final String DEFAULT_LANG = "default_lang";
    29     public static final String ALLOW_CLIENT_SIDE_XSLT = "allow_client_side_xslt";
    30     public static final String CLIENT_SIDE_XSLT_INTERFACE_SUFFIX = "-client-xslt";
    31 
    32     public static final String META_RELATION_SEP = "_";
    33     public static final String META_SEPARATOR_SEP = "*";
    34     public static final String META_FIRST = "first";
    35     public static final String META_LAST = "last";
    36     public static final String META_POS = "pos";
     33    public static final String META_RELATION_SEP = "_";
     34    public static final String META_SEPARATOR_SEP = "*";
     35    public static final String META_FIRST = "first";
     36    public static final String META_LAST = "last";
     37    public static final String META_POS = "pos";
    3738}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r27078 r27617  
    788788    {
    789789        Element request = owner.createElement(REQUEST_ELEM);
     790        request.setAttribute(TO_ATT, to);
    790791        request.setAttribute(TYPE_ATT, request_type);
    791         request.setAttribute(LANG_ATT, userContext._lang);
    792         request.setAttribute(TO_ATT, to);
    793         request.setAttribute(USER_ID_ATT, userContext._userID);
    794        
    795         if(userContext._groups != null)
     792
     793        Element userContextElem = owner.createElement("userContext");
     794        request.appendChild(userContextElem);
     795        userContextElem.setAttribute(LANG_ATT, userContext._lang);
     796        userContextElem.setAttribute(USERNAME_ATT, userContext._username);
     797        userContextElem.setAttribute(USER_ID_ATT, userContext._userID);
     798
     799        if (userContext._groups != null)
    796800        {
    797801            String groupString = "";
    798             for(int i = 0; i < userContext._groups.length; i++)
     802            for (int i = 0; i < userContext._groups.length; i++)
    799803            {
    800804                groupString += userContext._groups[i];
    801                 if(i != userContext._groups.length - 1)
     805                if (i != userContext._groups.length - 1)
    802806                {
    803807                    groupString += ",";
    804808                }
    805809            }
    806            
    807             if(groupString.length() > 0)
    808             {
    809                 request.setAttribute(GROUPS_ATT, groupString);
    810             }
    811         }
     810
     811            if (groupString.length() > 0)
     812            {
     813                userContextElem.setAttribute(GROUPS_ATT, groupString);
     814            }
     815        }
     816
    812817        return request;
    813818    }
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/UserContext.java

    r27077 r27617  
    22
    33import org.w3c.dom.Element;
     4import org.w3c.dom.NodeList;
    45
    56public class UserContext
    67{
    78    protected String _userID = null;
     9    protected String _username = null;
    810    protected String _lang = null;
    911    protected String[] _groups = null;
     
    1517    public UserContext(Element xmlRequest)
    1618    {
    17         _lang = xmlRequest.getAttribute(GSXML.LANG_ATT);
    18         _userID = xmlRequest.getAttribute(GSXML.USER_ID_ATT);
    19         _groups = xmlRequest.getAttribute(GSXML.GROUPS_ATT).split(",");
     19        NodeList elems = xmlRequest.getElementsByTagName("userContext");
     20
     21        if (elems.getLength() > 0)
     22        {
     23            Element userContext = (Element) elems.item(0);
     24            _userID = userContext.getAttribute(GSXML.USER_ID_ATT);
     25            _username = userContext.getAttribute(GSXML.USERNAME_ATT);
     26            _lang = userContext.getAttribute(GSXML.LANG_ATT);
     27            _groups = userContext.getAttribute(GSXML.GROUPS_ATT).split(",");
     28        }
    2029    }
    2130
    22     public UserContext(String lang, String userID, String[] groups)
     31    public UserContext(String lang, String username, String userID, String[] groups)
    2332    {
     33        _userID = userID;
     34        _username = username;
    2435        _lang = lang;
    25         _userID = userID;
    2636        _groups = groups;
     37    }
     38
     39    public void setUsername(String username)
     40    {
     41        _username = username;
    2742    }
    2843
     
    6075    }
    6176
     77    public String getUsername()
     78    {
     79        if (_username != null)
     80        {
     81            return _username;
     82        }
     83        return "";
     84    }
     85
    6286    public String[] getGroups()
    6387    {
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XMLTransformer.java

    r27090 r27617  
    217217    }
    218218
    219     public Node transform(Document stylesheet, Document source, HashMap<String, Comparable> parameters)
     219    public Node transform(Document stylesheet, Document source, HashMap<String, Object> parameters)
    220220    {
    221221        return transform(stylesheet, source, parameters, null, null);
    222222    }
    223223
    224     public Node transform(Document stylesheet, Document source, HashMap<String, Comparable> parameters, Document docDocType)
     224    public Node transform(Document stylesheet, Document source, HashMap<String, Object> parameters, Document docDocType)
    225225    {
    226226        return transform(stylesheet, source, parameters, docDocType, null);
     
    229229    // This method will now set the docType in the new document created and returned, if any are specified in the
    230230    // (merged) stylesheet being applied. The docDocType parameter is therefore no longer necessary nor used by default.
    231     protected Node transform(Document stylesheet, Document source, HashMap<String, Comparable> parameters, Document docDocType, Document resultNode)
     231    protected Node transform(Document stylesheet, Document source, HashMap<String, Object> parameters, Document docDocType, Document resultNode)
    232232    {
    233233        try
Note: See TracChangeset for help on using the changeset viewer.