Package org.primefaces.json

Examples of org.primefaces.json.JSONObject


      for(String paramName : params.keySet()) {
       
        writer.write("<callbackParam>");
        try {
          Object paramValue = params.get(paramName);
          String json = isBean(paramValue) ? "{\"" + paramName + "\":" + new JSONObject(paramValue).toString() + "}": new JSONObject().put(paramName, paramValue).toString();
          writer.write(json);
        } catch (JSONException e) {
          logger.log(Level.SEVERE, "Error in serializing callback parameter \"{0}\"", paramName);
          throw new FacesException(e.getMessage());
        }
View Full Code Here


    Trip newTrip = new Trip(mockTripCreator,departure,4,waypoint, "");
    Trip tripWithPoint = newTrip;
    List<Point> points = new ArrayList<Point>();
    points.add(new Point(0, 0.0, 0.0, 0, newTrip.getId()));
    tripWithPoint.setPoints(points);
    JSONObject jsonObject = null;
   
   
    // Setup Mocks:
    EasyMock.expect(mockJsfUtil.getLoggedInUser()).andReturn(mockTripCreator);
    mockBegin();
View Full Code Here

    Trip newTrip = new Trip(mockTripCreator,departure,4,waypoint, "");
    Trip tripWithPoint = newTrip;
    List<Point> points = new ArrayList<Point>();
    points.add(new Point(0, 0.0, 0.0, 0, newTrip.getId()));
    tripWithPoint.setPoints(points);
    JSONObject jsonObject = null;
   
   
    // Setup Mocks:
    EasyMock.expect(mockJsfUtil.getLoggedInUser()).andReturn(mockTripCreator);
    mockBegin();
View Full Code Here

    Trip newTrip = new Trip(mockTripCreator,departure,4,waypoint, "");
    Trip tripWithPoint = newTrip;
    List<Point> points = new ArrayList<Point>();
    points.add(new Point(0, 0.0, 0.0, 0, newTrip.getId()));
    tripWithPoint.setPoints(points);
    JSONObject jsonObject = null;
   
   
    // Setup Mocks:
    EasyMock.expect(mockJsfUtil.getLoggedInUser()).andReturn(mockTripCreator);
    mockBegin();
View Full Code Here

    Trip newTrip = new Trip(mockTripCreator,departure,4,waypoint, "");
    Trip tripWithPoint = newTrip;
    List<Point> points = new ArrayList<Point>();
    points.add(new Point(0, 0.0, 0.0, 0, newTrip.getId()));
    tripWithPoint.setPoints(points);
    JSONObject jsonObject = null;
   
   
    // Setup Mocks:
    EasyMock.expect(mockJsfUtil.getLoggedInUser()).andReturn(mockTripCreator);
    mockBegin();
View Full Code Here

    Trip newTrip = new Trip(mockTripCreator,departure,4,waypoint, "");
    Trip tripWithPoint = newTrip;
    List<Point> points = new ArrayList<Point>();
    points.add(new Point(0, 0.0, 0.0, 0, newTrip.getId()));
    tripWithPoint.setPoints(points);
    JSONObject jsonObject = null;
   
   
    // Setup Mocks:
    EasyMock.expect(mockJsfUtil.getLoggedInUser()).andReturn(mockTripCreator);
    mockBegin();
View Full Code Here

   * @throws IOException
   */
  @Override
  public JSONObject getJsonObj(Trip trip, List<Waypoint> stops)
      throws IOException {
    JSONObject jsonObject = null;
    try {
      // A waypoint contains to and from resulting in the possibility that
      // a location is mentioned multiple times.
      List<String> filtered = new LinkedList<String>();
      filtered.add(trip.getWaypoint().getFromLocation().getCity()
          .replaceAll("\\W+", "+"));
      filtered.add(trip.getWaypoint().getToLocation().getCity()
          .replaceAll("\\W+", "+"));

      for (Waypoint w : stops) {
        String from = w.getFromLocation().getCity()
            .replaceAll("\\W+", "+");
        if (!filtered.contains(from))
          filtered.add(from);
        String to = w.getToLocation().getCity().replaceAll("\\W+", "+");
        if (!filtered.contains(to))
          filtered.add(to);
      }

      StringBuilder urlBuilder = new StringBuilder();
      urlBuilder
          .append("http://maps.google.com/maps/api/directions/json");
      urlBuilder.append("?origin=").append(filtered.get(0));
      urlBuilder.append("&destination=").append(filtered.get(1));

      if (filtered.size() > 2) { // first two entrys are the
                    // trips-Endpoints
        urlBuilder.append("&waypoints=");
        for (int i = 2; i < filtered.size() - 1; i++)
          // the last without '|'
          urlBuilder.append(filtered.get(i)).append("|");
        urlBuilder.append(filtered.get(filtered.size() - 1));
      }

      urlBuilder.append("&sensor=false");

      BufferedReader in = new BufferedReader(new InputStreamReader(
          new URL(urlBuilder.toString()).openStream()));
      StringBuilder answerBuilder = new StringBuilder();
      String inputLine;

      while ((inputLine = in.readLine()) != null)
        answerBuilder.append(inputLine);
      in.close();

      jsonObject = new JSONObject(answerBuilder.toString());
    } catch (JSONException e) {
      logger.error("Problem with initializing JSONObject", e);
    }
    return jsonObject;
  }
View Full Code Here

      JSONArray routes = json.getJSONArray("routes");
      // routes contains// routes contains possible routes; use the
      // first one?
      if (routes.length() > 0) {
        // a route contains legs from start to endpoint
        JSONObject route = routes.getJSONObject(0);

        JSONArray legs = route.getJSONArray("legs");
        int order = 1;
        for (int l = 0; l < legs.length(); l++) {
          // a leg contains steps between waypoints
          JSONObject leg = legs.getJSONObject(l);
          JSONArray steps = leg.getJSONArray("steps");

          if (steps.length() < 0)
            continue;

          for (int s = 0; s < steps.length(); s++) {
            JSONObject step = steps.getJSONObject(s);
            JSONObject poly = step.getJSONObject("polyline");
            if (!points.isEmpty())
              order = points.get(points.size() - 1).getOrder();

            List<Point> polyline = decode(poly.getString("points"),
                trip.getId(), order);

            int avgDuration = Math.round(step.getJSONObject(
                "duration").getInt("value")
                / (float)polyline.size());
View Full Code Here

          getConnection()));
      for (int i = stops.size() - 1; i >= 0; i--)
        if (!stops.get(i).getUser().equals(newTrip.getUser()))
          stops.remove(i); // use only drivers assignet waypoints

      JSONObject jsonObject = googleUtil.getJsonObj(newTrip, stops);
      newTrip = googleUtil.loadGoogleData(newTrip, jsonObject);
      getPointDAO().insertPoints(newTrip.getPoints(), getConnection());
      commit();
    } catch (JSONException je) {
      logger.error("JSONException: failed to load mapdata: " + newTrip);
View Full Code Here

        try {
            StringBuilder jsonBuilder = new StringBuilder();
            jsonBuilder.append("{");

            if(isBean(data)) {
                jsonBuilder.append("\"").append("data").append("\":").append(new JSONObject(data).toString());
            }
            else {
                String json = new JSONObject().put("data", data).toString();

                jsonBuilder.append(json.substring(1, json.length() - 1));
            }

            jsonBuilder.append("}");
View Full Code Here

TOP

Related Classes of org.primefaces.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.