Search in sources :

Example 6 with FileColumn

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

the class Minutes method _newViewDef.

// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.equals(m_table))
        return addHooks(new MinutesViewDef(name, m_table, m_access_policy, m_name));
    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 : ViewDef(db.ViewDef) FileColumn(db.column.FileColumn)

Example 7 with FileColumn

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

the class DB method doPost.

// --------------------------------------------------------------------------
@Override
protected void doPost(HttpServletRequest http_request, HttpServletResponse http_response) throws ServletException, IOException {
    http_request.setCharacterEncoding("UTF-8");
    http_response.setCharacterEncoding("UTF-8");
    Request request = new Request(http_request, http_response);
    http_response.setContentType("text/plain");
    String db_cmd = request.getParameter("db_cmd");
    if ("set_session_attribute".equals(db_cmd)) {
        Enumeration<String> parameter_names = request.getParameterNames();
        while (parameter_names.hasMoreElements()) {
            String parameter_name = parameter_names.nextElement();
            if (!parameter_name.equals("db_cmd")) {
                request.setSessionAttribute(parameter_name, request.getParameter(parameter_name));
                request.release();
                return;
            }
        }
    } else if ("set_setting".equals(db_cmd)) {
        Enumeration<String> parameter_names = request.getParameterNames();
        while (parameter_names.hasMoreElements()) {
            String parameter_name = parameter_names.nextElement();
            if (!parameter_name.startsWith("db_")) {
                request.site.getSettings().set(parameter_name, request.getParameter(parameter_name), request.db);
                request.writer.write("fade_alert('saved',$('" + Validation.getValidIdentifier("db_submit_id", request) + "'))");
                request.release();
                return;
            }
        }
    } else if ("set_theme".equals(db_cmd)) {
        Person user = request.getUser();
        request.db.update("people", "theme='" + request.getParameter("theme") + "'", user.getId());
        request.setSessionAttribute("user", null);
        request.release();
        return;
    }
    String task = request.getParameter("db_task");
    String view_def_name = request.getParameter("db_view_def");
    ViewDef view_def = request.site.getViewDef(view_def_name, request.db);
    if (task != null) {
        view_def.m_tasks.get(task).perform(request);
        request.release();
        return;
    }
    try {
        if (db_cmd.equals("and_filter")) {
            ViewState view_state = (ViewState) request.getState(ViewState.class, view_def_name);
            int index = view_state.filter.lastIndexOf(" AND " + request.getParameter("db_column") + " ");
            if (index != -1)
                // TODO: assumes is last expression
                view_state.filter = view_state.filter.substring(0, index);
            setFilterFromForm(view_def, true, request);
        } else if (db_cmd.equals("clear_filter"))
            ViewState.setFilter(view_def_name, null, request);
        else if (db_cmd.equals("delete")) {
            // exists if we're unlinking a OneToManyLink
            String one = request.getParameter("db_one_from");
            if (one != null)
                request.db.update(view_def.getFrom(), one + "_id=NULL", Validation.getValidInteger("db_key_value", -1, request));
            else
                view_def.delete(Validation.getValidIntegerString("db_key_value", request), request);
            String on_delete = view_def.getOnDelete(request);
            if (on_delete != null)
                request.writer.write(on_delete).write(';');
            String form = request.getParameter("form");
            if (form != null)
                request.writer.write(view_def.getFormCloseOnClick(View.Mode.EDIT_FORM));
        } else if (db_cmd.equals("import_views"))
            Admin.importViews(request.getParameter("site_url"), request);
        else if (db_cmd.equals("insert"))
            insert(view_def, request);
        else if (db_cmd.equals("link")) {
            request.db.update(view_def.getFrom(), request.getParameter("db_one_from") + "_id=" + ((ViewState) request.getOrCreateState(ViewState.class, request.getParameter("db_one_name"))).key_value, request.getInt("many_id", -1));
            request.writer.write(view_def.getOnSuccess(View.Mode.EDIT_FORM, request));
        } else if (db_cmd.equals("quicksearch")) {
            String value = request.getParameter("value");
            List<Feature> features = view_def.getFeatures();
            if (features != null)
                for (Feature feature : features) if (feature instanceof Quicksearch)
                    ViewState.setQuicksearch(view_def.getName(), value.length() > 0 ? value : null, ((Quicksearch) feature).getColumns(), request);
        } else if (db_cmd.equals("read"))
            writeFile(view_def, request);
        else if (db_cmd.equals("reorder"))
            view_def.getReorderable(request).reorder(request);
        else if (db_cmd.equals("set")) {
            String value;
            if ((value = request.getParameter("password")) != null) {
                int id = request.getInt("id", 0);
                Person user = request.getUser();
                if (id == user.getId() || request.userIsAdmin() || request.db.rowExists("user_roles", "people_id=" + user.getId() + " AND role='people'")) {
                    request.db.update("people", "password=md5('" + DBConnection.escape(value) + "')", id);
                    request.writer.write("dialog_alert('','password changed')");
                }
            }
        } else if (db_cmd.equals("set_filter_from_form"))
            setFilterFromForm(view_def, false, request);
        else if (db_cmd.equals("update"))
            update(view_def, request);
        else if (db_cmd.equals("update_file")) {
            String column = request.getParameter("db_column");
            int id = Validation.getValidInteger("db_key_value", 0, request);
            NameValuePairs name_value_pairs = new NameValuePairs();
            name_value_pairs.set(column, request.db.lookupString(new Select(column).from(view_def_name).whereIdEquals(id)));
            name_value_pairs.set(column + "_text", request.getParameter(column + "_text"));
            FileColumn file_column = (FileColumn) view_def.getColumn(column);
            String dir_column = file_column.getDirColumn();
            if (dir_column != null)
                name_value_pairs.set(dir_column, request.getParameter(dir_column));
            file_column.beforeUpdate(id, name_value_pairs, null, request);
        } else if (db_cmd.equals("toggle_column"))
            ViewState.toggleColumn(view_def_name, request.getParameter("db_column"), request);
        request.release();
    } catch (Exception e) {
        String s = e.toString();
        if (s.indexOf("ERROR: duplicate key value") != -1) {
            e.printStackTrace(System.out);
            request.abortAlert(s.substring(s.indexOf("Detail:") + 12));
        } else
            request.abortAlert(e);
    }
}
Also used : Enumeration(java.util.Enumeration) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(app.Request) FileColumn(db.column.FileColumn) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Person(app.Person)

Example 8 with FileColumn

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

the class DB method listFiles.

// --------------------------------------------------------------------------
private void listFiles(ViewDef view_def, Request request) throws IOException {
    FileColumn column = (FileColumn) view_def.getColumn(request.getParameter("column"));
    File[] files = column.listDirectory(request);
    if (files != null) {
        Set<String> file_names = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
        for (File file : files) if (file.isFile()) {
            String name = file.getName();
            if (name.charAt(0) != '.')
                file_names.add(name);
        }
        int num_files = 0;
        for (String file_name : file_names) {
            if (num_files > 0)
                request.writer.write('/');
            request.writer.write(file_name);
            ++num_files;
        }
    }
}
Also used : TreeSet(java.util.TreeSet) FileColumn(db.column.FileColumn) File(java.io.File)

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