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

Examples of org.apache.isis.viewer.scimpi.dispatcher.ScimpiException


        // 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
View Full Code Here


        }
    }

    private void disallowSourceAndDefault(final Request request) {
        if (request.getOptionalProperty(DEFAULT) != null && request.getOptionalProperty(OBJECT) != null) {
            throw new ScimpiException("Cannot specify both " + OBJECT + " and " + DEFAULT + " for the " + getName() + " element");
        }
    }
View Full Code Here

            if (propertyName.equals("set")) {
                result = request.isPropertySet("set");
            } else {
                final Test test = tests.get(propertyName);
                if (test == null) {
                    throw new ScimpiException("No such test: " + propertyName);
                }
                final String attributeValue = request.getOptionalProperty(propertyName, false);
                result = test.test(request, attributeValue, id);
                if (test.negateResult) {
                    result = !result;
                }
            }
            checkMade = true;
            allConditionsMet &= result;
        }

        /*
         *
         * // Check variables if
         * (request.isPropertySpecified("variable-exists")) { boolean
         * valuePresent = request.isPropertySet("variable-exists"); checkMade =
         * true; allConditionsMet &= valuePresent; }
         *
         * String variable = request.getOptionalProperty("variable-true"); if
         * (variable != null) { String value = (String)
         * request.getContext().getVariable(variable); checkMade = true;
         * allConditionsMet &= Attributes.isTrue(value); }
         *
         * variable = request.getOptionalProperty("variable-equals"); if
         * (variable != null) { String value = (String)
         * request.getContext().getVariable(variable); checkMade = true;
         * allConditionsMet &= variable.equals(value); }
         */
        // Check Object

        /*
         * // Check Collection String collection =
         * request.getOptionalProperty("collection-" + TYPE); if (collection !=
         * null) { ObjectAdapter object =
         * MethodsUtils.findObject(request.getContext(), collection); Class<?>
         * cls = forClass(request); TypeOfFacet facet =
         * object.getSpecification().getFacet(TypeOfFacet.class); boolean
         * hasType = object != null && (cls == null ||
         * cls.isAssignableFrom(facet.value())); checkMade = true;
         * allConditionsMet &= hasType;; }
         *
         * collection = request.getOptionalProperty("collection-" + "empty"); if
         * (collection != null) { ObjectAdapter object =
         * MethodsUtils.findObject(request.getContext(), id); CollectionFacet
         * facet = object.getSpecification().getFacet(CollectionFacet.class);
         * boolean isEmpty = facet != null && facet.size(object) == 0;
         * processTags(isEmpty, request); allConditionsMet &= isEmpty; }
         */

        // Check Methods
        /*
         * String method = request.getOptionalProperty(METHOD + "-exists"); if
         * (method != null) { ObjectAdapter object =
         * MethodsUtils.findObject(request.getContext(), id); List<? extends
         * ObjectAction> objectActions =
         * object.getSpecification().getObjectActions(ActionType.USER); boolean
         * methodExists = false; for (ObjectAction objectAssociation :
         * objectActions) { if (objectAssociation.getId().equals(method)) {
         * methodExists = true; break; } } checkMade = true; allConditionsMet &=
         * methodExists; }
         *
         * method = request.getOptionalProperty(METHOD + "-visible"); if (method
         * != null) { ObjectAdapter object =
         * MethodsUtils.findObject(request.getContext(), id); // TODO needs to
         * work irrespective of parameters ObjectAction objectAction =
         * object.getSpecification().getObjectAction(ActionType.USER, method,
         * ObjectSpecification.EMPTY_LIST); Consent visible =
         * objectAction.isVisible(IsisContext.getAuthenticationSession(),
         * object); checkMade = true; allConditionsMet &= visible.isAllowed(); }
         *
         * method = request.getOptionalProperty(METHOD + "-usable"); if (method
         * != null) { ObjectAdapter object =
         * MethodsUtils.findObject(request.getContext(), id); // TODO needs to
         * work irrespective of parameters ObjectAction objectAction =
         * object.getSpecification().getObjectAction(ActionType.USER, method,
         * ObjectSpecification.EMPTY_LIST); Consent usable =
         * objectAction.isUsable(IsisContext.getAuthenticationSession(),
         * object); checkMade = true; allConditionsMet &= usable.isAllowed(); }
         *
         *
         * // Check Fields String field = request.getOptionalProperty(FIELD +
         * "-exists"); if (field != null) { ObjectAdapter object =
         * MethodsUtils.findObject(request.getContext(), id); List<? extends
         * ObjectAssociation> objectFields =
         * object.getSpecification().getAssociations(); boolean fieldExists =
         * false; for (ObjectAssociation objectAssociation : objectFields) { if
         * (objectAssociation.getId().equals(field)) { fieldExists = true;
         * break; } } checkMade = true; allConditionsMet &= fieldExists; }
         *
         * field = request.getOptionalProperty(FIELD + "-visible"); if (field !=
         * null) { ObjectAdapter object =
         * MethodsUtils.findObject(request.getContext(), id); ObjectAssociation
         * objectField = object.getSpecification().getAssociation(field);
         * Consent visible =
         * objectField.isVisible(IsisContext.getAuthenticationSession(),
         * object); checkMade = true; allConditionsMet &= visible.isAllowed(); }
         *
         * field = request.getOptionalProperty(FIELD + "-editable"); if (field
         * != null) { ObjectAdapter object =
         * MethodsUtils.findObject(request.getContext(), id); ObjectAssociation
         * objectField = object.getSpecification().getAssociation(field);
         * Consent usable =
         * objectField.isUsable(IsisContext.getAuthenticationSession(), object);
         * checkMade = true; allConditionsMet &= usable.isAllowed(); }
         *
         * field = request.getOptionalProperty(FIELD + "-empty"); if (field !=
         * null) { ObjectAdapter object =
         * MethodsUtils.findObject(request.getContext(), id); ObjectAssociation
         * objectField = object.getSpecification().getAssociation(field);
         * IsisContext.getPersistenceSession().resolveField(object,
         * objectField); ObjectAdapter fld = objectField.get(object); if (fld ==
         * null) { checkMade = true; allConditionsMet &= true; } else {
         * CollectionFacet facet =
         * fld.getSpecification().getFacet(CollectionFacet.class); boolean
         * isEmpty = facet != null && facet.size(fld) == 0; processTags(isEmpty,
         * request); allConditionsMet &= isEmpty; } }
         *
         * field = request.getOptionalProperty(FIELD + "-set"); if (field !=
         * null) { ObjectAdapter object =
         * MethodsUtils.findObject(request.getContext(), id); ObjectAssociation
         * objectField = object.getSpecification().getAssociation(field);
         * IsisContext.getPersistenceSession().resolveField(object,
         * objectField); ObjectAdapter fld = objectField.get(object); if (fld ==
         * null) { throw new ScimpiException("No object for field-set " +
         * field); } Object fieldValue = fld.getObject(); if (fieldValue
         * instanceof Boolean) { checkMade = true; allConditionsMet &=
         * ((Boolean) fieldValue).booleanValue(); } else { checkMade = true;
         * allConditionsMet &= true; } }
         */

        // Check User
        /*
         * String hasRole = request.getOptionalProperty("has-role"); if (hasRole
         * != null) { AuthenticationSession session =
         * IsisContext.getSession().getAuthenticationSession(); List<String>
         * roles = session.getRoles(); boolean hasMatchingRole = false; for
         * (String role : roles) { if (role.equals(hasRole.trim())) {
         * hasMatchingRole = true; break; } } checkMade = true; allConditionsMet
         * &= hasMatchingRole; }
         */

        final String persistent = request.getOptionalProperty("persistent");
        if (persistent != null) {
            final ObjectAdapter object = request.getContext().getMappedObjectOrResult(persistent);
            checkMade = true;
            allConditionsMet &= object.representsPersistent();
        }
        /*
         * String type = request.getOptionalProperty(TYPE); if (type != null) {
         * ObjectAdapter object = MethodsUtils.findObject(request.getContext(),
         * id); Class<?> cls = forClass(request); boolean hasType = object !=
         * null && (cls == null ||
         * cls.isAssignableFrom(object.getObject().getClass())); checkMade =
         * true; allConditionsMet &= hasType;; }
         */
        if (request.isPropertySpecified("empty")) {
            if (request.isPropertySet("empty")) {
                final String collection = request.getOptionalProperty("empty");
                if (collection != null) {
                    final ObjectAdapter object = request.getContext().getMappedObjectOrResult(collection);
                    final CollectionFacet facet = object.getSpecification().getFacet(CollectionFacet.class);
                    checkMade = true;
                    allConditionsMet &= facet.size(object) == 0;
                }
            } else {
                checkMade = true;
                allConditionsMet &= true;
            }
        }

        if (request.isPropertySpecified("set")) {
            final boolean valuePresent = request.isPropertySet("set");
            checkMade = true;
            allConditionsMet &= valuePresent;
        }

        if (checkMade) {
            processTags(allConditionsMet, request);
        } else {
            throw new ScimpiException("No condition in " + getName());
        }
    }
View Full Code Here

        Class<?> cls = null;
        if (className != null) {
            try {
                cls = Class.forName(className);
            } catch (final ClassNotFoundException e) {
                throw new ScimpiException("No class for " + className, e);
            }
        }
        return cls;
    }
View Full Code Here

    }
   
    protected ObjectAction findMethod(final String attributeName, final ObjectAdapter object) {
        final ObjectAction objectAction = object.getSpecification().getObjectAction(ActionType.USER, attributeName, ObjectSpecification.EMPTY_LIST);
        if (objectAction == null) {
            throw new ScimpiException("No such method found in " + object.getSpecification().getIdentifier().getClassName() + " : " + attributeName);
        }
        return objectAction;
    }
View Full Code Here

    }

    protected ObjectAssociation findProperty(final String attributeName, final ObjectAdapter object) {
        final ObjectAssociation objectField = object.getSpecification().getAssociation(attributeName);
        if (objectField == null) {
            throw new ScimpiException("No such property found in " + object.getSpecification().getIdentifier().getClassName() + ": " + attributeName);
        }
        return objectField;
    }
View Full Code Here

    }

    public static void write(final Request request, final ObjectAdapter adapter, final String fieldName, final ObjectAdapter element, final String resultOverride, final String view, final String error, final String title, final String cssClass) {
        final ObjectAssociation field = adapter.getSpecification().getAssociation(fieldName);
        if (field == null) {
            throw new ScimpiException("No field " + fieldName + " in " + adapter.getSpecification().getFullIdentifier());
        }
        if (!field.isOneToManyAssociation()) {
            throw new ScimpiException("Field " + fieldName + " not a collection, in " + adapter.getSpecification().getFullIdentifier());
        }
        if (field.isVisible(IsisContext.getAuthenticationSession(), adapter, where).isVetoed()) {
            throw new ForbiddenException(field, ForbiddenException.VISIBLE);
        }
        IsisContext.getPersistenceSession().resolveField(adapter, field);
View Full Code Here

            index = 0;
        } else {
            index = Integer.valueOf(field).intValue() - 1;
        }
        if (index < 0 || index >= parameters.size()) {
            throw new ScimpiException("Parameter numbers should be between 1 and " + parameters.size() + ": " + index);
        }

        request.appendAsHtmlEncoded(parameters.get(index).getName());
    }
View Full Code Here

        Page page;
        try {
            page = new Page(in, null);
        } catch (final UnsupportedEncodingException e) {
            throw new ScimpiException(e);
        }
        final Lexer lexer = new Lexer(page);

        Node node = null;
        try {
            Stack<Snippet> tags = allTags;
            String lineNumbers = "1";
            String template = null;
            tags.push(new HtmlSnippet(lineNumbers, filePath));

            // NOTE done like this the tags can be cached for faster processing
            while ((node = lexer.nextNode()) != null) {
                if (node instanceof Remark) {
                    // TODO need to pick up on comments within tags; at the
                    // moment this splits a tag into two causing a
                    // failure later
                    continue;

                } else if (node instanceof TagNode && ((TagNode) node).getTagName().startsWith("SWF:")) {
                    final TagNode tagNode = (TagNode) node;
                    final String tagName = tagNode.getTagName().toUpperCase();
                    LOG.debug(tagName);

                    // TODO remove context & request from Attributes -- the tags
                    // will be re-used across
                    // requests
                    final Attributes attributes = new Attributes(tagNode, context);
                    int type = 0;
                    if (tagNode.isEndTag()) {
                        type = SwfTag.END;
                    } else {
                        type = tagNode.isEmptyXmlTag() ? SwfTag.EMPTY : SwfTag.START;
                    }
                    testForProcessorForTag(lexer, tagName);
                    lineNumbers = lineNumbering(node);
                    final SwfTag tag = new SwfTag(tagName, attributes, type, lineNumbers, loadFile.getCanonicalPath());
                    tags.push(tag);

                    if (tagName.equals("SWF:IMPORT")) {
                        if (!tagNode.isEmptyXmlTag()) {
                            throw new ScimpiException("Import tag must be empty");
                        }
                        String importFile = tagNode.getAttribute("file");
                        if (context.isDebug()) {
                            context.getWriter().println("<!-- " + "import file " + importFile + " -->");
                        }
                        importFile = context.replaceVariables(importFile);
                        parseHtmlFile(loadPath, importFile, context, tags, tagsForPreviousTemplate);
                    }

                    if (tagName.equals("SWF:TEMPLATE")) {
                        if (!tagNode.isEmptyXmlTag()) {
                            throw new ScimpiException("Template tag must be empty");
                        }
                        if (template != null) {
                            throw new ScimpiException("Template tag can only be used once within a file");
                        }
                        template = tagNode.getAttribute("file");
                        template = context.replaceVariables(template);
                        if (context.isDebug()) {
                            context.getWriter().println("<!-- " + "apply template " + template + " -->");
                        }
                        tags = new Stack<Snippet>();
                    }

                    if (tagName.equals("SWF:CONTENT")) {
                        if (!tagNode.isEmptyXmlTag()) {
                            throw new ScimpiException("Content tag must be empty");
                        }
                        if (context.isDebug()) {
                            context.getWriter().println("<!-- " + "insert content into template -->");
                        }
                        tags.addAll(tagsForPreviousTemplate);
                    }
                } else {
                    final Snippet snippet = tags.size() == 0 ? null : tags.peek();
                    if (snippet instanceof HtmlSnippet) {
                        ((HtmlSnippet) snippet).append(node.toHtml());
                    } else {
                        final HtmlSnippet htmlSnippet = new HtmlSnippet(lineNumbers, filePath);
                        htmlSnippet.append(node.toHtml());
                        tags.push(htmlSnippet);
                    }
                }

            }
            in.close();

            if (template != null) {
                final String filePathRoot = loadPath.startsWith("/") ? "" : "/";
                parseHtmlFile(filePathRoot + loadPath, template, context, allTags, tags);
            }

        } catch (final ParserException e) {
            exception(loadPath, node, e);
            // throw new ScimpiException(e);
        } catch (final RuntimeException e) {
            // TODO: extend to deal with other exceptions
            exception(loadPath, node, e);
        } catch (final IOException e) {
            throw new ScimpiException(e);
        }
    }
View Full Code Here

        String element = ("" + node).toLowerCase();
        if (node instanceof TagNode) {
            lineNumbers = ":" + lineNumbering(node);
            element = "tag &lt;" + node.getText() + "&gt;";
        }
        throw new ScimpiException("Error processing " + element + " in " + filePath + lineNumbers, e);
    }
View Full Code Here

TOP

Related Classes of org.apache.isis.viewer.scimpi.dispatcher.ScimpiException

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.