Package com.adobe.epubcheck.messages

Examples of com.adobe.epubcheck.messages.MessageLocation


  }

  private void processMetaProperty(String property)
  {
    VocabUtil.parseProperty(property, metaVocabs, report,
        new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()));
  }
View Full Code Here


      {
        if (mimeType == null)
        {
          mimeType = "null";
        }
        report.message(MessageId.OPF_036, new MessageLocation(this.getFileName(),
            locator.getLineNumber(),
            locator.getColumnNumber()), mimeType);
      }
    }
    else if (("source".compareTo(tagName) == 0) && ("audio".compareTo(tagStack.peek()) == 0))
    {
      String mimeType = attributes.getValue("type");

      if (mimeType == null || !isBlessedAudioType(mimeType))
      {
        if (mimeType == null)
        {
          mimeType = "null";
        }
        report.message(MessageId.OPF_056, new MessageLocation(this.getFileName(),
            locator.getLineNumber(),
            locator.getColumnNumber()), mimeType);
      }
    }
    else if (("ul".compareTo(tagName) == 0) || ("ol".compareTo(tagName) == 0) || ("Dl".compareTo(tagName) == 0))
    {
      listItemCounters.add(0);
    }
    else if (("li".compareTo(tagName) == 0) &&
        (("ul".compareTo(tagStack.peek()) == 0) ||
            ("ol".compareTo(tagStack.peek()) == 0)))
    {
      listItemCounters.set(listItemCounters.size() - 1, 1 + listItemCounters.get(listItemCounters.size() - 1));
    }
    else if (("dh".compareTo(tagName) == 0) && ("dl".compareTo(tagStack.peek()) == 0))
    {
      listItemCounters.set(listItemCounters.size() - 1, 1 + listItemCounters.get(listItemCounters.size() - 1));
    }
    else if ("input".compareTo(tagName) == 0)
    {
      String id = attributes.getValue("id");
      String type = attributes.getValue("type");
      if (id != null)
      {
        ControlMark mark = formInputMarks.get(id);
        if (mark == null)
        {
          mark = new ControlMark();
          mark.controlId = id;
        }
        mark.location = new MessageLocation(this.getFileName(), locator.getLineNumber(), locator.getColumnNumber(), id);
        mark.mark |= HAS_INPUT;
        formInputMarks.put(id, mark);
      }
      else if (type == null || "submit".compareToIgnoreCase(type) != 0// submit buttons don't need a label
      {
        report.message(MessageId.HTM_028, new MessageLocation(this.fileName,
            locator.getLineNumber(),
            locator.getColumnNumber()), tagName);
      }
    }
    else if ("label".compareTo(tagName) == 0)
    {
      String id = attributes.getValue("for");
      if (id != null)
      {
        ControlMark mark = formInputMarks.get(id);
        if (mark == null)
        {
          mark = new ControlMark();
          mark.controlId = id;

          // only set the location if we are creating the entry here.  This location will be overwritten
          // by the input control location, but if there is no input that overrides it, the label location will
          // be the one reported.
          mark.location = new MessageLocation(this.getFileName(), locator.getLineNumber(), locator.getColumnNumber(), id);
        }
        mark.mark |= HAS_LABEL;
        formInputMarks.put(id, mark);
      }
      else
      {
        report.message(MessageId.HTM_029, new MessageLocation(this.getFileName(),
            locator.getLineNumber(),
            locator.getColumnNumber(), tagName));
      }
    }
    else if ("form".compareTo(tagName) == 0)
    {
      this.formInputMarks = new HashMap<String, ControlMark>();
    }
    else if ("html".compareTo(tagName) == 0)
    {
      String ns = attributes.getValue("xmlns");
      if (ns == null || EpubConstants.HtmlNamespaceUri.compareTo(ns) != 0)
      {
        report.message(MessageId.HTM_049, new MessageLocation(this.getFileName(),
            locator.getLineNumber(),
            locator.getColumnNumber(), tagName));
      }
    }
    else if ("body".compareTo(tagName) == 0)
    {
      String title = attributes.getValue("title");
      if (title != null && title.length() > 0)
      {
        hasTitle = true;
      }
    }
    else if (("title".compareTo(tagName) == 0) && ("head".compareTo(tagStack.peek()) == 0))
    {
      inTitle = true;
    }
    else if ("nav".compareTo(tagName) == 0)
    {
      String type = attributes.getValue(EpubConstants.EpubTypeNamespaceUri, "type");
      if (type != null && "landmark".compareToIgnoreCase(type) == 0)
      {
        ++landmarkNavCount;
      }
    }
    else if ("blockquote".compareTo(tagName) == 0)
    {
      inBlockQuote = true;
    }
    else if ("figure".compareTo(tagName) == 0)
    {
      inFigure = true;
    }
    else if ("meta".compareTo(tagName) == 0)
    {
      String nameAttribute = attributes.getValue("name");
      if (nameAttribute != null && "viewport".compareTo(nameAttribute) == 0)
      {
        hasViewport = true;
        String contentAttribute = attributes.getValue("content");
        if (contentAttribute == null || !(contentAttribute.contains("width") && contentAttribute.contains("height")))
        {
          report.message(MessageId.HTM_047, new MessageLocation(this.getFileName(),
              locator.getLineNumber(),
              locator.getColumnNumber(), tagName));
        }
      }
    }
    if (headerTags.contains(tagName))
    {
      if (inBlockQuote || inFigure)
      {
        report.message(MessageId.ACC_010, new MessageLocation(getFileName(), locator.getLineNumber(), locator.getColumnNumber(), tagName));
      }
    }

    if (nonTextTagsAlt.contains(tagName))
    {
      if (null != this.getFileName() && null == attributes.getValue("alt"))
      {
        report.message(MessageId.ACC_001, new MessageLocation(this.getFileName(),
            locator.getLineNumber(),
            locator.getColumnNumber(), tagName));
      }
    }
    if (nonTextTagsTitle.contains(tagName))
    {
      if (null != this.getFileName() && null == attributes.getValue("title"))
      {
        report.message(MessageId.ACC_003, new MessageLocation(this.getFileName(),
            locator.getLineNumber(),
            locator.getColumnNumber(), tagName));
      }
    }
    String epubPrefix = namespaceHelper.findPrefixForUri(EpubConstants.EpubTypeNamespaceUri);
    if (epubPrefix != null)
    {
      String typeAttr = attributes.getValue(epubPrefix+":type");
      if (typeAttr != null)
      {
        if (typeAttr.contains("pagebreak"))
        {
          report.message(MessageId.HTM_050, new MessageLocation(this.getFileName(),
              locator.getLineNumber(),
              locator.getColumnNumber(), "pagebreak"));
        }
      }
    }
View Full Code Here

      {
        Integer count = listItemCounters.remove(listItemCounters.size() - 1);
        if (count < 1)
        {
          report.message(MessageId.HTM_027,
              new MessageLocation(this.getFileName(),
                  locator.getLineNumber(),
                  locator.getColumnNumber(),
                  qName)
          );
        }
      }
      if ("body".compareTo(tagName) == 0)
      {
        for (String id : formInputMarks.keySet())
        {
          ControlMark mark = formInputMarks.get(id);
          if (((mark.mark & HAS_LABEL) != HAS_LABEL) && (mark.mark & HAS_INPUT) == HAS_INPUT)
          {
            report.message(MessageId.ACC_002, mark.location, id);
          }
        }
      }
      if (inTitle && "title".compareTo(tagName) == 0)
      {
        inTitle = false;
      }
      else if ("head".compareTo(tagName) == 0)
      {
        if (!hasTitle)
        {
          report.message(MessageId.HTM_033, new MessageLocation(this.getFileName(),
              locator.getLineNumber(),
              locator.getColumnNumber()));
        }
        if (isFixed() && !hasViewport)
        {
          report.message(MessageId.HTM_046, new MessageLocation(this.getFileName(),
              locator.getLineNumber(),
              locator.getColumnNumber()));
        }
      }
      else if ("blockquote".compareTo(tagName) == 0)
View Full Code Here

      if (p > 0)
      {
        message = message.substring(0, message.indexOf("("));
      }
      message = message.trim();
      report.message(MessageId.RSC_001, new MessageLocation(fileEntry, -1, -1), message);
    }
    catch (IOException e)
    {
      report.message(MessageId.PKG_008, new MessageLocation(fileEntry, -1, -1), fileEntry);
    }
    catch (SAXException e)
    {
      report.message(MessageId.RSC_005, new MessageLocation(fileEntry, -1, -1), e.getMessage());
    }
    catch (ParserConfigurationException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
View Full Code Here

      parser.getXMLReader().setErrorHandler(handler);
      parser.getXMLReader().setContentHandler(handler);
      parser.getXMLReader().parse(new InputSource(inputStream));
    } catch (ParserConfigurationException e)
    {
      report.message(MessageId.RSC_005, new MessageLocation(path, -1, -1),
          e.getMessage());
    } catch (InvalidVersionException e)
    {
      throw e;
    } catch (SAXException e)
    {
      if (FINISHED_PARSING.equals(e.getMessage()))
      {
        OPFData data = builder.build();
        return data;
      } 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

  public void runChecks()
  {
    if (!ocf.hasEntry(path))
    {
      report.message(MessageId.RSC_001, new MessageLocation(this.ocf.getName(), -1, -1), path);
    }
    else if (!ocf.canDecrypt(path))
    {
      report.message(MessageId.RSC_004, new MessageLocation(this.ocf.getName(), 0, 0), path);
    }
    else
    {
      validate();
    }
View Full Code Here

      overlayParser.addXMLHandler(overlayHandler);
      overlayParser.process();
    }
    catch (IOException e)
    {
      report.message(MessageId.RSC_001, new MessageLocation(this.ocf.getName(), -1, -1), path);
    }
    finally
    {
      try
      {
View Full Code Here

  public void runChecks()
  {
    ocf.setReport(getReport());
    if (!ocf.hasEntry(OCFData.containerEntry))
    {
      getReport().message(MessageId.RSC_002, new MessageLocation(ocf.getName(), 0, 0));
      return;
    }
    long l = ocf.getTimeEntry(OCFData.containerEntry);
    if (l > 0)
    {
      Date d = new Date(l);
      String formattedDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(d);
      getReport().info(OCFData.containerEntry, FeatureEnum.CREATION_DATE, formattedDate);
    }
    OCFData containerHandler = ocf.getOcfData();

    // retrieve the paths of root files
    List<String> opfPaths = containerHandler.getEntries(OPFData.OPF_MIME_TYPE);
    if (opfPaths == null || opfPaths.isEmpty())
    {
      getReport().message(MessageId.RSC_003, new MessageLocation(OCFData.containerEntry, -1, -1));
      return;
    }
    else if (opfPaths.size() > 0)
    {
      if(opfPaths.size() > 1)
      {
        getReport().info(null, FeatureEnum.EPUB_RENDITIONS_COUNT, Integer.toString(opfPaths.size()));
      }

      // test every element for empty or missing @full-path attribute
      // bugfix for issue 236 / issue 95
      int rootfileErrorCounter = 0;
      for (String opfPath : opfPaths)
      {
        if (opfPath == null)
        {
          ++rootfileErrorCounter;
          getReport().message(MessageId.OPF_016, new MessageLocation(OCFData.containerEntry, -1, -1));
        }
        else if (opfPath.isEmpty())
        {
          ++rootfileErrorCounter;
          getReport().message(MessageId.OPF_017, new MessageLocation(OCFData.containerEntry, -1, -1));
         }
        else if (!ocf.hasEntry(opfPath))
        {
          getReport().message(MessageId.OPF_002, new MessageLocation(OCFData.containerEntry, -1, -1), opfPath);
          return;
        }
      }
      if(rootfileErrorCounter == opfPaths.size())
      {
        // end validation at this point when @full-path attribute is missing in container.xml
        // otherwise, tons of errors would be thrown ("XYZ exists in the zip file, but is not declared in the OPF file")
        return;
      }
    }


    // Detect the version of the first root file
    // and compare with the asked version (if set)
    EPUBVersion detectedVersion = null;
    EPUBVersion validationVersion;
    OPFData opfData = ocf.getOpfData().get(opfPaths.get(0));
    if (opfData == null)
        return;// The error must have been reported during parsing
    detectedVersion = opfData.getVersion();
    report.info(null, FeatureEnum.FORMAT_VERSION, detectedVersion.toString());
    assert (detectedVersion != null);

    if (version != null && version != detectedVersion)
    {
      getReport().message(MessageId.PKG_001, new MessageLocation(opfPaths.get(0), -1, -1), version, detectedVersion);

      validationVersion = version;
    }
    else
    {
      validationVersion = detectedVersion;
    }

    // EPUB 2.0 says there SHOULD be only one OPS rendition
    if (validationVersion == EPUBVersion.VERSION_2 && opfPaths.size() > 1)
    {
      getReport().message(MessageId.PKG_013, new MessageLocation(OCFData.containerEntry, -1, -1));
    }

    // Check the mimetype file
    InputStream mimetype = null;
    try
    {
      mimetype = ocf.getInputStream("mimetype");
      StringBuilder sb = new StringBuilder(2048);
      if (ocf.hasEntry("mimetype")
          && !CheckUtil.checkTrailingSpaces(mimetype,
          validationVersion, sb))
      {
        getReport().message(MessageId.PKG_007, new MessageLocation("mimetype", 0, 0));
      }
      if (sb.length() != 0)
      {
        getReport().info(null, FeatureEnum.FORMAT_NAME, sb.toString().trim());
      }
    }
    catch (IOException ignored)
    {
      // missing file will be reported later
    }
    finally
    {
      try
      {
        if (mimetype != null)
        {
          mimetype.close();
        }
      }
      catch (IOException ignored)
      {
        // eat it
      }
    }

    // Validate the OCF files against the schema definitions
    validate(validationVersion);

    // Validate each OPF and keep a reference of the OPFHandler
    List<OPFHandler> opfHandlers = new LinkedList<OPFHandler>();
    for (String opfPath : opfPaths)
    {
      OPFChecker opfChecker;

      if (validationVersion == EPUBVersion.VERSION_2)
      {
        opfChecker = new OPFChecker(ocf, getReport(), opfPath, validationVersion);
      }
      else
      {
        opfChecker = new OPFChecker30(ocf, getReport(), opfPath, validationVersion);
      }
      opfChecker.runChecks();
      opfHandlers.add(opfChecker.getOPFHandler());
    }

   
   
    // Check all file and directory entries in the container
    try
    {
      Set<String> entriesSet = new HashSet<String>();
      Set<String> normalizedEntriesSet = new HashSet<String>();
      for (String entry : ocf.getFileEntries())
      {
        if (!entriesSet.add(entry.toLowerCase(Locale.ENGLISH)))
        {
          getReport().message(MessageId.OPF_060, new MessageLocation(ocf.getPackagePath(), 0, 0), entry);
        }
        else if (!normalizedEntriesSet.add(Normalizer.normalize(entry, Form.NFC)))
        {
          getReport().message(MessageId.OPF_061, new MessageLocation(ocf.getPackagePath(), 0, 0), entry);
        }

        ocf.reportMetadata(entry, report);

        if (!entry.startsWith("META-INF/")
            && !entry.startsWith("META-INF\\")
            && !entry.equals("mimetype")
            && !containerHandler.getEntries().contains(entry))
        {
          boolean isDeclared = false;
          for (OPFHandler opfHandler : opfHandlers)
          {
            if (opfHandler.getItemByPath(entry) != null)
            {
              isDeclared = true;
              break;
            }
          }
          if (!isDeclared)
          {
            report.message(MessageId.OPF_003, new MessageLocation(ocf.getName(), -1, -1), entry);
          }
        }
        OCFFilenameChecker.checkCompatiblyEscaped(entry, getReport(), validationVersion);
      }

      for (String directory : ocf.getDirectoryEntries())
      {
        boolean hasContents = false;
        for (String file : ocf.getFileEntries())
        {
          if (file.startsWith(directory))
          {
            hasContents = true;
            break;
          }
        }
        if (!hasContents)
        {
          getReport().message(MessageId.PKG_014, new MessageLocation(ocf.getName(), -1, -1), directory);
        }
      }
    }
    catch (IOException e)
    {
      getReport().message(MessageId.PKG_015, new MessageLocation(ocf.getName(), -1, -1), e.getMessage());
    }

    Report r = getReport();

  }
View Full Code Here

  public void runChecks()
  {
    if (!ocf.hasEntry(path))
    {
      report.message(MessageId.RSC_001, new MessageLocation(this.ocf.getName(), -1, -1), path);
    }
    else if (!ocf.canDecrypt(path))
    {
      report.message(MessageId.RSC_004, new MessageLocation(this.ocf.getName(), 0, 0), path);
    }
  }
View Full Code Here

  }

  @Override
  public void startPrefixMapping (String prefix, String uri) throws SAXException
  {
    namespaceHelper.declareNamespace(prefix, uri, new MessageLocation(fileName, locator.getLineNumber(), locator.getColumnNumber(), prefix), report);
  }
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.