Example usage for javax.json.stream JsonParser next

List of usage examples for javax.json.stream JsonParser next

Introduction

In this page you can find the example usage for javax.json.stream JsonParser next.

Prototype

Event next();

Source Link

Document

Returns the event for the next parsing state.

Usage

From source file:com.seniorproject.semanticweb.services.WebServices.java

public String generateSparqlForSelectValue(String json, String category) {
    JsonParser parser = Json.createParser(new StringReader(json));
    Event event = parser.next();// START_OBJECT
    String iri = getIRI(category);
    String queryString = "SELECT ?subject ?label WHERE { ?subject rdf:type " + iri + " . ";
    while ((event = parser.next()) != Event.END_OBJECT) {
        if (parser.getString().substring(0, 2).equalsIgnoreCase("is")) {
            String[] parts = parser.getString().split(" ");
            event = parser.next();/* ww w . j  a  v a  2s.  c  om*/
            String value = parser.getString();
            value = convertToNoPrefix(value);
            queryString += value + " " + parts[1] + " ?subject .";
        } else {
            queryString += "?subject " + parser.getString() + " ";
            event = parser.next();
            String value = parser.getString();
            value = convertToNoPrefix(value);
            queryString += value + ". ";
        }
    }
    queryString += "?subject rdfs:label ?label. }";
    return queryString;
}

From source file:com.products.ProductResource.java

@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)// ww  w.ja v a2  s.co  m
public String putProduct(@PathParam("id") int id, String str) throws SQLException {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> productMap = new LinkedHashMap<>();
    String key = "";
    String val = "";

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            key = parser.getString();
            break;
        case VALUE_STRING:
            val = parser.getString();
            productMap.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            productMap.put(key, val);
            break;
        default:
            break;
        }
    }
    if (co == null) {
        return "Not connected";
    } else {
        String query = "UPDATE product SET  name = ?, description = ?, quantity = ? WHERE product_id =?";
        PreparedStatement stmt = co.prepareStatement(query);
        stmt.setString(1, productMap.get("name"));
        stmt.setString(2, productMap.get("description"));
        stmt.setInt(3, Integer.parseInt(productMap.get("quantity")));
        stmt.setInt(4, id);
        stmt.executeUpdate();
        return "row has been updated into the database";
    }

}

From source file:com.Assignment4.Prod.java

@POST
@Consumes(MediaType.APPLICATION_JSON)/*from  ww w .j av  a  2s.c om*/
@Produces(MediaType.TEXT_PLAIN)
public String postProduct(String str) throws SQLException {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> pMap = new LinkedHashMap<String, String>();
    String key = "";
    String val = "";

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            key = parser.getString();
            break;
        case VALUE_STRING:
            val = parser.getString();
            pMap.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            pMap.put(key, val);
            break;
        default:
            break;
        }
    }
    if (connect == null) {
        return "Not connected";
    } else {
        String query = "INSERT INTO product (product_id,name,description,quantity) VALUES (?,?,?,?)";
        PreparedStatement prepstmt = connect.prepareStatement(query);
        prepstmt.setInt(1, Integer.parseInt(pMap.get("product_id")));
        prepstmt.setString(2, pMap.get("name"));
        prepstmt.setString(3, pMap.get("description"));
        prepstmt.setInt(4, Integer.parseInt(pMap.get("quantity")));
        prepstmt.executeUpdate();
        return "row has been inserted into the database";
    }

}

From source file:com.oracle.products.ProductResource.java

@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)//from  w w w  . j ava2  s. com
public String putProduct(@PathParam("id") int id, String str) throws SQLException {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> productMap = new LinkedHashMap<>();
    String key = "";
    String val = "";

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            key = parser.getString();
            break;
        case VALUE_STRING:
            val = parser.getString();
            productMap.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            productMap.put(key, val);
            break;
        default:
            break;
        }
    }
    if (conn == null) {
        return "Not connected";
    } else {
        String query = "UPDATE product SET  name = ?, description = ?, quantity = ? WHERE product_id =?";
        PreparedStatement pstmt = conn.prepareStatement(query);
        pstmt.setString(1, productMap.get("name"));
        pstmt.setString(2, productMap.get("description"));
        pstmt.setInt(3, Integer.parseInt(productMap.get("quantity")));
        pstmt.setInt(4, id);
        pstmt.executeUpdate();
        return "row has been updated into the database";
    }

}

From source file:com.Assignment4.Assign.java

@POST
@Consumes(MediaType.APPLICATION_JSON)//from w  w w  .j  av a  2  s  .  c o m
@Produces(MediaType.TEXT_PLAIN)
public String postProduct(String str) throws SQLException {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> proMap = new LinkedHashMap<String, String>();
    String key = "";
    String val = "";

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            key = parser.getString();
            break;
        case VALUE_STRING:
            val = parser.getString();
            proMap.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            proMap.put(key, val);
            break;
        default:
            break;
        }
    }
    if (connected == null) {
        return "Not connected";
    } else {
        String query = "INSERT INTO product (product_id,name,description,quantity) VALUES (?,?,?,?)";
        PreparedStatement pst = connected.prepareStatement(query);
        pst.setInt(1, Integer.parseInt(proMap.get("product_id")));
        pst.setString(2, proMap.get("name"));
        pst.setString(3, proMap.get("description"));
        pst.setInt(4, Integer.parseInt(proMap.get("quantity")));
        pst.executeUpdate();
        return "row has been inserted into the database";
    }

}

From source file:com.product.Product.java

@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)/*from   w  w w  .j  ava 2  s.c o  m*/
public String putProduct(@PathParam("id") int id, String str) throws SQLException {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> prodMap = new LinkedHashMap<String, String>();
    String key = "";
    String val = "";

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            key = parser.getString();
            break;
        case VALUE_STRING:
            val = parser.getString();
            prodMap.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            prodMap.put(key, val);
            break;
        default:
            break;
        }
    }
    if (connect == null) {
        return "Not connected";
    } else {
        String query = "UPDATE product SET  name = ?, description = ?, quantity = ? WHERE product_id =?";
        PreparedStatement prepstmnt = connect.prepareStatement(query);
        prepstmnt.setString(1, prodMap.get("name"));
        prepstmnt.setString(2, prodMap.get("description"));
        prepstmnt.setInt(3, Integer.parseInt(prodMap.get("quantity")));
        prepstmnt.setInt(4, id);
        prepstmnt.executeUpdate();
        return "row has been updated into the database";
    }

}

From source file:com.product.Product.java

@POST
@Path("/products")
@Consumes(MediaType.APPLICATION_JSON)//from   w w w  .  j  a  v a  2s  .c o m
@Produces(MediaType.TEXT_PLAIN)
public String postProduct(String str) throws SQLException {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> prodMap = new LinkedHashMap<String, String>();
    String key = "";
    String val = "";

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            key = parser.getString();
            break;
        case VALUE_STRING:
            val = parser.getString();
            prodMap.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            prodMap.put(key, val);
            break;
        default:
            break;
        }
    }
    if (connect == null) {
        return "Not connected";
    } else {
        String query = "INSERT INTO product (product_id,name,description,quantity) VALUES (?,?,?,?)";
        PreparedStatement prepstmnt = connect.prepareStatement(query);
        prepstmnt.setInt(1, Integer.parseInt(prodMap.get("product_id")));
        prepstmnt.setString(2, prodMap.get("name"));
        prepstmnt.setString(3, prodMap.get("description"));
        prepstmnt.setInt(4, Integer.parseInt(prodMap.get("quantity")));
        prepstmnt.executeUpdate();
        return "row has been inserted into the database";
    }

}

From source file:com.products.ProductResource.java

@POST
@Consumes(MediaType.APPLICATION_JSON)/*from   ww w  .  ja v  a 2  s .  c o m*/
@Produces(MediaType.TEXT_PLAIN)
public String postProduct(String str) throws SQLException {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> productMap = new LinkedHashMap<String, String>();
    String key = "";
    String value = "";

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            key = parser.getString();
            break;
        case VALUE_STRING:
            value = parser.getString();
            productMap.put(key, value);
            break;
        case VALUE_NUMBER:
            value = parser.getString();
            productMap.put(key, value);
            break;
        default:
            break;
        }
    }
    if (co == null) {
        return "Not connected";
    } else {
        String query = "INSERT INTO product (product_id,name,description,quantity) VALUES (?,?,?,?)";
        PreparedStatement stmt = co.prepareStatement(query);
        stmt.setInt(1, Integer.parseInt(productMap.get("product_id")));
        stmt.setString(2, productMap.get("name"));
        stmt.setString(3, productMap.get("description"));
        stmt.setInt(4, Integer.parseInt(productMap.get("quantity")));
        stmt.executeUpdate();
        return "row has been inserted into the database";
    }

}

From source file:com.assignment4.productdetails.java

@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)//  w  w w. j a v a 2 s.  c o m
public String putProduct(@PathParam("id") int id, String str) throws SQLException {
    JsonParser parse = Json.createParser(new StringReader(str));
    Map<String, String> pdtmap = new LinkedHashMap<String, String>();
    String key = "";
    String value = "";

    while (parse.hasNext()) {
        JsonParser.Event event = parse.next();
        switch (event) {
        case KEY_NAME:
            key = parse.getString();
            break;
        case VALUE_STRING:
            value = parse.getString();
            pdtmap.put(key, value);
            break;
        case VALUE_NUMBER:
            value = parse.getString();
            pdtmap.put(key, value);
            break;
        default:
            break;
        }
    }
    if (conn == null) {
        return "Not able to connect";
    } else {
        String query = "UPDATE product SET  name = ?, description = ?, quantity = ? WHERE product_id =?";
        PreparedStatement pstmt = conn.prepareStatement(query);
        pstmt.setString(1, pdtmap.get("name"));
        pstmt.setString(2, pdtmap.get("description"));
        pstmt.setInt(3, Integer.parseInt(pdtmap.get("quantity")));
        pstmt.setInt(4, id);
        pstmt.executeUpdate();
        return "row has been updated into the database";
    }

}

From source file:com.oracle.products.ProductResource.java

@POST
@Consumes(MediaType.APPLICATION_JSON)//from  ww  w .j a va  2 s .co  m
@Produces(MediaType.TEXT_PLAIN)
public String postProduct(String str) throws SQLException {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> productMap = new LinkedHashMap<String, String>();
    String key = "";
    String val = "";

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            key = parser.getString();
            break;
        case VALUE_STRING:
            val = parser.getString();
            productMap.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            productMap.put(key, val);
            break;
        default:
            break;
        }
    }
    if (conn == null) {
        return "Not connected";
    } else {
        String query = "INSERT INTO product (product_id,name,description,quantity) VALUES (?,?,?,?)";
        PreparedStatement pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, Integer.parseInt(productMap.get("product_id")));
        pstmt.setString(2, productMap.get("name"));
        pstmt.setString(3, productMap.get("description"));
        pstmt.setInt(4, Integer.parseInt(productMap.get("quantity")));
        pstmt.executeUpdate();
        return "row has been inserted into the database";
    }

}