Package com.adobe.epubcheck.messages

Examples of com.adobe.epubcheck.messages.MessageLocation


  public void fatalError(SAXParseException ex) throws
      SAXException
  {
    report.message(MessageId.RSC_016,
        new MessageLocation(resource, ex.getLineNumber(), ex.getColumnNumber()),
        ex.getMessage());
  }
View Full Code Here


  public void warning(SAXParseException ex) throws
      SAXException
  {
    report.message(MessageId.RSC_017,
        new MessageLocation(resource, ex.getLineNumber(), ex.getColumnNumber()),
        ex.getMessage());
  }
View Full Code Here

        {
          //for heritage content collections, dont warn about this, as its not explicitly forbidden by the spec
        }
        else
        {
          report.message(MessageId.HTM_009, new MessageLocation(resource, 0, 0));
        }

      }

      if (mimeType != null && "application/x-dtbncx+xml".equals(mimeType))
      {
        String complete = "<!DOCTYPE ncx PUBLIC \"-//NISO//DTD ncx 2005-1//EN\" " +
            "\n \"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd\">";
        if (matchDoctypeId("-//NISO//DTD ncx 2005-1//EN", publicId, complete))
        {
          matchDoctypeId("http://www.daisy.org/z3986/2005/ncx-2005-1.dtd", systemId, complete);
        }
      }

    }
    else if (version == EPUBVersion.VERSION_3)
    {
      if (mimeType != null && "application/xhtml+xml".equals(mimeType) && "html".equalsIgnoreCase(root))
      {
        String complete = "<!DOCTYPE html>";
        //warn for obsolete or unknown doctypes
        if (publicId == null && (systemId == null || systemId.equals("about:legacy-compat")))
        {
          // we assume to have have <!DOCTYPE html> or <!DOCTYPE html SYSTEM "about:legacy-compat">
        }
        else
        {
          report.message(MessageId.HTM_004, new MessageLocation(resource, 0, 0), publicId, complete);
        }
      }
      else if ("image/svg+xml".equals(mimeType) && "svg".equalsIgnoreCase(root))
      {
        if (
            !(checkDTD("-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", publicId, systemId||
              checkDTD("-//W3C//DTD SVG 1.0//EN", "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd", publicId, systemId||
              checkDTD("-//W3C//DTD SVG 1.1 Basic//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd", publicId, systemId||
              checkDTD("-//W3C//DTD SVG 1.1 Tiny//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd", publicId, systemId))
           )
        {
          report.message(MessageId.HTM_009, new MessageLocation(resource, 0, 0));
        }
      }
      else if (mimeType != null && "application/x-dtbncx+xml".equals(mimeType))
      {
        String complete = "<!DOCTYPE ncx PUBLIC \"-//NISO//DTD ncx 2005-1//EN\" " +
            "\n \"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd\">";
        if (matchDoctypeId("-//NISO//DTD ncx 2005-1//EN", publicId, complete))
        {
          matchDoctypeId("http://www.daisy.org/z3986/2005/ncx-2005-1.dtd", systemId, complete);
        }
      }
      else
      {
        report.message(MessageId.HTM_009, new MessageLocation(resource, 0, 0));
      }
    }

    firstStartDTDInvocation = false;
  }
View Full Code Here

  boolean matchDoctypeId(String expected, String given, String messageParam)
  {
    if (given != null && !expected.equals(given))
    {
      report.message(MessageId.HTM_004, new MessageLocation(resource, 0, 0), given, messageParam);
      return false;
    }
    return true;
  }
View Full Code Here

      }
    }
    if (!entities.contains(ent) && !ent.equals("[dtd]"))
    {
      // This message may never be reported.  Undeclared entities result in a Sax Parser Error and message RSC_005.
      report.message(MessageId.HTM_011, new MessageLocation(resource, getLineNumber(), getColumnNumber(), ent));
    }
  }
View Full Code Here

      }
    }

    if (version == EPUBVersion.VERSION_3 && (mimeType.compareTo("application/xhtml+xml") == 0))
    {
      report.message(MessageId.HTM_003, new MessageLocation(resource, getLineNumber(), getColumnNumber(), name), name);
      return;
    }
    entities.add(name);
  }
View Full Code Here

      String name = e.getName();
      if (name.equals("package"))
      {
        if (!ns.equals("http://www.idpf.org/2007/opf"))
        {
          report.message(MessageId.OPF_047, new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()));
          opf12PackageFile = true;
        }
        /*
             * This section checks to see the value of the unique-identifier
             * attribute and stores it in the String uniqueIdent or reports
             * an error if the unique-identifier attribute is missing or
             * does not have a value
             */
        String uniqueIdentAttr = e.getAttribute("unique-identifier");
        if (uniqueIdentAttr != null && !uniqueIdentAttr.equals(""))
        {
          uniqueIdent = uniqueIdentAttr;
        }
        else
        {
          report.message(MessageId.OPF_048, new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()));
        }
      }
      else if (name.equals("item"))
      {
        String id = e.getAttribute("id");
        String href = e.getAttribute("href");
        if (href != null
            && !(version == EPUBVersion.VERSION_3 && href
                .matches("^[^:/?#]+://.*"))) {
          try
          {
            href = PathUtil.resolveRelativeReference(path, href,
                null);
          }
          catch (IllegalArgumentException ex)
          {
            report.message(MessageId.OPF_010,
                new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber(), href),
                ex.getMessage());
            href = null;
          }
        }
        if (href != null && href.matches("^[^:/?#]+://.*")) {
       
          report.info(path, FeatureEnum.REFERENCE, href);
        }
        String mimeType = e.getAttribute("media-type");
        String fallback = e.getAttribute("fallback");
       
        // dirty fix for issue 271: treat @fallback attribute in EPUB3 like fallback-style in EPUB2
        // then all the epubcheck mechanisms on checking stylesheet fallbacks will work as in EPUB 2
        String fallbackStyle = (version == EPUBVersion.VERSION_3) ? e.getAttribute("fallback") : e.getAttribute("fallback-style");
       
        String namespace = e.getAttribute("island-type");
        String properties = e.getAttribute("properties");
        if (properties != null)
        {
          properties = properties.replaceAll("[\\s]+", " ");
        }

        if (version == EPUBVersion.VERSION_3
            && href.matches("^[^:/?#]+://.*")
            && !OPFChecker30.isBlessedAudioType(mimeType)
            && !OPFChecker30.isBlessedVideoType(mimeType))
        {
          if (OPFChecker30.isCoreMediaType(mimeType))
          {
            report.message(MessageId.OPF_010,
                new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()), href);
          }
          else
          {
            // mgy 20120414: this shouldn't even be a warning
            // report.warning(
            // path,
            // parser.getLineNumber(),
            // parser.getColumnNumber(),
            // "Remote resource not validated");
          }
        }

        OPFItem item = new OPFItem(id, href, mimeType, fallback,
            fallbackStyle, namespace, properties,
            parser.getLineNumber(), parser.getColumnNumber());

        if (id != null)
        {
          itemMapById.put(id, item);
          report.info(href, FeatureEnum.UNIQUE_IDENT, id);
        }
        else
        {
          System.err.printf("Item is missing id : %s\n", href);
        }
        if (properties != null)
        {
          String propertyArray[] = properties.split(" ");
          for (String aPropertyArray : propertyArray)
          {
            if (aPropertyArray.equals("nav"))
            {
              item.setNav(true);
            }
            if (aPropertyArray.equals("scripted"))
            {
              item.setScripted(true);
            }
          }

        }
        if (href != null && registerEntry)
        {
          itemMapByPath.put(href, item);
          items.add(item);
        }
      }
      else if (name.equals("reference"))
      {
        String type = e.getAttribute("type");
        String title = e.getAttribute("title");
        String href = e.getAttribute("href");
        if (href != null && xrefChecker != null)
        {
          try
          {
            href = PathUtil.resolveRelativeReference(path, href,
                null);
            xrefChecker.registerReference(path,
                parser.getLineNumber(),
                parser.getColumnNumber(), href,
                XRefChecker.RT_GENERIC);
          }
          catch (IllegalArgumentException ex)
          {
            report.message(MessageId.OPF_010,
                new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber(), href), ex.getMessage());
            href = null;
          }
        }
        if (href != null && href.startsWith("http"))
        {
          report.info(path, FeatureEnum.REFERENCE, href);
        }
       
        OPFReference ref = new OPFReference(type, title, href,
            parser.getLineNumber(), parser.getColumnNumber());
        refs.add(ref);
      }
      else if (name.equals("spine"))
      {
        String pageMap = e.getAttribute("page-map");
        if (pageMap != null)
        {
          pageMapId = pageMap;
          pageMapReferenceLocation = new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber(), String.format("page-map=\"%1$s\"", pageMapId));
          report.message(MessageId.OPF_062, pageMapReferenceLocation);
        }

        String idref = e.getAttribute("toc");
        if (idref != null)
        {
          OPFItem toc = itemMapById.get(idref);
          if (toc == null)
          {
            report.message(MessageId.OPF_049,
                new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()),
                idref);
            report.info(null, FeatureEnum.HAS_NCX, "false");
          }
          else
          {
            toc.setNcx(true);
            report.info(toc.getPath(), FeatureEnum.HAS_NCX, "true");
            if (toc.getMimeType() != null
                && !toc.getMimeType().equals(
                "application/x-dtbncx+xml"))
            {
              report.message(MessageId.OPF_050,
                  new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()));
            }
          }
        }
        else
        {
          report.info(null, FeatureEnum.HAS_NCX, "false");
        }
      }
      else if (name.equals("itemref"))
      {
        String idref = e.getAttribute("idref");
        if (idref != null)
        {
          OPFItem item = getItemById(idref);
          if (item != null)
          {
            spine.add(item);
            item.setInSpine(true);
            report.info(item.getPath(), FeatureEnum.IS_SPINEITEM, "true");
            String linear = e.getAttribute("linear");
            if (linear != null && "no".equals(linear.trim()))
            {
              item.setSpineLinear(false);
            }
            else
            {
              item.setSpineLinear(true);
            }
            report.info(item.getPath(), FeatureEnum.IS_LINEAR, String.valueOf(item.getSpineLinear()));

            boolean isFixed = globalPrePaginated;
            String properties = e.getAttribute("properties");
            if (properties != null && !properties.equals(""))
            {
              properties = properties.replaceAll("[\\s]+", " ");
              String propertyArray[] = properties.split(" ");
              for (String prop : propertyArray)
              {
                if (prop.equals("rendition:layout-pre-paginated"))
                {
                  isFixed = true;
                }
                else if (prop.equals("rendition:layout-reflowable"))
                {
                  isFixed = false;
                }
              }
            }
            if (isFixed)
            {
              report.info(item.getPath(), FeatureEnum.HAS_FIXED_LAYOUT, String.valueOf(true));
            }
          }
          else
          {
            report.message(MessageId.OPF_049,
                new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()),
                idref);
          }
        }
      }
      else if (name.equals("dc-metadata") || name.equals("x-metadata"))
      {
        if (!opf12PackageFile)
        {
          report.message(MessageId.OPF_049,
              new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()),
              name);
        }
      }
    }
    else if (ns.equals("http://purl.org/dc/elements/1.1/"))
    {
      // in the DC metadata, when the <identifier> element is parsed, if
      // it has a non-null and non-empty id attribute value that is the
      // same as the value of the unique-identifier attribute of the
      // package element, set uniqueIdentExists = true (to make sure that
      // the unique-identifier attribute references an existing
      // <identifier> id attribute
      String name = e.getName();
      if (name.equals("identifier"))
      {
        String idAttr = e.getAttribute("id");
        if (idAttr != null && !idAttr.equals("")
            && idAttr.equals(uniqueIdent))
        {
          uniqueIdentExists = true;
        }
      }
      else if (name.equals("creator"))
      {
        String role = e.getAttributeNS("http://www.idpf.org/2007/opf", "role");
        if (role != null && !role.equals("") && !isValidRole(role))
        {
          report.message(MessageId.OPF_052,
              new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()), role);
        }
      }
    }
  }
View Full Code Here

        if (!valid)
        {
          if (this.version == EPUBVersion.VERSION_3)
          {
            report.message(MessageId.OPF_053,
                new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()),
                (dateval == null ? "" : dateval),
                detail);
          }
          else
          {
            report.message(MessageId.OPF_054,
                new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()),
                (dateval == null ? "" : dateval),
                detail);
          }
        }
      }
      else if (name.equals("title") || name.equals("language"))
      {
        // issue 138: issue a warning if dc:title and dc:language is
        // empty for 2.0 and 2.0.1
        // note that an empty dc:identifier is checked in opf20.rng and
        // will
        // therefore be reported as an error, that may or may not be a
        // good idea.
        if ("language".equals(name))
        {
          String value = (String) e.getPrivateData();
          if (value != null)
          {
            report.info(null, FeatureEnum.DC_LANGUAGE, value.trim());
          }
        }
        else if ("title".equals(name))
        {
          String value = (String) e.getPrivateData();
          if (value != null)
          {
            report.info(null, FeatureEnum.DC_TITLE, value.trim());
          }
        }
        if (version == EPUBVersion.VERSION_2)
        {
          String value = (String) e.getPrivateData();
          if (value == null || value.trim().length() < 1)
          {
            report.message(MessageId.OPF_055,
                new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()),
                name);
          }
        }
      }
      else if (name.equals("creator"))
View Full Code Here

        String fileToParse = getEntryFileName(itemEntry, epack);

        ZipEntry entry = epack.getZip().getEntry(fileToParse);
        if (entry == null)
        {
          report.message(MessageId.RSC_001, new MessageLocation(epack.getFileName(), -1, -1), fileToParse);
          continue;
        }

        try
        {
          InputStream inputStream = getInputStream(fileToParse);
          CssSource source = new CssSource(fileToParse, inputStream);
          CssParser parser = new CssParser();
          handler.setPath(fileToParse);

          parser.parse(source, handler, handler);
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    }

    for (int i = 0; i < epack.getManifest().itemsLength(); i++)
    {
      ManifestItem itemEntry = epack.getManifest().getItem(i);
      if (validTypes.isValidMediaType(itemEntry.getMediaType()))
      {
        String fileToParse = getEntryFileName(itemEntry, epack);
        ZipEntry entry = epack.getZip().getEntry(fileToParse);
        if (entry == null)
        {
          report.message(MessageId.RSC_001, new MessageLocation(epack.getFileName(), -1, -1), fileToParse);
          continue;
        }

        XMLContentDocParser parser;
        String properties = itemEntry.getProperties();
        boolean itemIsFixedFormat = (properties != null && properties.contains("rendition:layout-pre-paginated"));

        parser = new XMLContentDocParser(epack.getZip(), report);
        CSSStyleAttributeHandler h = new CSSStyleAttributeHandler(isGlobalFixed, itemIsFixedFormat);
        h.setCssHandler(handler);
        h.setReport(report);
        h.setFileName(fileToParse);
        parser.parseDoc(fileToParse, h);
        Vector<CSSStyleAttributeHandler.StyleAttribute> styleTags = h.getStyleTagValues();

        for (int t = 0; t < styleTags.size(); t++)
        {
          CSSStyleAttributeHandler.StyleAttribute value = styleTags.elementAt(t);
          searchInsideValue(value, tsd, fileToParse);
        }

        Collection<CSSStyleAttributeHandler.StyleAttribute> styleAttributes = h.getStyleAttributesValues();
        for (CSSStyleAttributeHandler.StyleAttribute value : styleAttributes)
        {
          searchInsideValue(value, tsd, fileToParse);
          report.message(MessageId.ACC_013, new MessageLocation(fileToParse, value.getLine(), value.getColumn(), value.getValue()));
        }
      }
    }

    CheckUnusedCSSClassSelectors(handler, report);

    if (numCssFiles > EXCESSIVE_CSS_THRESHOLD)
    {
      report.message(MessageId.CSS_011, new MessageLocation(epack.getFileName(), -1, -1));
    }
    return true;
  }
View Full Code Here

      Matcher matcher = p.matcher(entry.getValue());
      int position = 0;
      while (matcher.find(position))
      {
        position = matcher.end();
        report.message(messageCode, new MessageLocation(file, entry.getLine(), entry.getColumn(), entry.getValue().trim()));
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.adobe.epubcheck.messages.MessageLocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.