Search in sources :

Example 36 with ActionForward

use of org.apache.struts.action.ActionForward in project iaf by ibissource.

the class BrowseJdbcTableExecute method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    // -------------------------------
    if (isCancelled(request)) {
        log.debug("browseJdbcTable was cancelled");
        removeFormBean(mapping, request);
        return (mapping.findForward("cancel"));
    }
    // Retrieve form content
    // ---------------------
    IniDynaActionForm browseJdbcTableForm = (IniDynaActionForm) form;
    String form_jmsRealm = (String) browseJdbcTableForm.get("jmsRealm");
    String form_tableName = (String) browseJdbcTableForm.get("tableName");
    String form_where = (String) browseJdbcTableForm.get("where");
    boolean form_numberOfRowsOnly = false;
    String form_order = (String) browseJdbcTableForm.get("order");
    if (browseJdbcTableForm.get("numberOfRowsOnly") != null)
        form_numberOfRowsOnly = ((Boolean) browseJdbcTableForm.get("numberOfRowsOnly")).booleanValue();
    int form_rownumMin = ((Integer) browseJdbcTableForm.get("rownumMin")).intValue();
    int form_rownumMax = ((Integer) browseJdbcTableForm.get("rownumMax")).intValue();
    if (!form_numberOfRowsOnly) {
        if (form_rownumMin < 0) {
            form_rownumMin = 0;
        }
        if (form_rownumMax < 0) {
            form_rownumMax = 0;
        }
        if (form_rownumMin == 0 && form_rownumMax == 0) {
            form_rownumMin = 1;
            form_rownumMax = 100;
        }
        if (errors.isEmpty()) {
            if (form_rownumMax < form_rownumMin) {
                error("errors.generic", "Rownum max must be greater than or equal to Rownum min", null);
            }
        }
        if (errors.isEmpty()) {
            if (form_rownumMax - form_rownumMin >= 100) {
                error("errors.generic", "Difference between Rownum max and Rownum min must be less than hundred", null);
            }
        }
        if (!readAllowed(permissionRules, request, form_tableName)) {
            error("errors.generic", "Access to table (" + form_tableName + ") not allowed", null);
        }
    }
    if (errors.isEmpty()) {
        DirectQuerySender qs;
        String result = "";
        String query = null;
        try {
            qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
            try {
                qs.setName("QuerySender");
                qs.setJmsRealm(form_jmsRealm);
                // if (form_numberOfRowsOnly || qs.getDatabaseType() == DbmsSupportFactory.DBMS_ORACLE) {
                qs.setQueryType("select");
                qs.setBlobSmartGet(true);
                qs.setIncludeFieldDefinition(true);
                qs.configure(true);
                qs.open();
                ResultSet rs = qs.getConnection().getMetaData().getColumns(null, null, form_tableName, null);
                if (!rs.isBeforeFirst()) {
                    rs = qs.getConnection().getMetaData().getColumns(null, null, form_tableName.toUpperCase(), null);
                }
                String fielddefinition = "<fielddefinition>";
                while (rs.next()) {
                    String field = "<field name=\"" + rs.getString(4) + "\" type=\"" + DB2XMLWriter.getFieldType(rs.getInt(5)) + "\" size=\"" + rs.getInt(7) + "\"/>";
                    fielddefinition = fielddefinition + field;
                }
                fielddefinition = fielddefinition + "</fielddefinition>";
                String browseJdbcTableExecuteREQ = "<browseJdbcTableExecuteREQ>" + "<dbmsName>" + qs.getDbmsSupport().getDbmsName() + "</dbmsName>" + "<tableName>" + form_tableName + "</tableName>" + "<where>" + XmlUtils.encodeChars(form_where) + "</where>" + "<numberOfRowsOnly>" + form_numberOfRowsOnly + "</numberOfRowsOnly>" + "<order>" + form_order + "</order>" + "<rownumMin>" + form_rownumMin + "</rownumMin>" + "<rownumMax>" + form_rownumMax + "</rownumMax>" + fielddefinition + "<maxColumnSize>1000</maxColumnSize>" + "</browseJdbcTableExecuteREQ>";
                URL url = ClassUtils.getResourceURL(this, DB2XML_XSLT);
                if (url != null) {
                    Transformer t = XmlUtils.createTransformer(url);
                    query = XmlUtils.transformXml(t, browseJdbcTableExecuteREQ);
                }
                result = qs.sendMessage("dummy", query);
            // } else {
            // error("errors.generic","This function only supports oracle databases",null);
            // }
            } catch (Throwable t) {
                error("errors.generic", "error occured on executing jdbc query [" + query + "]", t);
            } finally {
                qs.close();
            }
        } catch (Exception e) {
            error("errors.generic", "error occured on creating or closing connection", e);
        }
        String resultEnvelope = "<resultEnvelope>" + "<request " + "tableName=\"" + form_tableName + "\">" + XmlUtils.encodeChars(query) + "</request>" + result + "</resultEnvelope>";
        request.setAttribute("DB2Xml", resultEnvelope);
    }
    // Report any errors we have discovered back to the original form
    if (!errors.isEmpty()) {
        StoreFormData(browseJdbcTableForm);
        saveErrors(request, errors);
        return (new ActionForward(mapping.getInput()));
    }
    // Successfull: store cookie
    String cookieValue = "";
    cookieValue += "jmsRealm=\"" + form_jmsRealm + "\"";
    // separator
    cookieValue += " ";
    cookieValue += "tableName=\"" + form_tableName + "\"";
    // separator
    cookieValue += " ";
    cookieValue += "where=\"" + form_where + "\"";
    // separator
    cookieValue += " ";
    cookieValue += "order=\"" + form_order + "\"";
    // separator
    cookieValue += " ";
    cookieValue += "numberOfRowsOnly=\"" + form_numberOfRowsOnly + "\"";
    // separator
    cookieValue += " ";
    cookieValue += "rownumMin=\"" + form_rownumMin + "\"";
    // separator
    cookieValue += " ";
    cookieValue += "rownumMax=\"" + form_rownumMax + "\"";
    Cookie sendJdbcBrowseCookie = new Cookie(AppConstants.getInstance().getProperty("WEB_JDBCBROWSECOOKIE_NAME"), cookieValue);
    sendJdbcBrowseCookie.setMaxAge(Integer.MAX_VALUE);
    log.debug("Store cookie for " + request.getServletPath() + " cookieName[" + AppConstants.getInstance().getProperty("WEB_JDBCBROWSECOOKIE_NAME") + "] " + " cookieValue[" + new StringTagger(cookieValue).toString() + "]");
    try {
        response.addCookie(sendJdbcBrowseCookie);
    } catch (Throwable e) {
        log.warn("unable to add cookie to request. cookie value [" + sendJdbcBrowseCookie.getValue() + "]");
    }
    // Forward control to the specified success URI
    log.debug("forward to success");
    return (mapping.findForward("success"));
}
Also used : Cookie(javax.servlet.http.Cookie) Transformer(javax.xml.transform.Transformer) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) StringTagger(nl.nn.adapterframework.util.StringTagger) URL(java.net.URL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ActionForward(org.apache.struts.action.ActionForward) ResultSet(java.sql.ResultSet) IniDynaActionForm(nl.nn.adapterframework.webcontrol.IniDynaActionForm)

Example 37 with ActionForward

use of org.apache.struts.action.ActionForward in project iaf by ibissource.

the class BrowseQueueExecute method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    // -------------------------------
    if (isCancelled(request)) {
        log.debug("browseQueue was cancelled");
        removeFormBean(mapping, request);
        return (mapping.findForward("cancel"));
    }
    // Retrieve form content
    // ---------------------
    IniDynaActionForm browseQueueForm = (IniDynaActionForm) form;
    String form_jmsRealm = (String) browseQueueForm.get("jmsRealm");
    String form_destinationName = (String) browseQueueForm.get("destinationName");
    String form_destinationType = (String) browseQueueForm.get("destinationType");
    boolean form_numberOfMessagesOnly = false;
    boolean form_showPayload = false;
    if (browseQueueForm.get("numberOfMessagesOnly") != null)
        form_numberOfMessagesOnly = ((Boolean) browseQueueForm.get("numberOfMessagesOnly")).booleanValue();
    if (browseQueueForm.get("showPayload") != null)
        form_showPayload = ((Boolean) browseQueueForm.get("showPayload")).booleanValue();
    // initiate MessageSender
    JmsMessageBrowser jmsBrowser = new JmsMessageBrowser();
    jmsBrowser.setName("BrowseQueueAction");
    jmsBrowser.setJmsRealm(form_jmsRealm);
    jmsBrowser.setDestinationName(form_destinationName);
    jmsBrowser.setDestinationType(form_destinationType);
    IMessageBrowser browser = jmsBrowser;
    IMessageBrowsingIterator it = null;
    try {
        it = browser.getIterator();
        List messages = new ArrayList();
        while (it.hasNext()) {
            messages.add(it.next());
        }
        log.debug("Browser returned " + messages.size() + " messages");
        browseQueueForm.set("numberOfMessages", Integer.toString(messages.size()));
        if (!form_numberOfMessagesOnly) {
            /*				
				try {
					for (int i = 0; i < messages.size(); i++) {
						Message msg = (Message) messages.get(i);
						if (msg instanceof TextMessage) {
							TextMessage tm = (TextMessage) msg;
							if (log.isDebugEnabled())
								log.debug("Found message " + tm.getText());
						}
					}
				} catch (JMSException je) {
					log.error(je);
					errors.add(
						"",
						new ActionError(
							"errors.generic",
							"error occured browsing messages:" + je.getMessage()));
				}
*/
            browseQueueForm.set("messages", messages);
        } else
            browseQueueForm.set("messages", new ArrayList());
    } catch (ListenerException e) {
        error("Error occured browsing messages", e);
    } finally {
        try {
            if (it != null) {
                it.close();
            }
        } catch (ListenerException e1) {
            log.error(e1);
        }
    }
    // Report any errors we have discovered back to the original form
    if (!errors.isEmpty()) {
        StoreFormData(browseQueueForm);
        saveErrors(request, errors);
        return (new ActionForward(mapping.getInput()));
    }
    // Successfull: store cookie
    String cookieValue = "";
    cookieValue += "jmsRealm=\"" + form_jmsRealm + "\"";
    // separator
    cookieValue += " ";
    cookieValue += "destinationName=\"" + form_destinationName + "\"";
    // separator
    cookieValue += " ";
    cookieValue += "destinationType=\"" + form_destinationType + "\"";
    // separator
    cookieValue += " ";
    cookieValue += "showPayload=\"" + form_showPayload + "\"";
    log.debug("*** value :  " + AppConstants.getInstance().getString("WEB_QBROWSECOOKIE_NAME", "WEB_QBROWSECOOKIE"));
    Cookie sendJmsCookie = new Cookie(AppConstants.getInstance().getString("WEB_QBROWSECOOKIE_NAME", "WEB_QBROWSECOOKIE"), cookieValue);
    sendJmsCookie.setMaxAge(Integer.MAX_VALUE);
    log.debug("Store cookie for " + request.getServletPath() + " cookieName[" + sendJmsCookie.getName() + "] " + " cookieValue[" + new StringTagger(cookieValue).toString() + "]");
    try {
        response.addCookie(sendJmsCookie);
    } catch (Throwable e) {
        log.warn("unable to add cookie to request. cookie value [" + sendJmsCookie.getValue() + "]");
    }
    // Forward control to the specified success URI
    log.debug("forward to success");
    return (mapping.findForward("success"));
}
Also used : Cookie(javax.servlet.http.Cookie) IMessageBrowser(nl.nn.adapterframework.core.IMessageBrowser) ArrayList(java.util.ArrayList) IMessageBrowsingIterator(nl.nn.adapterframework.core.IMessageBrowsingIterator) StringTagger(nl.nn.adapterframework.util.StringTagger) ActionForward(org.apache.struts.action.ActionForward) ListenerException(nl.nn.adapterframework.core.ListenerException) JmsMessageBrowser(nl.nn.adapterframework.jms.JmsMessageBrowser) ArrayList(java.util.ArrayList) List(java.util.List) IniDynaActionForm(nl.nn.adapterframework.webcontrol.IniDynaActionForm)

Example 38 with ActionForward

use of org.apache.struts.action.ActionForward in project sonar-java by SonarSource.

the class ForwardTag method doEndTag.

/**
 * Look up the ActionForward associated with the specified name, and
 * perform a forward or redirect to that path as indicated.
 *
 * @throws JspException if a JSP exception has occurred
 */
public int doEndTag() throws JspException {
    // Look up the desired ActionForward entry
    ActionForward forward = null;
    ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
    if (config != null) {
        forward = (ActionForward) config.findForwardConfig(name);
    }
    if (forward == null) {
        JspException e = new JspException(messages.getMessage("forward.lookup", name));
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
    }
    // Forward or redirect to the corresponding actual path
    String path = forward.getPath();
    path = config.getPrefix() + path;
    if (forward.getRedirect()) {
        this.doRedirect(path);
    } else {
        this.doForward(path);
    }
    // Skip the remainder of this page
    return (SKIP_PAGE);
}
Also used : JspException(javax.servlet.jsp.JspException) ModuleConfig(org.apache.struts.config.ModuleConfig) ActionForward(org.apache.struts.action.ActionForward)

Example 39 with ActionForward

use of org.apache.struts.action.ActionForward in project sonar-java by SonarSource.

the class TestActionConfigMatcher method buildActionConfig.

private ActionConfig buildActionConfig(String path) {
    ActionMapping mapping = new ActionMapping();
    mapping.setName("name,{1}");
    mapping.setPath(path);
    mapping.setScope("request");
    mapping.setUnknown(false);
    mapping.setValidate(true);
    mapping.setPrefix("foo,{1}");
    mapping.setSuffix("bar,{1}");
    mapping.setType("foo.bar.{1}Action");
    mapping.setRoles("public,{1}");
    mapping.setParameter("param,{1}");
    mapping.setAttribute("attrib,{1}");
    mapping.setForward("fwd,{1}");
    mapping.setInclude("include,{1}");
    mapping.setInput("input,{1}");
    ForwardConfig cfg = new ActionForward();
    cfg.setName("name");
    cfg.setPath("path,{1}");
    cfg.setModule("mod{1}");
    cfg.setProperty("foo", "bar,{1}");
    mapping.addForwardConfig(cfg);
    cfg = new ActionForward();
    cfg.setName("name2");
    cfg.setPath("path2");
    cfg.setModule("mod{1}");
    mapping.addForwardConfig(cfg);
    ExceptionConfig excfg = new ExceptionConfig();
    excfg.setKey("foo");
    excfg.setType("foo.Bar");
    excfg.setPath("path");
    mapping.addExceptionConfig(excfg);
    excfg = new ExceptionConfig();
    excfg.setKey("foo2");
    excfg.setType("foo.Bar2");
    excfg.setPath("path2");
    mapping.addExceptionConfig(excfg);
    mapping.setProperty("testprop", "testval");
    mapping.setProperty("testprop2", "test{1}");
    mapping.freeze();
    return mapping;
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) ActionForward(org.apache.struts.action.ActionForward)

Example 40 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class AddUserRoleAction method execute.

/**
 * AddUserRoleAction.
 *
 * @param mapping
 *            action mapping
 * @param form
 *            action form
 * @param request
 *            http servlet request
 * @param response
 *            http servlet response
 *
 * @return action forward instance
 *
 * @throws Exception
 *             any errors happened
 */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
    // check admin
    ActionForward forward = this.checkAdmin(mapping, context);
    if (forward != null) {
        return forward;
    }
    long userId = Utility.parseLong(String.valueOf(context.getRequest().getParameter("userId")));
    long roleId = Utility.parseLong(String.valueOf(context.getRequest().getParameter("roleId")));
    UserProfile user = UserManager.getInstance().getUserProfile(userId);
    if (user == null) {
        return this.handleSuccess(mapping, context, "failure");
    }
    PersistenceManager.getInstance().getAuthorizationPersistence().addUserRole(userId, roleId);
    return this.handleSuccess(mapping, context, "success", "?userId=" + userId);
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) ActionForward(org.apache.struts.action.ActionForward)

Aggregations

ActionForward (org.apache.struts.action.ActionForward)117 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)16 ActionMessages (org.apache.struts.action.ActionMessages)14 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)11 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)11 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)9 ActionMessage (org.apache.struts.action.ActionMessage)9 KualiDocumentFormBase (org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)8 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)7 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)7 UserContext (org.mifos.security.util.UserContext)7 IOException (java.io.IOException)6 Date (java.util.Date)6 AuthorizationPersistence (cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence)5 ArrayList (java.util.ArrayList)5 Cookie (javax.servlet.http.Cookie)5 ActionMapping (org.apache.struts.action.ActionMapping)5 CloseSession (org.mifos.framework.util.helpers.CloseSession)5 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)4 IWantDocumentService (edu.cornell.kfs.module.purap.document.service.IWantDocumentService)4