Exemplo n.º 1
0
  @Override
  public TrackerConfig parse(Element el) {
    TrackerConfig trackerConfig = new TrackerConfig();
    TrackerHodler trackerHodler = new TrackerHodler();

    String type = ParseUtils.getAttr(el, "type");
    trackerConfig.setType(type);
    trackerHodler.setTrackPoint(TrackPoint.parse(type));

    String threshold = ParseUtils.getAttr(el, "threshold");
    trackerConfig.setThreshold(Long.valueOf(threshold));
    trackerHodler.setThreshold(Long.valueOf(threshold));

    try {
      String className = ParseUtils.getAttr(el, "class");
      trackerConfig.setClassName(className);
      Tracker tracker = (Tracker) Class.forName(className).newInstance();
      trackerHodler.setTracker(tracker);
    } catch (Exception e) {
      throw new ConfigurationException(e);
    }

    trackerHodler.regist();
    return trackerConfig;
  }
Exemplo n.º 2
0
  @Override
  public void onLinkClick(
      final String link,
      final String orig,
      final long account_id,
      final int type,
      final boolean sensitive) {
    if (activity == null) return;
    // UCD
    ProfilingUtil.profile(activity, account_id, "Click, " + link + ", " + type);

    if (activity == null) return;
    switch (type) {
      case TwidereLinkify.LINK_TYPE_MENTION:
        {
          openUserProfile(activity, account_id, -1, link);
          break;
        }
      case TwidereLinkify.LINK_TYPE_HASHTAG:
        {
          openTweetSearch(activity, account_id, link);
          break;
        }
      case TwidereLinkify.LINK_TYPE_LINK_WITH_IMAGE_EXTENSION:
        {
          openImage(activity, link, sensitive);
          break;
        }
      case TwidereLinkify.LINK_TYPE_LINK:
        {
          openLink(link);
          break;
        }
      case TwidereLinkify.LINK_TYPE_LIST:
        {
          final String[] mention_list = link.split("\\/");
          if (mention_list == null || mention_list.length != 2) {
            break;
          }
          openUserListDetails(activity, account_id, -1, -1, mention_list[0], mention_list[1]);
          break;
        }
      case TwidereLinkify.LINK_TYPE_CASHTAG:
        {
          openTweetSearch(activity, account_id, link);
          break;
        }
      case TwidereLinkify.LINK_TYPE_USER_ID:
        {
          openUserProfile(activity, account_id, ParseUtils.parseLong(link), null);
          break;
        }
      case TwidereLinkify.LINK_TYPE_STATUS:
        {
          openStatus(activity, account_id, ParseUtils.parseLong(link));
          break;
        }
    }
  }
 private void parseArgument(
     ValueProviderArg arg,
     JsonObject jsonData,
     Map<ValueProviderArg, Object> arguments,
     ParseValueType valueType) {
   String argName = ParseUtils.toCamelCase(arg.toString());
   if (!jsonData.has(argName)) {
     return;
   }
   Object value = ParseUtils.parse(argName, jsonData, valueType);
   arguments.put(arg, value);
 }
Exemplo n.º 4
0
  /**
   * 支持匹配的Service
   *
   * @param servicePattern
   * @param serviceName
   */
  static boolean isSerivceNameMatched(String servicePattern, String serviceName) {
    final int pip = servicePattern.indexOf('/');
    final int pi = serviceName.indexOf('/');
    if (pip != -1) { // pattern有group
      if (pi == -1) return false; // servicename无group

      String gp = servicePattern.substring(0, pip);
      servicePattern = servicePattern.substring(pip + 1);

      String g = serviceName.substring(0, pi);
      if (!gp.equals(g)) return false;
    }
    if (pi != -1) serviceName = serviceName.substring(pi + 1);

    final int vip = servicePattern.lastIndexOf(':');
    final int vi = serviceName.lastIndexOf(':');
    if (vip != -1) { // pattern有group
      if (vi == -1) return false;

      String vp = servicePattern.substring(vip + 1);
      servicePattern = servicePattern.substring(0, vip);

      String v = serviceName.substring(vi + 1);
      if (!vp.equals(v)) return false;
    }
    if (vi != -1) serviceName = serviceName.substring(0, vi);

    return ParseUtils.isMatchGlobPattern(servicePattern, serviceName);
  }
 @Override
 public void onSharedPreferenceChanged(
     final SharedPreferences sharedPreferences, final String key) {
   final long userId = ParseUtils.parseLong(key, -1);
   if (mListener != null) {
     mListener.onUserColorChanged(userId, sharedPreferences.getInt(key, 0));
   }
 }
  @Override
  public void loadData(InputStream inputStream, Node node, ElementArea area) throws IOException {

    BufferedImage image = ImageIO.read(inputStream);
    IntUnaryOperator mapper = parseMapper(node);
    Point position = ParseUtils.parsePosition(node);

    apply(area, image, mapper, supplier.get(), position.getX(), position.getY());
  }
Exemplo n.º 7
0
 public ASTNode toAST(Context ctx) throws LensException {
   String hql = toHQL();
   ParseDriver pd = new ParseDriver();
   ASTNode tree;
   try {
     log.info("HQL:{}", hql);
     tree = pd.parse(hql, ctx);
   } catch (ParseException e) {
     throw new LensException(e);
   }
   return ParseUtils.findRootNonNullToken(tree);
 }
Exemplo n.º 8
0
  static Map<String, String> appendMethodsToUrls(
      Map<String, String> serviceUrls, Map<String, Set<String>> url2Methods) {
    // 为URL上加上方法参数
    Map<String, String> results = new HashMap<String, String>();
    for (Map.Entry<String, Set<String>> entry : url2Methods.entrySet()) {
      String url = entry.getKey();
      String query = serviceUrls.get(url);

      Set<String> methodNames = entry.getValue();
      if (methodNames != null && methodNames.size() > 0) {
        String ms = StringUtils.join(methodNames.toArray(new String[0]), ParseUtils.METHOD_SPLIT);
        query = ParseUtils.replaceParameter(query, "methods", ms);
      }
      results.put(url, query);
    }
    return results;
  }
Exemplo n.º 9
0
  @Test
  @Category({P3, UNIT, FAST})
  @Description("Correct parsing spaces in comments")
  public void testSpaceComment() throws Exception {

    String name = "vjospacecomment.txt";
    String file = FileUtils.getResourceAsString(ParsingTests.class, name);
    VjoParser p = new VjoParser();
    p.addLib(LibManager.getInstance().getJavaPrimitiveLib());
    p.addLib(LibManager.getInstance().getJsNativeGlobalLib());
    p.addLib(LibManager.getInstance().getBrowserTypesLib());

    IJstParseController c = new JstParseController(p);

    IJstType type = c.parse(name, name, file).getType();
    ParseUtils.printTree(type);
  }
Exemplo n.º 10
0
  @Test
  @Category({P1, UNIT, FAST})
  @Description("Parses and validates property declared public and final")
  public void testPublicFinal() throws Exception {

    String name = "vjopublicfinal.txt";
    String file = FileUtils.getResourceAsString(ParsingTests.class, name);
    VjoParser p = new VjoParser();
    p.addLib(LibManager.getInstance().getJavaPrimitiveLib());
    p.addLib(LibManager.getInstance().getJsNativeGlobalLib());
    p.addLib(LibManager.getInstance().getBrowserTypesLib());

    IJstParseController c = new JstParseController(p);

    IJstType type = c.parse(name, name, file).getType();
    ParseUtils.printTree(type);
  }
Exemplo n.º 11
0
  /**
   * Are all of the "defining parameters" required to create an AU available?
   *
   * @return true If so
   */
  private boolean verifyDefiningParameters() {
    KeyedList parameters;
    int size;

    if (!isCreateCommand()) {
      return true;
    }

    parameters = ParseUtils.getDynamicFields(getXmlUtils(), getRequestDocument(), AP_MD_AUDEFINING);
    size = parameters.size();

    for (int i = 0; i < size; i++) {
      if (StringUtil.isNullString((String) parameters.getValue(i))) {
        return false;
      }
    }
    return true;
  }
Exemplo n.º 12
0
  public static boolean matchRoute(
      String consumerAddress,
      String consumerQueryUrl,
      Route route,
      Map<String, List<String>> clusters) {
    RouteRule rule = RouteRule.parseQuitely(route);
    Map<String, RouteRule.MatchPair> when =
        RouteRuleUtils.expandCondition(
            rule.getWhenCondition(), "consumer.cluster", "consumer.host", clusters);
    Map<String, String> consumerSample = ParseUtils.parseQuery("consumer.", consumerQueryUrl);

    final int index = consumerAddress.lastIndexOf(":");
    String consumerHost = null;
    if (index != -1) {
      consumerHost = consumerAddress.substring(0, index);
    } else {
      consumerHost = consumerAddress;
    }
    consumerSample.put("consumer.host", consumerHost);

    return RouteRuleUtils.isMatchCondition(when, consumerSample, consumerSample);
  }
Exemplo n.º 13
0
  // FIXME clusters和routes的合并,可以在clusters或routes变化时预先做
  // FIXME 从Util方法中分离出Cache的操作
  public static Map<String, String> route(
      String serviceName,
      String consumerAddress,
      String consumerQueryUrl,
      Map<String, String> serviceUrls,
      List<Route> routes,
      Map<String, List<String>> clusters,
      List<Route> routed) {
    if (serviceUrls == null || serviceUrls.size() == 0) {
      return serviceUrls;
    }
    if (routes == null || routes.isEmpty()) {
      return serviceUrls;
    }

    Map<Long, RouteRule> rules = route2RouteRule(routes, clusters);

    final Map<String, String> consumerSample = ParseUtils.parseQuery("consumer.", consumerQueryUrl);
    final int index = consumerAddress.lastIndexOf(":");
    final String consumerHost;
    if (consumerAddress != null && index != -1) {
      consumerHost = consumerAddress.substring(0, index);
    } else {
      consumerHost = consumerAddress;
    }
    consumerSample.put("consumer.host", consumerHost);

    Map<String, Map<String, String>> url2ProviderSample =
        new HashMap<String, Map<String, String>>();
    for (Map.Entry<String, String> entry : serviceUrls.entrySet()) {
      URI uri;
      try {
        uri = new URI(entry.getKey());
      } catch (URISyntaxException e) {
        throw new IllegalStateException(
            "fail to parse url(" + entry.getKey() + "):" + e.getMessage(), e);
      }
      Map<String, String> sample = new HashMap<String, String>();
      sample.putAll(ParseUtils.parseQuery("provider.", entry.getValue()));
      sample.put("provider.protocol", uri.getScheme());
      sample.put("provider.host", uri.getHost());
      sample.put("provider.port", String.valueOf(uri.getPort()));

      url2ProviderSample.put(entry.getKey(), sample);
    }

    Map<String, Set<String>> url2Methods = new HashMap<String, Set<String>>();

    // consumer可以通过consumer.methods Key指定需要的方法
    String methodsString = consumerSample.get("consumer.methods");
    String[] methods =
        methodsString == null || methodsString.length() == 0
            ? new String[] {Route.ALL_METHOD}
            : methodsString.split(ParseUtils.METHOD_SPLIT);
    for (String method : methods) {
      consumerSample.put("method", method);
      // NOTE:
      // <*方法>只配置 <no method key>
      // method1方法匹配 <no method key> 和 <method = method1>, 此时要把<no method key>的Route的优先级降低即可
      if (routes != null && routes.size() > 0) {
        for (Route route : routes) {
          if (isSerivceNameMatched(route.getService(), serviceName)) {
            RouteRule rule = rules.get(route.getId());
            // 当满足when条件时
            if (rule != null
                && RouteRuleUtils.isMatchCondition(
                    rule.getWhenCondition(), consumerSample, consumerSample)) {
              if (routed != null && !routed.contains(route)) {
                routed.add(route);
              }
              Map<String, RouteRule.MatchPair> then = rule.getThenCondition();
              if (then != null) {
                Map<String, Map<String, String>> tmp =
                    getUrlsMatchedCondition(then, consumerSample, url2ProviderSample);
                // 如果规则的结果是空,则该规则无效,使用所有Provider
                if (route.isForce() || !tmp.isEmpty()) {
                  url2ProviderSample = tmp;
                }
              }
            }
          }
        }
      }
      for (String url : url2ProviderSample.keySet()) {
        Set<String> mts = url2Methods.get(url);
        if (mts == null) {
          mts = new HashSet<String>();
          url2Methods.put(url, mts);
        }
        mts.add(method);
      }
    } // end of for methods

    return appendMethodsToUrls(serviceUrls, url2Methods);
  }
Exemplo n.º 14
0
 /** Reads geospatial latitude then a comma then longitude. */
 private static Point readLatCommaLonPoint(String value, SpatialContext ctx)
     throws InvalidShapeException {
   double[] latLon = ParseUtils.parseLatitudeLongitude(value);
   return ctx.makePoint(latLon[1], latLon[0]);
 }