예제 #1
0
  public void startElement() {
    super.startElement();

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

    if (name.equals("package")) {
      HandlerUtil.processPrefixes(
          e.getAttribute("prefix"),
          prefixSet,
          report,
          path,
          parser.getLineNumber(),
          parser.getColumnNumber());
    } else if (name.equals("meta")) {
      processMeta(e);
    } else if (name.equals("link")) {
      processLink(e);
    } else if (name.equals("item")) {
      processItemProperties(e.getAttribute("properties"), e.getAttribute("media-type"));
    } else if (name.equals("itemref")) {
      processItemrefProperties(e.getAttribute("properties"));
    } else if (name.equals("mediaType")) {
      processBinding(e);
    }
  }
예제 #2
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"));
    }
  }
예제 #3
0
  public void startElement() {
    openElements++;
    XMLElement e = parser.getCurrentElement();
    ElementLocation currentLocation =
        new ElementLocation(parser.getLineNumber(), parser.getColumnNumber());
    elementLocationStack.push(currentLocation);

    if (!checkedUnsupportedXMLVersion) {
      HandlerUtil.checkXMLVersion(parser);
      checkedUnsupportedXMLVersion = true;
    }

    String id = e.getAttribute("id");

    String baseTest = e.getAttributeNS(XMLConstants.XML_NS_URI, "base");
    if (baseTest != null) {
      base = checkURI(baseTest);
    }

    if (!epubTypeInUse) {
      String eNS = e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "type");
      if (eNS != null) {
        epubTypeInUse = true;
      }
    }

    String ns = e.getNamespace();
    String name = e.getName().toLowerCase();
    XRefChecker.Type resourceType = XRefChecker.Type.GENERIC;
    if (ns != null) {
      if (ns.equals("http://www.w3.org/2000/svg")) {
        if (name.equals("lineargradient")
            || name.equals("radialgradient")
            || name.equals("pattern")) {
          resourceType = XRefChecker.Type.SVG_PAINT;
        } else if (name.equals("clippath")) {
          resourceType = XRefChecker.Type.SVG_CLIP_PATH;
        } else if (name.equals("symbol")) {
          resourceType = XRefChecker.Type.SVG_SYMBOL;
        } else if (name.equals("a")) {
          checkHRef(e, "http://www.w3.org/1999/xlink", "href");
        } else if (name.equals("use")) {
          checkSymbol(e, "http://www.w3.org/1999/xlink", "href");
        } else if (name.equals("image")) {
          checkImage(e, "http://www.w3.org/1999/xlink", "href");
        }
        checkPaint(e, "fill");
        checkPaint(e, "stroke");
      } else if (ns.equals(EpubConstants.HtmlNamespaceUri)) {
        if (name.equals("a")) {
          checkHRef(e, null, "href");
        } else if (name.equals("img")) {
          checkImage(e, null, "src");
        } else if (name.equals("object")) {
          checkObject(e, null, "data");
        } else if (name.equals("link")) {
          checkLink(e, null, "href");
        } else if (name.equals("base")) {
          base = checkURI(e.getAttribute("href"));
        } else if (name.equals("style")) {
          textNode = new StringBuilder();
        } else if (name.equals("iframe")) {
          checkIFrame(e);
        } else if (name.equals("table")) {
          ++tableDepth;
        } else if (name.equals("th") && tableDepth > 0) {
          hasTh = true;
        } else if (name.equals("thead") && tableDepth > 0) {
          hasThead = true;
        } else if (name.equals("caption") && tableDepth > 0) {
          hasCaption = true;
        } else if (name.equals("i")
            || name.equals("b")
            || name.equals("em")
            || name.equals("strong")) {
          checkBoldItalics(e);
        }

        resourceType = XRefChecker.Type.HYPERLINK;

        String style = e.getAttribute("style");
        if (style != null && style.length() > 0) {
          CSSCheckerFactory.getInstance()
              .newInstance(context, style, currentLocation.getLineNumber(), true)
              .runChecks();
        }
      }
    }
    if (xrefChecker.isPresent() && id != null) {
      xrefChecker
          .get()
          .registerAnchor(
              path,
              currentLocation.getLineNumber(),
              currentLocation.getColumnNumber(),
              id,
              resourceType);
    }
  }