Package org.apache.cocoon.sitemap

Examples of org.apache.cocoon.sitemap.PatternException


     * @throws PatternException DOCUMENT ME!
     */
    protected REProgram preparePattern(String pattern)
        throws PatternException {
        if (pattern == null) {
            throw new PatternException("null passed as a pattern", null);
        }

        if (pattern.length() == 0) {
            pattern = "^$";

            if (getLogger().isWarnEnabled()) {
                getLogger().warn("The empty pattern string was rewritten to '^$'" +
                    " to match for empty strings.  If you intended" +
                    " to match all strings, please change your" + " pattern to '.*'");
            }
        }

        try {
            RECompiler compiler = new RECompiler();
            REProgram program = compiler.compile(pattern);

            return program;
        } catch (RESyntaxException rse) {
            getLogger().debug("Failed to compile the pattern '" + pattern + "'", rse);
            throw new PatternException(rse.getMessage(), rse);
        }
    }
View Full Code Here


     * @throws PatternException when something went wrong.
     */
    protected REProgram preparePattern(String pattern)
        throws PatternException {
        if (pattern == null) {
            throw new PatternException("null passed as a pattern", null);
        }

        if (pattern.length() == 0) {
            pattern = "^$";

            if (getLogger().isWarnEnabled()) {
                getLogger().warn("The empty pattern string was rewritten to '^$'" +
                    " to match for empty strings.  If you intended" +
                    " to match all strings, please change your" + " pattern to '.*'");
            }
        }

        try {
            RECompiler compiler = new RECompiler();
            REProgram program = compiler.compile(pattern);

            return program;
        } catch (RESyntaxException rse) {
            getLogger().debug("Failed to compile the pattern '" + pattern + "'", rse);
            throw new PatternException(rse.getMessage(), rse);
        }
    }
View Full Code Here

            REProgram program = compiler.compile(pattern);
            return program;
           
        } catch (RESyntaxException rse) {
            getLogger().debug("Failed to compile the pattern '" + pattern + "'", rse);
            throw new PatternException(rse.getMessage(), rse);
        }
    }
View Full Code Here

     * Compile the pattern in a <code>org.apache.regexp.REProgram</code>.
     */
    public Object preparePattern(String pattern) throws PatternException {
        if (pattern == null)
        {
            throw new PatternException("null passed as a pattern", null);
        }

        if (pattern.length() == 0)
        {
            pattern = "^$";
            if (getLogger().isWarnEnabled()) {
                getLogger().warn("The empty pattern string was rewritten to '^$'"
                                 + " to match for empty strings.  If you intended"
                                 + " to match all strings, please change your"
                                 + " pattern to '.*'");
            }
        }

        try {
            RECompiler compiler = new RECompiler();
            REProgram program = compiler.compile(pattern);
            return program;

        } catch (RESyntaxException rse) {
            getLogger().debug("Failed to compile the pattern '" + pattern + "'", rse);
            throw new PatternException(rse.getMessage(), rse);
        }
    }
View Full Code Here

    public Map match(String pattern, Map objectModel, Parameters parameters)
            throws PatternException {

        if (pattern == null) {
            throw new PatternException("No cookie name given.");
        }

        Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
        Cookie[] cookies = request.getCookies();
        HashMap result = null;
View Full Code Here

                    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

                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

        if (!source.exists()) {
            resolver.release(source);
            if (this.ignoreMissingTables) {
                return Collections.EMPTY_MAP;
            } else {
                throw new PatternException("Mount table does not exist: '" + uri + "'");
            }
        }
       
        // Source exists
        Object[] values = (Object[])this.mountTables.get(uri);
       
        if (values != null) {
            // Check validity
            SourceValidity oldValidity = (SourceValidity)values[1];
           
            int valid = oldValidity != null ? oldValidity.isValid() : SourceValidity.INVALID;
           
            if (valid == SourceValidity.VALID) {
                // Valid without needing the new validity
                return (Map)values[0];
            }
           
            if (valid == SourceValidity.UNKNOWN &&
                oldValidity.isValid(source.getValidity()) == SourceValidity.VALID) {
                // Valid after comparing with the new validity
                return (Map)values[0];
            }
           
            // Invalid: fallback below to read the mount table
        } else {
            values = new Object[2];
        }
       
        // Read the mount table
        Map mounts = new HashMap();
        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
        Configuration config = builder.build(SourceUtil.getInputSource(source));
        this.resolver.release(source);
       
        Configuration[] children = config.getChildren();
        for (int i = 0; i < children.length; i++) {
            Configuration child = children[i];
            if ("mount".equals(child.getName())) {
                String prefix = children[i].getAttribute("uri-prefix");
                // Append a '/' at the end of a not-empty prefix
                // this avoids flat uri matching which would cause
                // exceptions in the sub sitemap!
                if (!prefix.endsWith("/") && prefix.length() != 0) {
                    prefix = prefix + '/';
                }
                mounts.put(prefix, children[i].getAttribute("src"));
            } else {
                throw new PatternException(
                    "Unexpected element '" + child.getName() + "' (awaiting 'mount'), at " + child.getLocation());
            }
        }
        values[0] = mounts;
        values[1] = source.getValidity();
View Full Code Here

        try {
            mounts = getMountTable(pattern);
        } catch(PatternException pe) {
            throw pe;
        } catch(Exception e) {
            throw new PatternException(e);
        }
       
        // Get the request URI
        Request request = ObjectModelHelper.getRequest(objectModel);
        String uri = request.getSitemapURI();
View Full Code Here

                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

TOP

Related Classes of org.apache.cocoon.sitemap.PatternException

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.