Пример #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);
       }
     }
   }
 }
Пример #2
0
 /**
  * Get the first topic id.
  *
  * @param path file path
  * @param dir file dir
  * @param useCatalog whether use catalog file for validation
  * @return topic id
  */
 public static String getFirstTopicId(final URI path, final File dir, final boolean useCatalog) {
   if (path == null && dir == null) {
     return null;
   }
   final DITAOTLogger logger = new DITAOTJavaLogger();
   final StringBuilder firstTopicId = new StringBuilder();
   final TopicIdParser parser = new TopicIdParser(firstTopicId);
   try {
     final XMLReader reader = XMLUtils.getXMLReader();
     reader.setContentHandler(parser);
     if (useCatalog) {
       reader.setEntityResolver(CatalogUtils.getCatalogResolver());
     }
     reader.parse(dir.toURI().resolve(path).toString());
   } catch (final Exception e) {
     logger.error(e.getMessage(), e);
   }
   return firstTopicId.toString();
 }