Beispiel #1
0
  /**
   * 获取所有索引字段
   *
   * @return
   */
  public List<RDocItem> getDocItemList() {
    List<RDocItem> docItemList = new ArrayList<RDocItem>();
    String fieldNames = "";

    Map<String, RDocItem> map = getDocItemMap();
    if (map == null || map.size() <= 0) {
      return docItemList;
    }

    Object[][] objects = UtilTool.getMapKeyValue(map);

    int length = objects.length;
    for (int i = 0; i < length; i++) {
      RDocItem docItem = (RDocItem) objects[i][1];
      docItemList.add(docItem);
      fieldNames +=
          StringClass.getString(objects[i][0]).toUpperCase()
              + RetrievalConstant.DEFAULT_INDEX_FIELD_NAME_SPLIT;
    }

    RDocItem allFieldRDocItem = new RDocItem();
    allFieldRDocItem.setName(RetrievalType.RDocItemSpecialName._IAF);
    allFieldRDocItem.setContent(fieldNames);
    allFieldRDocItem.setItemType(RetrievalType.RDocItemType.STORE_ONLY);

    docItemList.add(allFieldRDocItem);

    return docItemList;
  }
  public DefaultRetrievalProperties() {

    ReadProperties readProperties = new ReadProperties();

    InputStream inputStream =
        DefaultRDatabaseIndexAllImpl.class.getResourceAsStream("/" + RETRIEVAL_PROPERTY_FILE_NAME);

    if (inputStream != null) {

      RetrievalUtil.debugLog(
          log, "发现DefaultRDatabaseIndexAllImpl属性配置文件:" + RETRIEVAL_PROPERTY_FILE_NAME + ",载入数据库配置");

      Properties properties = new Properties();

      try {
        properties.load(inputStream);
      } catch (IOException e) {
        throw new RetrievalLoadException(e);
      }

      readProperties.setProperties(properties);
      readProperties.parse();
      String taskparam = null;
      taskparam =
          StringClass.getString(
              readProperties.readValue(PROPERTIES_RETRIEVAL_SINGLE_THREAD_DEALNUMS));
      if (!taskparam.equals("")) {
        default_single_thread_dealnums = Integer.parseInt(taskparam);
      }
      taskparam =
          StringClass.getString(
              readProperties.readValue(PROPERTIES_RETRIEVAL_CONCURRENT_THREAD_MAXNUM));
      if (!taskparam.equals("")) {
        default_thread_maxnum = Integer.parseInt(taskparam);
      }
      taskparam = StringClass.getString(readProperties.readValue(PROPERTIES_RETRIEVAL_WORKSPACE));
      if (!taskparam.equals("")) {
        default_retrieval_workspace = taskparam;
      }
      taskparam = StringClass.getString(readProperties.readValue(PROPERTIES_RETRIEVAL_REDIS_START));
      if (!taskparam.equals("")) {
        default_retrieval_redis_start = taskparam;
      }
      taskparam =
          StringClass.getString(readProperties.readValue(PROPERTIES_RETRIEVAL_REDIS_SERVER_PATH));
      if (!taskparam.equals("")) {
        default_retrieval_redis_server_path = taskparam;
      }

      taskparam = StringClass.getString(readProperties.readValue(PARAM_NAME_JDBC_DRIVER));
      if (!taskparam.equals("")) {
        jdbcDriver = taskparam;
      }
      taskparam = StringClass.getString(readProperties.readValue(PARAM_NAME_JDBC_URL));
      if (!taskparam.equals("")) {
        jdbcUrl = taskparam;
      }
      taskparam = StringClass.getString(readProperties.readValue(PARAM_NAME_JDBC_USER));
      if (!taskparam.equals("")) {
        jdbcUser = taskparam;
      }
      taskparam = StringClass.getString(readProperties.readValue(PARAM_NAME_JDBC_PASSWORD));
      if (!taskparam.equals("")) {
        jdbcPassword = taskparam;
      }
      taskparam =
          StringClass.getString(readProperties.readValue(DEFAULT_RETRIEVAL_DATABASE_CHOOSE_CLASS));
      if (!taskparam.equals("")) {
        default_retrieval_database_choose_class = taskparam;
      }
      taskparam =
          StringClass.getString(readProperties.readValue(DEFAULT_RETRIEVAL_IMAGEMAGICK_PATH));
      if (!taskparam.equals("")) {
        default_retrieval_imagemagick_path = taskparam;
      }
      taskparam = StringClass.getString(readProperties.readValue(DEFAULT_RETRIEVAL_INDEXFILE_SIZE));
      if (!taskparam.equals("")) {
        default_retrieval_indexfile_size = Long.valueOf(taskparam);
      }
      taskparam =
          StringClass.getString(readProperties.readValue(DEFAULT_MOVE_FILE_AFTER_INDEX_FOLDER));
      if (!taskparam.equals("")) {
        default_move_file_after_index_folder = taskparam;
      }
      readProperties.close();
    }
  }
  /**
   * 读取配置文件中的 系统配置文件保存路径
   *
   * @param configpathfile
   * @return String
   */
  private void readConfigpath(Object configpathfile) {
    String configpath = "";
    String systemFilename = "";
    boolean relativize = false;
    if (configpathfile instanceof SystemInitConfig) {
      SystemInitConfig theSystemInitConfig = (SystemInitConfig) systemInitConfig;
      configpath = theSystemInitConfig.getConfigpath();
      systemFilename = theSystemInitConfig.getSystemFilename();
      relativize = theSystemInitConfig.isRelativize();
    } else {
      readXml.reset();
      readXml.setXmlfile(configpathfile);
      readXml.parseXMLFile();
      try {
        configpath =
            (String)
                readXml
                    .getNodeValue(SystemCommonUtil.PROPERTIES_CONFIGPATH_FILENAME_NODE_PATH)
                    .get(0);
      } catch (Exception e) {
        configpath = "";
      }

      try {
        systemFilename =
            (String)
                readXml
                    .getNodeValue(SystemCommonUtil.PROPERTIES_CONFIGPATH_FILENAME_NODE_FILENAME)
                    .get(0);
      } catch (Exception e) {
        systemFilename = SystemCommonUtil.SYSTEM_SYSTEMCONFIGFILE;
      }

      readXml.setCurrentNodeList(SystemCommonUtil.PROPERTIES_CONFIGPATH_FILENAME_NODE_PATH);
      readXml.setCurrentNode(0);

      String isRelativize = "false";
      isRelativize =
          ((String)
                  readXml.getAttribute(
                      SystemCommonUtil
                          .PROPERTIES_CONFIGPATH_FILENAME_NODE_PATH_PROPERTY_RELATIVIZE))
              .toLowerCase();
      isRelativize = StringClass.getString(isRelativize);
      if (isRelativize.equals("")) {
        isRelativize =
            SystemCommonUtil
                .PROPERTIES_CONFIGPATH_FILENAME_NODE_PATH_PROPERTY_RELATIVIZE_DEFAULT_VALUE;
      }
      relativize = Boolean.parseBoolean(isRelativize);
    }
    if (relativize) {
      //        	String basePath=StringClass.getRealPath(this.getClass(),"",null);
      String basePath = StringClass.getRealPath(this.getClass());
      UrlTool snoicsUrl = new UrlTool();
      basePath = StringClass.getFormatPath(basePath);
      configpath = StringClass.getFormatPath(configpath);
      basePath = StringClass.getReplaceString(basePath, " ", spaceChar);
      configpath = StringClass.getReplaceString(configpath, " ", spaceChar);
      configpath =
          StringClass.getFormatPath((snoicsUrl.getResolved(basePath, configpath)).toString() + "/");
      configpath = StringClass.getReplaceString(configpath, spaceChar, " ");
    }

    this.configpath = configpath;

    System.setProperty(SystemCommonUtil.SYSTEM_PARAMETERS_SNOICS_CONFIG_HOME, configpath);

    this.systemFilename = systemFilename;

    log.info("ConfigHome : " + configpath);
    log.info("systemFilename : " + systemFilename);
  }
 /**
  * 设置系统配置文件路径
  *
  * @param configpath 路径
  */
 public void setConfigpath(String configpath) {
   if (configpath != null) {
     configpath = StringClass.getFormatPath(configpath);
     this.configpath = configpath;
   }
 }
  /** 初始化系统配置文件路径 */
  public void init() throws SnoicsRuntimeException {
    log.getLogger(this.getClass());

    //		String
    // classPath=StringClass.getFormatPath(StringClass.getRealPath(this.getClass(),"/",null));
    String classPath = StringClass.getFormatPath(StringClass.getRealPath(this.getClass()));
    log.debug("Class Path:" + classPath);

    configpath = StringClass.getString(configpath);
    systemFilename = StringClass.getString(systemFilename);
    if (!configpath.equals("") && !systemFilename.equals("")) {
      return;
    }

    try {
      spaceChar = "\\" + URLEncoder.encode(spaceChar, "utf-8");
      log.debug("ConfigHome Path spaceChar :" + spaceChar);
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (systemInitConfig != null) {
      readConfigpath(systemInitConfig);
    } else if (configPathInputStream != null) {
      readConfigpath(configPathInputStream);
    } else {
      InputStream inputStream = null;
      String theConfigPathFileName = "";

      if ((configPathFileName != null) && (!configPathFileName.equals(""))) {
        theConfigPathFileName = configPathFileName;
      } else {
        theConfigPathFileName = SystemCommonUtil.PROPERTIES_CONFIGPATH_FILENAME;
      }
      log.debug("读取系统路径配置文件信息:" + theConfigPathFileName);

      String realPath = null;

      if (snoicsFile.isFile(theConfigPathFileName)) {
        realPath = StringClass.getFormatPath(theConfigPathFileName);
        try {
          inputStream = snoicsFile.fileToInputStream(theConfigPathFileName);
        } catch (Exception e) {
          throw new SnoicsRuntimeException("找不到系统路径配置文件 '" + realPath + "' ,系统处于未初始化状态", e);
          //            		e.printStackTrace();
        }
      } else {
        realPath =
            StringClass.getFormatPath(
                StringClass.getRealPath(this.getClass()) + "/" + theConfigPathFileName);
        //
        //	realPath=StringClass.getFormatPath(StringClass.getRealPath(this.getClass(),"/",null)+"/"+theConfigPathFileName);
        try {
          inputStream = this.getClass().getResourceAsStream("/" + theConfigPathFileName);
        } catch (Exception e) {
          throw new SnoicsRuntimeException(
              "找不到系统路径配置文件 '" + theConfigPathFileName + "' ,系统处于未初始化状态", e);
        }
      }

      if (inputStream == null) {
        //        		throw new SnoicsRuntimeException(" 找不到系统路径配置文件 '"+ realPath +"' ,系统处于未初始化状态",e);
        log.error("找不到系统路径配置文件 '" + theConfigPathFileName + "' ,系统处于未初始化状态 ");
        return;
      } else {
        //        		log.info("读取系统路径配置文件 '"+ theConfigPathFileName +"'");
        readConfigpath(inputStream);
      }
    }
  }