use of io.milton.common.Path in project lobcder by skoulouzis.
the class AnnotationResourceFactory method getResource.
@Override
public Resource getResource(String host, String url) throws NotAuthorizedException, BadRequestException {
log.info("getResource: host: " + host + " - url:" + url);
AnnoCollectionResource hostRoot = locateHostRoot(host, HttpManager.request());
if (hostRoot == null) {
log.warn("Could not find a root resource for host: " + host + " Using " + rootAnnotationHandler.controllerMethods.size() + " root methods");
return null;
}
Resource r;
url = stripContext(url);
if (url.equals("/") || url.equals("")) {
r = hostRoot;
} else {
Path path = Path.path(url);
r = findFromRoot(hostRoot, path);
if (r == null) {
log.info("Resource not found: host=" + host + " path=" + path);
} else {
if (r instanceof AnnoResource) {
AnnoResource ar = (AnnoResource) r;
log.info("Found AnnoResource: " + r.getClass() + " for path=" + path + " with source: " + ar.getSource());
} else {
log.info("Found resource: " + r.getClass() + " for path=" + path);
}
}
}
return r;
}
use of io.milton.common.Path in project lobcder by skoulouzis.
the class WellKnownResourceFactory method getResource.
//
// public WellKnownResourceFactory(ResourceFactory wrapped) {
// this.wrapped = wrapped;
// }
@Override
public Resource getResource(String host, String sPath) throws NotAuthorizedException, BadRequestException {
if (sPath.startsWith(URI_PREFIX)) {
Path path = Path.path(sPath);
path = path.getStripFirst();
WellKnownHandler wellKnown = mapOfWellKnownHandlers.get(path.getFirst());
if (wellKnown != null) {
Resource hostRes = wrapped.getResource(host, "/");
if (hostRes != null) {
return wellKnown.locateWellKnownResource(hostRes);
}
}
}
return wrapped.getResource(host, sPath);
}
use of io.milton.common.Path in project lobcder by skoulouzis.
the class StaticResourceFactory method getResource.
@Override
public Resource getResource(String host, String url) {
Path p = Path.path(url);
String s = stripContext(url);
for (File root : roots) {
File file = new File(root, s);
if (file.exists() && file.isFile()) {
return new StaticResource(file);
}
}
return null;
}
use of io.milton.common.Path in project lobcder by skoulouzis.
the class WebResourceFactory method getResource.
@Override
public Resource getResource(String host, String url) {
Path p = Path.path(url);
String contentType;
if (config != null) {
contentType = MiltonUtils.getContentType(config.getServletContext(), p.getName());
} else {
contentType = ContentTypeUtils.findContentTypes(p.getName());
}
File file;
String path = stripContext(url);
path = basePath + path;
path = path.trim();
String realPath = config.getServletContext().getRealPath(path);
if (realPath != null) {
file = new File(path);
} else {
file = null;
}
if (file == null || !file.exists()) {
URL resource;
try {
resource = config.getServletContext().getResource(path);
} catch (MalformedURLException ex) {
// throw new RuntimeException(ex);
log.warn("malformed url when attempting to locate servlet resource", path);
return null;
}
if (resource != null) {
return new UrlResource(p.getName(), resource, contentType, modDate);
}
return null;
} else {
return new StaticResource(file);
}
}
use of io.milton.common.Path in project lobcder by skoulouzis.
the class GraphPopulator method getTransitions.
private ArrayList<Vertex> getTransitions(Connection connection, ArrayList<Path> nodes) throws SQLException, MalformedURLException {
ArrayList<Vertex> trans = new ArrayList<>();
StringBuilder query = new StringBuilder();
query.append("SELECT requestURL, methodName FROM requests_table WHERE ");
String queryPath;
if (nodes.get(0).isRoot()) {
queryPath = "/lobcder/dav";
} else {
queryPath = nodes.get(0).toString();
}
query.append("(requestURL LIKE '%" + queryPath + "' ");
for (int i = 1; i < nodes.size(); i++) {
if (nodes.get(i).isRoot()) {
queryPath = "/lobcder/dav";
} else {
queryPath = nodes.get(i).toString();
}
query.append("OR requestURL LIKE '%" + queryPath + "' ");
}
query.append(")");
try (PreparedStatement ps = connection.prepareStatement(query.toString())) {
ResultSet rs = ps.executeQuery();
while (rs.next()) {
String url = rs.getString(1);
String method = rs.getString(2);
// log.log(Level.FINE, "URL: {0}", new URL(url).getPath());
// String[] parts = url.split("http://localhost:8080/lobcder/dav");
String strPath = new URL(url).getPath();
String[] parts = strPath.split("/lobcder/dav");
Path path;
if (parts != null && parts.length > 1) {
path = Path.path(parts[1]);
} else {
path = Path.root;
}
trans.add(new Vertex(Method.valueOf(method), path.toString()));
// log.log(Level.FINE, "path: {0} method {1}, size: {2}", new Object[]{path, method, trans.size()});
}
}
return trans;
}
Aggregations