Package org.json

Examples of org.json.JSONWriter


      Workspace workspace) {
    try {

      JSONStringer x = new JSONStringer();

      JSONWriter topA = x.array();
      topA.object().key("a").value("a_1").key("b").array()
          //
          .object().key("b.1").value("b.1_1").key("b.2")
          .value("b.2_1").endObject()
          //
          // .object().key("b.1").value("b.1_2").key("b.2")
          // .value("b.2_2").endObject()
          //
          .endArray().endObject();

      topA.object().key("a").value("a_2").endObject();

      topA.endArray();

      JsonImport ji = new JsonImport(x.toString(),
          "Empty Nested Table 1", workspace, "UTF-8", -1);
      Worksheet w = ji.generateWorksheet();
      return w;
View Full Code Here


      Workspace workspace) {
    try {

      JSONStringer x = new JSONStringer();

      JSONWriter topA = x.array();
      topA.object().key("a").value("a_1").key("b").array()
          //
          .object().key("b.1").value("b.1_1").key("b.2")
          .value("b.2_1").endObject()
          //
          .object().key("b.1").value("b.1_2").endObject()
          //
          .endArray().endObject();

      topA.object().key("a").value("a_2").endObject();

      topA.endArray();

      JsonImport ji = new JsonImport(x.toString(),
          "Empty Nested Table 2", workspace, "UTF-8", -1);
      Worksheet w = ji.generateWorksheet();
      return w;
View Full Code Here

      Workspace workspace) {
    try {

      JSONStringer x = new JSONStringer();

      JSONWriter topA = x.array();
      topA.object().key("a").value("a_1").key("b").array()
          //
          .object().key("b.1").value("b.1_1").key("b.2")
          .value("b.2_1").endObject()
          //
          .endArray().endObject();

      topA.object().key("b").array().endArray().endObject();

      topA.endArray();

      JsonImport ji = new JsonImport(x.toString(),
          "Empty Nested Table 3", workspace, "UTF-8", -1);
      Worksheet w = ji.generateWorksheet();
      return w;
View Full Code Here

      Workspace workspace) {
    try {

      JSONStringer x = new JSONStringer();

      JSONWriter topA = x.array();
      topA.object().key("a").value("a_1").key("b").array()
          //
          .object().key("b.1").value("b.1_1").key("b.2")
          .value("b.2_1").endObject()
          //
          .object().key("b.2").value("b.2_2").endObject()
          //
          .object().key("b.1").value("b.1_3").endObject()
          //
          .endArray().endObject();

      topA.object().key("a").value("a_2").endObject();

      topA.endArray();

      JsonImport ji = new JsonImport(x.toString(),
          "Empty Nested Table 4", workspace, "UTF-8", -1);
      Worksheet w = ji.generateWorksheet();
      return w;
View Full Code Here

  public static Worksheet createSampleJsonWithNestedTable1(Workspace workspace) {
    try {

      JSONStringer x = new JSONStringer();

      JSONWriter topA = x.array();
      topA.object().key("a").value("a/1").key("b")
          .array()
          //
          .object().key("b.1").value("b.1/1,1").key("b.2")
          .value("b.2/1,1").endObject()
          //
          .object().key("b.1").value("b.1/1,2").key("b.2")
          .value("b.2/1,2").endObject()
          //
          .endArray().endObject();

      topA.object().key("a").value("a/2").key("b")
          .array()
          //
          .object().key("b.1").value("b.1/2,1").key("b.2")
          .value("b.2/2,1").endObject()
          //
          .object().key("b.1").value("b.1/2,2").key("b.2")
          .value("b.2/2,2").endObject()
          //
          .endArray().endObject();

      topA.endArray();

      JsonImport ji = new JsonImport(x.toString(),
          "Nested Table 1", workspace, "UTF-8", -1);
      Worksheet w = ji.generateWorksheet();
      return w;
View Full Code Here

      boolean hasTwoRows, Workspace workspace) {
    try {

      JSONStringer x = new JSONStringer();

      JSONWriter topA = x.array();
      topA.object().key("a").value("a/1").key("b").array()
      //
          .object()//
          .key("b.1").value("b.1/1,1")//
          .key("b.2").array()//
          .object()//
          .key("b.2.1").value("b.2.1/1,1,1")//
          .key("b.2.2").value("b.2.2/1,1,1")//
          .endObject()//
          .object()//
          .key("b.2.1").value("b.2.1/1,1,2")//
          .key("b.2.2").value("b.2.2/1,1,2")//
          .endObject()//
          .endArray()//
          .endObject()//
          //
          .object()//
          .key("b.1").value("b.1/1,2")//
          .key("b.2").array()//
          .object()//
          .key("b.2.1").value("b.2.1/1,2,1")//
          .key("b.2.2").value("b.2.2/1,2,1")//
          .endObject()//
          .endArray()//
          .endObject();//
      topA.endArray().endObject();

      if (hasTwoRows) {
        topA.object().key("a").value("a/2").key("b").array()
        //
            .object()//
            .key("b.1").value("b.1/2,1")//
            .key("b.2").array()//
            .object()//
            .key("b.2.1").value("b.2.1/2,1,1")//
            .key("b.2.2").value("b.2.2/2,1,1")//
            .endObject()//
            .endArray()//
            .endObject()//
            //
            .object()//
            .key("b.1").value("b.1/2,2")//
            .key("b.2").array()//
            .object()//
            .key("b.2.1").value("b.2.1/2,2,1")//
            .key("b.2.2").value("b.2.2/2,2,1")//
            .endObject()//
            .endArray()//
            .endObject()//
        //
        ;

        topA.endArray().endObject();
      }

      topA.endArray();

      JsonImport ji = new JsonImport(x.toString(),
          "Nested Table 2", workspace, "UTF-8", -1);
      Worksheet w = ji.generateWorksheet();
      return w;
View Full Code Here

        public void generateJson(String prefix, PrintWriter pw,
            VWorkspace vWorkspace) {
          try {
            JSONStringer jsonStr = new JSONStringer();
           
            JSONWriter writer = jsonStr.object();
            writer.key("worksheetId").value(worksheetId);
            writer.key("updateType").value("LiteralNodeUpdate")
            writer.key("node");
           
            writer.object();
            writer.key("value").value(lNode.getValue())
            String type = lNode.getDatatype().getLocalName();
            if(type != null && type.length() > 0)
              type = lNode.getDatatype().getDisplayName();
            else
              type = "";
            writer.key("type").value(type);
            writer.key("isUri").value(lNode.isUri());
            writer.endObject();
           
            writer.endObject();
 
            pw.print(writer.toString());
          } catch (JSONException e) {
            logger.error("Error occured while writing to JSON!", e);
            uc.add(new ErrorUpdate("Error occured while writing to JSON"));
          }
        }
View Full Code Here

     
      ArrayList<ArrayList<String>> data = dbUtil.getDataForLimitedRows(dbType, hostname,
          portnumber, username, password, tableName, dBorSIDName, 10);
     
      JSONStringer jsonStr = new JSONStringer();
      JSONWriter writer = jsonStr.object().key(JsonKeys.commandId.name()).value(commandId)
        .key(GenericJsonKeys.updateType.name()).value("ImportDatabaseTablePreview").key(JsonKeys.tableName.name()).value(tableName);
     
      // Add the headers
      JSONArray arr = new JSONArray(data.get(0));
      writer.key(JsonKeys.headers.name()).value(arr);
     
      // Add the data
      JSONArray dataRows = new JSONArray();
      for(int i = 1; i<data.size(); i++) {
        dataRows.put(data.get(i));
      }
      writer.key(JsonKeys.rows.name()).value(dataRows);
     
      writer.endObject();
      pw.println(jsonStr.toString());
    } catch (SQLException e) {
      e.printStackTrace();
      String message = e.getMessage().replaceAll("\n", "").replaceAll("\"","\\\"");
      ErrorUpdate er = new ErrorUpdate(message);
View Full Code Here

          public void generateJson(String prefix, PrintWriter pw,
              VWorkspace vWorkspace) {
            try {
              JSONStringer jsonStr = new JSONStringer();
             
              JSONWriter writer = jsonStr.object();
              writer.key("worksheetId").value(worksheetId);
              writer.key("updateType").value("AddLiteralNodeUpdate")
              writer.key("hNodeId").value(ln.getId());
              writer.key("uri").value(literalValue);
              writer.endObject();
              pw.print(writer.toString());
            } catch (JSONException e) {
              logger.error("Error occured while writing to JSON!", e);
             
            }
           
View Full Code Here

    Map<String, ColumnNode> hNodeIdTocolumnNodeMap = createColumnNodeMap();
    Map<String, InternalNode> hNodeIdToDomainNodeMap = createDomainNodeMap();
   
    JSONStringer jsonStr = new JSONStringer();
    try {
      JSONWriter writer = jsonStr.object();
      writer.key("worksheetId").value(worksheetId).key("updateType")
          .value("SemanticTypesUpdate");

      writer.key(JsonKeys.Types.name());
      writer.array();
      // Iterate through all the columns
      for (HNodePath path : worksheet.getHeaders().getAllPaths()) {
        HNode node = path.getLeaf();
        String nodeId = node.getId();

        writer.object();

        // Check if a semantic type exists for the HNode
        SemanticType type = types.getSemanticTypeForHNodeId(nodeId);
        if (type != null && type.getConfidenceLevel() != SemanticType.ConfidenceLevel.Low) {
          writer.key(JsonKeys.HNodeId.name())
              .value(type.getHNodeId())
              .key(JsonKeys.SemanticTypesArray.name()).array();
         
          ColumnNode alignmentColumnNode = hNodeIdTocolumnNodeMap.get(type.getHNodeId());
          InternalNode domainNode = hNodeIdToDomainNodeMap.get(type.getHNodeId());
         
          if (alignmentColumnNode == null || domainNode == null) {
            logger.error("Column node or domain node not found in alignment." +
                " (This should not happen conceptually!):" + type);
            continue;
          }
         
          // Add the primary semantic type
          writer.object()
              .key(JsonKeys.Origin.name())
              .value(type.getOrigin().name())
              .key(JsonKeys.ConfidenceLevel.name())
              .value(type.getConfidenceLevel().name())
              .key(JsonKeys.isPrimary.name())
              .value(true);
         
          // Add the RDF literal type to show in the text box
          String rdfLiteralType = alignmentColumnNode.getRdfLiteralType() == null? "" :
            alignmentColumnNode.getRdfLiteralType().getDisplayName();
          writer.key(JsonKeys.rdfLiteralType.name())
            .value(rdfLiteralType);
         
//          String domainDisplayLabel = (domainNode.getLabel().getPrefix() != null && (!domainNode.getLabel().getPrefix().equals(""))) ?
//              (domainNode.getLabel().getPrefix() + ":" + domainNode.getLocalId()) : domainNode.getLocalId();
          if (!type.isClass()) {
            writer
              .key(JsonKeys.FullType.name()).value(type.getType().getUri())
              .key(JsonKeys.DisplayLabel.name()).value(type.getType().getDisplayName())
              .key(JsonKeys.DomainId.name()).value(domainNode.getId())
              .key(JsonKeys.DomainUri.name()).value(domainNode.getUri())
              .key(JsonKeys.DisplayDomainLabel.name()).value(domainNode.getDisplayId());
          } else {
            writer
              .key(JsonKeys.FullType.name()).value(domainNode.getId())
              .key(JsonKeys.DisplayLabel.name()).value(domainNode.getDisplayId())
              .key(JsonKeys.DomainId.name()).value("")
              .key(JsonKeys.DomainUri.name()).value("")
              .key(JsonKeys.DisplayDomainLabel.name())
              .value("");
          }
         
          // Mark the special properties
          writer
            .key(JsonKeys.isMetaProperty.name())
            .value(isMetaProperty(type.getType(), alignmentColumnNode));
         
         
          writer.endObject();

          // Iterate through the synonym semantic types
          SynonymSemanticTypes synTypes = types
              .getSynonymTypesForHNodeId(nodeId);

          if (synTypes != null) {
            for (SemanticType synType : synTypes.getSynonyms()) {
              writer.object()
                  .key(JsonKeys.HNodeId.name())
                  .value(synType.getHNodeId())
                  .key(JsonKeys.FullType.name())
                  .value(synType.getType().getUri())
                  .key(JsonKeys.Origin.name())
                  .value(synType.getOrigin().name())
                  .key(JsonKeys.ConfidenceLevel.name())
                  .value(synType.getConfidenceLevel().name())
                  .key(JsonKeys.DisplayLabel.name())
                  .value(synType.getType().getDisplayName())
                  .key(JsonKeys.isPrimary.name())
                  .value(false);
              if (!synType.isClass()) {
                writer.key(JsonKeys.DomainUri.name()).value(synType.getDomain().getUri())
                  .key(JsonKeys.DomainId.name()).value("")
                  .key(JsonKeys.DisplayDomainLabel.name())
                  .value(synType.getDomain().getDisplayName());
              } else {
                writer.key(JsonKeys.DomainId.name()).value("")
                  .key(JsonKeys.DomainUri.name()).value("")
                  .key(JsonKeys.DisplayDomainLabel.name())
                  .value("");
              }
              writer.endObject();
            }
          }
          writer.endArray();
        } else {
          writer.key(JsonKeys.HNodeId.name()).value(nodeId);
          writer.key(JsonKeys.SemanticTypesArray.name()).array()
              .endArray();
        }
       
        writer.endObject();
      }
      writer.endArray();
      writer.endObject();

      pw.print(writer.toString());
    } catch (JSONException e) {
      logger.error("Error occured while writing to JSON!", e);
    }
  }
View Full Code Here

TOP

Related Classes of org.json.JSONWriter

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.