示例#1
0
  public void computeKeySignalType(
      Result result,
      String typeName,
      int keyCode,
      int which,
      String keyIdentifier,
      boolean metaKey,
      boolean ctrlKey,
      boolean altKey,
      boolean shiftKey) {

    boolean ret = true;

    int typeInt;
    if ("keydown".equals(typeName)) {
      typeInt = Event.ONKEYDOWN;
    } else if ("keypress".equals(typeName)) {
      typeInt = Event.ONKEYPRESS;
    } else if ("keyup".equals(typeName)) {
      result.type = null;
      return;
    } else {
      throw new AssertionError("Non-key-event passed to computeKeySignalType");
    }

    KeySignalType type;

    int computedKeyCode = which != 0 ? which : keyCode;

    if (computedKeyCode == 10) {
      computedKeyCode = KeyCodes.KEY_ENTER;
    }

    // For non-firefox browsers, we only get keydown events for IME, no keypress
    boolean isIME = computedKeyCode == IME_CODE;

    boolean commandKey = commandIsCtrl ? ctrlKey : metaKey;

    // Some trace logging very useful to debug
    EditorStaticDeps.logger
        .trace()
        .log(
            "KEY SIGNAL IN PROCESS identifier = "
                + keyIdentifier
                + " code = "
                + computedKeyCode
                + " type = "
                + (typeInt == Event.ONKEYDOWN ? "KeyDown" : "KeyPress")
                + (ctrlKey ? " CTRL" : "")
                + (shiftKey ? " SHIFT" : "")
                + (altKey ? " ALT" : ""));

    switch (userAgent) {
      case WEBKIT:
        // This is a bit tricky because there are significant differences
        // between safari 3.0 and safari 3.1...

        // We could probably actually almost use the same code that we use for IE
        // for safari 3.1, because with 3.1 the webkit folks made a big shift to
        // get the events to be in line with IE for compatibility. 3.0 events
        // are a lot more similar to FF, but different enough to need special
        // handling. However, it seems that using more advanced features like
        // keyIdentifier for safaris is probably better and more future-proof,
        // as well as being compatible between the two, so for now we're not
        // using IE logic for safari 3.1

        // Weird special large keycode numbers for safari 3.0, where it gives
        // us keypress events (though they happen after the dom is changed,
        // for some things like delete. So not too useful). The number
        // 63200 is known as the cutoff mark.
        if (typeInt == Event.ONKEYDOWN && computedKeyCode > 63200) {
          result.type = null;
          return;
        } else if (typeInt == Event.ONKEYPRESS) {
          // Skip keypress for tab and escape, because they are the only non-input keys
          // that don't have keycodes above 63200. This is to prevent them from being treated
          // as INPUT in the || = keypress below. See (X) below
          if (computedKeyCode == KeyCodes.KEY_ESCAPE || computedKeyCode == KeyCodes.KEY_TAB) {
            result.type = null;
            return;
          }
        }

        // boolean isPossiblyCtrlInput = typeInt == Event.ONKEYDOWN && ret.getCtrlKey();
        boolean isActuallyCtrlInput = false;

        boolean startsWithUPlus = keyIdentifier != null && keyIdentifier.startsWith("U+");

        // Need to use identifier for the delete key because the keycode conflicts
        // with the keycode for the full stop.
        if (isIME) {
          // If is IME, override the logic below - we get keyIdentifiers for IME events,
          // but those are basically useless as the event is basically still an IME input
          // event (e.g. keyIdentifier might say "Up", but it's certainly not navigation,
          // it's just the user selecting from the IME dialog).
          type = KeySignalType.INPUT;
        } else if ((DELETE_KEY_IDENTIFIER.equals(keyIdentifier) && typeInt == Event.ONKEYDOWN)
            || computedKeyCode == KeyCodes.KEY_BACKSPACE) {
          // WAVE-407 Avoid missing the '.' char (KEYPRESS + CODE 46)
          // ensuring it's a KEYDOWN event with a DELETE_KEY_IDENTIFIER

          type = KeySignalType.DELETE;
        } else if (NAVIGATION_KEY_IDENTIFIERS.containsKey(keyIdentifier)
            && typeInt == Event.ONKEYDOWN) {
          // WAVE-407 Avoid missing chars with NAVIGATION_KEY_IDENTIFIERS but
          // represeting a SHIFT + key char (! " · ...). Navigation events come
          // with KEYDOWN, not with KEYPRESS

          type = KeySignalType.NAVIGATION;
          // Escape, backspace and context-menu-key (U+0010) are, to my knowledge,
          // the only non-navigation keys that
          // have a "U+..." keyIdentifier, so we handle them explicitly.
          // (Backspace was handled earlier).
        } else if (computedKeyCode == KeyCodes.KEY_ESCAPE || "U+0010".equals(keyIdentifier)) {
          type = KeySignalType.NOEFFECT;
        } else if (computedKeyCode < 63200
            && // if it's not a safari 3.0 non-input key (See (X) above)
            (typeInt == Event.ONKEYPRESS
                || // if it's a regular keypress
                startsWithUPlus
                || computedKeyCode == KeyCodes.KEY_ENTER)) {
          type = KeySignalType.INPUT;
          isActuallyCtrlInput = ctrlKey || (commandComboDoesntGiveKeypress && commandKey);
        } else {
          type = KeySignalType.NOEFFECT;
        }

        // Maybe nullify it with the same logic as IE, EXCEPT for the special
        // Ctrl Input webkit behaviour, and IME for windows
        if (isActuallyCtrlInput) {
          if (computedKeyCode == KeyCodes.KEY_ENTER) {
            ret = typeInt == Event.ONKEYDOWN;
          }
          // HACK(danilatos): Don't actually nullify isActuallyCtrlInput for key press.
          // We get that for AltGr combos on non-mac computers.
        } else if (isIME || keyCode == KeyCodes.KEY_TAB) {
          ret = typeInt == Event.ONKEYDOWN;
        } else {
          ret = maybeNullWebkitIE(ret, typeInt, type);
        }
        if (!ret) {
          result.type = null;
          return;
        }
        break;
      case GECKO:
        boolean hasKeyCodeButNotWhich = keyCode != 0 && which == 0;

        // Firefox is easy for deciding signal events, because it issues a keypress for
        // whenever we would want a signal. So we can basically ignore all keydown events.
        // It also, on all OSes, does any default action AFTER the keypress (even for
        // things like Ctrl/Meta+C, etc). So keypress is perfect for us.
        // Ctrl+Space is an exception, where we don't get a keypress
        // Firefox also gives us keypress events even for Windows IME input
        if (ctrlKey && !altKey && !shiftKey && computedKeyCode == ' ') {
          if (typeInt != Event.ONKEYDOWN) {
            result.type = null;
            return;
          }
        } else if (typeInt == Event.ONKEYDOWN) {
          result.type = null;
          return;
        }

        // Backspace fails the !hasKeyCodeButNotWhich test, so check it explicitly first
        if (computedKeyCode == KeyCodes.KEY_BACKSPACE) {
          type = KeySignalType.DELETE;
          // This 'keyCode' but not 'which' works very nicely for catching normal typing input keys,
          // the only 'exceptions' I've seen so far are bksp & enter which have both
        } else if (!hasKeyCodeButNotWhich
            || computedKeyCode == KeyCodes.KEY_ENTER
            || computedKeyCode == KeyCodes.KEY_TAB) {
          type = KeySignalType.INPUT;
        } else if (computedKeyCode == KeyCodes.KEY_DELETE) {
          type = KeySignalType.DELETE;
        } else if (NAVIGATION_KEYS.contains(computedKeyCode)) {
          type = KeySignalType.NAVIGATION;
        } else {
          type = KeySignalType.NOEFFECT;
        }

        break;
      case IE:

        // Unfortunately IE gives us the least information, so there are no nifty tricks.
        // So we pretty much need to use some educated guessing based on key codes.
        // Experimentation page to the rescue.

        boolean isKeydownForInputKey = isInputKeyCodeIE(computedKeyCode);

        // IE has some strange behaviour with modifiers and whether or not there will
        // be a keypress. Ctrl kills the keypress, unless shift is also held.
        // Meta doesn't kill it. Alt always kills the keypress, overriding other rules.
        boolean hasModifiersThatResultInNoKeyPress = altKey || (ctrlKey && !shiftKey);

        if (typeInt == Event.ONKEYDOWN) {
          if (isKeydownForInputKey) {
            type = KeySignalType.INPUT;
          } else if (computedKeyCode == KeyCodes.KEY_BACKSPACE
              || computedKeyCode == KeyCodes.KEY_DELETE) {
            type = KeySignalType.DELETE;
          } else if (NAVIGATION_KEYS.contains(computedKeyCode)) {
            type = KeySignalType.NAVIGATION;
          } else {
            type = KeySignalType.NOEFFECT;
          }
        } else {
          // Escape is the only non-input thing that has a keypress event
          if (computedKeyCode == KeyCodes.KEY_ESCAPE) {
            result.type = null;
            return;
          }
          assert typeInt == Event.ONKEYPRESS;
          // I think the guessCommandFromModifiers() check here isn't needed,
          // but i feel safer putting it in.
          type = KeySignalType.INPUT;
        }

        if (hasModifiersThatResultInNoKeyPress || isIME || computedKeyCode == KeyCodes.KEY_TAB) {
          ret = typeInt == Event.ONKEYDOWN ? ret : false;
        } else {
          ret = maybeNullWebkitIE(ret, typeInt, type);
        }
        if (!ret) {
          result.type = null;
          return;
        }
        break;
      default:
        throw new UnsupportedOperationException("Unhandled user agent");
    }

    if (ret) {
      result.type = type;
      result.keyCode = computedKeyCode;
    } else {
      result.type = null;
      return;
    }
  }
  /**
   * Parses a method type definition
   *
   * @param docMethod
   * @return
   */
  protected static Method ParseMethod(MethodDoc docMethod) {
    assert (docMethod != null);

    Method xmlMethod = new Method();

    xmlMethod.name = docMethod.name();
    xmlMethod.hash = computeHash(docMethod.qualifiedName(), docMethod.signature());
    xmlMethod.qualifiedName = docMethod.qualifiedName();
    xmlMethod.comment = docMethod.commentText();
    xmlMethod.signature = docMethod.signature();
    xmlMethod.isNative = docMethod.isNative();
    xmlMethod.isVarArgs = docMethod.isVarArgs();
    xmlMethod.isSynchronized = docMethod.isSynchronized();
    xmlMethod.isFinal = docMethod.isFinal();
    xmlMethod.isAbstract = docMethod.isAbstract();
    xmlMethod.isStatic = docMethod.isStatic();

    xmlMethod.scope = DetermineScope(docMethod);

    // Parse parameters of the method
    Parameter[] parameters = docMethod.parameters();

    if (parameters != null && parameters.length > 0) {
      ParamTag[] paramComments = docMethod.paramTags();

      ArrayList<Param> paramList = new ArrayList<Param>();

      for (Parameter parameter : parameters) {
        ParamTag paramComment = null;

        // look to see if this parameter has comments
        // if so, paramComment will be set
        for (ParamTag testParam : paramComments) {
          String testParamName = testParam.parameterName();
          if (testParamName != null) {
            if (testParamName.compareTo(parameter.name()) == 0) {
              paramComment = testParam;
              break;
            }
          }
        }

        paramList.add(ParseParameter(parameter, paramComment));
      }

      xmlMethod.parameters = paramList.toArray(new Param[] {});
    } else {
      log.debug("No parameters for method: " + docMethod.name());
    }

    // Parse result data

    Result returnInfo = new Result();

    Tag[] returnTags = docMethod.tags("@return");
    if (returnTags != null && returnTags.length > 0) {
      // there should be only one return tag.  but heck,
      // if they specify two, so what...
      StringBuilder builder = new StringBuilder();
      for (Tag returnTag : returnTags) {
        String returnTagText = returnTag.text();
        if (returnTagText != null) {
          builder.append(returnTagText);
          builder.append("\n");
        }
      }

      returnInfo.comment = builder.substring(0, builder.length() - 1);
    }

    returnInfo.type = ParseType(docMethod.returnType());
    xmlMethod.result = returnInfo;

    // Parse exceptions of the method

    Type[] types = docMethod.thrownExceptionTypes();
    ThrowsTag[] exceptionComments = docMethod.throwsTags();

    if (types != null && types.length > 0) {
      ArrayList<ExceptionInstance> exceptionList = new ArrayList<ExceptionInstance>();

      for (Type exceptionType : types) {
        ExceptionInstance exception = new ExceptionInstance();

        exception.type = ParseType(exceptionType);

        for (ThrowsTag exceptionComment : exceptionComments) {
          if (exceptionType == exceptionComment.exceptionType()) {
            exception.comment = exceptionComment.exceptionComment();

            ClassDoc exceptionDetails = exceptionComment.exception();

            // not yet parsing Exceptions defined within the supplied code set
            exception.type = ParseType(exceptionComment.exceptionType());
            break;
          }
        }

        exceptionList.add(exception);
      }

      xmlMethod.exceptions = exceptionList.toArray(new ExceptionInstance[] {});
    }

    // parse annotations from the method
    xmlMethod.annotationInstances =
        ParseAnnotationInstances(docMethod.annotations(), docMethod.qualifiedName());

    return xmlMethod;
  }
示例#3
0
    protected Result doInBackground(String... upcs) {
      Result res = new Result();
      try {
        String query = PREFIX + upcs[0];

        HttpClient httpclient = new DefaultHttpClient();

        HttpGet request = new HttpGet();
        URI website = new URI(query);
        request.setURI(website);
        HttpResponse response = httpclient.execute(request);

        BufferedReader in =
            new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        // dump header
        String line = in.readLine();
        Pattern ph = Pattern.compile("/head");
        Matcher mh = ph.matcher(line);
        while (!mh.find()) mh = ph.matcher(in.readLine());

        Cursor ts = mdb.getTypes();
        Cursor bs = mdb.getAllBrands();
        int[] bcount = new int[bs.getCount()];

        int[] tcount = new int[ts.getCount()];
        int tpos = 0;
        int bpos = 0;
        line = in.readLine();
        String allRes = "";
        String brand = "";
        boolean brandFound = false;
        int bestCount = 0;
        while (line != null) {
          allRes += line;
          tpos = 0;
          ts.moveToFirst();
          do {
            Pattern p = Pattern.compile(ts.getString(1));
            Matcher m = p.matcher(line);
            int findCount = 0;
            while (m.find()) findCount += 1;
            tcount[tpos] += findCount;
            tpos += 1;
          } while (ts.moveToNext());

          if (!brandFound) {
            bpos = 0;
            bs.moveToFirst();
            do {
              String testBrand = bs.getString(1);
              String s = testBrand.split("'")[0]; // simple throw away of ' not found in html
              if (!reserved(s)) {
                Pattern p1 = Pattern.compile(s);
                Matcher m1 = p1.matcher(line);
                int brandCount = 0;
                while (m1.find()) brandCount += 1;
                bcount[bpos] += brandCount;
                if (bcount[bpos] > 10) // good enough
                {
                  brand = bs.getString(1);
                  brandFound = true;
                }

                if (bcount[bpos] > bestCount) {
                  bestCount = bcount[bpos];
                  brand = bs.getString(1);
                }
                bpos += 1;
              }
            } while (!brandFound && bs.moveToNext());
          }

          line = in.readLine();
        }

        int c = 0;
        ts.moveToFirst();
        for (int x : tcount) {
          if (x > c) res.type = ts.getString(1);
          ts.moveToNext();
        }

        res.brand = brand;

      } catch (Exception e) {
        MainActivity.log_exception(mc, e, "HttpTask");
      }

      return res;
    }