public Properties loadProperties(String path) {
   Properties pages = new Properties();
   try {
     FileInputStream filePages = new FileInputStream(path);
     pages.load(filePages);
     filePages.close();
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   }
   return pages;
 }
Exemplo n.º 2
0
  /**
   * Does the actual work of reading a catalog.
   *
   * @param factory use this InvCatalogFactory
   * @param path reletive path starting from content root
   * @param catalogFullPath absolute location on disk
   * @return the InvCatalogImpl, or null if failure
   */
  private InvCatalogImpl readCatalog(
      InvCatalogFactory factory, String path, String catalogFullPath) {

    InvCatalogImpl acat;
    try {
      catURI = new URI("file:" + StringUtil2.escape(catalogFullPath, "/:-_.")); // LOOK needed ?
    } catch (URISyntaxException e) {
      logServerStartup.info("radarServer readCatalog(): URISyntaxException=" + e.getMessage());
      return null;
    }

    // read the catalog
    logServerStartup.info(
        "radarServer readCatalog(): full path=" + catalogFullPath + "; path=" + path);
    FileInputStream ios = null;
    try {
      ios = new FileInputStream(catalogFullPath);
      acat = factory.readXML(ios, catURI);
    } catch (Throwable t) {
      logServerStartup.error(
          "radarServer readCatalog(): Exception on catalog="
              + catalogFullPath
              + " "
              + t.getMessage()); // +"\n log="+cat.getLog(), t);
      return null;
    } finally {
      if (ios != null) {
        try {
          ios.close();
        } catch (IOException e) {
          logServerStartup.info("radarServer readCatalog(): error closing" + catalogFullPath);
        }
      }
    }
    return acat;
  }
Exemplo n.º 3
0
  /**
   * This method handles PUT requests from the client. PUT requests will come from the applet
   * portion of this application and are the way that images and other files can be posted to the
   * server.
   *
   * @param request the HTTP request object
   * @param response the HTTP response object
   * @exception ServletException
   * @exception IOException
   */
  public void doPut(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    HttpSession session = request.getSession();
    /*
     * The Scan applet will zip all the files together to create a
     * faster upload and to use just one server connection.
     */
    ZipInputStream in = new ZipInputStream(request.getInputStream());

    /*
     * This will write all the files to a directory on the server.
     */
    try {
      try {

        File file = new File("scan");
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        String fileSize = null;
        while (true) {
          ZipEntry entry = in.getNextEntry();
          if (entry == null) {
            break;
          }
          File f = File.createTempFile("translate", entry.getName());
          FileOutputStream out = new FileOutputStream(f);
          FileInputStream inStream = null;
          try {
            int read;
            byte[] buf = new byte[2024];

            while ((read = in.read(buf)) > 0) {
              out.write(buf, 0, read);
            }
            out.close();
            inStream = new FileInputStream(f);
            System.out.println(entry.getSize());
            byte[] b = new byte[inStream.available()];
            inStream.read(b);
            System.out.println(b.length);
            com.itextpdf.text.Image image1 = com.itextpdf.text.Image.getInstance(b);
            image1.scalePercent(30);
            image1.setCompressionLevel(9);
            document.add(image1);
          } finally {
          }
        }
        document.close();
        //                fileSize = CommonUtils.getFileSize(file);
        //                DocumentStoreLogDAO documentStoreLogDAO = new DocumentStoreLogDAO();
        //                DocumentStoreLog documentStoreLog = null;
        //                DocumentStoreLog documentStore =
        // (DocumentStoreLog)session.getAttribute(CommonConstants.DOCUMENT_STORE_LOG);
        //                if(null != documentStore) {
        //                    documentStore.setFileSize(fileSize);
        //                }
        //                Transaction tx = documentStoreLogDAO.getSession().getTransaction();
        //                tx.begin();
        //                documentStoreLogDAO.save(documentStore);
        //                tx.commit();
      } catch (ZipException ze) {
        /*
         * We want to catch each sip exception separately because
         * there is a possibility that we can read more files from
         * the archive even if one of them is corrupted.
         */
        ze.printStackTrace();
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      in.close();
    }

    /*
     * Now that we have finished uploading the files
     * we will send a reponse to the server indicating
     * our success.
     */

    response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    out.println("<html><head><title>ImageSrv</title></head></html>");
    out.flush();
    out.close();
    response.setStatus(HttpServletResponse.SC_OK);
  }
Exemplo n.º 4
0
package com.jspsmart.upload;