Package net.sf.jpluck.util

Examples of net.sf.jpluck.util.LogUtil


      if (conf.getProxyUser().length() > 0) {
        System.setProperty(HttpClient.PROXY_USER_KEY, conf.getProxyUser());
        System.setProperty(HttpClient.PROXY_PASSWORD_KEY, conf.getProxyPassword());
      }
    }
    LogUtil logUtil = new LogUtil(LogUtil.DEFAULT_LOGGER_NAMES);
    logUtil.setLevel(conf.getLogLevel());
    logUtil.setUseParentHandler(false);
    String logFile = conf.getLogFile();
    FileHandler fileHandler = null;
    if (conf.isLogEnabled() && logFile.length() > 0) {
      try {
        fileHandler = new FileHandler(logFile, conf.getMaxLogSize() * 1024, 1, true);
        fileHandler.setFormatter(new LogFormatter());
        logUtil.addHandler(fileHandler);
      } catch (IOException e) {
        logger.warning("Could not create log file " + e.getMessage());
      }
    }

    for (int i = 0; (i < jxlDocuments.length) && running; i++) {
      try {
        net.sf.jpluck.jxl.Document jxlDocument = jxlDocuments[i];
        if (jxlDocument.getUserAgent() != null) {
          System.setProperty("http.agent", jxlDocument.getUserAgent());
        } else {
          System.setProperty("http.agent", conf.getUserAgent());
        }
        String s = "Starting conversion: " + jxlDocument.getName();
        if (jxlDocument.getJXL() != null) {
          File f = jxlDocument.getJXL().getFile();
          if (f != null) {
            s += " (" + f.getAbsolutePath() + ")";
          }
          logger.info(s);
        }
        jxlDocument.init();
        fireConversionStarted(jxlDocument, i + 1, jxlDocuments.length);

        String name = jxlDocument.getName();
        if (jxlDocument.isRemoveAccents()) {
          name = Database.convertToDatabaseName(name);
        }
        Document document = new Document(name, ClientConfiguration.getDefault().getCompression());

        Date date = jxlDocument.getDate();
        if (date != null) {
          document.setCreationDate(date);
          document.setModificationDate(date);
        }
        spider = new Spider(document, jxlDocument, httpCache, cookieStore, maxConnections,
                  Spider.DEFAULT_MAX_PARSE_THREADS, httpTimeout);
        try {
          for (Iterator iterator = spiderListenerList.iterator(); iterator.hasNext();) {
            SpiderListener spiderListener = (SpiderListener) iterator.next();
            spider.addSpiderListener(spiderListener);
          }
          if (!running) {
            break;
          }
          spider.run();
        } finally {
          for (Iterator iterator = spiderListenerList.iterator(); iterator.hasNext();) {
            SpiderListener spiderListener = (SpiderListener) iterator.next();
            spider.removeSpiderListener(spiderListener);
          }
        }

        boolean success = false;
        if (!running) {
          break;
        }

        String uri = jxlDocument.getStartingURI().toString();
        if (document.contains(uri)) {
          try {
            document.setHome(uri);
            document.setOutputEncoding(jxlDocument.getOutputEncoding());
            document.setIncludeImageAltText(jxlDocument.isIncludeAltText());
            document.setCategories(jxlDocument.getCategories());
            document.setDefaultLinkColor(jxlDocument.getLinkColor());
            document.setUnresolvedLinkColor(jxlDocument.getUnresolvedLinkColor());
            document.setRemoveUnresolvedLinks(jxlDocument.isRemoveUnresolvedLinks());
            document.setIncludeURIInfo(jxlDocument.isIncludeURIInfo());
            document.setBackup(jxlDocument.isSetBackupBit());
            document.setEncoding(jxlDocument.getOutputEncoding());
            // Sort bookmarks for sites
            if (jxlDocument instanceof Site) {
              Site site = (Site) jxlDocument;
              if (site.isSortBookmarks()) {
                document.sortBookmarks();
              }
            }

            fireGenerationStarted(jxlDocument);
            for (Iterator it = recordListenerList.iterator(); it.hasNext();) {
              document.addRecordListener((RecordListener) it.next());
            }
            document.setFilename(jxlDocument.getFilename());
            long size = destination.write(document);
            jxlDocument.converted(size);
            fireGenerationCompleted(jxlDocument);
            logger.info("Completed conversion: " + jxlDocument.getName());
            success = true;
          } catch (Exception e) {
            logger.severe("Could not generate document: " + e.getClass() + " " + e.getMessage());
            e.printStackTrace();
          } finally {
            for (Iterator it = recordListenerList.iterator(); it.hasNext();) {
              document.removeRecordListener((RecordListener) it.next());
            }
          }
        } else {
          logger.severe(jxlDocument.getName() + ": could not load starting URI " + jxlDocument.getUri() +
                  ". Document cannot be generated.");
        }
        if (!success) {
          failCount++;
        }
        fireConversionCompleted(jxlDocument, i + 1, jxlDocuments.length, success);
      } catch (Exception e) {
        logger.severe("Error initializing transformation:\n" + e.getClass().getName() + ": " +
                e.getMessage());
        e.printStackTrace();
      }
      TemporaryFile.clean();
    }
    closeHttpCache();
    fireStatusMessage("Completed");
    running = false;
    conversionActive = false;
    fireConversionFinished();
    logUtil.close();
    if (fileHandler != null) {
      logUtil.removeHandler(fileHandler);
    }
    if ((window != null) && (failCount == 0) && ClientConfiguration.getDefault().isAutoCloseConversion()) {
      window.hide();
    }
  }
View Full Code Here


    defaults.rows = 16;
    textArea = new JEditTextArea(defaults);
    textArea.setEditable(false);
    textArea.setBorder(UIManager.getBorder("TextField.border"));

    logUtil = new LogUtil(LogUtil.DEFAULT_LOGGER_NAMES);
    logHandler = new JEditTextAreaHandler(textArea, new LogFormatter());
    logUtil.addHandler(logHandler);

    FormLayout formLayout = new FormLayout("fill:250dlu:grow",
                         "pref, 4dlu, pref, 4dlu, pref, 4dlu, pref, " +
View Full Code Here

      if (cl.hasOption("version")) {
        OptionsUtil.printVersion("JPluckC", VersionInfo.VERSION, VersionInfo.RELEASE_DATE);
        System.exit(ExitCodes.OK);
      }

      LogUtil logUtil = new LogUtil(LogUtil.DEFAULT_LOGGER_NAMES);
      logUtil.addHandler(new SystemOutHandler());
      logUtil.setUseParentHandler(false);

      String[] args = cl.getArgs();
      JXL jxl = null;

      Destination destination = ClientConfiguration.getDefault().getDestination();
View Full Code Here

        }

        if (name.length() > 31) {
            name = name.substring(0, 31).trim();
        }
        LogUtil logUtil = new LogUtil(LogUtil.DEFAULT_LOGGER_NAMES);
        logUtil.setLevel(Level.OFF);
        document.setName(name);
        document.setHome("http://127.0.0.1/");
        document.setCompression(Document.ZLIB_COMPRESSION);
        document.setIncludeURIInfo(false);
        document.write(System.out);
View Full Code Here

TOP

Related Classes of net.sf.jpluck.util.LogUtil

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.