예제 #1
0
  protected void checkHRef(XMLElement e, String attrNS, String attr) {
    String href = e.getAttributeNS(attrNS, attr);
    if (href == null) {
      return;
    }
    href = href.trim();
    if (href.isEmpty()) {
      // if href="" then selfreference which is valid,
      // but as per issue 225, issue a hint
      report.message(
          MessageId.HTM_045,
          EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber(), href));
      return;
    } else if (href.contains("#epubcfi")) {
      return; // temp until cfi implemented
    } else if (".".equals(href)) {
      // selfreference, no need to check
      return;
    }

    URI uri = checkURI(href);
    if (uri == null) return;

    if ("http".equals(uri.getScheme())) {
      report.info(path, FeatureEnum.REFERENCE, href);
    }

    /*
     * mgy 20120417 adding check for base to initial if clause as part of
     * solution to issue 155
     */
    if (URISchemes.contains(uri.getScheme())
        || (null != base && URISchemes.contains(base.getScheme()))) {
      return;
    }
    // This if statement is needed to make sure XML Fragment identifiers
    // are not reported as non-registered URI scheme types
    else if (uri.getScheme() != null) {
      report.message(
          MessageId.HTM_025,
          EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber(), href));
      return;
    }

    try {
      href = PathUtil.resolveRelativeReference(path, href, base == null ? null : base.toString());
    } catch (IllegalArgumentException err) {
      report.message(
          MessageId.OPF_010,
          EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber(), href),
          err.getMessage());
      return;
    }
    processHyperlink(href);
  }
예제 #2
0
 public void runChecks() {
   OCFPackage ocf = context.ocf.get();
   if (!ocf.hasEntry(path)) {
     report.message(MessageId.RSC_001, EPUBLocation.create(ocf.getName()), path);
   } else if (!ocf.canDecrypt(path)) {
     report.message(MessageId.RSC_004, EPUBLocation.create(ocf.getName()), path);
   } else if (!path.endsWith(".xml")) {
     report.message(MessageId.OPF_080, EPUBLocation.create(path));
   } else {
     validate();
   }
 }
예제 #3
0
  public void endElement() {
    openElements--;
    XMLElement e = parser.getCurrentElement();
    String ns = e.getNamespace();
    String name = e.getName();

    if (openElements == 0) {
      report.info(path, FeatureEnum.CHARS_COUNT, Long.toString(charsCount));
      if (!epubTypeInUse) {
        if (context.version == EPUBVersion.VERSION_3) {
          report.message(MessageId.ACC_007, EPUBLocation.create(path));
        }
      } else {
        epubTypeInUse = false;
      }
    }

    ElementLocation currentLocation = elementLocationStack.pop();

    if (EpubConstants.HtmlNamespaceUri.equals(ns)) {

      if ("script".equals(name)) {
        String attr = e.getAttribute("type");
        report.info(path, FeatureEnum.HAS_SCRIPTS, (attr == null) ? "" : attr);
      } else if ("style".equals(name)) {
        String style = textNode.toString();
        if (style.length() > 0) {
          CSSCheckerFactory.getInstance()
              .newInstance(context, style, currentLocation.getLineNumber(), false)
              .runChecks();
        }
        textNode = null;
      } else if ("head".equals(name)) {
        checkStylesheetFallback();
      } else if ("table".equals(name)) {
        if (tableDepth > 0) {
          --tableDepth;
          EPUBLocation location =
              EPUBLocation.create(
                  path,
                  currentLocation.getLineNumber(),
                  currentLocation.getColumnNumber(),
                  "table");

          checkDependentCondition(MessageId.ACC_005, tableDepth == 0, hasTh, location);
          checkDependentCondition(MessageId.ACC_006, tableDepth == 0, hasThead, location);
          checkDependentCondition(MessageId.ACC_012, tableDepth == 0, hasCaption, location);

          hasTh = hasThead = hasCaption = false;
        }
      }
    }
  }
예제 #4
0
 private void checkType(String type) {
   VocabUtil.parsePropertyList(
       type,
       vocabs,
       report,
       EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
 }
예제 #5
0
  public void startElement() {
    if (!checkedUnsupportedXMLVersion) {
      HandlerUtil.checkXMLVersion(parser);
      checkedUnsupportedXMLVersion = true;
    }

    XMLElement e = parser.getCurrentElement();
    String name = e.getName();

    if (name.equals("smil")) {
      vocabs =
          VocabUtil.parsePrefixDeclaration(
              e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "prefix"),
              RESERVED_VOCABS,
              KNOWN_VOCAB_URIS,
              DEFAULT_VOCAB_URIS,
              report,
              EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
    } else if (name.equals("seq")) {
      processSeq(e);
    } else if (name.equals("text")) {
      processSrc(e);
    } else if (name.equals("audio")) {
      processRef(e.getAttribute("src"), XRefChecker.Type.AUDIO);
    } else if (name.equals("body") || name.equals("par")) {
      checkType(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "type"));
    }
  }
예제 #6
0
  protected void checkLink(XMLElement e, String attrNS, String attr) {
    String href = e.getAttributeNS(attrNS, attr);
    String rel = e.getAttributeNS(attrNS, "rel");
    if (xrefChecker.isPresent()
        && href != null
        && rel != null
        && rel.toLowerCase().contains("stylesheet")) {
      href = PathUtil.resolveRelativeReference(path, href, base == null ? null : base.toString());
      xrefChecker
          .get()
          .registerReference(
              path,
              parser.getLineNumber(),
              parser.getColumnNumber(),
              href,
              XRefChecker.Type.STYLESHEET);

      // Check the mimetype to record possible non-standard stylesheets
      // with no fallback
      String mimetype = xrefChecker.get().getMimeType(href);
      if (mimetype != null) {
        if (OPFChecker.isBlessedStyleType(mimetype)
            || OPFChecker.isDeprecatedBlessedStyleType(mimetype)) {
          hasCss = true;
        } else {
          nonStandardStylesheetLink =
              Optional.of(
                  EPUBLocation.create(
                      path, parser.getLineNumber(), parser.getColumnNumber(), href));
        }
      }
    }
  }
예제 #7
0
 private void processRef(String ref, XRefChecker.Type type) {
   if (ref != null && context.xrefChecker.isPresent()) {
     ref = PathUtil.resolveRelativeReference(path, ref, null);
     if (type == XRefChecker.Type.AUDIO) {
       String mimeType = context.xrefChecker.get().getMimeType(ref);
       if (mimeType != null && !OPFChecker30.isBlessedAudioType(mimeType)) {
         report.message(
             MessageId.MED_005,
             EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()),
             ref,
             mimeType);
       }
     }
     context
         .xrefChecker
         .get()
         .registerReference(path, parser.getLineNumber(), parser.getColumnNumber(), ref, type);
   }
 }
예제 #8
0
 protected void checkIFrame(XMLElement e) {
   report.message(
       MessageId.HTM_036,
       EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber(), e.getName()));
 }