Search in sources :

Example 1 with WithParameters

use of com.manydesigns.portofino.dispatcher.WithParameters in project Portofino by ManyDesigns.

the class DepthFirstVisitor method visit.

public void visit(Resource resource) throws Exception {
    if (resource instanceof WithParameters) {
        WithParameters withParameters = (WithParameters) resource;
        for (int i = 0; i < withParameters.getMinParameters(); i++) {
            withParameters.consumeParameter("{" + withParameters.getParameterName(i) + "}");
        }
    }
    visitResource(resource);
    if (resource instanceof WithParameters && ((WithParameters) resource).getMinParameters() == 0) {
        WithParameters withParameters = (WithParameters) resource;
        for (int i = 0; i < Math.min(maxParameters, withParameters.getMaxParameters()); i++) {
            withParameters.consumeParameter("{" + withParameters.getParameterName(i) + "}");
        }
        visitResource(resource);
    }
}
Also used : WithParameters(com.manydesigns.portofino.dispatcher.WithParameters)

Example 2 with WithParameters

use of com.manydesigns.portofino.dispatcher.WithParameters in project Portofino by ManyDesigns.

the class ActionsAction method getResource.

public Resource getResource(String actionPath) {
    Resource resource = getRoot();
    if (actionPath.isEmpty()) {
        return resource;
    }
    String[] pathSegments = actionPath.split("/");
    for (String segment : pathSegments) {
        if (resource instanceof WithParameters) {
            WithParameters withParameters = (WithParameters) resource;
            if (withParameters.getParameters().size() < withParameters.getMinParameters()) {
                withParameters.consumeParameter(segment);
                continue;
            }
        }
        Object subResource = null;
        try {
            subResource = resource.getSubResource(segment);
        } catch (Exception e) {
            logger.debug("Could not load resource", e);
        }
        if (subResource instanceof Resource) {
            resource = (Resource) subResource;
        } else if (resource instanceof WithParameters) {
            WithParameters withParameters = (WithParameters) resource;
            if (withParameters.getParameters().size() < withParameters.getMaxParameters()) {
                withParameters.consumeParameter(segment);
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
    return resource;
}
Also used : Resource(com.manydesigns.portofino.dispatcher.Resource) FileObject(org.apache.commons.vfs2.FileObject) WithParameters(com.manydesigns.portofino.dispatcher.WithParameters) FileSystemException(org.apache.commons.vfs2.FileSystemException)

Aggregations

WithParameters (com.manydesigns.portofino.dispatcher.WithParameters)2 Resource (com.manydesigns.portofino.dispatcher.Resource)1 FileObject (org.apache.commons.vfs2.FileObject)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1