Example #1
0
 /**
  * Get the image binary data, with hexical output. For RTF transformation
  *
  * @param dirName - The directory name that will be added to the path of the image file.
  * @param fileName - The file name of the image file.
  * @return java.lang.String - The Hexical binary of image data converted to String.
  */
 public static String getBinData(final String dirName, final String fileName) {
   final DITAOTJavaLogger logger = new DITAOTJavaLogger();
   final File imgInput = new File(dirName, toFile(fileName).getPath());
   FileInputStream binInput = null;
   try {
     String binStr = null;
     final StringBuilder ret = new StringBuilder(16 * 1024);
     binInput = new FileInputStream(imgInput);
     int bin = binInput.read();
     while (bin != -1) {
       binStr = Integer.toHexString(bin);
       if (binStr.length() < 2) {
         ret.append("0");
       }
       ret.append(binStr);
       bin = binInput.read();
     }
     return ret.toString();
   } catch (final Exception e) {
     logger.error(MessageUtils.getInstance().getMessage("DOTJ023E").toString());
     logger.error(e.getMessage(), e);
     return null;
   } finally {
     if (binInput != null) {
       try {
         binInput.close();
       } catch (final IOException ioe) {
         logger.error(ioe.getMessage(), ioe);
       }
     }
   }
 }
Example #2
0
 /**
  * Get the image height.
  *
  * @param dirName - The directory name that will be added to the path of the image file.
  * @param fileName - The file name of the image file.
  * @return int - The height of the picture in pixels.
  */
 @Deprecated
 public static int getHeight(final String dirName, final String fileName) {
   final DITAOTJavaLogger logger = new DITAOTJavaLogger();
   final File imgInput = new File(dirName, toFile(fileName).getPath());
   try {
     final BufferedImage img = ImageIO.read(imgInput);
     return img.getHeight();
   } catch (final Exception e) {
     logger.error(
         MessageUtils.getInstance()
             .getMessage("DOTJ023E", dirName + File.separatorChar + fileName)
             .toString(),
         e);
     return -1;
   }
 }
Example #3
0
 /**
  * Get Base64 encoding content. For ODT transformation
  *
  * @param dirName - The directory name that will be added to the path of the image file.
  * @param fileName - The file name of the image file.
  * @return base64 encoded binary data.
  */
 public static String getBASE64(final String dirName, final String fileName) {
   final DITAOTJavaLogger logger = new DITAOTJavaLogger();
   final URI imgInputURI = toURI(fileName);
   final File imgInput =
       imgInputURI.isAbsolute()
           ? new File(imgInputURI)
           : new File(dirName, toFile(imgInputURI).getPath());
   // BASE64Encoder encoder = new BASE64Encoder();
   final Base64 encoder = new Base64();
   final byte buff[] = new byte[(int) imgInput.length()];
   FileInputStream file = null;
   try {
     file = new FileInputStream(imgInput);
     file.read(buff);
     // String ret = encoder.encode(buff);
     return encoder.encodeToString(buff);
   } catch (final FileNotFoundException e) {
     logger.error(MessageUtils.getInstance().getMessage("DOTJ023E").toString());
     logger.error(e.getMessage(), e);
     return null;
   } catch (final IOException e) {
     logger.error(MessageUtils.getInstance().getMessage("DOTJ023E").toString());
     logger.error(e.getMessage(), e);
     return null;
   } finally {
     if (file != null) {
       try {
         file.close();
       } catch (final IOException ioe) {
         logger.error(ioe.getMessage(), ioe);
       }
     }
   }
 }
Example #4
0
  /**
   * Parse the catalog file to get catalog map.
   *
   * @param ditaDir absolute path to directory to find catalog-dita.xml
   * @return catalog map
   * @deprecated use Apache Commons Catalog Resolver instead
   */
  @Deprecated
  public static synchronized HashMap<String, String> getCatalog(final File ditaDir) {
    if (map != null) {
      return map;
    }

    final File catalogFilePath =
        (ditaDir == null) ? new File(FILE_NAME_CATALOG) : new File(ditaDir, FILE_NAME_CATALOG);

    map = new HashMap<String, String>();
    final CatalogParser parser = new CatalogParser(map, ditaDir.getAbsolutePath());
    try {
      final XMLReader reader = StringUtils.getXMLReader();
      reader.setContentHandler(parser);
      reader.parse(catalogFilePath.toURI().toASCIIString());
    } catch (final Exception e) {
      logger.logException(e);
    }

    return map;
  }
Example #5
0
  /**
   * Get CatalogResolver.
   *
   * @return CatalogResolver
   */
  public static synchronized CatalogResolver getCatalogResolver() {
    if (catalogResolver == null) {
      final CatalogManager manager = new CatalogManager();
      manager.setIgnoreMissingProperties(true);
      manager.setUseStaticCatalog(false); // We'll use a private catalog.
      manager.setPreferPublic(true);

      // manager.setVerbosity(10);
      catalogResolver = new CatalogResolver(manager);

      final File catalogFilePath = new File(ditaDir, FILE_NAME_CATALOG);

      final Catalog catalog = catalogResolver.getCatalog();
      try {
        catalog.parseCatalog(catalogFilePath.toURI().toURL());
      } catch (final Exception e) {
        logger.logException(e);
      }
    }

    return catalogResolver;
  }