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