Example usage for com.google.gson JsonObject getAsJsonArray

List of usage examples for com.google.gson JsonObject getAsJsonArray

Introduction

In this page you can find the example usage for com.google.gson JsonObject getAsJsonArray.

Prototype

public JsonArray getAsJsonArray(String memberName) 

Source Link

Document

Convenience method to get the specified member as a JsonArray.

Usage

From source file:hu.bme.mit.incqueryd.engine.test.util.TupleDeserializer.java

License:Open Source License

@Override
public Tuple deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    JsonObject jsonObject = json.getAsJsonObject();
    JsonArray array = jsonObject.getAsJsonArray("tuple");

    ArrayList<Object> list = new ArrayList<Object>();

    for (Object object : array) {
        // checking if the object is a primitive
        if (object instanceof JsonPrimitive) {
            JsonPrimitive primitive = (JsonPrimitive) object;

            // if it is a number, get it as a long
            if (primitive.isNumber()) {
                long i = primitive.getAsLong();
                list.add(i);//from ww w. j  a  va  2 s  . c om
            }
        }
    }

    Tuple tuple = new Tuple(list.toArray());
    return tuple;
}

From source file:ideal.showcase.coach.marshallers.marshaller.java

License:Open Source License

public @Nullable datastore_state unmarshal_state(json_data the_data) {
    if (the_data == null) {
        return null;
    }//  ww w.  ja  v a 2 s .  c  om

    JsonObject obj = the_data.the_object;

    String source_version = null;
    if (obj.has(SOURCE_VERSION.s())) {
        source_version = obj.getAsJsonPrimitive(SOURCE_VERSION.s()).getAsString();
    }

    string version_id;
    if (obj.has(VERSION_ID.s())) {
        version_id = new base_string(obj.getAsJsonPrimitive(VERSION_ID.s()).getAsString());
    } else {
        // Compatibility with old data format
        version_id = new base_string(the_schema.version, "/null");
    }

    datastore_state world = the_schema.new_value(new base_string(source_version), version_id);

    JsonArray values = obj.getAsJsonArray(DATA);

    // We need to do this in two passes to handle forward references correctly.
    // First pass: create data values with IDs only
    for (JsonElement val : values) {
        if (val instanceof JsonObject) {
            JsonObject val_object = (JsonObject) val;
            String val_type = val_object.get(DATA_TYPE).getAsString();
            data_type dt = the_schema.lookup_data_type(new base_string(val_type));
            if (dt == null) {
                continue;
            }
            data_value dv = dt.new_value(world);
            string_value id = from_json_string(val_object.get(DATA_ID));
            dv.put_var(the_schema.data_id_field(), id);
            world.do_add_data(dv);
        }
    }

    // Second pass: parse data values
    for (JsonElement val : values) {
        if (val instanceof JsonObject) {
            JsonObject val_object = (JsonObject) val;
            string_value id = from_json_string(val_object.get(DATA_ID));
            data_value dv = world.get_data_by_id(id.unwrap());
            if (dv != null) {
                read_from_json(dv, val_object, world);
            }
        }
    }

    // put_field()s might have reset the version_id, so we set it again.
    world.set_version_id(version_id);

    return world;
}

From source file:im.bci.jnuit.lwjgl.assets.AssetsLoader.java

License:Open Source License

private NanimationCollection loadJsonNanim(String name) {
    NanimationCollection nanim = new NanimationCollection();
    try {//from ww  w  . ja  v  a2  s .  c  o m
        InputStream is = vfs.open(name);
        try {
            InputStreamReader reader = new InputStreamReader(is);
            String nanimParentDir;
            final int lastIndexOfSlash = name.lastIndexOf("/");
            if (lastIndexOfSlash < 0) {
                nanimParentDir = "";
            } else {
                nanimParentDir = name.substring(0, name.lastIndexOf("/") + 1);
            }
            JsonObject json = new Gson().fromJson(reader, JsonObject.class);
            for (JsonElement jsonAnimationElement : json.getAsJsonArray("animations")) {
                JsonObject jsonAnimation = jsonAnimationElement.getAsJsonObject();
                Nanimation animation = new Nanimation(jsonAnimation.get("name").getAsString());
                for (JsonElement jsonFrameElement : jsonAnimation.getAsJsonArray("frames")) {
                    JsonObject jsonFrame = jsonFrameElement.getAsJsonObject();
                    final String imageFilename = nanimParentDir + jsonFrame.get("image").getAsString();
                    Texture texture = this.loadTexture(imageFilename);
                    NanimationImage image = new NanimationImage(texture);
                    animation.addFrame(image, jsonFrame.get("duration").getAsInt(),
                            jsonFrame.get("u1").getAsFloat(), jsonFrame.get("v1").getAsFloat(),
                            jsonFrame.get("u2").getAsFloat(), jsonFrame.get("v2").getAsFloat());
                }
                nanim.addAnimation(animation);
            }
        } finally {
            is.close();
        }
    } catch (IOException e) {
        throw new RuntimeException("Cannot load animation " + name, e);
    }
    return nanim;
}

From source file:im.delight.android.ddp.Meteor.java

License:Apache License

/**
 * Called whenever a JSON payload has been received from the websocket
 *
 * @param payload the JSON payload to process
 */// w  ww  .  j  a v  a2 s . c o m
private void handleMessage(final String payload) {
    final JsonObject data = mGson.fromJson(payload, JsonObject.class);
    if (data != null) {
        if (data.has(Protocol.Field.MESSAGE)) {
            final String message = data.get(Protocol.Field.MESSAGE).getAsString();

            if (message.equals(Protocol.Message.CONNECTED)) {
                if (data.has(Protocol.Field.SESSION)) {
                    mSessionID = data.get(Protocol.Field.SESSION).getAsString();
                }

                // initialize the new session
                initSession();
            } else if (message.equals(Protocol.Message.FAILED)) {
                if (data.has(Protocol.Field.VERSION)) {
                    // the server wants to use a different protocol version
                    final String desiredVersion = data.get(Protocol.Field.VERSION).getAsString();

                    // if the protocol version that was requested by the server is supported by this client
                    if (isVersionSupported(desiredVersion)) {
                        // remember which version has been requested
                        mDdpVersion = desiredVersion;

                        // the server should be closing the connection now and we will re-connect afterwards
                    } else {
                        throw new RuntimeException("Protocol version not supported: " + desiredVersion);
                    }
                }
            } else if (message.equals(Protocol.Message.PING)) {
                final String id;

                if (data.has(Protocol.Field.ID)) {
                    id = data.get(Protocol.Field.ID).getAsString();
                } else {
                    id = null;
                }

                sendPong(id);
            } else if (message.equals(Protocol.Message.ADDED)
                    || message.equals(Protocol.Message.ADDED_BEFORE)) {
                final String documentID;

                if (data.has(Protocol.Field.ID)) {
                    documentID = data.get(Protocol.Field.ID).getAsString();
                } else {
                    documentID = null;
                }

                final String collectionName;

                if (data.has(Protocol.Field.COLLECTION)) {
                    collectionName = data.get(Protocol.Field.COLLECTION).getAsString();
                } else {
                    collectionName = null;
                }

                final String newValuesJson;

                if (data.has(Protocol.Field.FIELDS)) {
                    newValuesJson = data.get(Protocol.Field.FIELDS).toString();
                } else {
                    newValuesJson = null;
                }

                if (mDataStore != null) {
                    mDataStore.onDataAdded(collectionName, documentID, fromJson(newValuesJson, Fields.class));
                }

                mCallbackProxy.onDataAdded(collectionName, documentID, newValuesJson);
            } else if (message.equals(Protocol.Message.CHANGED)) {
                final String documentID;

                if (data.has(Protocol.Field.ID)) {
                    documentID = data.get(Protocol.Field.ID).getAsString();
                } else {
                    documentID = null;
                }

                final String collectionName;

                if (data.has(Protocol.Field.COLLECTION)) {
                    collectionName = data.get(Protocol.Field.COLLECTION).getAsString();
                } else {
                    collectionName = null;
                }

                final String updatedValuesJson;

                if (data.has(Protocol.Field.FIELDS)) {
                    updatedValuesJson = data.get(Protocol.Field.FIELDS).toString();
                } else {
                    updatedValuesJson = null;
                }

                final String removedValuesJson;

                if (data.has(Protocol.Field.CLEARED)) {
                    removedValuesJson = data.get(Protocol.Field.CLEARED).toString();
                } else {
                    removedValuesJson = null;
                }

                if (mDataStore != null) {
                    mDataStore.onDataChanged(collectionName, documentID,
                            fromJson(updatedValuesJson, Fields.class),
                            fromJson(removedValuesJson, String[].class));
                }

                mCallbackProxy.onDataChanged(collectionName, documentID, updatedValuesJson, removedValuesJson);
            } else if (message.equals(Protocol.Message.REMOVED)) {
                final String documentID;

                if (data.has(Protocol.Field.ID)) {
                    documentID = data.get(Protocol.Field.ID).getAsString();
                } else {
                    documentID = null;
                }

                final String collectionName;

                if (data.has(Protocol.Field.COLLECTION)) {
                    collectionName = data.get(Protocol.Field.COLLECTION).getAsString();
                } else {
                    collectionName = null;
                }

                if (mDataStore != null) {
                    mDataStore.onDataRemoved(collectionName, documentID);
                }

                mCallbackProxy.onDataRemoved(collectionName, documentID);
            } else if (message.equals(Protocol.Message.RESULT)) {
                // check if we have to process any result data internally
                if (data.has(Protocol.Field.RESULT)) {
                    final JsonObject resultData = data.getAsJsonObject(Protocol.Field.RESULT);

                    // if the result is from a previous login attempt
                    if (isLoginResult(resultData)) {
                        // extract the login token for subsequent automatic re-login
                        final String loginToken = resultData.get(Protocol.Field.TOKEN).getAsString();
                        saveLoginToken(loginToken);

                        // extract the user's ID
                        mLoggedInUserId = resultData.get(Protocol.Field.ID).getAsString();
                    }
                }

                final String id;

                if (data.has(Protocol.Field.ID)) {
                    id = data.get(Protocol.Field.ID).getAsString();
                } else {
                    id = null;
                }

                final Listener listener = mListeners.get(id);

                if (listener instanceof ResultListener) {
                    mListeners.remove(id);

                    final String result;

                    if (data.has(Protocol.Field.RESULT)) {
                        result = data.get(Protocol.Field.RESULT).toString();
                    } else {
                        result = null;
                    }

                    if (data.has(Protocol.Field.ERROR)) {
                        final Protocol.Error error = Protocol.Error
                                .fromJson(data.getAsJsonObject(Protocol.Field.ERROR));
                        mCallbackProxy.forResultListener((ResultListener) listener).onError(error.getError(),
                                error.getReason(), error.getDetails());
                    } else {
                        mCallbackProxy.forResultListener((ResultListener) listener).onSuccess(result);
                    }
                }
            } else if (message.equals(Protocol.Message.READY)) {
                if (data.has(Protocol.Field.SUBS)) {
                    final JsonArray subs = data.getAsJsonArray(Protocol.Field.SUBS);
                    for (JsonElement sub : subs) {
                        String subscriptionId = sub.getAsString();
                        final Listener listener = mListeners.get(subscriptionId);
                        if (listener instanceof SubscribeListener) {
                            mListeners.remove(subscriptionId);

                            mCallbackProxy.forSubscribeListener((SubscribeListener) listener).onSuccess();
                        }
                    }
                }
            } else if (message.equals(Protocol.Message.NOSUB)) {
                final String subscriptionId;

                if (data.has(Protocol.Field.ID)) {
                    subscriptionId = data.get(Protocol.Field.ID).getAsString();
                } else {
                    subscriptionId = null;
                }

                final Listener listener = mListeners.get(subscriptionId);

                if (listener instanceof SubscribeListener) {
                    mListeners.remove(subscriptionId);

                    if (data.has(Protocol.Field.ERROR)) {
                        final Protocol.Error error = Protocol.Error
                                .fromJson(data.getAsJsonObject(Protocol.Field.ERROR));
                        mCallbackProxy.forSubscribeListener((SubscribeListener) listener)
                                .onError(error.getError(), error.getReason(), error.getDetails());
                    } else {
                        mCallbackProxy.forSubscribeListener((SubscribeListener) listener).onError(null, null,
                                null);
                    }
                } else if (listener instanceof UnsubscribeListener) {
                    mListeners.remove(subscriptionId);

                    mCallbackProxy.forUnsubscribeListener((UnsubscribeListener) listener).onSuccess();
                }
            }
        }
    }
}

From source file:Implement.DAO.TripperDAOImpl.java

@Override
public String paywithPaypal(AccountSession account, int packageID, int numberOfChilds, int numberOfAdults,
        String selectedDate, HttpServletRequest request, String currency, String amount, String description,
        List<Item> item) throws PayPalRESTException {

    Map<String, String> sdkConfig = new HashMap<String, String>();
    sdkConfig.put("mode", "sandbox");

    String accessToken = new OAuthTokenCredential(
            "AbHiUaWBpZ2nL7iWNJDkyUqW7pQ1dOLmadliqd_lS9YROi63M1UP3_qV-MWzCkU9VP1kaHiFCgeehfL3",
            "EArWWwOuT7qMSftpOs0yZwU3x-i-eCqyrstn7D-WvH5nWc-IQKnEeyHCCScko25pMopZOsZ3yeCLuUpZ", sdkConfig)
                    .getAccessToken();//w  w  w.  j a va 2s  .co  m
    APIContext apiContext = new APIContext(accessToken);
    apiContext.setConfigurationMap(sdkConfig);

    Amount amount1 = new Amount();
    amount1.setCurrency(currency);
    amount1.setTotal(amount);

    ItemList list = new ItemList();
    list.setItems(item);
    Transaction transaction = new Transaction();
    transaction.setDescription(description);
    transaction.setAmount(amount1);
    transaction.setItemList(list);

    List<Transaction> transactions = new ArrayList<>();
    transactions.add(transaction);

    Payer payer = new Payer();
    payer.setPaymentMethod("paypal");

    Payment payment = new Payment();
    payment.setIntent("sale");
    payment.setPayer(payer);
    payment.setTransactions(transactions);
    RedirectUrls redirectUrls = new RedirectUrls();
    String contextPath = request.getContextPath();
    String baseUrl;
    if (contextPath != null || contextPath.isEmpty() || !contextPath.equals("")) {
        baseUrl = String.format("%s:/%s:%d" + contextPath, request.getScheme(), request.getServerName(),
                request.getServerPort());
    } else {
        baseUrl = String.format("%s:/%s:%d", request.getScheme(), request.getServerName(),
                request.getServerPort());
    }
    String info = "accountID=" + account.getId() + "&selDate=" + selectedDate + "&packageID=" + packageID
            + "&numChild=" + numberOfChilds + "&numAdult=" + numberOfAdults;
    String failInfo = "selDate=" + selectedDate + "&packageID=" + packageID + "&numChild=" + numberOfChilds
            + "&numAdult=" + numberOfAdults;
    redirectUrls.setCancelUrl(baseUrl + "/Tripper/payPaypalFail?" + failInfo);
    redirectUrls.setReturnUrl(baseUrl + "/Tripper/payPaypalSuccess?" + info);
    payment.setRedirectUrls(redirectUrls);

    Payment createdPayment = payment.create(apiContext);
    Gson gson = new GsonBuilder().disableHtmlEscaping().create();
    String json = gson.toJson(createdPayment);
    JsonParser parser = new JsonParser();
    JsonObject jObject = parser.parse(json).getAsJsonObject();
    JsonArray jArray = jObject.getAsJsonArray("links");
    return jArray.get(1).getAsJsonObject().get("href").getAsString();

}

From source file:Implement.Service.ProviderServiceImpl.java

@Override
public boolean insertActivityForm(String dataJson, int providerID) {
    // get data from json string
    JsonObject object = gson.fromJson(dataJson, JsonObject.class);
    int packageID = object.get("packageID").getAsInt();
    //        String activites = object.get("activities").getAsString();

    // delete old data and update groupID, tripID
    packageDAO.insertActivityFormToTempPackage(packageID, providerID);
    String otherSubCategoryContent = "";
    try {/*from  w  w w . ja v  a2  s  . c om*/
        otherSubCategoryContent = object.get("subCategoryContent").getAsString();
    } catch (Exception e) {
    }
    int subCategoryID = 0;
    try {
        subCategoryID = object.get("subCategoryID").getAsInt();
    } catch (Exception e) {
    }

    System.out.println("subCategoryID" + subCategoryID);
    // get list suitability json
    JsonArray suitabilityJson = object.getAsJsonArray("suitability");
    // insert list suitability
    for (JsonElement suitabilityElm : suitabilityJson) {
        // convert to object
        JsonObject suitabilityObj = suitabilityElm.getAsJsonObject();
        boolean selected = suitabilityObj.get("selected").getAsBoolean();
        if (selected) { // check this suitbaility is selected or not
            // if is selected then insert
            int suitablityID = suitabilityObj.get("suitabilityID").getAsInt();
            String content = suitabilityObj.get("content").getAsString();
            temporarySuitabilityClassifierDAO.insertTemporarySuitabilityClassifier(packageID, suitablityID,
                    content, providerID);
        }
    }

    //Get Package Color,Target Country,Feeling of Package
    int packageColor = object.get("packageColor").getAsInt();
    int targetCountryID = object.get("targetCountryID").getAsInt();
    int adventureLevel = object.get("adventureLevel").getAsInt();
    int challengeLevel = object.get("challengeLevel").getAsInt();
    int friendshipLevel = object.get("friendshipLevel").getAsInt();
    int happinessLevel = object.get("happinessLevel").getAsInt();
    int healthinessLevel = object.get("healthinessLevel").getAsInt();
    int knowledgeLevel = object.get("knowledgeLevel").getAsInt();
    int peacefulnessLevel = object.get("peacefulnessLevel").getAsInt();
    int romanceLevel = object.get("romanceLevel").getAsInt();
    int sophisticationLevel = object.get("sophisticationLevel").getAsInt();
    int unexpectedLevel = object.get("unexpectedLevel").getAsInt();
    packageDAO.saveAdditionalCategory(packageID, packageColor, targetCountryID, adventureLevel, challengeLevel,
            friendshipLevel, happinessLevel, healthinessLevel, knowledgeLevel, peacefulnessLevel, romanceLevel,
            sophisticationLevel, unexpectedLevel, subCategoryID, otherSubCategoryContent, providerID);
    return true;
}

From source file:Implement.Service.ProviderServiceImpl.java

@Override
public boolean editActivityForm(String dataJson, int providerID) {

    // get data from json string
    JsonObject object = gson.fromJson(dataJson, JsonObject.class);
    int packageID = object.get("packageID").getAsInt();
    //        String activites = object.get("activities").getAsString();
    int tripID = object.get("tripID").getAsInt();
    int groupID = object.get("groupID").getAsInt();
    // insert data
    JsonArray activitiesJson = object.getAsJsonArray("activities");
    packageDAO.updateActivity(packageID, "", groupID, tripID, providerID);
    //------------------------------
    String subCategoryContent = "";
    int categoryID = 0;
    if (object.get("subCategoryContent") != null
            && !object.get("subCategoryContent").getAsString().equals("")) {
        subCategoryContent = object.get("subCategoryContent").getAsString();
        categoryID = object.get("subCategoryID").getAsInt();
    }//from  ww  w.  ja va  2 s .c  o m

    for (JsonElement activityJson : activitiesJson) { // get json activities array
        JsonObject activityObj = activityJson.getAsJsonObject(); // convert to object
        int activityID = activityObj.get("activityID").getAsInt();
        String content = "";
        try {
            content = activityObj.get("content").getAsString();
        } catch (Exception e) {
            content = "";
        }

        classifierDAO.updateClassifier(packageID, activityID, content, categoryID, subCategoryContent,
                providerID);
    }

    // get list suitability json
    JsonArray suitabilityJson = object.getAsJsonArray("suitability");
    // insert list suitability
    int delete = 1;
    for (JsonElement suitabilityElm : suitabilityJson) {
        // convert to object
        JsonObject suitabilityObj = suitabilityElm.getAsJsonObject();
        boolean selected = suitabilityObj.get("selected").getAsBoolean();
        if (selected) { // check this suitbaility is selected or not
            // if is selected then insert
            int suitabilityID = suitabilityObj.get("suitabilityID").getAsInt();
            System.out.println(suitabilityID);
            String content = suitabilityObj.get("content").getAsString();
            suitabilityClassifierDAO.updateSuitabilityClassifier(packageID, suitabilityID, content, delete,
                    providerID);
        }
        delete = 0;
    }
    //Get Package Color,Target Country,Feeling of Package
    int packageColor = object.get("packageColor").getAsInt();
    int targetCountryID = object.get("targetCountryID").getAsInt();
    int adventureLevel = object.get("adventureLevel").getAsInt();
    int challengeLevel = object.get("challengeLevel").getAsInt();
    int friendshipLevel = object.get("friendshipLevel").getAsInt();
    int happinessLevel = object.get("happinessLevel").getAsInt();
    int healthinessLevel = object.get("healthinessLevel").getAsInt();
    int knowledgeLevel = object.get("knowledgeLevel").getAsInt();
    int peacefulnessLevel = object.get("peacefulnessLevel").getAsInt();
    int romanceLevel = object.get("romanceLevel").getAsInt();
    int sophisticationLevel = object.get("sophisticationLevel").getAsInt();
    int unexpectedLevel = object.get("unexpectedLevel").getAsInt();
    packageDAO.editAdditionalCategory(packageID, packageColor, targetCountryID, adventureLevel, challengeLevel,
            friendshipLevel, happinessLevel, healthinessLevel, knowledgeLevel, peacefulnessLevel, romanceLevel,
            sophisticationLevel, unexpectedLevel, providerID);

    return true;
}

From source file:info.semanticsoftware.sempub2016.LocationInferer.java

License:Open Source License

private String dbpediaLookup(final String university) {
    try {//from  ww w . j  a  v a2  s .  co m
        //System.out.println("----- dbpediaLookup " + university);
        final String endpointQuery = "http://lookup.dbpedia.org/api/search/KeywordSearch?QueryClass=University&MaxHits=1&QueryString="
                + university;
        //System.out.println("----- query: " + endpointQuery);
        final URL url = new URL(endpointQuery);
        final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/json");
        conn.setRequestProperty("content-type", "application/x-www-form-urlencoded");
        conn.setDoOutput(true);
        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed: Http error code " + conn.getResponseCode());
        }
        BufferedReader in = new BufferedReader(
                new InputStreamReader(conn.getInputStream(), Charset.forName("UTF-8")));
        String s = null;
        StringBuffer sb = new StringBuffer();
        while ((s = in.readLine()) != null) {
            sb.append(s);
        }
        //System.out.println(sb.toString());
        JsonParser parser = new JsonParser();
        JsonObject object = parser.parse(sb.toString()).getAsJsonObject();
        JsonArray arr = object.getAsJsonArray("results");
        // get(0) throws java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 when nothing is found
        String uri = arr.get(0).getAsJsonObject().getAsJsonPrimitive("uri").getAsString();
        return uri;
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    } catch (IOException e2) {
        e2.printStackTrace();
    } catch (Exception e3) {
        e3.printStackTrace();
    }
    return null;
}

From source file:instagramcontentcatcher.ContentCatcher.java

public void getCaptionText() {
    try {/* w  ww .j av  a2 s.com*/
        WriterToFile.openFile();
        URL insta = new URL("https://www.instagram.com/trip_aum_shanti/media/");
        if (!max_id.isEmpty()) {
            insta = new URL("https://www.instagram.com/trip_aum_shanti/media/?max_id=" + max_id);
        }
        HttpURLConnection request = (HttpURLConnection) insta.openConnection();
        request.connect();
        JsonParser jp = new JsonParser();
        JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
        JsonObject rootobj = root.getAsJsonObject();
        JsonArray array = rootobj.getAsJsonArray("items");
        String more_available = rootobj.get("more_available").getAsString();
        for (int i = 0; i < array.size(); i++) {
            JsonObject item_broj = (JsonObject) array.get(i);
            JsonObject caption = (JsonObject) item_broj.getAsJsonObject("caption");
            String caption_text = caption.get("text").getAsString();
            if (i == array.size() - 1) {
                max_id = item_broj.get("id").getAsString();
            }
            WriterToFile.writeContent(caption_text);
        }
        if (more_available.equals("true")) {
            getCaptionText();
        }
    } catch (IOException ex) {
        Logger.getLogger(ContentCatcher.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        WriterToFile.closeFile();
    }
}

From source file:inventory.StockInOUTReport.java

private void setData() throws IOException {
    lb.addGlassPane(this);
    JsonObject call = inventoryAPI.GetStockInOutReport(lb.ConvertDateFormetForDB(jtxtFromDate.getText()),
            lb.ConvertDateFormetForDB(jtxtToDate.getText())).execute().body();

    lb.removeGlassPane(StockInOUTReport.this);
    if (call != null) {
        System.out.println(call.toString());
        if (call.get("result").getAsInt() == 1) {
            JsonArray header = call.getAsJsonArray("data");
            dtm.setRowCount(0);//from w w w .  j  a  v a2  s  . c o m
            for (int i = 0; i < header.size(); i++) {
                Vector row = new Vector();
                row.add(header.get(i).getAsJsonObject().get("ref_no").getAsString());
                row.add(header.get(i).getAsJsonObject().get("inv_no").getAsString());
                row.add(lb.ConvertDateFormetForDisplay(
                        header.get(i).getAsJsonObject().get("v_date").getAsString()));
                row.add(header.get(i).getAsJsonObject().get("TAG_NO").getAsString());
                row.add(header.get(i).getAsJsonObject().get("SR_NAME").getAsString());
                row.add(Constants.BRANCH.get(header.get(i).getAsJsonObject().get("from_loc").getAsInt() - 1)
                        .getBranch_name());
                row.add(Constants.BRANCH.get(header.get(i).getAsJsonObject().get("to_loc").getAsInt() - 1)
                        .getBranch_name());
                row.add(header.get(i).getAsJsonObject().get("approve_by").getAsString());
                row.add(header.get(i).getAsJsonObject().get("approve_time").getAsString());
                dtm.addRow(row);
            }
            lb.setColumnSizeForTable(jTable1, jPanel2.getWidth());
        } else {
            lb.showMessageDailog(call.get("Cause").getAsString());
        }
    }
}