Search in sources :

Example 1 with DataRepository

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);
}
Also used : InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) URLConnection(java.net.URLConnection) DataRepository(net.sourceforge.processdash.data.repository.DataRepository) Map(java.util.Map)

Example 2 with DataRepository

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);
        }
    }
}
Also used : DataRepository(net.sourceforge.processdash.data.repository.DataRepository)

Example 3 with DataRepository

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;
}
Also used : EVTaskList(net.sourceforge.processdash.ev.EVTaskList) DataRepository(net.sourceforge.processdash.data.repository.DataRepository)

Example 4 with DataRepository

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;
}
Also used : DataRepository(net.sourceforge.processdash.data.repository.DataRepository) SimpleData(net.sourceforge.processdash.data.SimpleData)

Example 5 with DataRepository

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);
}
Also used : DataRepository(net.sourceforge.processdash.data.repository.DataRepository)

Aggregations

DataRepository (net.sourceforge.processdash.data.repository.DataRepository)37 SimpleData (net.sourceforge.processdash.data.SimpleData)11 DashHierarchy (net.sourceforge.processdash.hier.DashHierarchy)4 IOException (java.io.IOException)3 ListData (net.sourceforge.processdash.data.ListData)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 StringData (net.sourceforge.processdash.data.StringData)2 PropertyKey (net.sourceforge.processdash.hier.PropertyKey)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1