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