Changeset 28850 for main


Ignore:
Timestamp:
2014-02-27T11:25:07+13:00 (10 years ago)
Author:
kjdon
Message:

moved a couple of methods here from OAIXML as they are just generic xml stuff. With OAIserver I am creating a request with no user context, so modified createBasicRequest to handle that. Should this be allowed? Should oaiserver use user context???

File:
1 edited

Legend:

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

    r28847 r28850  
    320320    }
    321321
     322      public static HashMap<String, String> getParamMap(NodeList params) {
     323      HashMap<String, String> map = new HashMap<String, String>();
     324      for(int i=0; i<params.getLength(); i++) {
     325        Element param = (Element)params.item(i);
     326        String param_name = param.getAttribute(NAME_ATT);
     327        String param_value = param.getAttribute(VALUE_ATT);
     328        map.put(param_name, param_value);
     329      }
     330      return map;
     331    }
     332
    322333    public static HashMap<String, Serializable> extractParams(Element xml, boolean deep)
    323334    {
     
    790801        }
    791802    }
     803 
     804   public static void copyElement(Element to, Element from, String elem_name) {
     805     
     806      Document to_doc = to.getOwnerDocument();
     807      Node child = from.getFirstChild();
     808      while (child != null) {
     809        if (child.getNodeName().equals(elem_name)) {
     810          to.appendChild(to_doc.importNode(child, true));
     811          return;
     812        }
     813        child = child.getNextSibling();
     814      }
     815    }
    792816
    793817    /** returns a basic request message */
     
    797821        request.setAttribute(TO_ATT, to);
    798822        request.setAttribute(TYPE_ATT, request_type);
    799                 request.setAttribute(LANG_ATT, userContext._lang);
    800         Element userContextElem = owner.createElement("userContext");
    801         request.appendChild(userContextElem);
    802         userContextElem.setAttribute(LANG_ATT, userContext._lang);
    803         userContextElem.setAttribute(USERNAME_ATT, userContext._username);
    804         userContextElem.setAttribute(USER_ID_ATT, userContext._userID);
    805 
    806         if (userContext._groups != null)
    807         {
    808             String groupString = "";
    809             for (int i = 0; i < userContext._groups.length; i++)
    810             {
    811                 groupString += userContext._groups[i];
    812                 if (i != userContext._groups.length - 1)
    813                 {
    814                     groupString += ",";
    815                 }
    816             }
    817 
    818             if (groupString.length() > 0)
    819             {
    820                 userContextElem.setAttribute(GROUPS_ATT, groupString);
    821             }
    822         }
    823 
     823        request.setAttribute(LANG_ATT, userContext._lang);
     824        if (userContext != null) { // should we allow this??
     825          Element userContextElem = owner.createElement("userContext");
     826          request.appendChild(userContextElem);
     827          userContextElem.setAttribute(LANG_ATT, userContext._lang);
     828          userContextElem.setAttribute(USERNAME_ATT, userContext._username);
     829          userContextElem.setAttribute(USER_ID_ATT, userContext._userID);
     830         
     831          if (userContext._groups != null)
     832            {
     833              String groupString = "";
     834              for (int i = 0; i < userContext._groups.length; i++)
     835            {
     836              groupString += userContext._groups[i];
     837              if (i != userContext._groups.length - 1)
     838                {
     839                  groupString += ",";
     840                }
     841            }
     842             
     843              if (groupString.length() > 0)
     844            {
     845              userContextElem.setAttribute(GROUPS_ATT, groupString);
     846            }
     847            }
     848        }
    824849        return request;
    825850    }
     
    15811606        return groups;
    15821607    }
     1608
    15831609}
Note: See TracChangeset for help on using the changeset viewer.