use of net.sourceforge.processdash.data.repository.DataRepository in project processdash by dtuma.
the class TextPreprocessingHandlerServlet method handleFile.
private void handleFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Look up the named resource. If it doesn't exist, return an error.
String uri = req.getServletPath();
URL url = getServletContext().getResource(uri);
if (url == null) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
// determine the content type of the resource
String contentType;
boolean isPreprocessedFileType;
if (StringUtil.endsWithIgnoreCase(uri, ".shtm") || StringUtil.endsWithIgnoreCase(uri, ".shtml")) {
contentType = "text/html; charset=utf-8";
isPreprocessedFileType = true;
} else {
contentType = getContentType(uri);
isPreprocessedFileType = false;
}
// open a connection to the resource, and read some initial data
URLConnection conn = url.openConnection();
InputStream in = conn.getInputStream();
byte[] buffer = new byte[SCAN_BUF_SIZE];
int numBytes = in.read(buffer);
if (numBytes < 1) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Couldn't read file '" + uri + "'");
FileUtils.safelyClose(in);
return;
}
// if the file does not need preprocessing, serve it verbatim
if (isPreprocessedFileType == false && containsServerParsedOverride(buffer, numBytes) == false) {
if (contentType != null)
resp.setContentType(contentType);
int len = conn.getContentLength();
if (len >= 0)
resp.setContentLength(len);
long mod = conn.getLastModified();
if (mod > 0)
resp.setDateHeader("Last-Modified", mod);
resp.getOutputStream().write(buffer, 0, numBytes);
FileUtils.copyFile(in, resp.getOutputStream());
FileUtils.safelyClose(in);
return;
}
// build the environment we will use for handling the request
Map env = PDashServletUtils.buildEnvironment(req);
// read the original resource as a string
ByteArrayOutputStream rawBytes = new ByteArrayOutputStream(Math.max(numBytes, conn.getContentLength()));
rawBytes.write(buffer, 0, numBytes);
FileUtils.copyFile(in, rawBytes);
FileUtils.safelyClose(in);
String content = rawBytes.toString("utf-8");
rawBytes = null;
// invoke the preprocessor on the content
WebServer webServer = (WebServer) env.get(TinyCGI.TINY_WEB_SERVER);
DataRepository data = (DataRepository) env.get(TinyCGI.DATA_REPOSITORY);
String prefix = (String) env.get("PATH_TRANSLATED");
HTMLPreprocessor p = new HTMLPreprocessor(webServer, data.getSubcontext(prefix), env);
if (contentType != null && contentType.indexOf("html") != -1)
p.setDefaultEchoEncoding("html");
content = p.preprocess(content);
byte[] resultBytes = content.getBytes("utf-8");
if (contentType != null)
resp.setContentType(HTTPUtils.setCharset(contentType, "utf-8"));
resp.setContentLength(resultBytes.length);
resp.getOutputStream().write(resultBytes);
}
use of net.sourceforge.processdash.data.repository.DataRepository in project processdash by dtuma.
the class EditDefectTypeStandards method handleImportConfirm.
protected void handleImportConfirm() throws IOException {
// save each of the selected defect type standards
String[] selected = (String[]) parameters.get("sel_ALL");
if (selected != null) {
DataRepository data = getDataRepository();
for (String selectedNum : selected) {
String oneName = getParameter("name" + selectedNum);
String oneSpec = getParameter("spec" + selectedNum);
DefectTypeStandard.save(oneName, data, oneSpec);
}
}
}
use of net.sourceforge.processdash.data.repository.DataRepository in project processdash by dtuma.
the class TeamProjectSetupWizard method getScheduleNameErr.
private String getScheduleNameErr() {
String scheduleName = getValue(IND_SCHEDULE);
if (scheduleName == null)
return "scheduleNameMissing";
if (!EVTaskListData.validName(scheduleName))
return "scheduleNameInvalid";
DataRepository data = getDataRepository();
if (EVTaskListData.exists(data, scheduleName) || EVTaskListRollup.exists(data, scheduleName)) {
// if a task list already exists with this name, check to see if
// it is empty (i.e., contains no tasks or subschedules). If it
// is empty, then it's OK to delete and replace it. If not, we
// should display an error message indicating that this schedule
// name is already taken.
EVTaskList tl = EVTaskList.openExisting(scheduleName, data, getPSPProperties(), getObjectCache(), false);
if (tl != null && !tl.getTaskRoot().isLeaf()) {
return "scheduleNameDuplicate";
}
}
return null;
}
use of net.sourceforge.processdash.data.repository.DataRepository in project processdash by dtuma.
the class EditSubprojectList method getSimpleValue.
/** Get a value from the data repository. */
protected SimpleData getSimpleValue(String name) {
DataRepository data = getDataRepository();
String prefix = getPrefix();
if (prefix == null)
prefix = "";
String dataName = DataRepository.createDataName(prefix, name);
SimpleData d = data.getSimpleValue(dataName);
return d;
}
use of net.sourceforge.processdash.data.repository.DataRepository in project processdash by dtuma.
the class EditSubprojectList method putValue.
protected void putValue(String name, SimpleData dataValue) {
DataRepository data = getDataRepository();
String prefix = getPrefix();
if (prefix == null)
prefix = "";
String dataName = DataRepository.createDataName(prefix, name);
data.putValue(dataName, dataValue);
}
Aggregations