Example #1
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;
        }
      }
    }
  }
Example #2
0
 @Override
 protected void initContentCheckerFactoryMap() {
   HashMap<String, ContentCheckerFactory> map = new HashMap<String, ContentCheckerFactory>();
   map.put("application/xhtml+xml", OPSCheckerFactory.getInstance());
   map.put("application/x-dtbook+xml", DTBookCheckerFactory.getInstance());
   map.put("image/jpeg", BitmapCheckerFactory.getInstance());
   map.put("image/gif", BitmapCheckerFactory.getInstance());
   map.put("image/png", BitmapCheckerFactory.getInstance());
   map.put("image/svg+xml", OPSCheckerFactory.getInstance());
   map.put("text/css", CSSCheckerFactory.getInstance());
   map.put("application/smil+xml", OverlayCheckerFactory.getInstance());
   contentCheckerFactoryMap.clear();
   contentCheckerFactoryMap.putAll(map);
 }
Example #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);
    }
  }