Examples of PatternException


Examples of org.apache.cocoon.sitemap.PatternException

                tokens.add(OPEN_TOKEN);
                int colonPos = indexOf(expr, ":", i);
                int closePos = indexOf(expr, "}", i);
                int openPos  = indexOf(expr, "{", i);
                if (openPos < colonPos && openPos < closePos) {
                    throw new PatternException("Invalid '{' at position "+ i + " in expression " + expr);
                } else if (colonPos < closePos) {
                    // we've found a module
                    Token token;
                    String module = expr.substring(i+1, colonPos);
                   
                    if (module.equals("sitemap")) {
                        // Explicit prefix for sitemap variable
                        needsMapStack = true;
                        token = new Token(PREFIXED_SITEMAP_VAR);
                    } else if (module.startsWith("#")) {
                        // anchor syntax refering to a name result level
                        needsMapStack = true;
                        token = new Token(ANCHOR_VAR, module.substring(1));
                    } else {
                        // Module used
                        token = getNewModuleToken(module);
                    }
                    tokens.add(token);
                    i = colonPos-1;
                } else {
                    // Unprefixed name : sitemap variable
                    needsMapStack = true;
                    tokens.add(getNewSitemapToken(expr.substring(i+1, closePos)));
                    i = closePos-1;
                }
                pos=i+1;
            } else if (c=='}') {
                if (i>0 && expr.charAt(i-1) == '\\') {
                    continue;
                }
                if (i> pos) {
                    tokens.add(new Token(expr.substring(pos, i)));
                }
                closeCount++;
                tokens.add(CLOSE_TOKEN);
                pos=i+1;
            } else if (c==':') {
                if (tokens.size()>0) {
                    int lastTokenType = ((Token)tokens.get(tokens.size()-1)).getType();
                    if (lastTokenType != PREFIXED_SITEMAP_VAR &&
                        lastTokenType != ANCHOR_VAR &&
                        lastTokenType != THREADSAFE_MODULE &&
                        lastTokenType != STATEFUL_MODULE) {
                            continue;
                    }
                }
                if (i != pos || tokens.size()==0) {
                    // this colon isn't part of a module reference
                    continue;
                }
                if (i> pos) {
                    tokens.add(new Token(expr.substring(pos, i)));
                }
                tokens.add(COLON_TOKEN);
                pos=i+1;
            }
        }
        if (i> pos) {
            tokens.add(new Token(expr.substring(pos, i)));
        }
        if (openCount != closeCount) {
            throw new PatternException("Mismatching braces in expression: " + expr);
        }
    }
View Full Code Here

Examples of org.apache.cocoon.sitemap.PatternException

        if (this.selector == null) {
            try {
                // First access to a module : lookup selector
                this.selector = (ComponentSelector)this.manager.lookup(InputModule.ROLE + "Selector");
            } catch(ComponentException ce) {
                throw new PatternException("Cannot access input modules selector", ce);
            }
        }
       
        // Get the module
        InputModule module;
        try {
            module = (InputModule)this.selector.select(moduleName);
        } catch(ComponentException ce) {
            throw new PatternException("Cannot get InputModule named '" + moduleName +
                "' in expression '" + this.originalExpr + "'", ce);
        }
        Token token;
       
        // Is this module threadsafe ?
View Full Code Here

Examples of org.apache.cocoon.sitemap.PatternException

        List mapStack = null; // get the stack only when necessary - lazy inside the loop
        int stackSize = 0;
       
        if (needsMapStack) {
            if (context == null) {
                throw new PatternException("Need an invoke context to resolve " + this);
            }
            mapStack = context.getMapStack();
            stackSize = mapStack.size();
        }

        Stack stack = new Stack();

        for (Iterator i = tokens.iterator(); i.hasNext();) {
            Token token = (Token) i.next();
            Token last;
            switch (token.getType()){
                case TEXT:
                    if (stack.empty()) {
                        stack.push(new Token(EXPR, token.getStringValue()));
                    } else {
                        last = (Token)stack.peek();
                        if (last.hasType(EXPR)) {
                            last.merge(token);
                        } else {
                            stack.push(new Token(EXPR, token.getStringValue()));
                        }
                    }
                    break;
                case CLOSE:
                    Token expr = (Token)stack.pop();
                    Token lastButOne = (Token)stack.pop();
                    Token result;
                    if (expr.hasType(COLON)) { // i.e. nothing was specified after the colon
                        stack.pop(); // Pop the OPEN
                        result = processModule(lastButOne, EMPTY_TOKEN, objectModel, context, mapStack, stackSize);
                    } else if (lastButOne.hasType(COLON)) {
                        Token module = (Token)stack.pop();
                        stack.pop(); // Pop the OPEN
                        result = processModule(module, expr, objectModel, context, mapStack, stackSize);
                    } else {
                        result = processVariable(expr, mapStack, stackSize);
                    }
                    if (stack.empty()) {
                        stack.push(result);
                    } else {
                        last = (Token)stack.peek();
                        if (last.hasType(EXPR)) {
                            last.merge(result);
                        } else {
                            stack.push(result);
                        }
                    }
                    break;
                case OPEN:
                case COLON:
                case EVAL:
                case SITEMAP_VAR:
                case ANCHOR_VAR:
                case THREADSAFE_MODULE:
                case STATEFUL_MODULE:
                case ROOT_SITEMAP_VARIABLE:
                default: {
                    stack.push(token);
                    break;
                }
            }
        }
        if (stack.size() !=1) {
            throw new PatternException("Evaluation error in expression: " + originalExpr);
        }
        return ((Token)stack.pop()).getStringValue();
    }
View Full Code Here

Examples of org.apache.cocoon.sitemap.PatternException

       
        if (type == ANCHOR_VAR) {
            Map levelResult = context.getMapByAnchor(module.getStringValue());
   
            if (levelResult == null) {
              throw new PatternException("Error while evaluating '" + this.originalExpr +
                "' : no anchor '" + String.valueOf(module.getStringValue()) + "' found in context");
            }
   
            Object result = levelResult.get(expr.getStringValue());
            return new Token(EXPR, result==null ? "" : result.toString());
        } else if (type == THREADSAFE_MODULE) {
            try {                   
                InputModule im = module.getModule();
                Object result = im.getAttribute(expr.getStringValue(), null, objectModel);
                return new Token(EXPR, result==null ? "" : result.toString());

            } catch(ConfigurationException confEx) {
                throw new PatternException("Cannot get variable '" + expr.getStringValue() +
                    "' in expression '" + this.originalExpr + "'", confEx);
            }
            
        } else if (type == STATEFUL_MODULE) {
            InputModule im = null;
            String moduleName = module.getStringValue();
            try {
                im = (InputModule)this.selector.select(moduleName);
                               
                Object result = im.getAttribute(expr.getStringValue(), null, objectModel);
                return new Token(EXPR, result==null ? "" : result.toString());

            } catch(ComponentException compEx) {
                throw new PatternException("Cannot get module '" + moduleName +
                    "' in expression '" + this.originalExpr + "'", compEx);
                                   
            } catch(ConfigurationException confEx) {
                throw new PatternException("Cannot get variable '" + expr.getStringValue() +
                    "' in expression '" + this.originalExpr + "'", confEx);
                                   
            } finally {
                this.selector.release(im);
            }
        } else if (type == PREFIXED_SITEMAP_VAR) {
            // Prefixed sitemap variable must be parsed at runtime
            String variable = expr.getStringValue();
            Token token;
            if (variable.startsWith("/")) {
                token = new Token(ROOT_SITEMAP_VARIABLE, variable.substring(1));
            } else {
                // Find level
                int level = 1; // Start at 1 since it will be substracted from list.size()
                int pos = 0;
                while (variable.startsWith("../", pos)) {
                    level++;
                    pos += "../".length();
                }
                token = new Token(level, variable.substring(pos));
            }
            return processVariable(token, mapStack, stackSize);
        } else {
            throw new PatternException("Unknown token type: " + expr.getType());
        }
    }
View Full Code Here

Examples of org.apache.cocoon.sitemap.PatternException

            Object result = ((Map)mapStack.get(0)).get(value);
            return new Token(EXPR, result==null ? "" : result.toString());
        } else {
            // relative sitemap variable
            if (type > stackSize) {
                throw new PatternException("Error while evaluating '" + this.originalExpr +
                    "' : not so many levels");
            }
   
            Object result = ((Map)mapStack.get(stackSize - type)).get(value);
            return new Token(EXPR, result==null ? "" : result.toString());
View Full Code Here

Examples of org.apache.cocoon.sitemap.PatternException

                    pos += "../".length();
                }

                int end = expr.indexOf('}', pos);
                if (end == -1) {
                    throw new PatternException("Unmatched '{' in " + expr);
                }

                stringList.add(expr.substring(pos, end));
                levelList.add(new Integer(level));
View Full Code Here

Examples of org.apache.cocoon.sitemap.PatternException

                if (level == -1) {
                    result.append(this.strings[i]);

                } else {
                    if (level > stackSize) {
                        throw new PatternException("Error while evaluating '" + this.originalExpr +
                            "' : not so many levels");
                    }

                    Object value = ((Map)mapStack.get(stackSize - level)).get(this.strings[i]);
                    if (value != null) {
View Full Code Here

Examples of org.apache.cocoon.sitemap.PatternException

                addLiteral(expr.substring(prev, pos - 1));
            }

            int end = expr.indexOf('}', pos);
            if (end == -1) {
                throw new PatternException("Unmatched '{' in " + expr);
            }

            int colon = expr.indexOf(':', pos);
            if (colon != -1 && colon < end) {
                   
                String module = expr.substring(pos, colon);
                String variable = expr.substring(colon + 1, end);

                // Module used
                addModuleVariable(module, variable);
            } else {
                throw new PatternException("Unknown variable format " + expr.substring(pos, end));
            }

            prev = end + 1;
        }
    }
View Full Code Here

Examples of org.apache.cocoon.sitemap.PatternException

        if (this.selector == null) {
            try {
                // First access to a module : lookup selector
                this.selector = (ServiceSelector)this.manager.lookup(InputModule.ROLE + "Selector");
            } catch(ServiceException ce) {
                throw new PatternException("Cannot access input modules selector", ce);
            }
        }
       
        // Get the module
        InputModule module;
        try {
            module = (InputModule)this.selector.select(moduleName);
        } catch(ServiceException ce) {
            throw new PatternException("Cannot get InputModule named '" + moduleName +
                "' in expression '" + this.expression + "'", ce);
        }
       
        // Is this module threadsafe ?
        if (module instanceof ThreadSafe) {
View Full Code Here

Examples of org.apache.cocoon.sitemap.PatternException

                        if (value != null) {
                            result.append(value);
                        }

                    } catch(ConfigurationException confEx) {
                        throw new PatternException("Cannot get variable '" + variable +
                            "' in expression '" + this.expression + "'", confEx);
                    }
                }
                break;
               
                case STATEFUL_MODULE :
                {
                    InputModule module = null;
                    String moduleName = (String)items.get(++i);
                    String variableName = (String)items.get(++i);
                    try {
                        module = (InputModule)this.selector.select(moduleName);
                       
                        Object value = module.getAttribute(variableName, null, ContextHelper.getObjectModel(this.context));
                       
                        if (value != null) {
                            result.append(value);
                        }
                       
                    } catch(ServiceException compEx) {
                        throw new PatternException("Cannot get module '" + moduleName +
                            "' in expression '" + this.expression + "'", compEx);
                           
                    } catch(ConfigurationException confEx) {
                        throw new PatternException("Cannot get variable '" + variableName +
                            "' in expression '" + this.expression + "'", confEx);
                           
                    } finally {
                        this.selector.release(module);
                    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.