Package org.apache.cocoon.sitemap

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);
        }
       
        // Is this module threadsafe ?
        if (module instanceof ThreadSafe) {
View Full Code Here


            int type = ((Integer)this.items.get(i)).intValue();
           
            if (type > 0) {
                // relative sitemap variable
                if (type > stackSize) {
                    throw new PatternException("Error while evaluating '" + this.originalExpr +
                        "' : not so many levels");
                }

                Object key = this.items.get(++i);
                Object value = ((Map)mapStack.get(stackSize - type)).get(key);
                if (value != null) {
                    result.append(value);
                }
               
            } else {
                // other variable types
                switch(type) {
                    case LITERAL :
                        result.append(items.get(++i));
                    break;

                    case ROOT :
                    {
                        Object key = this.items.get(++i);
                        Object value = ((Map)mapStack.get(0)).get(key);
                        if (value != null) {
                            result.append(value);
                        }
                    }
                    break;

                    case ANCHOR:
                    {
                        String name = (String) this.items.get(++i);
                        Object variable = this.items.get(++i);
                        Map levelResult = null; //context.getMapByAnchor(name);

                        if (levelResult == null) {
                          throw new PatternException("Error while evaluating '" + this.originalExpr +
                            "' : no anchor '" + String.valueOf(name) + "' found in context");
                        }

                        Object value = levelResult.get(variable);
                        if (value != null) {
                            result.append(value);
                        }
                    }
                    break;

                    case THREADSAFE_MODULE :
                    {
                        InputModule module = (InputModule)items.get(++i);
                        String variable = (String)items.get(++i);
                       
                        try {                   
                            Object value = module.getAttribute(variable, null, objectModel);
                           
                            if (value != null) {
                                result.append(value);
                            }
   
                        } catch(ConfigurationException confEx) {
                            throw new PatternException("Cannot get variable '" + variable +
                                "' in expression '" + this.originalExpr + "'", 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, objectModel);
                           
                            if (value != null) {
                                result.append(value);
                            }
                           
                        } catch(ComponentException compEx) {
                            throw new PatternException("Cannot get module '" + moduleName +
                                "' in expression '" + this.originalExpr + "'", compEx);
                               
                        } catch(ConfigurationException confEx) {
                            throw new PatternException("Cannot get variable '" + variableName +
                                "' in expression '" + this.originalExpr + "'", confEx);
                               
                        } finally {
                            this.selector.release(module);
                        }
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 = ObjectModelHelper.getRequest(objectModel);
        Cookie[] cookies = request.getCookies();
        HashMap result = null;
View Full Code Here

     * Match the prepared pattern against the result of {@link #getMatchString(Map, Parameters)}.
     */
    public Map preparedMatch(Object preparedPattern, Map objectModel, Parameters parameters) throws PatternException {

        if(preparedPattern == null) {
            throw new PatternException("A pattern is needed at " +
                    SitemapParameters.getStatementLocation(parameters));
        }

        String match = getMatchString(objectModel, parameters);

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

     * Match the prepared pattern against the value returned by {@link #getMatchString(Map, Parameters)}.
     */
    public Map preparedMatch(Object preparedPattern, Map objectModel, Parameters parameters) throws PatternException {

        if(preparedPattern == null) {
            throw new PatternException("A pattern is needed at " + SitemapParameters.getStatementLocation(parameters));
        }

        RE re = new RE((REProgram)preparedPattern);
        String match = getMatchString(objectModel, parameters);

View Full Code Here

            // Check if source exists
            if (!source.exists()) {
                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));

            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();

            // Cache it with the source validity
            this.mountTables.put(uri, values);

            return mounts;

        } catch (SecurityException e) {
            if (this.ignoreMissingTables) {
                return Collections.EMPTY_MAP;
            } else {
                throw new PatternException("Mount table is not accessible: '" + src + "' (" + e + ")");
            }

        } finally {
            if (source != null) {
                this.resolver.release(source);
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

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

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

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

     * @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

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.