Package org.apache.isis.viewer.scimpi.dispatcher.context

Examples of org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext


        // TODO need a mechanism for globally dealing with encoding; then use
        // the new encode method
        final String confirmSegment = confirm == null ? "" : "&" + "_" + CONFIRM + "=" + URLEncoder.encode(confirm);
        final String messageSegment = completionMessage == null ? "" : "&" + "_" + MESSAGE + "=" + URLEncoder.encode(completionMessage);

        final RequestContext context = request.getContext();
        final ObjectAdapter object = MethodsUtils.findObject(context, objectId);
        final String version = context.mapVersion(object);
        final ObjectAction action = MethodsUtils.findAction(object, method);

        final ActionContent parameterBlock = new ActionContent(action);
        request.setBlockContent(parameterBlock);
        request.pushNewBuffer();
View Full Code Here


            } else if (type.equals("object-graph")) {
                objectGraph(request);

            } else if (type.equals("object")) {
                final String value = request.getOptionalProperty(VALUE);
                final RequestContext context = request.getContext();
                final ObjectAdapter object = context.getMappedObject(value);
                final DebugString str = new DebugString();
                Dump.adapter(object, str);
                Dump.graph(object, IsisContext.getAuthenticationSession(), str);
                request.appendHtml("<h2>" + object.getSpecification().getFullIdentifier() + "</h2>");
                request.appendHtml("<pre class=\"debug\">" + str + "</pre>");
            }

        }

        if (alwaysShow || request.getContext().getDebug() == RequestContext.Debug.ON) {

            final RequestContext context = request.getContext();

            final String id = request.getOptionalProperty("object");
            if (id != null) {
                final ObjectAdapter object = context.getMappedObject(id);
                if (object instanceof DebuggableWithTitle) {
                    final DebugString debug = new DebugString();
                    ((DebuggableWithTitle) object).debugData(debug);
                    request.appendHtml("<pre class=\"debug\">" + debug + "</pre>");
                } else {
                    request.appendHtml(object.toString());
                }
            }

            final String variable = request.getOptionalProperty("variable");
            if (variable != null) {
                final Object object = context.getVariable(variable);
                request.appendHtml(variable + " => " + (object == null ? "null" : object.toString()));
            }

            final String list = request.getOptionalProperty("list");
            if (list != null) {
                final DebugString debug = new DebugString();
                context.append(debug, list);
                request.appendHtml(debug.toString());
            }

            final String uri = request.getOptionalProperty("uri");
            if (uri != null) {
                request.appendHtml("<pre class=\"debug\">");
                request.appendHtml(context.getUri());
                request.appendHtml("</pre>");
            }

        }
    }
View Full Code Here

    @Override
    public void process(final Request request) {
        final String name = request.getRequiredProperty(NAME);

        final RequestContext context = request.getContext();
        if (context.getVariable(name) != null) {
            request.skipUntilClose();
        } else {
            final String scopeName = request.getOptionalProperty(SCOPE);
            final Scope scope = RequestContext.scope(scopeName, Scope.SESSION);

            final String cookieName = request.getOptionalProperty("cookie", name);
            final String cookieValue = context.getCookie(cookieName);
            boolean hasObject;
            if (cookieValue != null) {
                try {
                    context.getMappedObject(cookieValue);
                    hasObject = true;
                } catch (final ObjectNotFoundException e) {
                    hasObject = false;
                }
            } else {
                hasObject = false;
            }

            if (hasObject) {
                request.skipUntilClose();
                context.addVariable(name, cookieValue, scope);
            } else {
                final String expiresString = request.getOptionalProperty("expires", SEVEN_DAYS);
                request.pushNewBuffer();
                request.processUtilCloseTag();
                request.popBuffer();
                final String id = (String) context.getVariable(RequestContext.RESULT);
                final ObjectAdapter variable = context.getMappedObject(id);
                if (variable != null) {
                    context.addCookie(cookieName, id, Integer.valueOf(expiresString));
                    context.addVariable(name, id, scope);
                }
            }
        }
    }
View Full Code Here

    }

    protected void displayVariables(final Request request) {
        request.appendHtml("<h1>Variables</h1>");
        final DebugHtmlString debug = new DebugHtmlString();
        final RequestContext context = request.getContext();
        context.append(debug, "variables");
        request.appendHtml(debug.toString());
    }
View Full Code Here

        request.popBlockContent();
    }

    public static void write(final Request request, final ObjectAdapter object, final ObjectAction action, final String[] parameters, final String objectId, final String version, String forwardResultTo, String forwardVoidTo, String forwardErrorTo, final String variable, final String scope,
            String buttonTitle, final String completionMessage, final String resultOverride, final String idName, final String className) {
        final RequestContext context = request.getContext();

        buttonTitle = buttonTitle != null ? buttonTitle : action.getName();

        if (action.isVisible(IsisContext.getAuthenticationSession(), object).isVetoed()) {
            LOG.info("action not visible " + action.getName());
            return;
        }
        final Consent usable = action.isUsable(IsisContext.getAuthenticationSession(), object);
        if (usable.isVetoed()) {
            LOG.info("action not available: " + usable.getReason());
            return;
        }

        /*
         *
         * TODO this mechanism fails as it tries to process tags - which we dont
         * need! Also it calls action 'edit' (not 'action'). Field[] fields =
         * new Field[0]; HiddenField[] hiddenFields = new HiddenField[] { new
         * HiddenField("service", serviceId), new HiddenField("method",
         * methodName), new HiddenField("view", forwardToView), variable == null
         * ? null : new HiddenField("variable", variable), };
         * Form.createForm(request, buttonTitle, fields, hiddenFields, false);
         */

        final String idSegment = idName == null ? "" : ("id=\"" + idName + "\" ");
        final String classSegment = "class=\"" + (className == null ? "action in-line" : className) + "\"";
        request.appendHtml("\n<form " + idSegment + classSegment + " action=\"action.app\" method=\"post\">\n");
        if (objectId == null) {
            request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + OBJECT + "\" value=\"" + context.getVariable(RequestContext.RESULT) + "\" />\n");
        } else {
            request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + OBJECT + "\" value=\"" + objectId + "\" />\n");
        }
        request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + VERSION + "\" value=\"" + version + "\" />\n");
        if (scope != null) {
            request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + SCOPE + "\" value=\"" + scope + "\" />\n");
        }
        request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + METHOD + "\" value=\"" + action.getId() + "\" />\n");
        if (forwardResultTo != null) {
            forwardResultTo = context.fullFilePath(forwardResultTo);
            request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + VIEW + "\" value=\"" + forwardResultTo + "\" />\n");
        }
        if (forwardErrorTo == null) {
            forwardErrorTo = request.getContext().getResourceFile();
        }
        forwardErrorTo = context.fullFilePath(forwardErrorTo);
        request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + ERROR + "\" value=\"" + forwardErrorTo + "\" />\n");
        if (forwardVoidTo == null) {
            forwardVoidTo = request.getContext().getResourceFile();
        }
        forwardVoidTo = context.fullFilePath(forwardVoidTo);
        request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + VOID + "\" value=\"" + forwardVoidTo + "\" />\n");
        if (variable != null) {
            request.appendHtml("  <input type=\"hidden\" name=\"" + "_" + RESULT_NAME + "\" value=\"" + variable + "\" />\n");
        }
        if (resultOverride != null) {
View Full Code Here

        final boolean isForced = request.isRequested("force");
        if (isForced || request.getContext().showDebugData()) {
            request.appendHtml("<div class=\"debug\">");
            if ("page".equals(type)) {
                request.appendHtml("<pre>");
                final RequestContext context = request.getContext();
                request.appendHtml("URI:  " + context.getUri());
                request.appendHtml("\n");
                request.appendHtml("File: " + context.fullFilePath(context.getResourceFile()));
                final String result = (String) request.getContext().getVariable(RequestContext.RESULT);
                if (result != null) {
                    request.appendHtml("\n");
                    request.appendHtml("Object: " + result);
                }
                request.appendHtml("</pre>");
            } else if ("session".equals(type)) {
                request.appendHtml("<pre>");
                final AuthenticationSession session = IsisContext.getAuthenticationSession();
                request.appendHtml("Session:  " + session.getUserName() + " " + session.getRoles());
                request.appendHtml("</pre>");
            } else if ("variables".equals(type)) {
                final RequestContext context = request.getContext();
                final DebugHtmlString debug = new DebugHtmlString();
                debug.appendln("", "");
                context.append(debug, "variables");
                debug.close();
                request.appendHtml(debug.toString());
            } else if ("processing".equals(type)) {
                request.appendHtml("<pre>");
                request.appendHtml(request.getContext().getDebugTrace());
View Full Code Here

public class Specification extends AbstractElementProcessor {

    @Override
    public void process(final Request request) {
        final RequestContext context = request.getContext();
        if (context.isDebugDisabled()) {
            return;
        }

        if (request.isRequested("always") || context.getDebug() == RequestContext.Debug.ON) {
            request.appendHtml("<div class=\"debug\">");
            request.appendHtml("<pre>");

            final String id = request.getOptionalProperty("object");
            final ObjectAdapter object = context.getMappedObjectOrResult(id);
            final ObjectSpecification specification = object.getSpecification();
            request.appendHtml(specification.getSingularName() + " (" + specification.getFullIdentifier() + ") \n");
            final List<ObjectAssociation> fields = specification.getAssociations();
            for (int i = 0; i < fields.size(); i++) {
                request.appendHtml("    " + fields.get(i).getName() + " (" + fields.get(i).getSpecification().getSingularName() + ") \n");
View Full Code Here

    public void process(final Request request) {
        final String title = request.getOptionalProperty(BUTTON_TITLE, "Remove From List");
        final String cls = request.getOptionalProperty(CLASS, "action in-line delete confirm");
        final String object = request.getOptionalProperty(OBJECT);
        final String resultOverride = request.getOptionalProperty(RESULT_OVERRIDE);
        final RequestContext context = request.getContext();
        final String objectId = object != null ? object : (String) context.getVariable(RequestContext.RESULT);
        final ObjectAdapter adapter = MethodsUtils.findObject(context, objectId);

        final String element = request.getOptionalProperty(ELEMENT, (String) context.getVariable(ELEMENT));
        final ObjectAdapter elementId = MethodsUtils.findObject(context, element);

        final String fieldName = request.getRequiredProperty(FIELD);

        String view = request.getOptionalProperty(VIEW);
        view = context.fullFilePath(view == null ? context.getResourceFile() : view);
        String error = request.getOptionalProperty(ERROR);
        error = context.fullFilePath(error == null ? context.getResourceFile() : error);

        request.processUtilCloseTag();

        write(request, adapter, fieldName, elementId, resultOverride, view, error, title, cls);
    }
View Full Code Here

        return "print-authorization-clause";
    }

    @Override
    public void process(final Request request) {
        final RequestContext context = request.getContext();
        if (context.isDebugDisabled()) {
            return;
        }

        final Identifier identifier = (Identifier) context.getVariable("_security-identifier");
        final List<String> roles = (List<String>) context.getVariable("_security-roles");
        final StringBuffer roleList = new StringBuffer();
        for (final String role : roles) {
            if (roleList.length() > 0) {
                roleList.append("|");
            }
View Full Code Here

    public static void createForm(final Request request, final CreateFormParameter parameterObject) {
        createForm(request, parameterObject, false);
    }

    protected static void createForm(final Request request, final CreateFormParameter parameterObject, final boolean withoutProcessing) {
        final RequestContext context = request.getContext();
        final ObjectAdapter object = MethodsUtils.findObject(context, parameterObject.objectId);
        final String version = request.getContext().mapVersion(object);
        final ObjectAction action = MethodsUtils.findAction(object, parameterObject.methodName);
        // TODO how do we distinguish between overloaded methods?

        // REVIEW Is this useful?
        if (action.getParameterCount() == 0) {
            throw new ScimpiException("Action form can only be used for actions with parameters");
        }
        if (parameterObject.showMessage && MethodsUtils.isVisible(object, action)) {
            final String notUsable = MethodsUtils.isUsable(object, action);
            if (notUsable != null) {
                if (!withoutProcessing) {
                    request.skipUntilClose();
                }
                request.appendHtml("<div class=\"" + parameterObject.className + "-message\" >");
                request.appendAsHtmlEncoded(notUsable);
                request.appendHtml("</div>");
                return;
            }
        }
        if (!MethodsUtils.isVisibleAndUsable(object, action)) {
            if (!withoutProcessing) {
                request.skipUntilClose();
            }
            return;
        }
        final String objectId = context.mapObject(object, Scope.INTERACTION);
        final String errorView = context.fullFilePath(parameterObject.forwardErrorTo == null ? context.getResourceFile() : parameterObject.forwardErrorTo);
        final String voidView = context.fullFilePath(parameterObject.forwardVoidTo == null ? context.getResourceFile() : parameterObject.forwardVoidTo);
        final HiddenInputField[] hiddenFields = new HiddenInputField[] { new HiddenInputField("_" + OBJECT, objectId), new HiddenInputField("_" + VERSION, version), new HiddenInputField("_" + FORM_ID, parameterObject.formId), new HiddenInputField("_" + METHOD, parameterObject.methodName),
                parameterObject.forwardResultTo == null ? null : new HiddenInputField("_" + VIEW, context.fullFilePath(parameterObject.forwardResultTo)), new HiddenInputField("_" + VOID, voidView), new HiddenInputField("_" + ERROR, errorView),
                parameterObject.completionMessage == null ? null : new HiddenInputField("_" + MESSAGE, parameterObject.completionMessage), parameterObject.scope == null ? null : new HiddenInputField("_" + SCOPE, parameterObject.scope),
                parameterObject.resultOverride == null ? null : new HiddenInputField("_" + RESULT_OVERRIDE, parameterObject.resultOverride), parameterObject.resultName == null ? null : new HiddenInputField("_" + RESULT_NAME, parameterObject.resultName),
                parameterObject.resultName == null ? null : new HiddenInputField(RequestContext.RESULT, (String) request.getContext().getVariable(RequestContext.RESULT)) };

        // TODO when the block contains a selector tag it doesn't disable it if
        // the field cannot be edited!!!
        final FormFieldBlock containedBlock = new FormFieldBlock() {
            @Override
            public boolean isNullable(final String name) {
                final int index = Integer.parseInt(name.substring(5)) - 1;
                final ObjectActionParameter param = action.getParameters().get(index);
                return param.isOptional();
            }
        };
        request.setBlockContent(containedBlock);
        if (!withoutProcessing) {
            request.processUtilCloseTag();
        }

        final FormState entryState = (FormState) context.getVariable(ENTRY_FIELDS);

        // TODO the list of included fields should be considered in the next
        // method (see EditObject)
        final InputField[] formFields = createFields(action, object);
        containedBlock.hideExcludedParameters(formFields);
View Full Code Here

TOP

Related Classes of org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext

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.