Beispiel #1
0
 protected void updatePaint(String nextNonSpace) {
   Keyword keyword = getKeyword(text, nextNonSpace.equals("("));
   if (keyword != null) {
     paint = keyword.paint();
     isCustomPaint = true;
   } else paint = styles.get("base");
 }
  private void generateWordDoc(String docName) throws FileNotFoundException, IOException {
    XWPFDocument doc = new XWPFDocument();
    for (Theme t : themes) {
      for (Keyword k : t.getKeywords()) {
        for (Occurrence c : k.getOccurrs()) {
          XWPFParagraph p = doc.createParagraph();
          p.setAlignment(ParagraphAlignment.LEFT);
          XWPFRun r = p.createRun();
          setRunAttributes(r);
          r.setText(c.getOccurInfo());
          r.addCarriageReturn();

          String[] strings = c.getSentece().split(k.getName());
          for (int i = 0; i < strings.length; i++) {
            XWPFRun r2 = p.createRun();
            setRunAttributes(r2);
            r2.setText(strings[i]);

            if (i < strings.length - 1) {
              XWPFRun r3 = p.createRun();
              setRunAttributes(r3);
              r3.setBold(true);
              r3.setItalic(true);
              r3.setColor(t.getHexColor());
              r3.setText(k.getName());
            }
          }
        }
      }
    }
    FileOutputStream outStream = new FileOutputStream(docName);
    doc.write(outStream);
    outStream.close();
  }
 // There has to be a more efficient way to do this
 // Perhaps hashtables
 private void checkForKeywords(String fileName, String line, int loc) {
   for (Theme t : themes) {
     for (Keyword k : t.getKeywords()) {
       if (line.contains(k.getName())) k.addOccurrence(fileName, line, loc);
     }
   }
   lineCount++;
 }
 public Object valAt(Object key, Object notFound) {
   if (FORM_KW.equals(key)) {
     return this.form;
   } else if (SPLICING_KW.equals(key)) {
     return this.splicing;
   } else {
     return notFound;
   }
 }
  private String processQueueMsg(MsgObject msgObject, Keyword keyword) {
    ContentAbstract delegate = null;
    try {
      String classname = "";
      if (keyword.getClassname().startsWith("~")) {
        classname = "MyProcess.InvalidProcess";

        // Cau hinh tra loi luon
        // $msgtype$info
        String sInfo = keyword.getClassname();
        String[] arrInfo = sInfo.split("~");
        String mtreply = "";
        int msgtype = 2;
        if (arrInfo.length > 2) {
          mtreply = arrInfo[2];
          if (LocalConfig.MT_CHARGING.equals(arrInfo[1])) {
            msgtype = 1;
          } else if (LocalConfig.MT_PUSH.equals(arrInfo[1])) {
            msgtype = 3;
          } else if (LocalConfig.MT_REFUND_SYNTAX.equals(arrInfo[1])) {
            msgtype = 21;
          } else if (LocalConfig.MT_REFUND_CONTENT.equals(arrInfo[1])) {
            msgtype = 22;
          } else {
            msgtype = 2;
          }

        } else {
          mtreply = arrInfo[1];
          msgtype = 2;
        }
        msgObject.setUsertext(mtreply);
        msgObject.setMsgtype(msgtype);
      } else {
        classname = keyword.getClassname();
      }

      // Ghi log xem class nào xử lý MO này
      mLog.log.info(
          Common.GetStringLog("Call Class Process Keyword", "ClassName:" + classname, msgObject));

      // Khởi tạo đối tượng process xử lý keyword
      Class<?> delegateClass = Class.forName(classname);
      Object delegateObject = delegateClass.newInstance();
      delegate = (ContentAbstract) delegateObject;

      delegate.start(msgObject, keyword);
      return "OK";

    } catch (Exception e) {
      mLog.log.error(Common.GetStringLog(msgObject), e);

      return msgObject.getUserid() + ":" + e.toString();
    }
  }
Beispiel #6
0
 /**
  * Checks whether a keyword is already associated with an erratum.
  *
  * @param keywordIn The keyword to check.
  * @return returns whether keyword is already associated with given erratum
  */
 public boolean containsKeyword(String keywordIn) {
   if (this.keywords == null) {
     return false;
   }
   for (Keyword k : this.keywords) {
     if (k.getKeyword().equals(keywordIn)) {
       return true;
     }
   }
   return false;
 }
 /**
  * Checks whether a keyword is already associated with an erratum.
  *
  * @param keywordIn The keyword to check.
  * @return returns whether keyword is already associated with given erratum
  */
 public boolean containsKeyword(String keywordIn) {
   if (this.keywords == null) {
     return false;
   }
   for (Iterator i = this.keywords.iterator(); i.hasNext(); ) {
     Keyword k = (Keyword) i.next();
     if (k.getKeyword().equals(keywordIn)) {
       return true;
     }
   }
   return false;
 }
  /**
   * Return the string used to later have SOLR highlight the document with.
   *
   * @param query
   * @param literal_query
   * @param queryResults
   * @param file
   * @return
   */
  private String getHighlightQuery(
      KeywordSearchQuery query, boolean literal_query, QueryResults queryResults, Content content) {
    String highlightQueryEscaped;
    if (literal_query) {
      // literal, treat as non-regex, non-term component query
      highlightQueryEscaped = query.getQueryString();
    } else {
      // construct a Solr query using aggregated terms to get highlighting
      // the query is executed later on demand
      StringBuilder highlightQuery = new StringBuilder();

      if (queryResults.getKeywords().size() == 1) {
        // simple case, no need to process subqueries and do special escaping
        Keyword term = queryResults.getKeywords().iterator().next();
        highlightQuery.append(term.toString());
      } else {
        // find terms for this content hit
        List<String> hitTerms = new ArrayList<>();
        for (Keyword keyword : queryResults.getKeywords()) {
          for (KeywordHit hit : queryResults.getResults(keyword)) {
            if (hit.getContent().equals(content)) {
              hitTerms.add(keyword.toString());
              break; // go to next term
            }
          }
        }

        final int lastTerm = hitTerms.size() - 1;
        int curTerm = 0;
        for (String term : hitTerms) {
          // escape subqueries, they shouldn't be escaped again later
          final String termS = KeywordSearchUtil.escapeLuceneQuery(term);
          highlightQuery.append("\"");
          highlightQuery.append(termS);
          highlightQuery.append("\"");
          if (lastTerm != curTerm) {
            highlightQuery.append(" "); // acts as OR ||
            // force HIGHLIGHT_FIELD_REGEX index and stored content
            // in each term after first. First term taken care by HighlightedMatchesSource
            highlightQuery.append(LuceneQuery.HIGHLIGHT_FIELD_REGEX).append(":");
          }

          ++curTerm;
        }
      }
      // String highlightQueryEscaped =
      // KeywordSearchUtil.escapeLuceneQuery(highlightQuery.toString());
      highlightQueryEscaped = highlightQuery.toString();
    }

    return highlightQueryEscaped;
  }
Beispiel #9
0
  public Keyword getKeyword(String text, boolean function) {
    if (syntaxLoaded.get()) {
      for (Keyword keyword : syntax) {
        if (keyword != null) {
          if (keyword.name().equals(text) && keyword.function() == function) {
            return keyword;
          }
        }
      }
    }

    return null;
  }
    /** Retrieve the updated keyword search lists from the XML loader */
    private void updateKeywords() {
      KeywordSearchListsXML loader = KeywordSearchListsXML.getCurrent();

      keywords.clear();
      keywordToList.clear();

      for (String name : keywordLists) {
        KeywordSearchList list = loader.getList(name);
        for (Keyword k : list.getKeywords()) {
          keywords.add(k);
          keywordToList.put(k.getQuery(), list);
        }
      }
    }
public class ReaderConditional implements ILookup {

  public static final Keyword FORM_KW = Keyword.intern("form");
  public static final Keyword SPLICING_KW = Keyword.intern("splicing?");

  public final Object form;
  public final Boolean splicing;

  public static ReaderConditional create(Object form, boolean splicing) {
    return new ReaderConditional(form, splicing);
  }

  private ReaderConditional(Object form, boolean splicing) {
    this.form = form;
    this.splicing = splicing;
  }

  public Object valAt(Object key) {
    return valAt(key, null);
  }

  public Object valAt(Object key, Object notFound) {
    if (FORM_KW.equals(key)) {
      return this.form;
    } else if (SPLICING_KW.equals(key)) {
      return this.splicing;
    } else {
      return notFound;
    }
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    ReaderConditional that = (ReaderConditional) o;

    if (form != null ? !form.equals(that.form) : that.form != null) return false;
    if (splicing != null ? !splicing.equals(that.splicing) : that.splicing != null) return false;
    return true;
  }

  @Override
  public int hashCode() {
    int result = Util.hash(form);
    result = 31 * result + Util.hash(splicing);
    return result;
  }
}
Beispiel #12
0
  /** Verifies that a given string can be used as a valid Verilog identifier. */
  public static boolean verify(String id) {
    boolean valid = true;

    char[] id_chars = id.toCharArray();

    if (id_chars.length > 0) {
      if (!(Character.isLetter(id_chars[0]) || (id_chars[0] == '_'))) valid = false;

      if (valid) {
        for (int i = 1; i < id_chars.length; i++) {
          char c = id_chars[i];

          if (!(Character.isLetter(c) || Character.isDigit(c) || (c == '_') || (c == '$'))) {
            valid = false;
            break;
          }
        }
      }

      if (valid) {
        // make sure this isn't a Verilog keyword
        valid = !Keyword.isKeyword(id);
      }
    }

    return valid;
  } // verify()
Beispiel #13
0
	public void processLine(String line) throws Exception {
		line = line.trim();
		if (line.length() > 0 && line.substring(0, 1).equals("#")) {
			return;
		}
		String[] chunks = line.split(" ");
		String command = chunks[0];
		
		String[] params = new String[chunks.length -1];
		for (int i = 1; i< chunks.length; i++) {
			params[i - 1] = chunks[i];
		}
		
		switch (Keyword.toKeyword(command)) {
			case q:
			case quit:
				throw new RuntimeException("quit!");
			case trans:
			case t:
				translateSpelling(params[0]);
				break;
			case h:
			case help:
				InputStream stream = Console.class.getResourceAsStream("ConsoleHelp.txt");
				BufferedReader in = new BufferedReader(new InputStreamReader(stream));
				String tmpLine = null;
				while((tmpLine = in.readLine()) != null) out(tmpLine);
				stream.close();
				break;
			default:
				throw new RuntimeException("unknown command " + command);
		}
	}
Beispiel #14
0
  public void atKeyword(Keyword k) throws CompileError {
    arrayDim = 0;
    int token = k.get();
    switch (token) {
      case TRUE:
        bytecode.addIconst(1);
        exprType = BOOLEAN;
        break;
      case FALSE:
        bytecode.addIconst(0);
        exprType = BOOLEAN;
        break;
      case NULL:
        bytecode.addOpcode(ACONST_NULL);
        exprType = NULL;
        break;
      case THIS:
      case SUPER:
        if (inStaticMethod)
          throw new CompileError("not-available: " + (token == THIS ? "this" : "super"));

        bytecode.addAload(0);
        exprType = CLASS;
        if (token == THIS) className = getThisName();
        else className = getSuperName();
        break;
      default:
        fatal();
    }
  }
Beispiel #15
0
 public static Message operationNotAllowedForKeyword(
     final Keyword keyword, final Operation operation) {
   return new Message(
       Type.ERROR,
       "%s is not allowed when keyword %s is specified",
       operation.name(),
       keyword.name());
 }
  /** Initialize the keyword search lists from the XML loader */
  private void initKeywords() {
    KeywordSearchListsXML loader = KeywordSearchListsXML.getCurrent();

    keywords.clear();
    keywordLists.clear();
    keywordToList.clear();

    for (KeywordSearchList list : loader.getListsL()) {
      String listName = list.getName();
      if (list.getUseForIngest()) {
        keywordLists.add(listName);
      }
      for (Keyword keyword : list.getKeywords()) {
        keywords.add(keyword);
        keywordToList.put(keyword.getQuery(), list);
      }
    }
  }
Beispiel #17
0
  /**
   * Convienience method so we can add keywords logically Adds a keyword to the keywords set
   *
   * @param keywordIn The keyword to add.
   */
  public void addKeyword(String keywordIn) {
    if (this.keywords == null) {
      this.keywords = new HashSet<Keyword>();
    }
    for (Keyword k : getKeywords()) {
      if (k.getKeyword().equals(keywordIn)) {
        return;
      }
    }

    /*
     * Bah... this stinks since a keyword is just a string, but we have to
     * set the created/modified fields in the db.
     */
    Keyword k = new PublishedKeyword();
    k.setKeyword(keywordIn);
    addKeyword(k);
    k.setErrata(this);
  }
Beispiel #18
0
  public static int getModifiers(ASTList mods) {
    int m = 0;
    while (mods != null) {
      Keyword k = (Keyword) mods.head();
      mods = mods.tail();
      switch (k.get()) {
        case STATIC:
          m |= Modifier.STATIC;
          break;
        case FINAL:
          m |= Modifier.FINAL;
          break;
        case SYNCHRONIZED:
          m |= Modifier.SYNCHRONIZED;
          break;
        case ABSTRACT:
          m |= Modifier.ABSTRACT;
          break;
        case PUBLIC:
          m |= Modifier.PUBLIC;
          break;
        case PROTECTED:
          m |= Modifier.PROTECTED;
          break;
        case PRIVATE:
          m |= Modifier.PRIVATE;
          break;
        case VOLATILE:
          m |= Modifier.VOLATILE;
          break;
        case TRANSIENT:
          m |= Modifier.TRANSIENT;
          break;
        case STRICT:
          m |= Modifier.STRICT;
          break;
      }
    }

    return m;
  }
Beispiel #19
0
  public void atMethodDecl(MethodDecl method) throws CompileError {
    ASTList mods = method.getModifiers();
    setMaxLocals(1);
    while (mods != null) {
      Keyword k = (Keyword) mods.head();
      mods = mods.tail();
      if (k.get() == STATIC) {
        setMaxLocals(0);
        inStaticMethod = true;
      }
    }

    ASTList params = method.getParams();
    while (params != null) {
      atDeclarator((Declarator) params.head());
      params = params.tail();
    }

    Stmnt s = method.getBody();
    atMethodBody(s, method.isConstructor(), method.getReturn().getType() == VOID);
  }
Beispiel #20
0
  public void refreshTextSize() {
    textSize =
        Integer.parseInt(
            PreferenceManager.getDefaultSharedPreferences(context).getString("textsize", "14"));
    float scaledTextSize =
        TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_SP, textSize, getResources().getDisplayMetrics());

    setTextSize(textSize);

    ArrayList<TextPaint> styleList = new ArrayList<TextPaint>(styles.values());

    for (TextPaint paint : styleList) {
      paint.setTextSize(scaledTextSize);
    }

    for (Keyword keyword : syntax) {
      if (keyword != null) { // TODO figure out what's going on here
        keyword.paint().setTextSize(scaledTextSize);
      }
    }
  }
Beispiel #21
0
  @Override
  public MagicSet evaluate(GameState state, Identified thisObject) {
    MagicSet ret = new MagicSet();
    MagicSet what = this.what.evaluate(state, thisObject);
    auras:
    for (GameObject aura : state.getAllObjects()) {
      if (!aura.getSubTypes().contains(SubType.AURA)) continue;

      for (Keyword ability : aura.getKeywordAbilities())
        if (ability.isEnchant()) {
          Enchant e = (Enchant) ability;
          MagicSet intermediate = new MagicSet(what);
          intermediate.retainAll(e.filter.evaluate(state, aura));
          for (GameObject o : intermediate.getAll(GameObject.class))
            if (!o.cantBeAttachedBy().match(state, thisObject, new MagicSet(aura))) {
              ret.add(aura);
              continue auras;
            }
        }
    }
    return ret;
  }
Beispiel #22
0
  @Override
  public String toString() {
    String result = keyword.name() + " ";

    if (rowCount != null) {
      result += rowCount;
    } else if (jdbcParameter != null) {
      result += jdbcParameter.toString();
    } else if (variable != null) {
      result += variable;
    }

    return result;
  }
Beispiel #23
0
  /**
   * Reads an object definition, given the first numeric object, which has already been read and is
   * passed as an argument. This is called by the no-argument readObjectDef; the only other case in
   * which it will be called is for a cross-reference stream, which can be distinguished from a
   * cross-reference table only once the first token is read.
   */
  public PdfObject readObjectDef(Numeric objNumTok) throws IOException, PdfException {
    String invDef = "Invalid object definition";
    reset();
    // The start of an object must be <num> <num> obj
    // Numeric objNumTok = (Numeric) getNext (Numeric.class, invDef);
    Numeric genNumTok = (Numeric) getNext(Numeric.class, invDef);
    Keyword objKey = (Keyword) getNext(Keyword.class, invDef);
    if (!"obj".equals(objKey.getValue())) {
      throw new PdfMalformedException(invDef);
    }
    if (_tokenizer.getWSString().length() > 1) {
      _pdfACompliant = false;
    }
    PdfObject obj = readObject();

    // Now a special-case check to read a stream object, which
    // consists of a dictionary followed by a stream token.
    if (obj instanceof PdfDictionary) {
      Stream strm = null;
      try {
        strm = (Stream) getNext(Stream.class, "");
      } catch (Exception e) {
        // if we get an exception, it just means it wasn't a stream
      }
      if (strm != null) {
        // Assimilate the dictionary and the stream token into the
        // object to be returned
        PdfStream strmObj = new PdfStream((PdfDictionary) obj, strm);
        obj = strmObj;
      }
    }

    obj.setObjNumber(objNumTok.getIntegerValue());
    obj.setGenNumber(genNumTok.getIntegerValue());
    return obj;
  }
Beispiel #24
0
  public static void main(String... args) throws IOException {

    OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref();
    PrintWriter err = RT.errPrintWriter();
    String path = System.getProperty(PATH_PROP);
    int count = args.length;

    if (path == null) {
      err.println(
          "ERROR: Must set system property "
              + PATH_PROP
              + "\nto the location for compiled .class files."
              + "\nThis directory must also be on your CLASSPATH.");
      System.exit(1);
    }

    boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true");
    String uncheckedMathProp = System.getProperty(UNCHECKED_MATH_PROP);
    Object uncheckedMath = Boolean.FALSE;
    if ("true".equals(uncheckedMathProp)) uncheckedMath = Boolean.TRUE;
    else if ("warn-on-boxed".equals(uncheckedMathProp))
      uncheckedMath = Keyword.intern("warn-on-boxed");

    try {
      Var.pushThreadBindings(
          RT.map(
              compile_path,
              path,
              warn_on_reflection,
              warnOnReflection,
              unchecked_math,
              uncheckedMath));

      for (String lib : args) {
        out.write("Compiling " + lib + " to " + path + '\n');
        out.flush();
        compile.invoke(Symbol.intern(lib));
      }
    } finally {
      Var.popThreadBindings();
      try {
        out.flush();
      } catch (IOException e) {
        e.printStackTrace(err);
      }
    }
  }
Beispiel #25
0
 public Keyword getKeyword(String word) {
   for (Keyword k : Keyword.values()) {
     if (k.name.equals(word)) return (k);
   }
   return (NONE);
 }
 /**
  * キーワード情報のインスタンスを取得します。
  *
  * @since v0.2.0
  */
 @Override
 protected Keyword createKeyword() {
   return Keyword.create(this);
 }
  public void run() {

    MsgObject msgObject = null;
    String serviceId = "";
    String info = "";
    Keyword keyword = null;
    String process_result = "";

    try {
      sleep(1500);
    } catch (InterruptedException ex1) {
    }

    while (ConsoleSRV.processData) {
      process_result = "";
      try {
        msgObject = (MsgObject) queue.remove();
        serviceId = msgObject.getServiceid();
        info = msgObject.getUsertext();
        keyword = ConsoleSRV.loadconfig.getKeyword(info, serviceId);

        if (Constants.INV_KEYWORD.equalsIgnoreCase(keyword.getKeyword())) {
          keyword = ConsoleSRV.loadconfig.getKeywordInvalid(info, serviceId);
          if (!Constants.INV_KEYWORD.equalsIgnoreCase(keyword.getKeyword())) {
            String newinfo = Utilities.replaceWhiteLetter(info);
            msgObject.setUsertext(newinfo);
            Util.logger.info(
                "{userid="
                    + msgObject.getUserid()
                    + "}{info_old="
                    + info
                    + "}{info_new="
                    + newinfo
                    + "}");
          } else {
            keyword = ConsoleSRV.loadconfig.getKeywordInvalidLast(info, serviceId);

            if (!Constants.INV_KEYWORD.equalsIgnoreCase(keyword.getKeyword())) {
              String newinfo = Utilities.replaceWhiteLetter(info);
              newinfo = newinfo.replace(".", "");
              newinfo = newinfo.replace(" ", "");

              msgObject.setUsertext(newinfo);
              Util.logger.info(
                  "{userid="
                      + msgObject.getUserid()
                      + "}{info_old="
                      + info
                      + "}{info_new="
                      + newinfo
                      + "}");
            }
          }
        }

        msgObject.setKeyword(keyword.getKeyword());
        msgObject.setCpid(keyword.getCpid());
        process_result = processQueueMsg(msgObject, keyword);
        // if (!OK.equalsIgnoreCase(process_result)) {
        // queue.add(msgObject);
        // }
        // else {
        msgObject.setMsgNotes(process_result);

        ConsoleSRV.incrementAndGet_process(msgObject.getMobileoperator());

        queueLog.add(
            new MsgObject(
                serviceId,
                msgObject.getUserid(),
                keyword.getKeyword(),
                info,
                msgObject.getRequestid(),
                msgObject.getTTimes(),
                msgObject.getMobileoperator(),
                0,
                0,
                msgObject.getCpid(),
                msgObject.getMsgnotes()));
        // }

      } catch (Exception ex) {
        Util.logger.error("Execute queue. Ex:" + ex.toString());
        queue.add(msgObject);
      }
    }
  }
    @Override
    protected Object doInBackground() throws Exception {
      logger.log(Level.INFO, "Pending start of new searcher");

      final String displayName = "Keyword Search" + (finalRun ? " - Finalizing" : "");
      progress =
          ProgressHandleFactory.createHandle(
              displayName + (" (Pending)"),
              new Cancellable() {

                @Override
                public boolean cancel() {
                  logger.log(Level.INFO, "Cancelling the searcher by user.");
                  if (progress != null) {
                    progress.setDisplayName(displayName + " (Cancelling...)");
                  }
                  return Searcher.this.cancel(true);
                }
              });

      progress.start();
      progress.switchToIndeterminate();

      // block to ensure previous searcher is completely done with doInBackground()
      // even after previous searcher cancellation, we need to check this
      searcherLock.lock();
      try {
        logger.log(Level.INFO, "Started a new searcher");
        progress.setDisplayName(displayName);
        // make sure other searchers are not spawned
        searcherDone = false;
        runSearcher = false;
        if (searchTimer.isRunning()) {
          searchTimer.stop();
        }

        int numSearched = 0;

        updateKeywords();
        progress.switchToDeterminate(keywords.size());

        for (Keyword keywordQuery : keywords) {
          if (this.isCancelled()) {
            logger.log(
                Level.INFO,
                "Cancel detected, bailing before new keyword processed: "
                    + keywordQuery.getQuery());
            return null;
          }
          final String queryStr = keywordQuery.getQuery();
          final KeywordSearchList list = keywordToList.get(queryStr);
          final String listName = list.getName();

          // DEBUG
          // logger.log(Level.INFO, "Searching: " + queryStr);

          progress.progress(queryStr, numSearched);

          KeywordSearchQuery del = null;

          boolean isRegex = !keywordQuery.isLiteral();
          if (!isRegex) {
            del = new LuceneQuery(keywordQuery);
            del.escape();
          } else {
            del = new TermComponentQuery(keywordQuery);
          }

          Map<String, List<ContentHit>> queryResult = null;

          try {
            queryResult = del.performQuery();
          } catch (NoOpenCoreException ex) {
            logger.log(Level.WARNING, "Error performing query: " + keywordQuery.getQuery(), ex);
            // no reason to continue with next query if recovery failed
            // or wait for recovery to kick in and run again later
            // likely case has closed and threads are being interrupted
            return null;
          } catch (CancellationException e) {
            logger.log(
                Level.INFO,
                "Cancel detected, bailing during keyword query: " + keywordQuery.getQuery());
            return null;
          } catch (Exception e) {
            logger.log(Level.WARNING, "Error performing query: " + keywordQuery.getQuery(), e);
            continue;
          }

          // calculate new results but substracting results already obtained in this run
          Map<Keyword, List<ContentHit>> newResults = new HashMap<Keyword, List<ContentHit>>();

          for (String termResult : queryResult.keySet()) {
            List<ContentHit> queryTermResults = queryResult.get(termResult);
            Keyword termResultK = new Keyword(termResult, !isRegex);
            List<ContentHit> curTermResults = currentResults.get(termResultK);
            if (curTermResults == null) {
              currentResults.put(termResultK, queryTermResults);
              newResults.put(termResultK, queryTermResults);
            } else {
              // some AbstractFile hits already exist for this keyword
              for (ContentHit res : queryTermResults) {
                if (!previouslyHit(curTermResults, res)) {
                  // add to new results
                  List<ContentHit> newResultsFs = newResults.get(termResultK);
                  if (newResultsFs == null) {
                    newResultsFs = new ArrayList<ContentHit>();
                    newResults.put(termResultK, newResultsFs);
                  }
                  newResultsFs.add(res);
                  curTermResults.add(res);
                }
              }
            }
          }

          if (!newResults.isEmpty()) {

            // write results to BB

            // new artifacts created, to report to listeners
            Collection<BlackboardArtifact> newArtifacts = new ArrayList<BlackboardArtifact>();

            for (final Keyword hitTerm : newResults.keySet()) {
              List<ContentHit> contentHitsAll = newResults.get(hitTerm);
              Map<AbstractFile, Integer> contentHitsFlattened =
                  ContentHit.flattenResults(contentHitsAll);
              for (final AbstractFile hitFile : contentHitsFlattened.keySet()) {
                String snippet = null;
                final String snippetQuery =
                    KeywordSearchUtil.escapeLuceneQuery(hitTerm.getQuery(), true, false);
                int chunkId = contentHitsFlattened.get(hitFile);
                try {
                  snippet =
                      LuceneQuery.querySnippet(
                          snippetQuery, hitFile.getId(), chunkId, isRegex, true);
                } catch (NoOpenCoreException e) {
                  logger.log(Level.WARNING, "Error querying snippet: " + snippetQuery, e);
                  // no reason to continue
                  return null;
                } catch (Exception e) {
                  logger.log(Level.WARNING, "Error querying snippet: " + snippetQuery, e);
                  continue;
                }

                KeywordWriteResult written =
                    del.writeToBlackBoard(hitTerm.getQuery(), hitFile, snippet, listName);

                if (written == null) {
                  logger.log(
                      Level.WARNING,
                      "BB artifact for keyword hit not written, file: "
                          + hitFile
                          + ", hit: "
                          + hitTerm.toString());
                  continue;
                }

                newArtifacts.add(written.getArtifact());

                // generate a data message for each artifact
                StringBuilder subjectSb = new StringBuilder();
                StringBuilder detailsSb = new StringBuilder();
                // final int hitFiles = newResults.size();

                if (!keywordQuery.isLiteral()) {
                  subjectSb.append("RegExp hit: ");
                } else {
                  subjectSb.append("Keyword hit: ");
                }
                // subjectSb.append("<");
                String uniqueKey = null;
                BlackboardAttribute attr =
                    written.getAttribute(
                        BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD.getTypeID());
                if (attr != null) {
                  final String keyword = attr.getValueString();
                  subjectSb.append(keyword);
                  uniqueKey = keyword.toLowerCase();
                }

                // subjectSb.append(">");
                // String uniqueKey = queryStr;

                // details
                detailsSb.append("<table border='0' cellpadding='4' width='280'>");
                // hit
                detailsSb.append("<tr>");
                detailsSb.append("<th>Keyword hit</th>");
                detailsSb
                    .append("<td>")
                    .append(StringEscapeUtils.escapeHtml(attr.getValueString()))
                    .append("</td>");
                detailsSb.append("</tr>");

                // preview
                attr =
                    written.getAttribute(
                        BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_PREVIEW.getTypeID());
                if (attr != null) {
                  detailsSb.append("<tr>");
                  detailsSb.append("<th>Preview</th>");
                  detailsSb
                      .append("<td>")
                      .append(StringEscapeUtils.escapeHtml(attr.getValueString()))
                      .append("</td>");
                  detailsSb.append("</tr>");
                }

                // file
                detailsSb.append("<tr>");
                detailsSb.append("<th>File</th>");
                if (hitFile.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.FS)) {
                  detailsSb
                      .append("<td>")
                      .append(((FsContent) hitFile).getParentPath())
                      .append(hitFile.getName())
                      .append("</td>");
                } else {
                  detailsSb.append("<td>").append(hitFile.getName()).append("</td>");
                }
                detailsSb.append("</tr>");

                // list
                attr =
                    written.getAttribute(
                        BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID());
                detailsSb.append("<tr>");
                detailsSb.append("<th>List</th>");
                detailsSb.append("<td>").append(attr.getValueString()).append("</td>");
                detailsSb.append("</tr>");

                // regex
                if (!keywordQuery.isLiteral()) {
                  attr =
                      written.getAttribute(
                          BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_REGEXP.getTypeID());
                  if (attr != null) {
                    detailsSb.append("<tr>");
                    detailsSb.append("<th>RegEx</th>");
                    detailsSb.append("<td>").append(attr.getValueString()).append("</td>");
                    detailsSb.append("</tr>");
                  }
                }
                detailsSb.append("</table>");

                // check if should send messages on hits on this list
                if (list.getIngestMessages()) // post ingest inbox msg
                {
                  managerProxy.postMessage(
                      IngestMessage.createDataMessage(
                          ++messageID,
                          instance,
                          subjectSb.toString(),
                          detailsSb.toString(),
                          uniqueKey,
                          written.getArtifact()));
                }
              } // for each term hit
            } // for each file hit

            // update artifact browser
            if (!newArtifacts.isEmpty()) {
              IngestManager.fireServiceDataEvent(
                  new ServiceDataEvent(MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, newArtifacts));
            }
          }
          progress.progress(queryStr, ++numSearched);
        }

      } // end try block
      catch (Exception ex) {
        logger.log(Level.WARNING, "searcher exception occurred", ex);
      } finally {
        finalizeSearcher();
        searcherLock.unlock();
      }

      return null;
    }
  private void generateExcelDoc(String docName) throws FileNotFoundException, IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet overall = workbook.createSheet("Overall");
    XSSFRow row = overall.createRow(0);

    XSSFCellStyle topStyle = workbook.createCellStyle();
    topStyle.setAlignment(CellStyle.ALIGN_CENTER);

    XSSFCell theme = row.createCell(0);
    theme.setCellValue("Theme");
    overall.autoSizeColumn(0);

    XSSFCell occurs = row.createCell(1);
    occurs.setCellValue("Occurrences");
    overall.autoSizeColumn(1);

    XSSFCell prev = row.createCell(2);
    prev.setCellValue("Prevalence");
    overall.autoSizeColumn(2);

    theme.setCellStyle(topStyle);
    occurs.setCellStyle(topStyle);
    prev.setCellStyle(topStyle);

    for (int i = 0; i < themes.size(); i++) {
      XSSFRow r = overall.createRow((i + 1));

      XSSFCell c = r.createCell(0);
      c.setCellValue(themes.get(i).getName());

      XSSFCell c1 = r.createCell(1);
      c1.setCellValue(themes.get(i).getTotalOccurs());

      XSSFCell c2 = r.createCell(2);
      c2.setCellValue(calculatePrevalence(themes.get(i).getTotalOccurs(), lineCount));
    }

    // This could be done in the previous loop but since we don't need
    // indices as much, we may as well use the cleaner for each loop

    for (Theme t : themes) {
      XSSFSheet themeSheet = workbook.createSheet(t.getName());
      XSSFRow row1 = themeSheet.createRow(0);

      XSSFCell keyword = row1.createCell(0);
      keyword.setCellValue("Keyword");
      keyword.setCellStyle(topStyle);

      XSSFCell occ = row1.createCell(1);
      occ.setCellValue("Occurrences");
      occ.setCellStyle(topStyle);

      XSSFCell themePrev = row1.createCell(2);
      themePrev.setCellValue("Prevalence");
      themePrev.setCellStyle(topStyle);

      for (int i = 0; i < t.getKeywords().size(); i++) {
        Keyword k = t.getKeywords().get(i);
        XSSFRow r = themeSheet.createRow((i + 1));

        XSSFCell c = r.createCell(0);
        c.setCellValue(k.getName());

        XSSFCell c1 = r.createCell(1);
        c1.setCellValue(k.getNumOccurs());

        XSSFCell c2 = r.createCell(2);
        c2.setCellValue(calculatePrevalence(k.getNumOccurs(), t.getTotalOccurs()));
      }
    }

    FileOutputStream output = new FileOutputStream(docName);
    workbook.write(output);
    output.close();
  }
  public void run() {

    MsgObject msgObject = null;
    String serviceId = "";
    String info = "";
    Keyword keyword = null;
    String process_result = "";

    try {
      sleep(1500);
    } catch (InterruptedException ex1) {
    }

    while (ConsoleSRV.processData) {
      process_result = "";
      try {
        // Lấy 1 item trong MO Queue và xóa nó đi
        msgObject = (MsgObject) queue.remove();
        serviceId = msgObject.getServiceid();
        info = msgObject.getUsertext();

        keyword = ConsoleSRV.mLoadKeyword.getKeyword(info, serviceId);

        if (LocalConfig.INV_KEYWORD.equalsIgnoreCase(keyword.getKeyword())) {
          // Nếu keyword không nằm trong list keyword cho phép

          keyword = ConsoleSRV.mLoadKeyword.getKeywordInvalid(info, serviceId);

          if (!LocalConfig.INV_KEYWORD.equalsIgnoreCase(keyword.getKeyword())) {
            String newinfo = MyText.replaceWhiteLetter(info);
            msgObject.setUsertext(newinfo);
          } else {
            keyword = ConsoleSRV.mLoadKeyword.getKeywordInvalidLast(info, serviceId);

            if (!LocalConfig.INV_KEYWORD.equalsIgnoreCase(keyword.getKeyword())) {
              String newinfo = MyText.replaceWhiteLetter(info);
              newinfo = newinfo.replace(".", "");
              newinfo = newinfo.replace(" ", "");

              msgObject.setUsertext(newinfo);
            }
          }
        }

        mLog.log.info(
            Common.GetStringLog(
                "Check Exist Keyword", "Keyword:" + keyword.getKeyword(), msgObject));

        msgObject.setKeyword(keyword.getKeyword());
        msgObject.setCpid(keyword.getCpid());
        process_result = processQueueMsg(msgObject, keyword);

        msgObject.setMsgNotes(process_result);

        ConsoleSRV.incrementAndGet_process(msgObject.getMobileoperator());

        queueLog.add(
            new MsgObject(
                msgObject.getId(),
                serviceId,
                msgObject.getUserid(),
                keyword.getKeyword(),
                info,
                msgObject.getRequestid(),
                msgObject.getTTimes(),
                msgObject.getMobileoperator(),
                0,
                0,
                msgObject.getCpid(),
                msgObject.getMsgnotes()));

      } catch (Exception ex) {
        mLog.log.error(Common.GetStringLog(msgObject), ex);
        queue.add(msgObject);
      }
    }
  }