Search in sources :

Example 16 with Path

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;
}
Also used : Path(io.milton.common.Path) Resource(io.milton.resource.Resource) PropFindableResource(io.milton.resource.PropFindableResource) CollectionResource(io.milton.resource.CollectionResource)

Example 17 with Path

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);
}
Also used : Path(io.milton.common.Path) Resource(io.milton.resource.Resource)

Example 18 with Path

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;
}
Also used : Path(io.milton.common.Path) File(java.io.File)

Example 19 with Path

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);
    }
}
Also used : Path(io.milton.common.Path) MalformedURLException(java.net.MalformedURLException) File(java.io.File) URL(java.net.URL)

Example 20 with Path

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;
}
Also used : Path(io.milton.common.Path) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) URL(java.net.URL)

Aggregations

Path (io.milton.common.Path)25 Resource (io.milton.resource.Resource)9 CollectionResource (io.milton.resource.CollectionResource)8 LogicalData (nl.uva.cs.lobcder.resources.LogicalData)7 BadRequestException (io.milton.http.exceptions.BadRequestException)6 SQLException (java.sql.SQLException)5 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)4 Connection (java.sql.Connection)4 ConflictException (io.milton.http.exceptions.ConflictException)3 MakeCollectionableResource (io.milton.resource.MakeCollectionableResource)3 File (java.io.File)3 Permissions (nl.uva.cs.lobcder.auth.Permissions)3 GetableResource (io.milton.resource.GetableResource)2 PostableResource (io.milton.resource.PostableResource)2 PutableResource (io.milton.resource.PutableResource)2 ReplaceableResource (io.milton.resource.ReplaceableResource)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 PDRI (nl.uva.cs.lobcder.resources.PDRI)2