Search in sources :

Example 1 with FileColumn

use of db.column.FileColumn in project common by zenlunatics.

the class Documents method beforeDelete.

// --------------------------------------------------------------------------
@Override
public boolean beforeDelete(StringBuilder where, Request request) {
    FileColumn fc = (FileColumn) request.site.getViewDef("documents", request.db).getColumn("filename");
    File file = fc.getFile(Integer.parseInt(where.substring(where.indexOf("=") + 1)), request);
    if (file != null)
        file.delete();
    return true;
}
Also used : FileColumn(db.column.FileColumn) File(java.io.File)

Example 2 with FileColumn

use of db.column.FileColumn in project common by zenlunatics.

the class Documents method writeItem.

// --------------------------------------------------------------------------
/**
 * @throws IOException
 */
@Override
public void writeItem(int item_id, Request request) throws IOException {
    FileColumn file_column = (FileColumn) request.site.getViewDef("documents", request.db).getColumn("filename");
    Rows data = new Rows(request.db).select(new Select("*").from("documents").whereIdEquals(item_id));
    if (data.next())
        file_column.writeValue(data, request);
    data.close();
}
Also used : Select(db.Select) FileColumn(db.column.FileColumn) Rows(db.Rows)

Example 3 with FileColumn

use of db.column.FileColumn in project common by zenlunatics.

the class Documents method _newViewDef.

// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.equals("documents")) {
        ViewDef view_def = new ViewDef(name);
        view_def.setAccessPolicy(new RoleAccessPolicy("docs").add().delete().edit());
        view_def.setCenter(false);
        view_def.setDefaultOrderBy("title");
        view_def.setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM);
        view_def.setRecordName("Document");
        view_def.setRichTextEditId("db_filename_text");
        view_def.setShowDoneLink(true);
        view_def.setTimestampRecords(true);
        ArrayList<String> column_names = new ArrayList<String>();
        column_names.add("title");
        column_names.add("type");
        column_names.add("filename");
        if (m_extra_columns != null)
            for (JDBCColumn column : m_extra_columns) column_names.add(column.name);
        view_def.setColumnNamesForm(column_names.toArray(new String[column_names.size()]));
        view_def.setColumnNamesTable(new String[] { "filename" });
        FileColumn file_column = new FileColumn("filename", view_def, "documents").setTitleColumn("title");
        if (m_dir_column != null)
            file_column.setDirColumn(m_dir_column);
        view_def.setColumn(file_column.setDisplayName("document").setPrintUrl("/Documents?db_key_value="));
        view_def.setColumn(new Column("title").setIsRequired(true).setOrderBy("lower(title)"));
        view_def.setColumn(((Options) site.getObjects("documents_types")).newColumn("type"));
        return addHooks(view_def);
    }
    if (name.equals("documents_types"))
        return site.getObjects(name).newViewDef(name, site).setRecordName("Type").setShowNumRecords(false).setColumn(new Column("text").setIsRequired(true));
    return null;
}
Also used : FileColumn(db.column.FileColumn) JDBCColumn(db.JDBCColumn) Column(db.column.Column) ArrayList(java.util.ArrayList) JDBCColumn(db.JDBCColumn) ViewDef(db.ViewDef) RoleAccessPolicy(db.access.RoleAccessPolicy) FileColumn(db.column.FileColumn)

Example 4 with FileColumn

use of db.column.FileColumn in project common by zenlunatics.

the class Discussions method _newViewDef.

// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.equals("discussions")) {
        RecordOwnerAccessPolicy record_owner_access_policy = (RecordOwnerAccessPolicy) new RecordOwnerAccessPolicy().add().delete().edit().view();
        return addHooks(new ViewDef(name).setAccessPolicy(record_owner_access_policy).setDefaultOrderBy("_timestamp_ DESC").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM).setRecordName("Discussion").setTimestampRecords(true).setColumnNamesForm(new String[] { "title", "text", "_owner_" }).setColumnNamesTable(new String[] { "title" }).setColumn(record_owner_access_policy.getColumn("posted by", site)).setColumn(new Column("_timestamp_").setDisplayName("when"))).addRelationshipDef(new OneToMany(name + "_attachments"));
    }
    if (name.equals(m_table + "_attachments")) {
        ViewDef view_def = new ViewDef(name);
        view_def.setRecordName("Attachment");
        view_def.setColumn(new FileColumn("filename", view_def, m_table + "/attachments").setAllowEditing(false).setDirColumn(m_table + "_id").setTitleColumn("filename"));
        return view_def;
    }
    return null;
}
Also used : RecordOwnerAccessPolicy(db.access.RecordOwnerAccessPolicy) FileColumn(db.column.FileColumn) JDBCColumn(db.JDBCColumn) Column(db.column.Column) ViewDef(db.ViewDef) OneToMany(db.OneToMany) FileColumn(db.column.FileColumn)

Example 5 with FileColumn

use of db.column.FileColumn in project common by zenlunatics.

the class Documents method doGet.

// --------------------------------------------------------------------------
@Override
public boolean doGet(Request request) throws IOException {
    if (super.doGet(request))
        return true;
    int key_value = request.getInt("db_key_value", 0);
    if (key_value != 0) {
        Rows data = new Rows(request.db).select(new Select("*").from("documents").whereIdEquals(key_value));
        if (data.next()) {
            new Head(request, data.getString("title")).styleSheet("admin").close();
            FileColumn column = (FileColumn) request.site.getViewDef("documents", request.db).getColumn("filename");
            File file = column.getFile(data, request);
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line = br.readLine();
            while (line != null) {
                request.writer.write(line);
                line = br.readLine();
            }
            br.close();
        } else
            request.writer.write("document not found");
        data.close();
    } else {
        request.site.writePageOpen("Documents", request);
        request.site.newView("documents", request).writeComponent();
    }
    request.close();
    return true;
}
Also used : Head(web.Head) Select(db.Select) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) FileColumn(db.column.FileColumn) File(java.io.File) Rows(db.Rows)

Aggregations

FileColumn (db.column.FileColumn)8 ViewDef (db.ViewDef)3 File (java.io.File)3 JDBCColumn (db.JDBCColumn)2 Rows (db.Rows)2 Select (db.Select)2 Column (db.column.Column)2 Person (app.Person)1 Request (app.Request)1 OneToMany (db.OneToMany)1 RecordOwnerAccessPolicy (db.access.RecordOwnerAccessPolicy)1 RoleAccessPolicy (db.access.RoleAccessPolicy)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 TreeSet (java.util.TreeSet)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1