All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dict.SearchKeyMapHandler Maven / Gradle / Ivy

Go to download

EpubCheck is a tool to validate IDPF EPUB files. It can detect many types of errors in EPUB. OCF container structure, OPF and OPS mark-up, and internal reference consistency are checked. EpubCheck can be run as a standalone command-line tool, installed as a Java server-side web application or used as a Java library.

There is a newer version: 4.1.1
Show newest version
package dict;

import com.adobe.epubcheck.opf.ValidationContext;
import com.adobe.epubcheck.opf.XRefChecker.Type;
import com.adobe.epubcheck.util.PathUtil;
import com.adobe.epubcheck.xml.XMLElement;
import com.adobe.epubcheck.xml.XMLHandler;
import com.adobe.epubcheck.xml.XMLParser;

public class SearchKeyMapHandler implements XMLHandler
{

  private final ValidationContext context;
  private final String path;
  private final XMLParser parser;

  public SearchKeyMapHandler(ValidationContext context, XMLParser parser)
  {
    this.context = context;
    this.path = context.path;
    this.parser = parser;
  }

  public void startElement()
  {

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

    if ("http://www.idpf.org/2007/ops".equals(e.getNamespace()))
    {

      if ("search-key-group".equals(name))
      {
        processRef(e.getAttribute("href"));
      }
      else if ("match".equals(name))
      {
        processRef(e.getAttribute("href"));
      }
    }
  }

  private void processRef(String ref)
  {
    if (ref != null && context.xrefChecker.isPresent())
    {
      ref = PathUtil.resolveRelativeReference(path, ref, null);
      context.xrefChecker.get().registerReference(path, parser.getLineNumber(),
          parser.getColumnNumber(), ref, Type.SEARCH_KEY);
    }
  }

  public void characters(char[] chars, int arg1, int arg2)
  {
  }

  public void endElement()
  {
  }

  public void ignorableWhitespace(char[] chars, int arg1, int arg2)
  {
  }

  public void processingInstruction(String arg0, String arg1)
  {
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy