@BeforeClass
  public static void setUp() throws IOException {
    tempDir = TestUtils.createTempDir(TestConrefPushParser.class);

    inputFile = new File(tempDir, "conrefpush_stub.xml");
    FileUtils.copyFile(new File(srcDir, "conrefpush_stub.xml"), inputFile);
    FileUtils.copyFile(
        new File(srcDir, "conrefpush_stub2.xml"), new File(tempDir, "conrefpush_stub2.xml"));
  }
  /**
   * add FlagImangesSet to Properties, which needn't to change the dir level, just ouput to the
   * ouput dir.
   *
   * @param prop job configuration
   * @param key list name
   * @param set relative flag image files
   */
  private void addFlagImagesSetToProperties(
      final Job prop, final String key, final Set<String> set) {
    String value = null;
    final Set<String> newSet = new LinkedHashSet<String>(INT_128);
    for (final String file : set) {
      if (new File(file).isAbsolute()) {
        // no need to append relative path before absolute paths
        newSet.add(FileUtils.normalize(file));
      } else {
        // In ant, all the file separator should be slash, so we need to
        // replace all the back slash with slash.
        newSet.add(
            FileUtils.separatorsToUnix(
                FileUtils.normalize(new StringBuffer().append(file).toString())));
      }
    }

    // write list attribute to file
    final String fileKey = key.substring(0, key.lastIndexOf("list")) + "file";
    prop.setProperty(fileKey, key.substring(0, key.lastIndexOf("list")) + ".list");
    final File list = new File(tempDir, prop.getProperty(fileKey));
    Writer bufferedWriter = null;
    try {
      bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(list)));
      final Iterator<String> it = newSet.iterator();
      while (it.hasNext()) {
        bufferedWriter.write(it.next());
        if (it.hasNext()) {
          bufferedWriter.write("\n");
        }
      }
      bufferedWriter.flush();
      bufferedWriter.close();
    } catch (final FileNotFoundException e) {
      logger.logException(e);
    } catch (final IOException e) {
      logger.logException(e);
    } finally {
      if (bufferedWriter != null) {
        try {
          bufferedWriter.close();
        } catch (final IOException e) {
          logger.logException(e);
        }
      }
    }

    value = StringUtils.assembleString(newSet, COMMA);

    prop.setProperty(key, value);

    // clear set
    set.clear();
    newSet.clear();
  }
  /**
   * Categorize file.
   *
   * <p>If {@code file} parameter contains a pipe character, the pipe character is followed by the
   * format of the file.
   *
   * <p>TODO: Pass format as separate DITA class parameter.
   *
   * @param file file path with optional format
   */
  private void categorizeResultFile(String file) {
    // edited by william on 2009-08-06 for bug:2832696 start
    String lcasefn = null;
    String format = null;
    // has format attribute set
    if (file.contains(STICK)) {
      // get lower case file name
      lcasefn = file.substring(0, file.indexOf(STICK)).toLowerCase();
      // get format attribute
      format = file.substring(file.indexOf(STICK) + 1);
      file = file.substring(0, file.indexOf(STICK));
    } else {
      lcasefn = file.toLowerCase();
    }

    // Added by William on 2010-03-04 for bug:2957938 start
    // avoid files referred by coderef being added into wait list
    if (subsidiarySet.contains(lcasefn)) {
      return;
    }
    // Added by William on 2010-03-04 for bug:2957938 end

    if (FileUtils.isDITAFile(lcasefn)
        && (format == null
            || ATTR_FORMAT_VALUE_DITA.equalsIgnoreCase(format)
            || ATTR_FORMAT_VALUE_DITAMAP.equalsIgnoreCase(format))) {

      addToWaitList(file);
    } else if (!FileUtils.isSupportedImageFile(lcasefn)) {
      // FIXME: Treating all non-image extensions as HTML/resource files is not correct if
      // HTML/resource files
      //        are defined by the file extension. Correct behaviour would be to remove this else
      // block.
      htmlSet.add(file);
    }
    // edited by william on 2009-08-06 for bug:2832696 end
    if (FileUtils.isSupportedImageFile(lcasefn)) {
      imageSet.add(file);
      try {
        final File image = new File(baseInputDir + File.separator + file).getCanonicalFile();
        if (!image.exists()) {
          final Properties prop = new Properties();
          prop.put("%1", image.getAbsolutePath());
          logger.logWarn(MessageUtils.getMessage("DOTX008W", prop).toString());
        }
      } catch (final IOException e) {
        logger.logError(e.getMessage());
      }
    }

    if (FileUtils.isHTMLFile(lcasefn) || FileUtils.isResourceFile(lcasefn)) {
      htmlSet.add(file);
    }
  }
示例#4
0
 /**
  * @param value string
  * @return URL
  */
 private String replaceURL(final String value) {
   if (value == null) {
     return null;
   } else if (target == null
       || FileUtils.isAbsolutePath(value)
       || value.contains(COLON_DOUBLE_SLASH)
       || value.startsWith(SHARP)) {
     return value;
   } else {
     final String source = FileUtils.resolve(fileDir, target).getPath();
     final String urltarget = FileUtils.resolveTopic(fileDir, value);
     return FileUtils.getRelativeUnixPath(source, urltarget);
   }
 }
  /**
   * Update uplevels if needed.
   *
   * @param file file path
   */
  private void updateUplevels(String file) {

    // Added by william on 2009-08-06 for bug:2832696 start
    if (file.contains(STICK)) {
      file = file.substring(0, file.indexOf(STICK));
    }
    // Added by william on 2009-08-06 for bug:2832696 end

    // for uplevels (../../)
    // modified start by wxzhang 20070518
    // ".."-->"../"
    final int lastIndex = FileUtils.separatorsToUnix(FileUtils.normalize(file)).lastIndexOf("../");
    // modified end by wxzhang 20070518
    if (lastIndex != -1) {
      final int newUplevels = lastIndex / 3 + 1;
      uplevels = newUplevels > uplevels ? newUplevels : uplevels;
    }
  }
  /**
   * Categorize current file type
   *
   * @param currentFile file path
   */
  private void categorizeCurrentFile(final String currentFile) {
    final String lcasefn = currentFile.toLowerCase();

    ditaSet.add(currentFile);

    if (FileUtils.isDITATopicFile(currentFile)) {
      hrefTargetSet.add(currentFile);
    }

    if (reader.hasConaction()) {
      conrefpushSet.add(currentFile);
    }

    if (reader.hasConRef()) {
      conrefSet.add(currentFile);
    }

    if (reader.hasKeyRef()) {
      keyrefSet.add(currentFile);
    }

    if (reader.hasCodeRef()) {
      coderefSet.add(currentFile);
    }

    if (FileUtils.isDITATopicFile(lcasefn)) {
      fullTopicSet.add(currentFile);
      if (reader.hasHref()) {
        hrefTopicSet.add(currentFile);
      }
    }

    if (FileUtils.isDITAMapFile(lcasefn)) {
      fullMapSet.add(currentFile);
      if (reader.hasHref()) {
        hrefMapSet.add(currentFile);
      }
    }
  }
  private void processWaitList() throws DITAOTException {
    // Added by William on 2009-07-18 for req #12014 start
    reader.setTranstype(transtype);
    // Added by William on 2009-07-18 for req #12014 end

    if (FileUtils.isDITAMapFile(inputFile)) {
      reader.setPrimaryDitamap(inputFile);
    }

    while (!waitList.isEmpty()) {
      processFile(waitList.remove(0));
    }
  }
 /**
  * Add key definition to job configuration
  *
  * @param prop job configuration
  * @param key list name
  * @param set key defintions to add
  */
 private void addKeyDefSetToProperties(
     final Job prop, final String key, final Collection<KeyDef> set) {
   // update value
   final Collection<KeyDef> updated = new ArrayList<KeyDef>(set.size());
   for (final KeyDef file : set) {
     String keys = FileUtils.separatorsToUnix(FileUtils.normalize(prefix + file.keys));
     String href = file.href;
     String source = file.source;
     if (prefix.length() != 0) {
       // cases where keymap is in map ancestor folder
       keys = keys.substring(prefix.length());
       if (href == null) {
         // href = FileUtils.separatorsToUnix(FileUtils.normalize(prefix));
         source = FileUtils.separatorsToUnix(FileUtils.normalize(prefix + source));
       } else {
         if (!exKeyDefMap.containsKey(file.keys)) {
           href = FileUtils.separatorsToUnix(FileUtils.normalize(prefix + href));
         }
         source = FileUtils.separatorsToUnix(FileUtils.normalize(prefix + source));
       }
     }
     final KeyDef keyDef = new KeyDef(keys, href, source);
     updated.add(keyDef);
   }
   // write key definition
   try {
     writeKeydef(new File(tempDir, "keydef.xml"), updated);
   } catch (final DITAOTException e) {
     logger.logError("Failed to write key definition file: " + e.getMessage(), e);
   }
   // write list file
   final Set<String> newSet = new LinkedHashSet<String>(set.size());
   for (final KeyDef keydef : updated) {
     newSet.add(keydef.toString());
   }
   prop.setSet(key, newSet);
   final String fileKey = key.substring(0, key.lastIndexOf("list")) + "file";
   prop.setProperty(fileKey, key.substring(0, key.lastIndexOf("list")) + ".list");
   try {
     prop.writeList(key);
   } catch (final IOException e) {
     logger.logError("Failed to write key list file: " + e.getMessage(), e);
   }
 }
示例#9
0
  /**
   * @param target target
   * @param pushcontent content
   * @param type push type
   */
  private void addtoPushTable(URI target, final DocumentFragment pushcontent, final String type) {
    if (target.getFragment() == null) {
      // if there is no '#' in target string, report error
      logger.error(MessageUtils.getInstance().getMessage("DOTJ041E", target.toString()).toString());
      return;
    }

    if (target.getPath().isEmpty()) {
      // means conref the file itself
      target = toURI(parsefilename.getPath() + target);
    }
    final File key = toFile(FileUtils.resolve(fileDir, target));
    Hashtable<MoveKey, DocumentFragment> table = null;
    if (pushtable.containsKey(key)) {
      // if there is something else push to the same file
      table = pushtable.get(key);
    } else {
      // if there is nothing else push to the same file
      table = new Hashtable<>();
      pushtable.put(key, table);
    }

    final MoveKey moveKey = new MoveKey(SHARP + target.getFragment(), type);

    if (table.containsKey(moveKey)) {
      // if there is something else push to the same target
      // append content if type is 'pushbefore' or 'pushafter'
      // report error if type is 'replace'
      if (ATTR_CONACTION_VALUE_PUSHREPLACE.equals(type)) {
        logger.error(
            MessageUtils.getInstance().getMessage("DOTJ042E", target.toString()).toString());
      } else {
        table.put(moveKey, appendPushContent(pushcontent, table.get(moveKey)));
      }

    } else {
      // if there is nothing else push to the same target
      table.put(moveKey, appendPushContent(pushcontent, null));
    }
  }
  /**
   * Add set of values of job configuration
   *
   * @param prop job configuration
   * @param key list name
   * @param set values to add
   */
  private void addSetToProperties(final Job prop, final String key, final Set<String> set) {
    // update value
    final Set<String> newSet = new LinkedHashSet<String>(INT_128);
    for (final String file : set) {
      if (new File(file).isAbsolute()) {
        // no need to append relative path before absolute paths
        newSet.add(FileUtils.normalize(file));
      } else {
        // In ant, all the file separator should be slash, so we need to
        // replace all the back slash with slash.
        final int index = file.indexOf(EQUAL);
        if (index != -1) {
          // keyname
          final String to = file.substring(0, index);
          final String source = file.substring(index + 1);

          newSet.add(
              FileUtils.separatorsToUnix(
                      FileUtils.normalize(new StringBuffer(prefix).append(to).toString()))
                  + EQUAL
                  + FileUtils.separatorsToUnix(
                      FileUtils.normalize(new StringBuffer(prefix).append(source).toString())));
        } else {
          newSet.add(
              FileUtils.separatorsToUnix(
                  FileUtils.normalize(new StringBuffer(prefix).append(file).toString())));
        }
      }
    }
    prop.setSet(key, newSet);
    // write list file
    final String fileKey = key.substring(0, key.lastIndexOf("list")) + "file";
    prop.setProperty(fileKey, key.substring(0, key.lastIndexOf("list")) + ".list");
    try {
      prop.writeList(key);
    } catch (final IOException e) {
      logger.logError("Failed to write list file: " + e.getMessage(), e);
    }
  }
示例#11
0
  @Test
  public void testWrite()
      throws DITAOTException, ParserConfigurationException, SAXException, IOException {
    /*
     * the part of content of conrefpush_stub2.xml is
     * <ol>
     * 	<li id="A">A</li>
     * 	<li id="B">B</li>
     * 	<li id="C">C</li>
     * </ol>
     *
     * the part of content of conrefpush_stup.xml is
     *  <steps>
     * 	 <step conaction="pushbefore"><cmd>before</cmd></step>
     *   <step conref="conrefpush_stub2.xml#X/A" conaction="mark"/>
     *   <step conref="conrefpush_stub2.xml#X/B" conaction="mark"/>
     *	 <step conaction="pushafter"><cmd>after</cmd></step>
     *	 <step conref="conrefpush_stub2.xml#X/C" conaction="pushreplace"><cmd>replace</cmd></step>
     *	</steps>
     *
     * after conrefpush the part of conrefpush_stub2.xml should be like this
     * <ol class="- topic/ol ">
     *  <li class="- topic/li task/step ">
     *  	<ph class="- topic/ph task/cmd ">
     *  	before
     *  	</ph>
     *  </li>
     *  <li id="A" class="- topic/li ">A</li>
     *	<li id="B" class="- topic/li ">B</li>
     *	<li class="- topic/li task/step ">
     *		<ph class="- topic/ph task/cmd ">
     *		after
     *		</ph>
     *	</li>
     *	<li class="- topic/li task/step ">
     *		<ph class="- topic/ph task/cmd ">
     *		replace
     *		</ph>
     *	</li>
     * </ol>
     */
    final ConrefPushParser parser = new ConrefPushParser();
    final ConrefPushReader reader = new ConrefPushReader();

    reader.read(inputFile.getAbsolutePath());
    final Map<String, Hashtable<String, String>> pushSet = reader.getPushMap();
    final Iterator<Map.Entry<String, Hashtable<String, String>>> iter =
        pushSet.entrySet().iterator();
    if (iter.hasNext()) {
      final Map.Entry<String, Hashtable<String, String>> entry = iter.next();
      // initialize the parsed file
      FileUtils.copyFile(new File(srcDir, "conrefpush_stub2_backup.xml"), new File(entry.getKey()));
      final Content content = new ContentImpl();
      content.setValue(entry.getValue());
      parser.setContent(content);
      parser.write(entry.getKey());
      final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      final DocumentBuilder builder = factory.newDocumentBuilder();
      final Document document = builder.parse(new File(entry.getKey()));
      final Element elem = document.getDocumentElement();
      NodeList nodeList = elem.getChildNodes();
      // according to the structure, it comes to the <li> after 2 iterations.
      for (int i = 0; i < 2; i++) {
        for (int j = 0; j < nodeList.getLength(); j++) {
          if (nodeList.item(j).getNodeType() == Node.ELEMENT_NODE) {
            nodeList = nodeList.item(j).getChildNodes();
            break;
          }
        }
      }
      Element element;
      for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
          element = (Element) node;
          if (element.getAttributes().getNamedItem("id") != null
              && element.getAttributes().getNamedItem("id").getNodeValue().equals("A")) {
            // get node of before
            node = element.getPreviousSibling();
            while (node.getNodeType() != Node.ELEMENT_NODE) {
              node = node.getPreviousSibling();
            }
            assertEquals(
                "<li class=\"- topic/li task/step \"><ph class=\"- topic/ph task/cmd \">before</ph></li>",
                nodeToString((Element) node));
          } else if (element.getAttributes().getNamedItem("id") != null
              && element.getAttributes().getNamedItem("id").getNodeValue().equals("B")) {
            // get node of after
            node = element.getNextSibling();
            while (node.getNodeType() != Node.ELEMENT_NODE) {
              node = node.getNextSibling();
            }
            assertEquals(
                "<li class=\"- topic/li task/step \"><ph class=\"- topic/ph task/cmd \">after</ph></li>",
                nodeToString((Element) node));

            // get node of replacement
            node = node.getNextSibling();
            while (node.getNodeType() != Node.ELEMENT_NODE) {
              node = node.getNextSibling();
            }
            assertEquals(
                "<li class=\"- topic/li task/step \" id=\"C\"><ph class=\"- topic/ph task/cmd \">replace</ph></li>",
                nodeToString((Element) node));
          }
        }
      }
    }
  }
示例#12
0
  @Override
  public void startElement(
      final String uri, final String localName, final String qName, final Attributes atts)
      throws SAXException {
    final int attsLen = atts.getLength();
    final String attrScope = atts.getValue(ATTRIBUTE_NAME_SCOPE);
    final String attrFormat = atts.getValue(ATTRIBUTE_NAME_FORMAT);

    if (qName.equals(firstMatchElement)) {
      final String hrefValue = atts.getValue(ATTRIBUTE_NAME_HREF);
      if (verifyIndexEntries(indexEntries) && topicPath != null) {
        /*
        String origin = (String) map.get(topicPath);
        map.put(topicPath, StringUtils.setOrAppend(origin, indexEntries.toString(), false));
         */
        String t = topicPath;
        String frag = SHARP;
        if (t.contains(SHARP)) {
          frag = t.indexOf(SHARP) + 1 >= t.length() ? SHARP : t.substring(t.indexOf(SHARP) + 1);
          t = t.substring(0, t.indexOf(SHARP));
        }
        Map<String, String> m = map.get(t);
        if (m != null) {
          final String orig = m.get(frag);
          m.put(frag, StringUtils.setOrAppend(orig, indexEntries.toString(), false));
        } else {
          m = new HashMap<String, String>(INT_16);
          m.put(frag, indexEntries.toString());
          map.put(t, m);
        }
        indexEntries = new StringBuffer(INT_1024);
      }
      topicPath = null;
      if (hrefValue != null
          && hrefValue.indexOf(INTERNET_LINK_MARK) == -1
          && (attrScope == null || ATTR_SCOPE_VALUE_LOCAL.equalsIgnoreCase(attrScope))
          && (attrFormat == null || ATTR_FORMAT_VALUE_DITA.equalsIgnoreCase(attrFormat))) {
        // If the href is internal dita topic file
        topicPath = FileUtils.resolveTopic(filePath, hrefValue);
        validHref = true;
      } else {
        // set up the boolean to prevent the invalid href's metadata inserted into indexEntries.
        topicPath = null;
        validHref = false;
      }
    }
    if (!match) {
      ancestorList.add(qName);
      if (lastMatchElement.contains(qName) && checkMatch()) {

        match = true;
        level = 0;
      }
    }

    if (match) {
      if (validHref) {
        indexEntries.append(LESS_THAN + qName + STRING_BLANK);

        for (int i = 0; i < attsLen; i++) {
          indexEntries.append(atts.getQName(i));
          indexEntries.append(EQUAL);
          indexEntries.append(QUOTATION);
          indexEntries.append(StringUtils.escapeXML(atts.getValue(i)));
          indexEntries.append(QUOTATION);
          indexEntries.append(STRING_BLANK);
        }

        indexEntries.append(GREATER_THAN);
      }
      level++;
    }
  }
  private void processParseResult(String currentFile) {
    final Map<String, String> cpMap = reader.getCopytoMap();
    final Map<String, KeyDef> kdMap = reader.getKeysDMap();
    // Added by William on 2010-06-09 for bug:3013079 start
    // the reader's reset method will clear the map.
    final Map<String, String> exKdMap = reader.getExKeysDefMap();
    exKeyDefMap.putAll(exKdMap);
    // Added by William on 2010-06-09 for bug:3013079 end

    // Category non-copyto result and update uplevels accordingly
    for (final String file : reader.getNonCopytoResult()) {
      categorizeResultFile(file);
      updateUplevels(file);
    }

    // Update uplevels for copy-to targets, and store copy-to map.
    // Note: same key(target) copy-to will be ignored.
    for (final String key : cpMap.keySet()) {
      final String value = cpMap.get(key);

      if (copytoMap.containsKey(key)) {
        // edited by Alan on Date:2009-11-02 for Work Item:#1590 start
        /*
         * StringBuffer buff = new StringBuffer();
         * buff.append("Copy-to task [href=\""); buff.append(value);
         * buff.append("\" copy-to=\""); buff.append(key);
         * buff.append("\"] which points to another copy-to target");
         * buff.append(" was ignored.");
         * logger.logWarn(buff.toString());
         */
        final Properties prop = new Properties();
        prop.setProperty("%1", value);
        prop.setProperty("%2", key);
        logger.logWarn(MessageUtils.getMessage("DOTX065W", prop).toString());
        // edited by Alan on Date:2009-11-02 for Work Item:#1590 end
        ignoredCopytoSourceSet.add(value);
      } else {
        updateUplevels(key);
        copytoMap.put(key, value);
      }
    }
    // TODO Added by William on 2009-06-09 for scheme key bug(497)
    schemeSet.addAll(reader.getSchemeRefSet());

    // collect key definitions
    for (final String key : kdMap.keySet()) {
      // key and value.keys will differ when keydef is a redirect to another keydef
      final KeyDef value = kdMap.get(key);
      if (keysDefMap.containsKey(key)) {
        // if there already exists duplicated key definition in
        // different map files.
        // Should only emit this if in a debug mode; comment out for now
        /*
         * Properties prop = new Properties(); prop.put("%1", key);
         * prop.put("%2", value); prop.put("%3", currentFile); logger
         * .logInfo(MessageUtils.getMessage("DOTJ048I",
         * prop).toString());
         */
      } else {
        updateUplevels(key);
        // add the ditamap where it is defined.
        /*
         * try { keydef.write("<keydef ");
         * keydef.write("keys=\""+key+"\" ");
         * keydef.write("href=\""+value+"\" ");
         * keydef.write("source=\""+currentFile+"\"/>");
         * keydef.write("\n"); keydef.flush(); } catch (IOException e) {
         *
         * logger.logException(e); }
         */
        keysDefMap.put(key, new KeyDef(key, value.href, currentFile));
      }
      // TODO Added by William on 2009-06-09 for scheme key bug(532-547)
      // if the current file is also a schema file
      if (schemeSet.contains(currentFile)) {
        // write the keydef into the scheme keydef file
        try {
          schemekeydef.writeStartElement(ELEMENT_KEYDEF);
          schemekeydef.writeAttribute(ATTRIBUTE_KEYS, key);
          if (value.href != null) {
            schemekeydef.writeAttribute(ATTRIBUTE_HREF, value.href);
          }
          schemekeydef.writeAttribute(ATTRIUBTE_SOURCE, currentFile);
          schemekeydef.writeEndElement();
        } catch (final SAXException e) {
          logger.logException(e);
        }
      }
    }

    hrefTargetSet.addAll(reader.getHrefTargets());
    hrefWithIDSet.addAll(reader.getHrefTopicSet());
    chunkTopicSet.addAll(reader.getChunkTopicSet());
    // schemeSet.addAll(reader.getSchemeRefSet());
    conrefTargetSet.addAll(reader.getConrefTargets());
    nonConrefCopytoTargetSet.addAll(reader.getNonConrefCopytoTargets());
    ignoredCopytoSourceSet.addAll(reader.getIgnoredCopytoSourceSet());
    subsidiarySet.addAll(reader.getSubsidiaryTargets());
    outDitaFilesSet.addAll(reader.getOutFilesSet());
    resourceOnlySet.addAll(reader.getResourceOnlySet());

    // Generate topic-scheme dictionary
    if (reader.getSchemeSet() != null && reader.getSchemeSet().size() > 0) {
      Set<String> children = null;
      children = this.schemeDictionary.get(currentFile);
      if (children == null) {
        children = new HashSet<String>();
      }
      children.addAll(reader.getSchemeSet());
      // for Linux support
      currentFile = FileUtils.separatorsToUnix(currentFile);

      this.schemeDictionary.put(currentFile, children);
      final Set<String> hrfSet = reader.getHrefTargets();
      for (final String f : hrfSet) {
        // for Linux support
        final String filename = FileUtils.separatorsToUnix(f);

        children = this.schemeDictionary.get(filename);
        if (children == null) {
          children = new HashSet<String>();
        }
        children.addAll(reader.getSchemeSet());
        this.schemeDictionary.put(filename, children);
      }
    }
  }
  private void processFile(String currentFile) throws DITAOTException {
    File fileToParse;
    final File file = new File(currentFile);
    if (file.isAbsolute()) {
      fileToParse = file;
      currentFile = FileUtils.getRelativePath(rootFile, currentFile);
    } else {
      fileToParse = new File(baseInputDir, currentFile);
    }
    try {
      fileToParse = fileToParse.getCanonicalFile();
    } catch (final IOException e1) {
      logger.logError(e1.toString());
    }
    logger.logInfo("Processing " + fileToParse.getAbsolutePath());
    String msg = null;
    final Properties params = new Properties();
    params.put("%1", currentFile);

    if (!fileToParse.exists()) {
      logger.logError(MessageUtils.getMessage("DOTX008E", params).toString());
      return;
    }
    try {
      if (FileUtils.isValidTarget(currentFile.toLowerCase())) {
        reader.setTranstype(transtype);
        reader.setCurrentDir(new File(currentFile).getParent());
        reader.parse(fileToParse);

      } else {
        // edited by Alan on Date:2009-11-02 for Work Item:#1590 start
        // logger.logWarn("Input file name is not valid DITA file name.");
        final Properties prop = new Properties();
        prop.put("%1", fileToParse);
        logger.logWarn(MessageUtils.getMessage("DOTJ053W", params).toString());
        // edited by Alan on Date:2009-11-02 for Work Item:#1590 end
      }

      // don't put it into dita.list if it is invalid
      if (reader.isValidInput()) {
        processParseResult(currentFile);
        categorizeCurrentFile(currentFile);
      } else if (!currentFile.equals(inputFile)) {
        logger.logWarn(MessageUtils.getMessage("DOTJ021W", params).toString());
      }
    } catch (final SAXParseException sax) {

      // To check whether the inner third level is DITAOTBuildException
      // :FATALERROR
      final Exception inner = sax.getException();
      if (inner != null && inner instanceof DITAOTException) { // second
        // level
        logger.logInfo(inner.getMessage());
        throw (DITAOTException) inner;
      }
      if (currentFile.equals(inputFile)) {
        // stop the build if exception thrown when parsing input file.
        final MessageBean msgBean = MessageUtils.getMessage("DOTJ012F", params);
        msg = MessageUtils.getMessage("DOTJ012F", params).toString();
        msg = new StringBuffer(msg).append(":").append(sax.getMessage()).toString();
        throw new DITAOTException(msgBean, sax, msg);
      }
      final StringBuffer buff = new StringBuffer();
      msg = MessageUtils.getMessage("DOTJ013E", params).toString();
      buff.append(msg).append(LINE_SEPARATOR).append(sax.getMessage());
      logger.logError(buff.toString());
    } catch (final Exception e) {

      if (currentFile.equals(inputFile)) {
        // stop the build if exception thrown when parsing input file.
        final MessageBean msgBean = MessageUtils.getMessage("DOTJ012F", params);
        msg = MessageUtils.getMessage("DOTJ012F", params).toString();
        msg = new StringBuffer(msg).append(":").append(e.getMessage()).toString();
        throw new DITAOTException(msgBean, e, msg);
      }
      final StringBuffer buff = new StringBuffer();
      msg = MessageUtils.getMessage("DOTJ013E", params).toString();
      buff.append(msg).append(LINE_SEPARATOR).append(e.getMessage());
      logger.logError(buff.toString());
    }

    if (!reader.isValidInput() && currentFile.equals(inputFile)) {

      if (xmlValidate == true) {
        // stop the build if all content in the input file was filtered
        // out.
        msg = MessageUtils.getMessage("DOTJ022F", params).toString();
        throw new DITAOTException(msg);
      } else {
        // stop the build if the content of the file is not valid.
        msg = MessageUtils.getMessage("DOTJ034F", params).toString();
        throw new DITAOTException(msg);
      }
    }

    doneList.add(currentFile);
    reader.reset();
  }
  private void parseInputParameters(final AbstractPipelineInput input) {
    final String basedir = input.getAttribute(ANT_INVOKER_PARAM_BASEDIR);
    final String ditaInput = input.getAttribute(ANT_INVOKER_PARAM_INPUTMAP);

    tempDir = input.getAttribute(ANT_INVOKER_PARAM_TEMPDIR);
    ditaDir = input.getAttribute(ANT_INVOKER_EXT_PARAM_DITADIR);
    ditavalFile = input.getAttribute(ANT_INVOKER_PARAM_DITAVAL);
    xmlValidate = Boolean.valueOf(input.getAttribute(ANT_INVOKER_EXT_PARAM_VALIDATE));

    // Added by William on 2009-07-18 for req #12014 start
    // get transtype
    transtype = input.getAttribute(ANT_INVOKER_EXT_PARAM_TRANSTYPE);
    // Added by William on 2009-07-18 for req #12014 start

    gramcache = "yes".equalsIgnoreCase(input.getAttribute(ANT_INVOKER_EXT_PARAM_GRAMCACHE));
    setSystemid = "yes".equalsIgnoreCase(input.getAttribute(ANT_INVOKER_EXT_PARAN_SETSYSTEMID));

    // For the output control
    outputUtils = new OutputUtils();
    outputUtils.setGeneratecopyouter(input.getAttribute(ANT_INVOKER_EXT_PARAM_GENERATECOPYOUTTER));
    outputUtils.setOutterControl(input.getAttribute(ANT_INVOKER_EXT_PARAM_OUTTERCONTROL));
    outputUtils.setOnlyTopicInMap(input.getAttribute(ANT_INVOKER_EXT_PARAM_ONLYTOPICINMAP));

    // Set the OutputDir
    final File path = new File(input.getAttribute(ANT_INVOKER_EXT_PARAM_OUTPUTDIR));
    if (path.isAbsolute()) {
      outputUtils.setOutputDir(path.getAbsolutePath());
    } else {
      throw new IllegalArgumentException("Output directory " + tempDir + " must be absolute");
    }

    // Resolve relative paths base on the basedir.
    File inFile = new File(ditaInput);
    if (!inFile.isAbsolute()) {
      // XXX Shouldn't this be resolved to current directory, not Ant script base directory?
      inFile = new File(basedir, ditaInput);
    }
    try {
      inFile = inFile.getCanonicalFile();
    } catch (final IOException e1) {
      logger.logException(e1);
    }
    if (!new File(tempDir).isAbsolute()) {
      throw new IllegalArgumentException("Temporary directory " + tempDir + " must be absolute");
    } else {
      tempDir = FileUtils.normalize(tempDir);
    }
    if (!new File(ditaDir).isAbsolute()) {
      throw new IllegalArgumentException(
          "DITA-OT installation directory " + tempDir + " must be absolute");
    } else {
      ditaDir = FileUtils.normalize(ditaDir);
    }
    if (ditavalFile != null && !new File(ditavalFile).isAbsolute()) {
      // XXX Shouldn't this be resolved to current directory, not Ant script base directory?
      ditavalFile = new File(basedir, ditavalFile).getAbsolutePath();
    }

    baseInputDir = new File(inFile.getAbsolutePath()).getParent();
    baseInputDir = FileUtils.normalize(baseInputDir);

    rootFile = inFile.getAbsolutePath();
    rootFile = FileUtils.normalize(rootFile);

    inputFile = inFile.getName();
    try {
      // Added by William on 2009-06-09 for scheme key bug
      // create the keydef file for scheme files
      schemekeydef =
          XMLSerializer.newInstance(new FileOutputStream(new File(tempDir, "schemekeydef.xml")));
      schemekeydef.writeStartDocument();
      schemekeydef.writeStartElement(ELEMENT_STUB);

      // Added by William on 2009-06-25 for req #12014 start
      // create the export file for exportanchors
      // write the head
      export =
          new OutputStreamWriter(new FileOutputStream(new File(tempDir, FILE_NAME_EXPORT_XML)));
      export.write(XML_HEAD);
      export.write("<stub>");
      // Added by William on 2009-06-25 for req #12014 end
    } catch (final FileNotFoundException e) {
      logger.logException(e);
    } catch (final IOException e) {
      logger.logException(e);
    } catch (final SAXException e) {
      logger.logException(e);
    }

    // Set the mapDir
    outputUtils.setInputMapPathName(inFile.getAbsolutePath());
  }