예제 #1
0
 private void fireOnOpen() {
   if (openHandler_ == null) {
     return;
   }
   final Scriptable scope = openHandler_.getParentScope();
   final JavaScriptEngine jsEngine = containingPage_.getWebClient().getJavaScriptEngine();
   jsEngine.callFunction(
       containingPage_, openHandler_, scope, WebSocket.this, ArrayUtils.EMPTY_OBJECT_ARRAY);
 }
  /** {@inheritDoc} */
  public String preProcess(
      final HtmlPage htmlPage,
      final String sourceCode,
      final String sourceName,
      final int lineNumber,
      final HtmlElement htmlElement) {

    final int startPos = indexOf(sourceCode, "/*@cc_on", 0);
    if (startPos == -1) {
      return sourceCode;
    }
    final int endPos = indexOf(sourceCode, "@*/", startPos);
    if (endPos == -1) {
      return sourceCode;
    }

    final StringBuilder sb = new StringBuilder();
    if (startPos > 0) {
      sb.append(sourceCode.substring(0, startPos));
    }
    final BrowserVersion browserVersion = htmlPage.getWebClient().getBrowserVersion();
    final String body = sourceCode.substring(startPos + 8, endPos);
    sb.append(processConditionalCompilation(body, browserVersion));
    if (endPos < sourceCode.length() - 3) {
      String remaining = sourceCode.substring(endPos + 3);
      int nextStart = remaining.indexOf("/*@");
      int nextEnd = remaining.indexOf("@*/", nextStart + 3);
      // handle other /*@ @*/ blocks
      while (nextStart >= 0 && nextEnd > 0) {
        sb.append(remaining.substring(0, nextStart));
        final String nextBody = remaining.substring(nextStart + 3, nextEnd);
        sb.append(processConditionalCompilation(nextBody, browserVersion));
        remaining = remaining.substring(nextEnd + 3);
        nextStart = remaining.indexOf("/*@");
        nextEnd = remaining.indexOf("@*/", nextStart + 3);
      }
      sb.append(remaining);
    }
    return sb.toString();
  }