Search in sources :

Example 1 with HtmlCanvas

use of org.rendersnake.HtmlCanvas in project lobcder by skoulouzis.

the class WebDataDirResource method sendContent.

@Override
public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException, BadRequestException {
    Logger.getLogger(WebDataDirResource.class.getName()).log(Level.FINEST, "sendContent({0}) for {1}", new Object[] { contentType, getPath() });
    try (Connection connection = getCatalogue().getConnection()) {
        try (PrintStream ps = new PrintStream(out)) {
            HtmlCanvas html = new HtmlCanvas();
            html.table(border("1")).tr().th().content("Name").th().content("Size").th().content("Modification Date").th().content("Creation Date").th().content("Owner").th().content("Content Type").th().content("Type").th().content("Is Supervised").th().content("Uid");
            String ref;
            for (LogicalData ld : getCatalogue().getChildrenByParentRef(getLogicalData().getUid(), connection)) {
                if (ld.isFolder()) {
                    ref = "../dav" + getPath() + "/" + ld.getName();
                // if (ld.getUid() != 1) {
                // } else {
                // }
                } else {
                    ref = "../dav" + getPath() + "/" + ld.getName();
                }
                html._tr().tr().td().a(href(ref)).img(src("").alt(ld.getName()))._a()._td().td().content(String.valueOf(ld.getLength())).td().content(new Date(ld.getModifiedDate()).toString()).td().content(new Date(ld.getCreateDate()).toString()).td().content(ld.getOwner()).td().content(ld.getContentTypesAsString()).td().content(ld.getType()).td().content(ld.getSupervised().toString()).td().content(ld.getUid().toString());
            }
            html._tr()._table();
            ps.println(html.toHtml());
            getCatalogue().addViewForRes(getLogicalData().getUid(), connection);
            connection.commit();
            connection.close();
        } catch (Exception e) {
            if (connection != null && !connection.isClosed()) {
                connection.rollback();
                connection.close();
            }
            throw e;
        }
    } catch (Exception e) {
        Logger.getLogger(WebDataDirResource.class.getName()).log(Level.SEVERE, null, e);
        throw new BadRequestException(this);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) Connection(java.sql.Connection) HtmlCanvas(org.rendersnake.HtmlCanvas) BadRequestException(io.milton.http.exceptions.BadRequestException) ConflictException(io.milton.http.exceptions.ConflictException) URISyntaxException(java.net.URISyntaxException) SQLException(java.sql.SQLException) BadRequestException(io.milton.http.exceptions.BadRequestException) PreConditionFailedException(io.milton.http.exceptions.PreConditionFailedException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

BadRequestException (io.milton.http.exceptions.BadRequestException)1 ConflictException (io.milton.http.exceptions.ConflictException)1 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)1 PreConditionFailedException (io.milton.http.exceptions.PreConditionFailedException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 LogicalData (nl.uva.cs.lobcder.resources.LogicalData)1 HtmlCanvas (org.rendersnake.HtmlCanvas)1