Changeset 27165


Ignore:
Timestamp:
2013-04-10T13:23:47+12:00 (11 years ago)
Author:
sjm84
Message:

Added a new call that resolves call-template calls

File:
1 edited

Legend:

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

    r27109 r27165  
    1414import org.apache.log4j.Logger;
    1515import org.greenstone.gsdl3.util.GSXML;
     16import org.greenstone.gsdl3.util.GSXSLT;
    1617import org.greenstone.gsdl3.util.UserContext;
    1718import org.greenstone.gsdl3.util.XMLConverter;
     
    3435    protected static final String GET_TEMPLATE_LIST_FROM_FILE = "GetTemplateListFromFile";
    3536    protected static final String GET_XSLT_FILES_FOR_COLLECTION = "GetXSLTFilesForCollection";
     37    protected static final String RESOLVE_CALL_TEMPLATE = "ResolveCallTemplate";
    3638    /*********************************************************/
    3739
    38     String[] services = { GET_TEMPLATE_FROM_XML_FILE, SAVE_TEMPLATE_TO_XML_FILE, GET_TEMPLATE_LIST_FROM_FILE, GET_XSLT_FILES_FOR_COLLECTION };
     40    String[] services = { GET_TEMPLATE_FROM_XML_FILE, SAVE_TEMPLATE_TO_XML_FILE, GET_TEMPLATE_LIST_FROM_FILE, GET_XSLT_FILES_FOR_COLLECTION, RESOLVE_CALL_TEMPLATE };
    3941
    4042    public boolean configure(Element info, Element extra_info)
     
    7375
    7476        return null;
     77    }
     78
     79    protected Element processResolveCallTemplate(Element request)
     80    {
     81        Element result = GSXML.createBasicResponse(this.doc, RESOLVE_CALL_TEMPLATE);
     82
     83        if (request == null)
     84        {
     85            GSXML.addError(this.doc, result, RESOLVE_CALL_TEMPLATE + ": Request is null", GSXML.ERROR_TYPE_SYNTAX);
     86            return result;
     87        }
     88
     89        UserContext context = new UserContext(request);
     90        boolean found = false;
     91        for (String group : context.getGroups())
     92        {
     93            if (group.equals("administrator"))
     94            {
     95                found = true;
     96            }
     97        }
     98
     99        if (!found)
     100        {
     101            GSXML.addError(this.doc, result, "This user does not have the required permissions to perform this action.");
     102            return result;
     103        }
     104
     105        // Get the parameters of the request
     106        Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     107
     108        if (param_list == null)
     109        {
     110            GSXML.addError(this.doc, result, RESOLVE_CALL_TEMPLATE + ": No param list specified", GSXML.ERROR_TYPE_SYNTAX);
     111            return result;
     112        }
     113
     114        HashMap<String, Serializable> params = GSXML.extractParams(param_list, false);
     115
     116        String interfaceName = (String) params.get("interfaceName");
     117        String siteName = (String) params.get("siteName");
     118        String collectionName = (String) params.get("collectionName");
     119        String fileName = (String) params.get("fileName");
     120        String nameToGet = (String) params.get("templateName");
     121
     122        fileName = fileName.replace("\\", "/");
     123
     124        Document xslDoc = GSXSLT.mergedXSLTDocumentCascade(fileName, siteName, collectionName, interfaceName, new ArrayList<String>(), true);
     125
     126        int sepIndex = fileName.lastIndexOf("/");
     127        String pathExtra = null;
     128        if (sepIndex != -1)
     129        {
     130            pathExtra = fileName.substring(0, sepIndex + 1);
     131            fileName = fileName.substring(sepIndex + 1);
     132        }
     133
     134        GSXSLT.inlineImportAndIncludeFilesDebug(xslDoc, pathExtra, true, fileName, siteName, collectionName, interfaceName, new ArrayList<String>());
     135
     136        NodeList templateList = xslDoc.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template");
     137        for (int i = 0; i < templateList.getLength(); i++)
     138        {
     139            Element current = (Element) templateList.item(i);
     140            if (current.hasAttribute("name") && current.getAttribute("name").equals(nameToGet))
     141            {
     142                Element debugElement = (Element) current.getElementsByTagName("debug").item(0);
     143
     144                Element requestedTemplate = this.doc.createElement("requestedTemplate");
     145                requestedTemplate.setTextContent(debugElement.getAttribute("filename"));
     146                result.appendChild(requestedTemplate);
     147            }
     148        }
     149
     150        return result;
    75151    }
    76152
Note: See TracChangeset for help on using the changeset viewer.