コード例 #1
0
  public int doEndTag() throws JspException {
    if ((jspFile.indexOf("..") >= 0)
        || (jspFile.toUpperCase().indexOf("/WEB-INF/") != 0)
        || (jspFile.toUpperCase().indexOf("/META-INF/") != 0))
      throw new JspTagException("Invalid JSP file " + jspFile);

    InputStream in = pageContext.getServletContext().getResourceAsStream(jspFile);

    if (in == null) throw new JspTagException("Unable to find JSP file: " + jspFile);

    InputStreamReader reader = new InputStreamReader(in);
    JspWriter out = pageContext.getOut();

    try {
      out.println("<body>");
      out.println("<pre>");
      for (int ch = in.read(); ch != -1; ch = in.read())
        if (ch == '<') out.print("&lt;");
        else out.print((char) ch);
      out.println("</pre>");
      out.println("</body>");
    } catch (IOException ex) {
      throw new JspTagException("IOException: " + ex.toString());
    }
    return super.doEndTag();
  }
コード例 #2
0
ファイル: WebRes.java プロジェクト: duxingzhe311/system4j
  public static String getResTxtContent(ClassLoader cl, String p) throws IOException {
    String s = res2txt_cont.get(p);
    if (s != null) return s;

    InputStream is = null;
    try {
      is = cl.getResourceAsStream(p);
      // is = this.getClass().getResourceAsStream(p);
      if (is == null) return null;

      byte[] buf = new byte[1024];
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      int len;
      while ((len = is.read(buf)) >= 0) {
        baos.write(buf, 0, len);
      }

      byte[] cont = baos.toByteArray();
      s = new String(cont, "UTF-8");

      res2txt_cont.put(p, s);
      return s;
    } finally {
      if (is != null) is.close();
    }
  }
コード例 #3
0
ファイル: WebRes.java プロジェクト: duxingzhe311/system4j
  public static void renderFile(
      HttpServletResponse resp,
      String filename,
      InputStream cont_stream,
      boolean showpic,
      boolean ignorespace)
      throws IOException {
    if (cont_stream == null) return;

    if (ignorespace) filename = filename.replace(" ", "");

    if (!showpic)
      resp.addHeader(
          "Content-Disposition",
          "attachment; filename=" + new String(filename.getBytes(), "iso8859-1"));

    resp.setContentType(Mime.getContentType(filename));
    ServletOutputStream os = resp.getOutputStream();
    byte[] buf = new byte[1024];
    int len = 0;
    while ((len = cont_stream.read(buf)) != -1) {
      os.write(buf, 0, len);
    }

    os.flush();
  }
コード例 #4
0
    private void processEncrypt(final ServletRequest servletRequest ,final HttpServletRequest httpRequest,final ServletResponse servletResponse,
                          final FilterChain filterChain)throws IOException, ServletException{


        InputStream inputStream = servletRequest.getInputStream();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte buf[] = new byte[1024];
        int letti=-1;
        while ((letti = inputStream.read(buf)) > 0){
            byteArrayOutputStream.write(buf, 0, letti);
        }
        final BufferedRequestWrapper bufferedRequest = new BufferedRequestWrapper(httpRequest,doEncrypt(byteArrayOutputStream));

        final HttpServletResponse response = (HttpServletResponse) servletResponse;
        final ByteArrayPrintWriter pw = new ByteArrayPrintWriter();
        HttpServletResponse wrappedResp = new HttpServletResponseWrapper(response) {
            public PrintWriter getWriter() {
                return pw.getWriter();
            }
            public ServletOutputStream getOutputStream() {
                return pw.getStream();
            }
        };

        filterChain.doFilter(bufferedRequest, wrappedResp);


    }
コード例 #5
0
ファイル: readPostParameters.java プロジェクト: kmizu/spnuts
 protected Object exec(Object[] args, Context context) {
   int nargs = args.length;
   if (nargs != 1 && nargs != 2) {
     undefined(args, context);
     return null;
   }
   HttpServletRequest request = (HttpServletRequest) args[0];
   String enc;
   if (nargs == 1) {
     enc = ServletEncoding.getDefaultInputEncoding(context);
   } else {
     enc = (String) args[1];
   }
   String contentType = request.getContentType();
   if (contentType != null && contentType.startsWith("multipart/form-data")) {
     throw new RuntimeException("not yet implemented");
   } else {
     try {
       ByteArrayOutputStream bout = new ByteArrayOutputStream();
       byte[] buf = new byte[512];
       int n;
       InputStream in = request.getInputStream();
       while ((n = in.read(buf, 0, buf.length)) != -1) {
         bout.write(buf, 0, n);
       }
       in.close();
       String qs = new String(bout.toByteArray());
       Map map = URLEncoding.parseQueryString(qs, enc);
       return new ServletParameter(map);
     } catch (IOException e) {
       throw new PnutsException(e, context);
     }
   }
 }
コード例 #6
0
 public BufferedRequestWrapper(HttpServletRequest req) throws IOException {
     super(req);
     InputStream is = req.getInputStream();
     baos = new ByteArrayOutputStream();
     byte buf[] = new byte[1024];
     int letti;
     while ((letti = is.read(buf)) > 0) {
         baos.write(buf, 0, letti);
     }
     buffer = baos.toByteArray();
 }
コード例 #7
0
ファイル: WebRes.java プロジェクト: duxingzhe311/system4j
  protected void service(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, java.io.IOException {
    String p = req.getParameter("r");
    if (p == null || (p = p.trim()).equals("")) {
      String pi = req.getPathInfo();

      return;
    }

    byte[] cont = res2cont.get(p);
    if (cont != null) {
      resp.setContentType(Mime.getContentType(p));
      ServletOutputStream os = resp.getOutputStream();
      os.write(cont);
      os.flush();
      return;
    }

    InputStream is = null;
    try {
      is = appCL.getResourceAsStream(p); // getInputStreamByPath(p) ;
      if (is == null) {
        is = new Object().getClass().getResourceAsStream(p);
        if (is == null) return;
      }

      byte[] buf = new byte[1024];
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      int len;
      while ((len = is.read(buf)) >= 0) {
        baos.write(buf, 0, len);
      }

      cont = baos.toByteArray();
      res2cont.put(p, cont);
      resp.setContentType(Mime.getContentType(p));
      ServletOutputStream os = resp.getOutputStream();
      os.write(cont);
      os.flush();
      return;
    } finally {
      if (is != null) is.close();
    }
  }
コード例 #8
0
ファイル: JasperReport.java プロジェクト: jackrain/framework
  /**
   * return OutputStream of JasperReport object, this page could only be viewed from localhost for
   * security concern. parameter can be (id), or (table and type)
   *
   * @param id - report id, or
   * @param table - table name
   * @param type - reporttype "s","l","o", case insensitive
   * @param client(*) - client domain
   * @param version - version number, default to -1
   */
  public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String clientName = request.getParameter("client");
    int objectId = ParamUtils.getIntAttributeOrParameter(request, "id", -1);
    if (objectId == -1) {
      // try using table and type
      objectId =
          getReportId(clientName, request.getParameter("table"), request.getParameter("type"));
    }
    if (objectId == -1) {
      logger.error("report not found, request is:" + Tools.toString(request));
      throw new NDSException("report not found");
    }
    int version = ParamUtils.getIntAttributeOrParameter(request, "version", -1);
    File reportXMLFile = new File(ReportTools.getReportFile(objectId, clientName));
    if (reportXMLFile.exists()) {
      // generate jasperreport if file not exists or not newer
      String reportName =
          reportXMLFile.getName().substring(0, reportXMLFile.getName().lastIndexOf("."));
      File reportJasperFile = new File(reportXMLFile.getParent(), reportName + ".jasper");
      if (!reportJasperFile.exists()
          || reportJasperFile.lastModified() < reportXMLFile.lastModified()) {
        JasperCompileManager.compileReportToFile(
            reportXMLFile.getAbsolutePath(), reportJasperFile.getAbsolutePath());
      }
      InputStream is = new FileInputStream(reportJasperFile);
      response.setContentType("application/octetstream;");
      response.setContentLength((int) reportJasperFile.length());

      // response.setHeader("Content-Disposition","inline;filename=\""+reportJasperFile.getName()+"\"");
      ServletOutputStream os = response.getOutputStream();

      byte[] b = new byte[8192];
      int bInt;
      while ((bInt = is.read(b, 0, b.length)) != -1) {
        os.write(b, 0, bInt);
      }
      is.close();
      os.flush();
      os.close();
    } else {
      throw new NDSException("Not found report template");
    }
  }
コード例 #9
0
ファイル: SmartUpload.java プロジェクト: geeksun/abbcc
package com.jspsmart.upload;
コード例 #10
0
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    // set the response

    Shepherd myShepherd = new Shepherd();

    Vector rEncounters = new Vector();

    // setup data dir
    String rootWebappPath = getServletContext().getRealPath("/");
    File webappsDir = new File(rootWebappPath).getParentFile();
    File shepherdDataDir = new File(webappsDir, CommonConfiguration.getDataDirectoryName());
    // if(!shepherdDataDir.exists()){shepherdDataDir.mkdir();}
    File encountersDir = new File(shepherdDataDir.getAbsolutePath() + "/encounters");
    // if(!encountersDir.exists()){encountersDir.mkdir();}

    // set up the files
    String gisFilename = "geneGIS_export_" + request.getRemoteUser() + ".csv";
    File gisFile = new File(encountersDir.getAbsolutePath() + "/" + gisFilename);

    myShepherd.beginDBTransaction();

    try {

      // set up the output stream
      FileOutputStream fos = new FileOutputStream(gisFile);
      OutputStreamWriter outp = new OutputStreamWriter(fos);

      try {

        EncounterQueryResult queryResult =
            EncounterQueryProcessor.processQuery(
                myShepherd, request, "year descending, month descending, day descending");
        rEncounters = queryResult.getResult();

        int numMatchingEncounters = rEncounters.size();

        // build the CSV file header
        StringBuffer locusString = new StringBuffer("");
        int numLoci = 2; // most covered species will be loci
        try {
          numLoci = (new Integer(CommonConfiguration.getProperty("numLoci"))).intValue();
        } catch (Exception e) {
          System.out.println("numPloids configuration value did not resolve to an integer.");
          e.printStackTrace();
        }

        for (int j = 0; j < numLoci; j++) {
          locusString.append(",Locus" + (j + 1) + " A1,Locus" + (j + 1) + " A2");
        }
        // out.println("<html><body>");
        // out.println("Individual ID,Other ID 1,Date,Time,Latitude,Longitude,Area,Sub
        // Area,Sex,Haplotype"+locusString.toString());

        outp.write(
            "Individual ID,Other ID 1,Date,Time,Latitude,Longitude,Area,Sub Area,Sex,Haplotype"
                + locusString.toString()
                + "\n");

        for (int i = 0; i < numMatchingEncounters; i++) {

          Encounter enc = (Encounter) rEncounters.get(i);
          String assembledString = "";
          if (enc.getIndividualID() != null) {
            assembledString += enc.getIndividualID();
          }
          if (enc.getAlternateID() != null) {
            assembledString += "," + enc.getAlternateID();
          } else {
            assembledString += ",";
          }

          String dateString = ",";
          if (enc.getYear() > 0) {
            dateString += enc.getYear();
            if (enc.getMonth() > 0) {
              dateString += ("-" + enc.getMonth());
              if (enc.getDay() > 0) {
                dateString += ("-" + enc.getDay());
              }
            }
          }
          assembledString += dateString;

          String timeString = ",";
          if (enc.getHour() > -1) {
            timeString += enc.getHour() + ":" + enc.getMinutes();
          }
          assembledString += timeString;

          if ((enc.getDecimalLatitude() != null) && (enc.getDecimalLongitude() != null)) {
            assembledString += "," + enc.getDecimalLatitude();
            assembledString += "," + enc.getDecimalLongitude();
          } else {
            assembledString += ",,";
          }

          assembledString += "," + enc.getVerbatimLocality();
          assembledString += "," + enc.getLocationID();
          assembledString += "," + enc.getSex();

          // find and print the haplotype
          String haplotypeString = ",";
          if (enc.getHaplotype() != null) {
            haplotypeString += enc.getHaplotype();
          }

          // find and print the ms markers
          String msMarkerString = "";
          List<TissueSample> samples = enc.getTissueSamples();
          int numSamples = samples.size();
          boolean foundMsMarkers = false;
          for (int k = 0; k < numSamples; k++) {
            if (!foundMsMarkers) {
              TissueSample t = samples.get(k);
              List<GeneticAnalysis> analyses = t.getGeneticAnalyses();
              int aSize = analyses.size();
              for (int l = 0; l < aSize; l++) {
                GeneticAnalysis ga = analyses.get(l);
                if (ga.getAnalysisType().equals("MicrosatelliteMarkers")) {
                  foundMsMarkers = true;
                  MicrosatelliteMarkersAnalysis ga2 = (MicrosatelliteMarkersAnalysis) ga;
                  List<Locus> loci = ga2.getLoci();
                  int localLoci = loci.size();
                  for (int m = 0; m < localLoci; m++) {
                    Locus locus = loci.get(m);
                    if (locus.getAllele0() != null) {
                      msMarkerString += "," + locus.getAllele0();
                    } else {
                      msMarkerString += ",";
                    }
                    if (locus.getAllele1() != null) {
                      msMarkerString += "," + locus.getAllele1();
                    } else {
                      msMarkerString += ",";
                    }
                  }
                }
              }
            }
          }

          // out.println("<p>"+assembledString+haplotypeString+msMarkerString+"</p>");
          outp.write(assembledString + haplotypeString + msMarkerString + "\n");
        }
        outp.close();
        outp = null;

        // now write out the file
        response.setContentType("text/csv");
        response.setHeader("Content-Disposition", "attachment;filename=" + gisFilename);
        ServletContext ctx = getServletContext();
        // InputStream is = ctx.getResourceAsStream("/encounters/"+gisFilename);
        InputStream is = new FileInputStream(gisFile);

        int read = 0;
        byte[] bytes = new byte[BYTES_DOWNLOAD];
        OutputStream os = response.getOutputStream();

        while ((read = is.read(bytes)) != -1) {
          os.write(bytes, 0, read);
        }
        os.flush();
        os.close();

      } catch (Exception ioe) {
        ioe.printStackTrace();
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println(ServletUtilities.getHeader(request));
        out.println(
            "<html><body><p><strong>Error encountered</strong> with file writing. Check the relevant log.</p>");
        out.println(
            "<p>Please let the webmaster know you encountered an error at: EncounterSearchExportGeneGISFormat servlet</p></body></html>");
        out.println(ServletUtilities.getFooter());
        out.close();
        outp.close();
        outp = null;
      }

    } catch (Exception e) {
      e.printStackTrace();
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      out.println(ServletUtilities.getHeader(request));
      out.println("<html><body><p><strong>Error encountered</strong></p>");
      out.println(
          "<p>Please let the webmaster know you encountered an error at: EncounterSearchExportGeneGISFormat servlet</p></body></html>");
      out.println(ServletUtilities.getFooter());
      out.close();
    }
    myShepherd.rollbackDBTransaction();
    myShepherd.closeDBTransaction();
  }