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

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


            } 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


    }

    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");
        debug.close();
        request.appendHtml(debug.toString());
    }
View Full Code Here

        final String name = request.getOptionalProperty(NAME);
        final boolean showAsButton = request.isRequested("show-as-button", false);
        final String linkClass = request.getOptionalProperty(CLASS, showAsButton ? "button" : defaultLinkClass());
        final String containerClass = request.getOptionalProperty(CONTAINER_CLASS, "action");
        final String object = request.getOptionalProperty(OBJECT);
        final RequestContext context = request.getContext();
        String objectId = object != null ? object : (String) context.getVariable(RequestContext.RESULT);
        ObjectAdapter adapter = MethodsUtils.findObject(context, objectId);

        // REVIEW this is common used code
        final String fieldName = request.getOptionalProperty(FIELD);
        if (fieldName != null) {
            final ObjectAssociation field = adapter.getSpecification().getAssociation(fieldName);
            if (field == null) {
                throw new ScimpiException("No field " + fieldName + " in " + adapter.getSpecification().getFullIdentifier());
            }
           
            // REVIEW: should provide this rendering context, rather than hardcoding.
            // the net effect currently is that class members annotated with
            // @Hidden(where=Where.ANYWHERE) or @Disabled(where=Where.ANYWHERE) will indeed
            // be hidden/disabled, but will be visible/enabled (perhaps incorrectly)
            // for any other value for Where
            final Where where = Where.ANYWHERE;
           
            if (field.isVisible(IsisContext.getAuthenticationSession(), adapter, where).isVetoed()) {
                throw new ForbiddenException(field, ForbiddenException.VISIBLE);
            }
            IsisContext.getPersistenceSession().resolveField(adapter, field);
            adapter = field.get(adapter);
            if (adapter != null) {
                objectId = context.mapObject(adapter, Scope.INTERACTION);
            }
        }

        if (adapter != null && valid(request, adapter)) {
            final String variable = request.getOptionalProperty("param-name", RequestContext.RESULT);
            final String variableSegment = variable + "=" + objectId;

            String view = request.getOptionalProperty(VIEW);
            if (view == null) {
                view = defaultView();
            }
            view = context.fullUriPath(view);
            final String classSegment = " class=\"" + linkClass + "\"";
            final String titleSegment = title == null ? "" : (" title=\"" + title + "\"");
            String additionalSegment = additionalParameters(request);
            additionalSegment = additionalSegment == null ? "" : "&amp;" + additionalSegment;
            if (showAsButton) {
                request.appendHtml("<div class=\"" + containerClass + "\">");
            }
            request.appendHtml("<a" + classSegment + titleSegment + " href=\"" + view + "?" + variableSegment + context.encodedInteractionParameters() + additionalSegment + "\">");
            request.pushNewBuffer();
            request.processUtilCloseTag();
            final String buffer = request.popBuffer();
            if (buffer.trim().length() > 0) {
                request.appendHtml(buffer);
View Full Code Here

        final String variableName = request.getRequiredProperty(NAME);
        final String defaultObjectId = request.getOptionalProperty(DEFAULT);
        final String scopeName = request.getOptionalProperty(SCOPE);
        final Scope scope = RequestContext.scope(scopeName, Scope.REQUEST);

        final RequestContext context = request.getContext();
        final ObjectAdapter sourceObject = context.getMappedObject(sourceObjectId);
        final boolean isSourceSet = sourceObject != null;
        final boolean isSourceAssignable = isSourceSet && (cls == null || cls.isAssignableFrom(sourceObject.getObject().getClass()));
        if (isSourceAssignable) {
            request.appendDebug("     " + variableName + " set to " + sourceObjectId + " (" + scope + ")");
            context.addVariable(variableName, sourceObjectId, scope);
        } else {
            request.appendDebug("     " + variableName + " set to " + sourceObjectId + " (" + scope + ")");
            if (defaultObjectId != null) {
                context.addVariable(variableName, defaultObjectId, scope);
            }
            context.changeScope(variableName, scope);
        }
    }
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();
            String type = request.getOptionalProperty(TYPE, "details");

            if (type.equals("graph")) {
                specificationGraph(request, specification, null, new ArrayList<ObjectSpecification>(), 0);
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

    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

            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, where).isVetoed()) {
            LOG.info("action not visible " + action.getName());
            return;
        }
        final Consent usable = action.isUsable(IsisContext.getAuthenticationSession(), object, where);
        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 objectId = context.mapObject(object, Scope.INTERACTION);
        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=\"" +  StringEscapeUtils.escapeHtml(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 ObjectAdapter element = iterator.next();

            request.appendHtml("<li>");
            if (linkRow != null) {
                final Scope scope = linkRow == null ? Scope.INTERACTION : RequestContext.scope(linkRow.getScope());
                RequestContext context = request.getContext();
                final String rowId = context.mapObject(element, scope);
                request.appendHtml("<a class=\"item-select\" href=\"" + linkRow.getForwardView() + "?" + linkRow.getVariable()
                        + "=" + rowId + context.encodedInteractionParameters() + "\">");
            }
            request.appendAsHtmlEncoded(element.titleString());
            if (linkRow != null) {
                request.appendHtml("</a>");
            }
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.