Package org.apache.nutch.plugin

Examples of org.apache.nutch.plugin.Extension


        "org.apache.nutch.parse.Parser").getExtensions();

    String contentType, command, timeoutString;

    for (int i = 0; i < extensions.length; i++) {
      Extension extension = extensions[i];

      // only look for extensions defined by plugin parse-ext
      if (!extension.getDescriptor().getPluginId().equals("parse-ext"))
        continue;

      contentType = extension.getAttribute("contentType");
      if (contentType == null || contentType.equals(""))
        continue;

      command = extension.getAttribute("command");
      if (command == null || command.equals(""))
        continue;

      timeoutString = extension.getAttribute("timeout");
      if (timeoutString == null || timeoutString.equals(""))
        timeoutString = "" + TIMEOUT_DEFAULT;

      TYPE_PARAMS_MAP.put(contentType, new String[] { command, timeoutString });
    }
View Full Code Here


      parserFactory = new ParserFactory(conf);
  }
   
  /** Unit test for <code>getExtensions(String)</code> method. */
  public void testGetExtensions() throws Exception {
    Extension ext = (Extension)parserFactory.getExtensions("text/html").get(0);
    assertEquals("parse-html", ext.getDescriptor().getPluginId());
    ext = (Extension) parserFactory.getExtensions("text/html; charset=ISO-8859-1").get(0);
    assertEquals("parse-html", ext.getDescriptor().getPluginId());
    ext = (Extension)parserFactory.getExtensions("foo/bar").get(0);
    assertEquals("parse-text", ext.getDescriptor().getPluginId());
  }
View Full Code Here

      throw new ParserNotFound(url, contentType);
    }

    parsers = new Vector(parserExts.size());
    for (Iterator i=parserExts.iterator(); i.hasNext(); ){
      Extension ext = (Extension) i.next();
      Parser p = null;
      try {
        //check to see if we've cached this parser instance yet
        p = (Parser) this.conf.getObject(ext.getId());
        if (p == null) {
          // go ahead and instantiate it and then cache it
          p = (Parser) ext.getExtensionInstance();
          this.conf.setObject(ext.getId(),p);
        }
        parsers.add(p);
      } catch (PluginRuntimeException e) {
        if (LOG.isWarnEnabled()) {
          e.printStackTrace(LogUtil.getWarnStream(LOG));
          LOG.warn("ParserFactory:PluginRuntimeException when "
                 + "initializing parser plugin "
                 + ext.getDescriptor().getPluginId()
                 + " instance in getParsers "
                 + "function: attempting to continue instantiating parsers");
        }
      }
    }
View Full Code Here

   *         {@link PluginRuntimeException} instantiating the {@link Parser}.
   */
  public Parser getParserById(String id) throws ParserNotFound {

    Extension[] extensions = this.extensionPoint.getExtensions();
    Extension parserExt = null;

    if (id != null) {
      parserExt = getExtension(extensions, id);
    }
    if (parserExt == null) {
      parserExt = getExtensionFromAlias(extensions, id);
    }

    if (parserExt == null) {
      throw new ParserNotFound("No Parser Found for id [" + id + "]");
    }
   
    // first check the cache          
    if (this.conf.getObject(parserExt.getId()) != null) {
      return (Parser) this.conf.getObject(parserExt.getId());

    // if not found in cache, instantiate the Parser   
    } else {
      try {
        Parser p = (Parser) parserExt.getExtensionInstance();
        this.conf.setObject(parserExt.getId(), p);
        return p;
      } catch (PluginRuntimeException e) {
        if (LOG.isWarnEnabled()) {
          LOG.warn("Canno initialize parser " +
                   parserExt.getDescriptor().getPluginId() +
                   " (cause: " + e.toString());
        }
        throw new ParserNotFound("Cannot init parser for id [" + id + "]");
      }
    }
View Full Code Here

    if (plugins != null) {
     
      for (Iterator i = plugins.iterator(); i.hasNext();) {
        String parsePluginId = (String) i.next();
       
        Extension ext = getExtension(extensions, parsePluginId, contentType);
        // the extension returned may be null
        // that means that it was not enabled in the plugin.includes
        // nutch conf property, but it was mapped in the
        // parse-plugins.xml
        // file.
View Full Code Here

      throw new RuntimeException(URLFilter.X_POINT_ID+" not found.");

    Extension[] extensions = point.getExtensions();

    for (int i = 0; i < extensions.length; i++) {
      Extension extension = extensions[i];
      filter = (URLFilter)extension.getExtensionInstance();
      if (filter.getClass().getName().equals(filterName)) {
        break;
      } else {
        filter = null;
      }
View Full Code Here

                    throw new RuntimeException(URLFilter.X_POINT_ID
                            + " not found.");
                Extension[] extensions = point.getExtensions();
                HashMap filterMap = new HashMap();
                for (int i = 0; i < extensions.length; i++) {
                    Extension extension = extensions[i];
                    URLFilter filter = (URLFilter) extension
                            .getExtensionInstance();
                    if (!filterMap.containsKey(filter.getClass().getName())) {
                        filterMap.put(filter.getClass().getName(), filter);
                    }
                }
View Full Code Here

        ExtensionPoint point = PluginRepository.get(conf).getExtensionPoint(ScoringFilter.X_POINT_ID);
        if (point == null) throw new RuntimeException(ScoringFilter.X_POINT_ID + " not found.");
        Extension[] extensions = point.getExtensions();
        HashMap filterMap = new HashMap();
        for (int i = 0; i < extensions.length; i++) {
          Extension extension = extensions[i];
          ScoringFilter filter = (ScoringFilter) extension.getExtensionInstance();
          if (!filterMap.containsKey(filter.getClass().getName())) {
            filterMap.put(filter.getClass().getName(), filter);
          }
        }
        if (orderedFilters == null) {
View Full Code Here

   * used. If none match, then the {@link NutchDocumentAnalyzer} is used.
   */
  public NutchAnalyzer get(String lang) {

    NutchAnalyzer analyzer = DEFAULT_ANALYZER;
    Extension extension = getExtension(lang);
    if (extension != null) {
        try {
            analyzer = (NutchAnalyzer) extension.getExtensionInstance();
        } catch (PluginRuntimeException pre) {
            analyzer = DEFAULT_ANALYZER;
        }
    }
    return analyzer;
View Full Code Here

  }

  private Extension getExtension(String lang) {

    if (lang == null) { return null; }
    Extension extension = (Extension) this.conf.getObject(lang);
    if (extension == null) {
      extension = findExtension(lang);
      if (extension != null) {
        this.conf.setObject(lang, extension);
      }
View Full Code Here

TOP

Related Classes of org.apache.nutch.plugin.Extension

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.