Package com.adobe.epubcheck.messages

Examples of com.adobe.epubcheck.messages.MessageLocation


        }
        else if (styleSheetsCount > 1)
        {
          if (firstOne != null)
          {
            report.message(MessageId.CSS_012, new MessageLocation(fileName, firstOne.getLocation().getLineNumber(), firstOne.getLocation().getColumnNumber(), firstOne.getHrefAttribute()));
            firstOne = null;
          }
          report.message(MessageId.CSS_012, new MessageLocation(fileName, linkTag.getLocation().getLineNumber(), linkTag.getLocation().getColumnNumber(), linkTag.getHrefAttribute()));
        }
      }

      if (linkTag.relAttribute.compareToIgnoreCase("alternate stylesheet") == 0)
      {
        String title = linkTag.getTitleAttribute();
        if (title == null || title.trim().equals(""))
        {
          report.message(MessageId.CSS_015, new MessageLocation(fileName, linkTag.getLocation().getLineNumber(), linkTag.getLocation().getColumnNumber(), linkTag.getHrefAttribute()));
        }
        if (styleSheetsCount == 0)
        {
          report.message(MessageId.CSS_016, new MessageLocation(fileName, linkTag.getLocation().getLineNumber(), linkTag.getLocation().getColumnNumber(), linkTag.getHrefAttribute()));
        }
      }
    }
  }
View Full Code Here


      parser.getXMLReader().setContentHandler(new OPFhandler());
      parser.getXMLReader().parse(new InputSource(inputStream));
    }
    catch (ParserConfigurationException e)
    {
      report.message(MessageId.RSC_005, new MessageLocation(path, -1, -1), e.getMessage());
    }
    catch (SAXException e)
    {
      if (VERSION_3.equals(e.getMessage()))
      {
        report.info(null, FeatureEnum.FORMAT_VERSION, EPUBVersion.VERSION_3.toString());
        return EPUBVersion.VERSION_3;
      }
      else if (VERSION_2.equals(e.getMessage()))
      {
        report.info(null, FeatureEnum.FORMAT_VERSION, EPUBVersion.VERSION_2.toString());
        return EPUBVersion.VERSION_2;
      }
      else if (InvalidVersionException.UNSUPPORTED_VERSION.equals(e.getMessage()))
      {
        throw new InvalidVersionException(InvalidVersionException.UNSUPPORTED_VERSION);
      }
      else if (InvalidVersionException.VERSION_ATTRIBUTE_NOT_FOUND.equals(e.getMessage()))
      {
        throw new InvalidVersionException(InvalidVersionException.VERSION_ATTRIBUTE_NOT_FOUND);
      }
      else if (InvalidVersionException.PACKAGE_ELEMENT_NOT_FOUND.equals(e.getMessage()))
      {
        throw new InvalidVersionException(InvalidVersionException.PACKAGE_ELEMENT_NOT_FOUND);
      }
      else
      {
        report.message(MessageId.RSC_005, new MessageLocation(path, -1, -1), e.getMessage());
      }
    }
    catch (IOException e)
    {
      report.message(MessageId.PKG_008, new MessageLocation(path, -1, -1), path);
    }
    throw new InvalidVersionException(InvalidVersionException.VERSION_NOT_FOUND);
  }
View Full Code Here

        String fileToParse = epack.getManifestItemFileName(mi);

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

        epub3StructureHandler.setFileName(epack.getFileName());
        epub3StructureHandler.setReport(report);
View Full Code Here

    if (qName.compareToIgnoreCase("SCRIPT") == 0)
    {
      inScript = true;
      if (this.version == EPUBVersion.VERSION_2)
      {
        report.message(MessageId.SCP_004, new MessageLocation(fileName, locator.getLineNumber(), locator.getColumnNumber(), qName));
      }
      ScriptElement scriptElement = new ScriptElement();
      boolean isExternal = false;
      for (int i = 0; i < attributes.getLength(); i++)
      {
        String attrName = attributes.getQName(i);
        String attrValue = attributes.getValue(i);
        if (attrName.equalsIgnoreCase("src"))
        {
          isExternal = true;
        }
        scriptElement.addAttribute(attrName, attrValue);
      }
      if (isExternal)
      {
        report.info(this.fileName, FeatureEnum.SCRIPT, "external");
      }
      else
      {
        report.info(this.fileName, FeatureEnum.SCRIPT, "tag");
      }
      scriptElements.add(scriptElement);
    }
    else
    {
      HashSet<String> scriptEvents = OPSHandler30.getScriptEvents();
      HashSet<String> mouseEvents = OPSHandler30.getMouseEvents();

      for (int i = 0; i < attributes.getLength(); i++)
      {
        String attrName = attributes.getLocalName(i).toLowerCase();
        if (scriptEvents.contains(attrName))
        {
          this.inlineScriptCount++;
          if (this.version == EPUBVersion.VERSION_2)
          {
            report.message(MessageId.SCP_004, new MessageLocation(fileName, locator.getLineNumber(), locator.getColumnNumber(), attrName));
          }
          report.message(MessageId.SCP_006,
              new MessageLocation(this.fileName, locator.getLineNumber(), locator.getColumnNumber(), attrName));
          String attrValue = attributes.getValue(i);

          CheckForInner(attrValue);
        }
        if (mouseEvents.contains(attrName))
        {
          if (this.version == EPUBVersion.VERSION_2)
          {
            report.message(MessageId.SCP_004, new MessageLocation(fileName, locator.getLineNumber(), locator.getColumnNumber(), attrName));
          }
          report.message(MessageId.SCP_009,
              new MessageLocation(this.fileName, locator.getLineNumber(), locator.getColumnNumber(), attrName));
        }
      }
    }
  }
View Full Code Here

  {
    String lower = script.toLowerCase();
    int column = lower.indexOf("innerhtml");
    if (column >= 0)
    {
      report.message(MessageId.SCP_007, new MessageLocation(fileName, locator.getLineNumber(), locator.getColumnNumber(), trimContext(script, column)));
    }
    column = lower.indexOf("innertext");
    if (column >= 0)
    {
      report.message(MessageId.SCP_008, new MessageLocation(fileName, locator.getLineNumber(), locator.getColumnNumber(), trimContext(script, column)));
    }


    // the exact pattern is very complex and it slows down all script checking.
    //  what we can do here is use a blunt check (for the word "eval").  if it is not found, keep moving.
    //  If it is found, look closely using the exact pattern to see if the line truly matches the exact eval() function and report that.
    Matcher m = null;
    if (script.contains("eval"))
    {
      m = evalPattern.matcher(script);
      if (m.find())
      {
        report.message(MessageId.SCP_001, new MessageLocation(fileName, locator.getLineNumber(), locator.getColumnNumber(), trimContext(script, m.start())));
      }
    }
    m = localStoragePattern.matcher(script);
    if (m.find())
    {
      report.message(MessageId.SCP_003, new MessageLocation(fileName, locator.getLineNumber(), locator.getColumnNumber(), trimContext(script, m.start())));
    }
    m = sessionStoragePattern.matcher(script);
    if (m.find())
    {
      report.message(MessageId.SCP_003, new MessageLocation(fileName, locator.getLineNumber(), locator.getColumnNumber(), trimContext(script, m.start())));
    }
    m = xmlHttpRequestPattern.matcher(script);
    if (m.find())
    {
      report.message(MessageId.SCP_002, new MessageLocation(fileName, locator.getLineNumber(), locator.getColumnNumber(), trimContext(script, m.start())));
    }
    m = microsoftXmlHttpRequestPattern.matcher(script);
    if (m.find())
    {
      report.message(MessageId.SCP_002, new MessageLocation(fileName, locator.getLineNumber(), locator.getColumnNumber(), trimContext(script, m.start())));
    }
  }
View Full Code Here

        String fileToParse = epack.getManifestItemFileName(mi);

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

        parser.parseDoc(fileToParse, sh);
        String langAttribute = sh.getLangAttr();
        String xmlLangAttribute = sh.getXmlLangAttr();
        if (langAttribute != null && xmlLangAttribute != null)
        {
          if (xmlLangAttribute.compareToIgnoreCase(langAttribute) != 0)
          {
            report.message(MessageId.HTM_017, new MessageLocation(fileToParse, -1, -1));
          }

          if (!isValidLanguageDefinition(xmlLangAttribute))
          {
            report.message(MessageId.HTM_018, new MessageLocation(fileToParse, -1, -1));
          }
          if (!isValidLanguageDefinition(langAttribute))
          {
            report.message(MessageId.HTM_019, new MessageLocation(fileToParse, -1, -1));
          }
        }
        else
        {
          if (xmlLangAttribute == null)
          {
            report.message(MessageId.HTM_020, new MessageLocation(fileToParse, -1, -1));
          }
          if (langAttribute == null)
          {
            report.message(MessageId.HTM_021, new MessageLocation(fileToParse, -1, -1));
          }
        }
      }
    }
    return result;
View Full Code Here

    if (!result && epack.getVersion() != EPUBVersion.VERSION_2)
    {
      if (report.getClass() == CheckingReport.class)
      {
        report.message(MessageId.NCX_003, new MessageLocation(pathRootFile, -1, -1));
      }
      else
      {
        report.info(pathRootFile, FeatureEnum.HAS_NCX, "false");
      }
View Full Code Here

          {
            path = PathUtil.resolveRelativeReference(navDocEntry, path, null);
          }
          catch (IllegalArgumentException ex)
          {
            report.message(MessageId.OPF_022, new MessageLocation(navDocEntry, getElementLineNumber(content), getElementColumnNumber(content)), path);
          }
          if (!path.equals(""))
          {
            tocLinkSet.add(path);
            playOrder = playOrder != null ? playOrder.trim() : playOrder;
            if (validateInt(playOrder))
            {
              report.info(path, FeatureEnum.NAVIGATION_ORDER, playOrder);
            }
          }
        }
      }
      n = doc.getElementsByTagNameNS(ncxNS, "pageList");
      if (n.getLength() > 0)
      {
        Element pageList = (Element) n.item(0);
        report.message(MessageId.NCX_005, new MessageLocation(navDocEntry, getElementLineNumber(pageList), getElementColumnNumber(pageList), pageList.getTagName()));
      }

      PackageManifest manifest = epack.getManifest();
      PackageSpine spine = epack.getSpine();

      if (spine != null)
      {
        String tocFileName = spine.getToc();
        for (int i = 0; i < spine.itemsLength(); ++i)
        {
          SpineItem si = spine.getItem(i);
          ManifestItem mi = manifest.getItem(si.getIdref());
          if (mi != null)
          {
            String path = mi.getHref();
            path = PathUtil.resolveRelativeReference(navDocEntry, path,  null);

            if (path != null && !path.equals(tocFileName) && !path.equals(navDocEntry) && !tocLinkSet.contains(path))
            {
              report.message(MessageId.OPF_059, new MessageLocation(navDocEntry, -1, -1, path));
            }
          }
          else
          {
            // id not found in manifest
            report.message(MessageId.OPF_049, new MessageLocation(navDocEntry, -1, -1, epack.getPackageMainPath()), si.getIdref());
          }
        }
      }
    }
  }
View Full Code Here

      String encoding = sniffEncoding(in);
      if (encoding != null && !encoding.equals("UTF-8")
          && !encoding.equals("UTF-16"))
      {
        report.message(MessageId.CSS_003, new MessageLocation(resource, 0, 0, ""), encoding);
      }

      InputSource ins = new InputSource(in);
      ins.setSystemId(zipRoot + resource);
      parser.parse(ins, this);

    }
    catch (FileNotFoundException e)
    {
      String message = e.getMessage();
      message = new File(message).getName();
      int p = message.indexOf("(");
      if (p > 0)
      {
        message = message.substring(0, message.indexOf("("));
      }
      message = message.trim();
      report.message(MessageId.RSC_001, new MessageLocation(resource, -1, -1), message);
    }
    catch (IOException e)
    {
      report.message(MessageId.PKG_008, new MessageLocation(resource, 0, 0), resource);
    }
    catch (IllegalArgumentException e)
    {
      report.message(MessageId.RSC_005, new MessageLocation(resource, 0, 0), e.getMessage());
    }
    catch (SAXException e)
    {
      report.message(MessageId.RSC_005, new MessageLocation(resource, 0, 0), e.getMessage());
    }
    catch (NullPointerException e)
    {
      // this happens for unresolved entities, reported in entityResolver
      // code.
View Full Code Here

  public void error(SAXParseException ex) throws
      SAXException
  {
    report.message(MessageId.RSC_005,
        new MessageLocation(resource, ex.getLineNumber(), ex.getColumnNumber()),
        ex.getMessage());
  }
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.