/**
   * Durchsucht die Verzeichnisse und verarbeitet die gefundenen Dateien.
   *
   * @return Statistic mit den verarbeiteten Dateien
   */
  @Override
  public DirectoryStatistic process() {
    LOG.debug("Processing directory " + directory);
    final DirectoryStatistic stat = new DirectoryStatistic(directory);

    final Scanner scanner = buildFileScanner(directory, suffix, false);
    final List<File> files = scanner.find();

    LOG.debug("Found " + files.size() + " files for processing");
    for (final File f : files) {
      final FileProcessor p = new FileProcessor(f, outputFormat);
      stat.add(p.process());
    }

    if (recursive) {
      LOG.debug("Start recursive for " + directory);
      final Scanner directoryScanner = buildDirectoryScanner(directory, false);
      final List<File> subDirectories = directoryScanner.find();
      for (final File d : subDirectories) {
        final DirectoryProcessor p = new DirectoryProcessor(d, suffix, outputFormat, true);

        stat.add(p.process());
      }
    }

    return stat;
  }
  @Test
  public void testGetImageInfoWithOrientation() throws Exception {
    Configuration.getInstance().setProperty(RESPECT_ORIENTATION_CONFIG_KEY, true);

    final File fixture = TestUtil.getImage("jpg-rotated.jpg");

    final FileProcessor fproc = (FileProcessor) newInstance();
    fproc.setSourceFile(fixture);
    fproc.setSourceFormat(Format.JPG);

    final ImageInfo info = fproc.getImageInfo();
    assertEquals(Orientation.ROTATE_90, info.getOrientation());
  }
 @Test
 @Override
 public void testGetSize() throws Exception {
   Dimension expectedSize = new Dimension(100, 88);
   if (getProcessor() instanceof StreamProcessor) {
     StreamProcessor proc = (StreamProcessor) getProcessor();
     Dimension actualSize =
         proc.getSize(new TestStreamSource(TestUtil.getImage("jp2")), SourceFormat.JP2);
     assertEquals(expectedSize, actualSize);
   }
   if (getProcessor() instanceof FileProcessor) {
     FileProcessor proc = (FileProcessor) getProcessor();
     Dimension actualSize = proc.getSize(TestUtil.getImage("jp2"), SourceFormat.JP2);
     assertEquals(expectedSize, actualSize);
   }
 }
  /**
   * Tile-aware override.
   *
   * @throws Exception
   */
  @Test
  @Override
  public void testGetImageInfo() throws Exception {
    ImageInfo expectedInfo = new ImageInfo(64, 56, Format.TIF);
    expectedInfo.getImages().get(0).tileWidth = 16;
    expectedInfo.getImages().get(0).tileHeight = 16;

    final File fixture = TestUtil.getImage("tif-rgb-monores-64x56x8-tiled-uncompressed.tif");

    // test as a StreamProcessor
    StreamProcessor sproc = (StreamProcessor) newInstance();
    StreamSource streamSource = new TestStreamSource(fixture);
    sproc.setStreamSource(streamSource);
    sproc.setSourceFormat(Format.TIF);
    assertEquals(expectedInfo, sproc.getImageInfo());

    // test as a FileProcessor
    FileProcessor fproc = (FileProcessor) newInstance();
    fproc.setSourceFile(fixture);
    fproc.setSourceFormat(Format.TIF);
    assertEquals(expectedInfo, fproc.getImageInfo());

    try {
      fproc.setSourceFile(TestUtil.getImage("mpg"));
      fproc.setSourceFormat(Format.MPG);
      expectedInfo = new ImageInfo(640, 360, Format.MPG);
      assertEquals(expectedInfo, fproc.getImageInfo());
    } catch (UnsupportedSourceFormatException e) {
      // pass
    }
  }
Exemple #5
0
 /** {@inheritDoc} */
 public Document read(InputStream input) throws DocumentException {
   try {
     ZipInputStream zip = new ZipInputStream(input);
     ZipEntry entry = zip.getNextEntry();
     while (entry != null) {
       FileProcessor processor = processors.get(entry.getName());
       if (processor != null) {
         processor.process(zip);
       }
       entry = zip.getNextEntry();
     }
     if (document != null) {
       document.postProcess(this);
     }
     zip.close();
     return document;
   } catch (IOException e) {
     throw new DocumentException(e);
   }
 }
  /**
   * Reads from data file using FileProcessor and stores in MusicStore
   *
   * @return Returns a MusicStore instance which has all the music records read from data file
   */
  public MusicStore read() {

    try {
      String line = null;
      StringTokenizer st = null;
      while ((line = fp.readLineFromFile()) != null) {
        // System.out.println("Line : " + line +"\n");

        st = new StringTokenizer(line);
        if (st.countTokens() == 3) mi.storeInfo(st.nextToken(), st.nextToken(), st.nextToken());
      }
    } catch (NullPointerException ex) {
      System.err.println("Null value read from Data file " + ex.getMessage());
      System.exit(1);
    } finally {
    }

    return mi;
  }
  /*
   * (non-Javadoc)
   *
   * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
   * javax.servlet.ServletResponse, javax.servlet.FilterChain)
   */
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    if (PropertiesUtil.getObject(SysParameterEnum.STATIC_PAGE_SUPPORT, Boolean.class)) {
      HttpServletRequest hreq = (HttpServletRequest) request;

      String str_uri = hreq.getRequestURI();
      // System.out.println("hreq.getRequestURL() = " +
      // hreq.getRequestURL());
      // System.out.println(" hreq.getRealPath = " +
      // hreq.getRealPath("/"));
      // System.out.println(" hreq.getRemoteAddr= " +
      // hreq.getRemoteAddr());
      // System.out.println("str_uri =================== " + str_uri);
      // System.out.println("context path = " +
      // config.getServletContext().getContextPath());

      String prefixUriPath = supportURL(str_uri, contextPath);
      if (prefixUriPath != null) {
        HttpServletResponse hresp = (HttpServletResponse) response;
        String name = str_uri.substring(str_uri.lastIndexOf("/") + 1);

        if (AppUtils.isBlank(name)) {
          name = "index";
        }

        String fileName = name + ".html";
        String chrrentShopName = ThreadLocalContext.getCurrentShopName(hreq, hresp);
        String htmPath = HTML_PATH + chrrentShopName;

        // full name
        StringBuilder sb =
            new StringBuilder(htmPath).append(prefixUriPath).append("/").append(fileName);
        String fullName = sb.toString();

        // to which html
        sb.setLength(0);
        String toHtmlPage =
            sb.append(contextPath)
                .append("/")
                .append(AttributeKeys.HTML_COMMON)
                .append(chrrentShopName)
                .append(prefixUriPath)
                .append("/")
                .append(fileName)
                .toString();
        File file = new File(fullName);
        if (!file.exists()) {
          ServletResponse newResponse = new CharResponseWrapper(hresp);
          chain.doFilter(request, newResponse);
          String text = newResponse.toString();
          if (text != null) {
            FileProcessor.writeFile(text, htmPath + prefixUriPath, fileName);
            hresp.sendRedirect(toHtmlPage);
            // request.getRequestDispatcher(toHtmlPage).forward(hreq,
            // hresp);
          }
        } else {
          hresp.sendRedirect(toHtmlPage);
          // request.getRequestDispatcher(toHtmlPage).forward(hreq,
          // hresp);
        }

      } else {
        chain.doFilter(request, response);
      }
    } else {
      chain.doFilter(request, response);
    }
  }