public Rendering init(Document d, InitParams initParams) throws OmException {
    this.ip = initParams;

    // Initialise available components and add question-specific components
    QComponentManager qcm = new QComponentManager(initParams);
    Element[] aeDefines = XML.getChildren(d.getDocumentElement(), "define-component");
    for (int i = 0; i < aeDefines.length; i++) {
      String sClassName = null;
      try {
        sClassName = XML.getRequiredAttribute(aeDefines[i], "class");
        qcm.register(Class.forName(sClassName));
      } catch (XMLException e) {
        throw new OmDeveloperException("<define-component> is missing class= attribute");
      } catch (ClassNotFoundException e) {
        throw new OmDeveloperException("<define-component>: " + sClassName + " cannot be found");
      }
    }

    // Set resource classpath location
    if (d.getDocumentElement().hasAttribute("resources")) {
      sResourcePath = d.getDocumentElement().getAttribute("resources");
      if (!sResourcePath.startsWith("/") || !sResourcePath.endsWith("/")) {
        throw new OmFormatException("<question> resources= must begin and end with /");
      }
    } else {
      sResourcePath = null;
    }

    // Set not-so-random number if variant has been fixed
    if (initParams.hasFixedVariant()) nsr = new NotSoRandom(initParams.getFixedVariant());

    // Build component tree
    qd = new QDocument(this, d, qcm);

    // Return
    Rendering r = new Rendering();

    // User-overridable init
    init();

    // Render current state to XHTML
    qd.render(r, true);

    fixPlaceholders(r);

    return r;
  }
 /**
  * Loads a question resource into memory.
  *
  * @param sName Name of resource (may be relative path including /; may not be absolute path
  *     beginning /)
  * @return Byte array containing entire resource
  * @throws IOException If the resource doesn't exist or there's another problem
  */
 public byte[] loadResource(String sName) throws IOException {
   if (sName.startsWith("/"))
     throw new IllegalArgumentException("loadResource with class reference must be relative name");
   if (sResourcePath != null) return IO.loadResource(ip.getClassLoader(), sResourcePath + sName);
   else {
     return IO.loadResource(getClass(), sName);
   }
 }
  /**
   * Obtains a random number generator based on the seed, attempts and navigatorVersion passed by
   * the test navigator. If 'incrementSeed' is false attempts and navigatorVersion wont be used to
   * get the random number generator.
   *
   * @param sGroup Group name (arbitrary string)
   * @param incrementSeed If true, then increments the random seed passed by the test navigator
   * @return Random number generator
   */
  private Random getRandom(String sGroup, boolean incrementSeed) {
    // Returns NotSoRandom object if fixed variant is used.
    if (nsr != null) {
      return nsr;
    }
    long randomSeed = ip.getRandomSeed();

    // Increment seed if the request is from OpenMark test navigator only
    if (ip.getNavigatorVersion() != null && incrementSeed) {
      int seedIncrement = MAGIC_RANDOM_SEED_INCREMENT;
      if (OmVersion.compareVersions(ip.getNavigatorVersion(), "1.3.0") <= 0) {
        seedIncrement = 1;
      }
      randomSeed = randomSeed + ip.getAttempt() * seedIncrement;
    }

    long lHash = sGroup.hashCode();
    return new Random(randomSeed ^ lHash);
  }
 /**
  * Returns a variant number between 0 (inclusive) and maxVariant (exclusive). Use this method to
  * get the next variant of a question in sequence. For the first attempt it returns a random
  * variant and for the repeat attempts it returns next variants in sequence, when the last variant
  * is reached it cycles back to the beginning.
  *
  * @param maxVariant
  * @return variant number
  */
 public int getNextVariant(int maxVariant) {
   // Passing false for the 'incrementSeed' parameter to get the same
   // random number generator for all question attempts.
   Random r = getRandom(getClass().getName(), false);
   if (r instanceof NotSoRandom) {
     // If it is an instanceof NotSoRandom that means variant is fixed
     // for testing, do not increment the variant
     return r.nextInt(maxVariant);
   }
   return (r.nextInt(maxVariant) + ip.getAttempt() - 1) % maxVariant;
 }
Example #5
0
  /**
   * Creates a configuration instance from a resource loader, a configuration name and a stream. If
   * the stream is null, the resource loader will open the configuration stream. If the stream is
   * not null, no attempt to load the resource will occur (the name is not used).
   *
   * @param loader the resource loader
   * @param name the configuration name
   * @param is the configuration stream
   */
  public SolrConfig(SolrResourceLoader loader, String name, InputSource is)
      throws ParserConfigurationException, IOException, SAXException {
    super(loader, name, is, "/config/");
    getOverlay(); // just in case it is not initialized
    getRequestParams();
    initLibs();
    luceneMatchVersion = getLuceneVersion("luceneMatchVersion");
    String indexConfigPrefix;

    // Old indexDefaults and mainIndex sections are deprecated and fails fast for
    // luceneMatchVersion=>LUCENE_4_0_0.
    // For older solrconfig.xml's we allow the old sections, but never mixed with the new
    // <indexConfig>
    boolean hasDeprecatedIndexConfig =
        (getNode("indexDefaults", false) != null) || (getNode("mainIndex", false) != null);
    if (hasDeprecatedIndexConfig) {
      throw new SolrException(
          ErrorCode.FORBIDDEN,
          "<indexDefaults> and <mainIndex> configuration sections are discontinued. Use <indexConfig> instead.");
    } else {
      defaultIndexConfig = mainIndexConfig = null;
      indexConfigPrefix = "indexConfig";
    }
    assertWarnOrFail(
        "The <nrtMode> config has been discontinued and NRT mode is always used by Solr."
            + " This config will be removed in future versions.",
        getNode(indexConfigPrefix + "/nrtMode", false) == null,
        true);
    assertWarnOrFail(
        "Solr no longer supports forceful unlocking via the 'unlockOnStartup' option.  "
            + "This is no longer neccessary for the default lockType except in situations where "
            + "it would be dangerous and should not be done.  For other lockTypes and/or "
            + "directoryFactory options it may also be dangerous and users must resolve "
            + "problematic locks manually.",
        null == getNode(indexConfigPrefix + "/unlockOnStartup", false),
        true // 'fail' in trunk
        );

    // Parse indexConfig section, using mainIndex as backup in case old config is used
    indexConfig = new SolrIndexConfig(this, "indexConfig", mainIndexConfig);

    booleanQueryMaxClauseCount =
        getInt("query/maxBooleanClauses", BooleanQuery.getMaxClauseCount());
    log.info("Using Lucene MatchVersion: " + luceneMatchVersion);

    // Warn about deprecated / discontinued parameters
    // boolToFilterOptimizer has had no effect since 3.1
    if (get("query/boolTofilterOptimizer", null) != null)
      log.warn(
          "solrconfig.xml: <boolTofilterOptimizer> is currently not implemented and has no effect.");
    if (get("query/HashDocSet", null) != null)
      log.warn("solrconfig.xml: <HashDocSet> is deprecated and no longer recommended used.");

    // TODO: Old code - in case somebody wants to re-enable. Also see SolrIndexSearcher#search()
    //    filtOptEnabled = getBool("query/boolTofilterOptimizer/@enabled", false);
    //    filtOptCacheSize = getInt("query/boolTofilterOptimizer/@cacheSize",32);
    //    filtOptThreshold = getFloat("query/boolTofilterOptimizer/@threshold",.05f);

    useFilterForSortedQuery = getBool("query/useFilterForSortedQuery", false);
    queryResultWindowSize = Math.max(1, getInt("query/queryResultWindowSize", 1));
    queryResultMaxDocsCached = getInt("query/queryResultMaxDocsCached", Integer.MAX_VALUE);
    enableLazyFieldLoading = getBool("query/enableLazyFieldLoading", false);

    filterCacheConfig = CacheConfig.getConfig(this, "query/filterCache");
    queryResultCacheConfig = CacheConfig.getConfig(this, "query/queryResultCache");
    documentCacheConfig = CacheConfig.getConfig(this, "query/documentCache");
    CacheConfig conf = CacheConfig.getConfig(this, "query/fieldValueCache");
    if (conf == null) {
      Map<String, String> args = new HashMap<>();
      args.put(NAME, "fieldValueCache");
      args.put("size", "10000");
      args.put("initialSize", "10");
      args.put("showItems", "-1");
      conf = new CacheConfig(FastLRUCache.class, args, null);
    }
    fieldValueCacheConfig = conf;
    useColdSearcher = getBool("query/useColdSearcher", false);
    dataDir = get("dataDir", null);
    if (dataDir != null && dataDir.length() == 0) dataDir = null;

    userCacheConfigs = CacheConfig.getMultipleConfigs(this, "query/cache");

    org.apache.solr.search.SolrIndexSearcher.initRegenerators(this);

    hashSetInverseLoadFactor = 1.0f / getFloat("//HashDocSet/@loadFactor", 0.75f);
    hashDocSetMaxSize = getInt("//HashDocSet/@maxSize", 3000);

    httpCachingConfig = new HttpCachingConfig(this);

    Node jmx = getNode("jmx", false);
    if (jmx != null) {
      jmxConfig =
          new JmxConfiguration(
              true,
              get("jmx/@agentId", null),
              get("jmx/@serviceUrl", null),
              get("jmx/@rootName", null));

    } else {
      jmxConfig = new JmxConfiguration(false, null, null, null);
    }
    maxWarmingSearchers = getInt("query/maxWarmingSearchers", Integer.MAX_VALUE);
    slowQueryThresholdMillis = getInt("query/slowQueryThresholdMillis", -1);
    for (SolrPluginInfo plugin : plugins) loadPluginInfo(plugin);
    updateHandlerInfo = loadUpdatehandlerInfo();

    multipartUploadLimitKB =
        getInt("requestDispatcher/requestParsers/@multipartUploadLimitInKB", 2048);

    formUploadLimitKB = getInt("requestDispatcher/requestParsers/@formdataUploadLimitInKB", 2048);

    enableRemoteStreams = getBool("requestDispatcher/requestParsers/@enableRemoteStreaming", false);

    // Let this filter take care of /select?xxx format
    handleSelect = getBool("requestDispatcher/@handleSelect", true);

    addHttpRequestToContext =
        getBool("requestDispatcher/requestParsers/@addHttpRequestToContext", false);

    List<PluginInfo> argsInfos = getPluginInfos(InitParams.class.getName());
    if (argsInfos != null) {
      Map<String, InitParams> argsMap = new HashMap<>();
      for (PluginInfo p : argsInfos) {
        InitParams args = new InitParams(p);
        argsMap.put(args.name == null ? String.valueOf(args.hashCode()) : args.name, args);
      }
      this.initParams = Collections.unmodifiableMap(argsMap);
    }

    solrRequestParsers = new SolrRequestParsers(this);
    Config.log.info("Loaded SolrConfig: " + name);
  }
 /** @return True if in 'plain mode' for accessibility */
 public boolean isPlainMode() {
   return ip.isPlainMode();
 }
 /** @return Zoom scale factor for accessibility */
 public double getZoom() {
   return ip.getZoom();
 }
 /** @return Fixed background colour in #rrggbb format */
 public String getDisabledColourFG() {
   return ip.getFixedColourBG();
 }
 /** @return Fixed background colour in #rrggbb format */
 public String getFixedColourBG() {
   return ip.getFixedColourBG();
 }
 /** @return True if colour has been fixed for accessibility reasons */
 public boolean isFixedColour() {
   return ip.getFixedColourFG() != null;
 }
 protected QEngineConfig getQEngineConfig() {
   return ip.getQEngineConfig();
 }