Search in sources :

Example 11 with FilePathStringBuilder

use of web.FilePathStringBuilder in project common by zenlunatics.

the class FileColumn method writeTextFile.

// --------------------------------------------------------------------------
private void writeTextFile(NameValuePairs name_value_pairs, String dir, boolean check_if_file_exists, Site site) {
    String text = name_value_pairs.getString("db_" + m_name + "_text");
    if (text == null)
        return;
    name_value_pairs.remove("db_" + m_name + "_text");
    FilePathStringBuilder fpsb = getDirectory(dir, site);
    File d = new File(fpsb.toString());
    if (!d.exists())
        d.mkdirs();
    fpsb.append(name_value_pairs.getString(m_name));
    File file = new File(fpsb.toString());
    if (check_if_file_exists && file.exists())
        throw new RuntimeException("A file with the name " + name_value_pairs.getString(m_name) + " already exists on the server.");
    try {
        FileWriter fw = new FileWriter(file);
        fw.write(text);
        fw.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : FileWriter(java.io.FileWriter) FilePathStringBuilder(web.FilePathStringBuilder) IOException(java.io.IOException) File(java.io.File)

Example 12 with FilePathStringBuilder

use of web.FilePathStringBuilder in project common by zenlunatics.

the class EventProvider method writeICS.

// --------------------------------------------------------------------------
@AdminTask
public synchronized void writeICS(Request request) throws IOException {
    ICalendar ical = new ICalendar();
    String string = request.site.getSettings().getString("time zone");
    TimeZone time_zone = TimeZone.getTimeZone(string);
    TimezoneAssignment tza = TimezoneAssignment.download(time_zone, false);
    ical.getTimezoneInfo().setDefaultTimezone(tza);
    ArrayList<Event> events = new ArrayList<Event>();
    addAllEvents(events, request);
    for (Event event : events) {
        VEvent vevent = event.newVEvent(request);
        if (vevent != null)
            ical.addEvent(vevent);
    }
    FilePathStringBuilder fpsb = request.site.getBaseFilePath().append("calendars");
    new File(fpsb.toString()).mkdirs();
    String file_path = fpsb.append(m_name).toString();
    Biweekly.write(ical).go(new File(file_path));
    new File(file_path).renameTo(new File(file_path + ".ics"));
}
Also used : VEvent(biweekly.component.VEvent) TimeZone(java.util.TimeZone) TimezoneAssignment(biweekly.io.TimezoneAssignment) ArrayList(java.util.ArrayList) VEvent(biweekly.component.VEvent) ICalendar(biweekly.ICalendar) FilePathStringBuilder(web.FilePathStringBuilder) File(java.io.File) AdminTask(web.AdminTask)

Example 13 with FilePathStringBuilder

use of web.FilePathStringBuilder in project common by zenlunatics.

the class FileManager method doPost.

// --------------------------------------------------------------------------
@Override
public boolean doPost(Request request) throws IOException {
    if (super.doPost(request))
        return true;
    if (!request.userIsAdmin())
        return false;
    String action = request.getParameter("action");
    if ("mkdir".equals(action)) {
        FilePathStringBuilder directory = getRoot(request);
        String servlet_path = request.request.getServletPath();
        String path = servlet_path.substring(servlet_path.indexOf("FileManager") + 12);
        if (path.length() > 0)
            directory.append(path);
        directory.append(request.getParameter("dir"));
        new File(directory.toString()).mkdirs();
        return true;
    }
    if ("upload".equals(action))
        try {
            FileItem file_item = request.getFileItem("file");
            FilePathStringBuilder directory = getRoot(request);
            String servlet_path = request.request.getServletPath();
            String path = servlet_path.substring(servlet_path.indexOf("FileManager") + 11);
            if (path.length() > 0)
                directory.append(path);
            file_item.write(new File(directory.append(file_item.getName()).toString()));
            return true;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    if ("write file".equals(action)) {
        writeFile(request.getParameter("file"), request.getParameter("data"), request);
        return true;
    }
    return false;
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) FilePathStringBuilder(web.FilePathStringBuilder) File(java.io.File) IOException(java.io.IOException)

Aggregations

FilePathStringBuilder (web.FilePathStringBuilder)13 File (java.io.File)11 IOException (java.io.IOException)5 AdminTask (web.AdminTask)3 Select (db.Select)2 SQLException (java.sql.SQLException)2 HTMLWriter (web.HTMLWriter)2 ICalendar (biweekly.ICalendar)1 VEvent (biweekly.component.VEvent)1 TimezoneAssignment (biweekly.io.TimezoneAssignment)1 NameValuePairs (db.NameValuePairs)1 BufferedImage (java.awt.image.BufferedImage)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 ResultSet (java.sql.ResultSet)1 DateFormat (java.text.DateFormat)1 NumberFormat (java.text.NumberFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TimeZone (java.util.TimeZone)1