/** * 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); } }
@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++; } }