Esempio n. 1
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);
   }
 }
Esempio n. 2
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++;
    }
  }