Package org.apache.turbine.util.parser

Examples of org.apache.turbine.util.parser.ParameterParser


       
        long time = System.currentTimeMillis();
        WorkflowAPI wfapi = new WorkflowAPI();
        String uname = data.getUser().getName();
        SWAMPTurbineUser user = (SWAMPTurbineUser) data.getUser();
        ParameterParser pp = data.getParameters();

        // get an Array of Workflow Templates (for filters)  
        ArrayList templateIdList = wfapi.getAllWorkflowTemplateNames(uname);
        context.put("wftmpls", templateIdList);

        MapToFilterlist urlToFilter = new MapToFilterlist();
        ArrayList filters = urlToFilter.getFilters(
                Workflows.parameterParserToHashMap(pp));
        StringBuffer filterText = urlToFilter.getFilterText();
        context.put("filters", filters);
        context.put("filtercount", String.valueOf(filters.size()));
        context.put("systemFilterText", filterText);  
       
        // do we have a multiple workflow type view?
        boolean multipleview = false;
        if (urlToFilter.getTemplateName() == null){
            multipleview = true;
        } else {
            WorkflowTemplate wfTemp = wfapi.getWorkflowTemplate(urlToFilter.getTemplateName(), uname);
          // automatically add filter for workflow user if needed
            if (wfTemp.getWorkflowRole(WorkflowRole.USER).isRestricted()) {
                RoleFilter filter = new RoleFilter(uname, WorkflowRole.USER, urlToFilter.getTemplateName());
                filters.add(filter);
            }
            context.put("mastertemplatename", urlToFilter.getTemplateName());
            SwampUIManager uitool = (SwampUIManager) TurbinePull.getTool(context, "ui");
            SwampUIManager.setInterface(data.getUser(), wfTemp.getMasterParentTemplate().getName());
            uitool.init(data.getUser());
        }
        context.put("multipleview", new Boolean(multipleview));
       
        // configure task display:
        if (urlToFilter.getTaskOwner() != null){
            context.put("taskOwner", urlToFilter.getTaskOwner());
        }
       
        // restrict the displayed tasks:
        if (pp.containsKey("systemfilter_displayedtasks")){
            SWAMPHashSet displayedTasks = new SWAMPHashSet();
            displayedTasks.add(pp.get("systemfilter_displayedtasks"), ",");
            context.put("displaytasks", displayedTasks);
        }
       
       
        // FIXME:
        // more than one workflowtype on one page not possible, because of
    // sorting criteria
        // sorting: get the order criteria from users permstorage -> wf-defaults -> default
        // need a template-type to load the default sorting criteria!
        // else automatically sorted by wf-id
        DatabaseFilter order = this.getOrderFilter(pp.
                getString("systemfilter_wftemplate"), data, context);
       
       
        List workflowIDList = wfapi.getWorkflowIds(filters, order, uname);
        int numberOfWorkflows = workflowIDList.size();
       
        // setting displaysubwfs user option
        HashMap displaysubwfsSet = new HashMap();
        // name: templatename, value: LinkedList with workflows
        HashMap wflists = new HashMap();
        // list of templates where the subworkflow-display config dropdown is shown
        List displaySubworkflowsDropdown = new ArrayList();
        for (Iterator it = templateIdList.iterator(); it.hasNext(); ){
            String templateName = (String) it.next();
            String displaysubwfs = "systemfilter_displaysubwfs_" + templateName;
            String value;
            // manual user-change:
            if (pp.containsKey("subwfsuserchange_" + templateName)){
                value = pp.get(displaysubwfs);
                user.setPerm(displaysubwfs, pp.get(displaysubwfs));
            // systemfilter parameter setting
            } else if (pp.containsKey(displaysubwfs)){
                value = pp.get(displaysubwfs);
            // fetch from usersession (only for masterworkflow or for all in multi-view)
            } else if (templateName.equals(urlToFilter.getTemplateName())
                    && user.getPerm(displaysubwfs) != null) {
                value = (String) user.getPerm(displaysubwfs);
            // default to none in multipleview
            } else if (multipleview) {
                value = "none";
            } else {
                value = "all";
            }
            // Logger.DEBUG("Set " + displaysubwfs + " - " + value);
            displaysubwfsSet.put(displaysubwfs, value);
            wflists.put(templateName, new LinkedList());
            // check if we need to show the subworkflow dropdown
            if (WorkflowManager.getInstance().getWorkflowTemplate(templateName).getSubworkflowTemplates().isEmpty()) {
                displaySubworkflowsDropdown.add(templateName);
            }
        }
        context.put("displaysubwfsSet", displaysubwfsSet);
       
        int wfsPerPage = 30, wfOffset = 0;
        HashMap wfsPerPageMap = new HashMap();
        for (Iterator it = templateIdList.iterator(); it.hasNext(); ){
            String template = (String) it.next();
            String wfsPerPageParam = "systemfilter_wfsPerPage_" + template;
            String wfsPerPageUser = "wfsPerPage_" + template;
            if (pp.containsKey(wfsPerPageUser) &&
                    pp.getInt(wfsPerPageUser) > 0 ){
                wfsPerPage = pp.getInt(wfsPerPageUser);
                user.setPerm(wfsPerPageParam, String.valueOf(wfsPerPage));
            } else if (pp.containsKey(wfsPerPageParam) &&
                    pp.getInt(wfsPerPageParam) > 0 ){
                wfsPerPage = pp.getInt(wfsPerPageParam);
            } else if (data.getUser().getPerm(wfsPerPageParam) != null) {
                try {
                    wfsPerPage = new Integer((String) user.getPerm(wfsPerPageParam)).intValue();
                } catch (NumberFormatException e) {
                    Logger.ERROR("Invalid wfsPerPage value:" + user.getPerm(wfsPerPageParam) + " in "
                            + user.getName() + "s permdata!");
                    wfsPerPage = 30;
                }
            }
            wfsPerPageMap.put(wfsPerPageParam, new Integer(wfsPerPage));
        }
        context.put("wfsPerPageMap", wfsPerPageMap);
        if (urlToFilter.getTemplateName() != null){
            wfsPerPage = ((Integer) wfsPerPageMap.get("systemfilter_wfsPerPage_" +
                    urlToFilter.getTemplateName())).intValue();
        }
       
       
        if (!multipleview){
            if (pp.containsKey("wfOffset") &&
                    pp.getInt("wfOffset") > 0 &&
                    pp.getInt("wfOffset") < workflowIDList.size()){
                wfOffset = pp.getInt("wfOffset");
            } else {
                wfOffset = 0;
            }
            context.put("wfOffset", new Integer(wfOffset));       
            ArrayList pages = new ArrayList();
            for (int i=1, total=numberOfWorkflows/wfsPerPage; i<=total; i++)
                pages.add(new Integer(i));
           
            if ((numberOfWorkflows % wfsPerPage) > 0)
                pages.add(new Integer(numberOfWorkflows/wfsPerPage + 1));
           
           
            context.put("currentPage", new Integer(wfOffset / wfsPerPage +1));
            context.put("pages", pages);
           
           
            if ((wfOffset + wfsPerPage) > workflowIDList.size())
                workflowIDList = workflowIDList.subList(wfOffset, workflowIDList.size());
            else
                workflowIDList = workflowIDList.subList(wfOffset, wfOffset + wfsPerPage);
        }       

        // iterate over all found workflows, sort them into a list of their template, check permissions.
        int wfcount = 0;
       
        for (Iterator it = workflowIDList.iterator(); it.hasNext();) {
            int wfid = ((Integer) it.next()).intValue();
            // only add those that he is allowed to see
            try {
                Workflow wf = wfapi.getWorkflow(wfid, uname);
                wfcount++;
                ((LinkedList) wflists.get(wf.getTemplateName())).add(wf);
            } catch (SecurityException e) {
                Logger.DEBUG("Removed wf-" + wfid + " (no permission for " + uname + ")");
            }
        }
        context.put("displayedWorkflows", new Integer(wfcount));
        context.put("numberOfWorkflows", new Integer(numberOfWorkflows));
        context.put("displaySubworkflowsDropdown", displaySubworkflowsDropdown);
       
        // Check each List for its Order Criteria and displayed Columns
        // we also need to add all possible subtypes
        if (urlToFilter.getTemplateName() != null) {
            List templates = wfapi.getSubworkflowTemplateNames(urlToFilter.getTemplateName(), uname);
            templates.add(urlToFilter.getTemplateName());
            populateColumns(context, data, templates);
        } else {
            populateColumns(context, data, wfapi.getWorkflowTemplateNames(uname));
        }
       
        // Set var for changing displayed columns
        if (pp.containsKey("editcolumns")) {
            String editcolumntemplate = pp.get("editcolumns");
            context.put("editcolumns", editcolumntemplate);
           
            // list of possible databit columns:
            WorkflowTemplate wfTemp = wfapi.getWorkflowTemplate(editcolumntemplate, uname);
            List pathList = wfTemp.getAllDatabitPaths();
View Full Code Here


    public void populateColumns(Context context, RunData data, List templateNames) throws Exception {
        WorkflowAPI wfapi = new WorkflowAPI();
        String uname = data.getUser().getName();
        HashMap displayedColumns = new HashMap();
        SWAMPTurbineUser SWAMPUser = (SWAMPTurbineUser) data.getUser();
        ParameterParser pp = data.getParameters();
        HashMap wfIcons = new HashMap();
       
        for (Iterator tempit = templateNames.iterator(); tempit.hasNext();) {
            String template = (String) tempit.next();
            displayedColumns.put(template, new ArrayList());

            WorkflowTemplate wfTemplate;
            // We may have a page that theoretically displays subworkflows, to which this user has no permission.
            // They won't get shown anyway, so avoid the errormessage and show what he is allowed to see
            try {
                wfTemplate = wfapi.getWorkflowTemplate(template, uname);
            } catch (Exception e) {
                Logger.WARN("Workflows.vm: Subworkflowpermission missing: " + e.getMessage());
                continue;
            }

            if (wfTemplate.containsConfigItem("icon")) {
                wfIcons.put(template, wfTemplate.getConfigItem("icon"));
            }

            context.put("defaultview", "workflow");
            // load user-specific columns for the actual wf-template
            ArrayList columns = SWAMPUser.getPermArray("wfcolumns_" + template);
            ArrayList templateColumns = (ArrayList) displayedColumns.get(template);
            String columnsParam = "systemfilter_columns_" + template;

            // checking for parameter config
            if (pp.containsKey(columnsParam) && !pp.get(columnsParam).equals("")) {
                templateColumns.clear();
                StringTokenizer st = new StringTokenizer(pp.get(columnsParam), ",");
                while (st.hasMoreTokens()) {
                    templateColumns.add(st.nextToken().trim());
                }
                // disable "edit columns" button for fixed views
                context.put("noeditcolumns", "true");
View Full Code Here

     * @param data - Turbine information.
     * @exception Exception, a generic exception.
     */
    public void doLoginuser(RunData data, Context context) throws Exception {

        ParameterParser pp = data.getParameters();
        String username = pp.getString("username", "").toLowerCase();
        String password = pp.getString("password", "");
       // cause of login-error
        String cause = null;

        if (StringUtils.isEmpty(username)) { return; }
       
        try {

            User user = TurbineSecurity.getAuthenticatedUser(username, password);
            // Store the user object.
            data.setUser(user);
            // Mark the user as being logged in.
            user.setHasLoggedIn(new Boolean(true));
            // Save the User object into the session.
            data.save();
            Logger.LOG(username + " has successfully logged in.");
           
            // if we have a "query", it's a redirect from the login page:
            // if we want restrict to do direct logins to special actions, we have to restrict it here
            if (pp.containsKey("query") && !pp.get("query").equals("")
                    && !(pp.get("query").indexOf("doLogoutuser") > 0)){
                Logger.DEBUG("Found a query, redirecting to " + pp.get("query"));
                data.declareDirectResponse();
                data.setRedirectURI(pp.get("query"));
            }
        } catch (Exception e) {
            Logger.ERROR("Login Error: " + e.getMessage());
            // Retrieve an anonymous user.
            data.setUser(TurbineSecurity.getAnonymousUser());
View Full Code Here

   */
  public void doSavedatabit(RunData data, Context context) throws Exception {
        DataAPI dataApi = new DataAPI();
        WorkflowAPI wfapi = new WorkflowAPI();
        String uname = data.getUser().getName();
        ParameterParser params = data.getParameters();
        int wfid = params.getInt("workflowid");
        String dsetname = params.get("dsetname");
        String dbitname = params.get("dbitname");
        String datatype = params.get("datatype");
        String datashortdesc = params.get("datashortdesc");
        String datadesc = params.get("datadesc");
        String dbitvalue ="";
        dataApi.doAddDatabit(wfid, dsetname, dbitname, dbitvalue, uname, datatype, datashortdesc, datadesc);
        Workflow wf = wfapi.getWorkflow(wfid, uname);
        Databit dbit = wf.getDataset(dsetname).getDatabit(dbitname);
        // file upload?
        if (params.getFileItem("filename") != null){
            FileItem fi = params.getFileItem("filename");
            if (!storeFile(dbit, false, fi, uname)){
                throw new Exception("Empty file uploaded!");
            }
            dbitvalue = fi.getName();
           
        } else if (params.get("dbitvalue") != null){
            dbitvalue = params.get("dbitvalue");
        } else {
            throw new Exception("Error while adding databit.");
        }
        dbit.setValue(dbitvalue);
        context.put("statusheader", "Data added");
View Full Code Here

            throws Exception
    {
        // Name of the button.
        String theButton = null;
        // Parameter parser.
        ParameterParser pp = data.getParameters();

        String button = pp.convert(BUTTON);
        String key = null;

        // Loop through and find the button.
        for (Iterator it = pp.keySet().iterator(); it.hasNext();)
        {
            key = (String) it.next();
            if (key.startsWith(button))
            {
                if (considerKey(key, pp))
                {
                    theButton = formatString(key);
                    break;
                }
            }
        }

        if (theButton == null)
        {
            throw new NoSuchMethodException("ActionEvent: The button was null");
        }

        try
        {
            Method method = getClass().getMethod(theButton, methodParams);
            Object[] methodArgs = new Object[] { data };

            if (log.isDebugEnabled())
            {
                log.debug("Invoking " + method);
            }

            method.invoke(this, methodArgs);
        }
        catch (InvocationTargetException ite)
        {
            Throwable t = ite.getTargetException();
            if (t instanceof Exception)
            {
                throw (Exception) t;
            }
            else
            {
                throw ite;
            }
        }
        finally
        {
            pp.remove(key);
        }
    }
View Full Code Here

    {
        // Name of the button.
        String theButton = null;

        // ParameterParser.
        ParameterParser pp = data.getParameters();

        String button = pp.convert(BUTTON);
        String key = null;

        // Loop through and find the button.
        for (Iterator it = pp.keySet().iterator(); it.hasNext();)
        {
            key = (String) it.next();
            if (key.startsWith(button))
            {
                if (considerKey(key, pp))
                {
                    theButton = formatString(key);
                    break;
                }
            }
        }

        if (theButton == null)
        {
            throw new NoSuchMethodException(
                    "ActionEvent: The button was null");
        }

        try
        {
            Method method = getClass().getMethod(theButton, methodParams);
            Object[] methodArgs = new Object[] { data, context };

            if (log.isDebugEnabled())
            {
                log.debug("Invoking " + method);
            }

            method.invoke(this, methodArgs);
        }
        catch (NoSuchMethodException nsme)
        {
            // Attempt to execute things the old way..
            if (log.isDebugEnabled())
            {
                log.debug("Couldn't locate the Event ( " + theButton
                        + "), running executeEvents() in "
                        + super.getClass().getName());
            }

            super.executeEvents(data);
        }
        catch (InvocationTargetException ite)
        {
            Throwable t = ite.getTargetException();
            if (t instanceof Exception)
            {
                throw (Exception) t;
            }
            else
            {
                throw ite;
            }
        }
        finally
        {
            pp.remove(key);
        }
    }
View Full Code Here

     *
     * @return the valid flag
     */
    protected boolean validate()
    {
        ParameterParser pp = (ParameterParser) super.parser;
        if (isMultiValued)
        {
            FileItem[] ss = pp.getFileItems(getKey());
            // this definition of not set might need refined.  But
            // not sure the situation will arise.
            if (ss.length == 0)
            {
                setFlag = false;
            }

            if (validator != null)
            {
                for (int i = 0; i < ss.length; i++)
                {
                    try
                    {
                        ((FileValidator) validator).assertValidity(ss[i]);
                    }
                    catch (ValidationException ve)
                    {
                        setMessage(ve.getMessage());
                    }
                }
            }

            if (setFlag && validFlag)
            {
                doSetValue();
            }
        }
        else
        {
            FileItem s = pp.getFileItem(getKey());
            if (s == null || s.getSize() == 0)
            {
                setFlag = false;
            }

View Full Code Here

    /**
     * Sets the value of the field from data in the parser.
     */
    protected void doSetValue()
    {
        ParameterParser pp = (ParameterParser) super.parser;
        if (isMultiValued)
        {
            setTestValue(pp.getFileItems(getKey()));
        }
        else
        {
            setTestValue(pp.getFileItem(getKey()));
        }
    }
View Full Code Here

                .append(" within the screen.")
                .append("<p>")
                .append("Please click ");

        message.addElement(sb.toString());
        ParameterParser pp;
        pp = (ParameterParser) data.getUser().getTemp("prev_parameters");
        pp.remove("_session_access_counter");

        TurbineURI back = new TurbineURI(data,(String) data.getUser().getTemp("prev_screen"));
        back.addPathInfo(pp);
        message.addElement(new A().setHref(back.getRelativeLink()).addElement("here"));
View Full Code Here

    {
        // Name of the button.
        String theButton = null;

        // ParameterParser.
        ParameterParser pp = data.getParameters();

        String button = pp.convert(BUTTON);
        String key = null;

        // Loop through and find the button.
        for (Iterator it = pp.keySet().iterator(); it.hasNext();)
        {
            key = (String) it.next();
            if (key.startsWith(button))
            {
                if (considerKey(key, pp))
                {
                    theButton = formatString(key);
                    break;
                }
            }
        }

        if (theButton == null)
        {
            throw new NoSuchMethodException(
                    "ActionEvent: The button was null");
        }

        Method method = null;
        try
        {
            method = getClass().getMethod(theButton, methodParams);
            Object[] methodArgs = new Object[] { data, context };

            if (log.isDebugEnabled())
            {
                log.debug("Invoking " + method);
            }

            method.invoke(this, methodArgs);
        }
        catch (NoSuchMethodException nsme)
        {
            // Attempt to execute things the old way..
            if (log.isDebugEnabled())
            {
                log.debug("Couldn't locate the Event ( " + theButton
                        + "), running executeEvents() in "
                        + super.getClass().getName());
            }

            super.executeEvents(data);
        }
        catch (InvocationTargetException ite)
        {
            Throwable t = ite.getTargetException();
            log.error("Invokation of " + method , t);
        }
        finally
        {
            pp.remove(key);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.turbine.util.parser.ParameterParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.