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);
}
}
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;
}
Aggregations