Examples of JSONStringer


Examples of org.json.JSONStringer

          @Override
          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();
View Full Code Here

Examples of org.json.JSONStringer

   
    SemanticTypes types = worksheet.getSemanticTypes();
    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();
View Full Code Here

Examples of org.json.JSONStringer

    Scanner scanner;
    int rowCount = 0;
    int previewRowCounter = 0;

    // Hold the updateContainer JSON
    JSONStringer jsonStr = new JSONStringer();

    try {
      logger.info("CSVFileImportPreview: Got encoding: " + encoding);

      if (encoding == null) {
        encoding = EncodingDetector.detect(csvFile);
      }
      scanner = new Scanner(csvFile, encoding);
      JSONWriter writer = jsonStr.object().key(JsonKeys.commandId.name())
          .value(commandId).key(GenericJsonKeys.updateType.name())
          .value("ImportCSVPreview").key(JsonKeys.fileName.name())
          .value(csvFile.getName()).key("encoding").value(encoding)
          .key("maxNumLines").value(maxNumLines);

      JSONArray dataRows = new JSONArray();
      while (scanner.hasNextLine()) {
        // Check for the header row
        if (rowCount + 1 == headerRowIndex) {
          String line = scanner.nextLine();
          CSVReader reader = new CSVReader(new StringReader(line),
              delimiter, quoteCharacter, escapeCharacter);
          String[] rowValues = reader.readNext();
          List<String> headers = new ArrayList<String>();
          if (rowValues == null || rowValues.length == 0) {
            logger.error("No data found in the Header row!");
            rowCount++;
            scanner.nextLine();
            continue;
          }
          for (int i = 0; i < rowValues.length; i++) {           
            headers.add(rowValues[i]);
          }
          // Add the row index
          headers.add(0, Integer.toString(rowCount + 1));

          // Add to the output JSON
          JSONArray arr = new JSONArray(headers);
          writer.key(JsonKeys.headers.name()).value(arr);
          rowCount++;
          reader.close();
          continue;
        }

        // Check for the data rows. We choose the first five for preview
        if (rowCount + 1 >= dataStartRowIndex
            && rowCount + 1 < dataStartRowIndex + 5) {
          if (previewRowCounter++ > 5) {
            break;
          }
          String line = scanner.nextLine();
          CSVReader reader = new CSVReader(new StringReader(line),
              delimiter, quoteCharacter, escapeCharacter);
          String[] rowValues = reader.readNext();
          List<String> vals = new ArrayList<String>();
          if (rowValues != null) {
            for (int i = 0; i < rowValues.length; i++) {
              vals.add(rowValues[i]);
            }
          } else
            vals.add("");
          // Add the row index
          vals.add(0, Integer.toString(rowCount + 1));
          reader.close();

          // Add to the data rows JSON
          dataRows.put(vals);
          rowCount++;
          continue;
        }

        rowCount++;
        scanner.nextLine();
      }

      writer.key(JsonKeys.rows.name()).value(dataRows);
      writer.endObject();
      pw.println(jsonStr.toString());
    } catch (FileNotFoundException e) {
      logger.error("File not found!", e);
    } catch (IOException e) {
      logger.error("Error occured while reading the file!", e);
    } catch (JSONException e) {
View Full Code Here

Examples of org.json.JSONStringer

    try {
      if(encoding == null) {
        encoding = EncodingDetector.detect(jsonFile);
      }

      JSONStringer jsonStr = new JSONStringer();
      JSONWriter writer = jsonStr.object()
          .key(JsonKeys.commandId.name()).value(commandId)
          .key(GenericJsonKeys.updateType.name()).value("ImportPropertiesUpdate")
          .key(JsonKeys.fileName.name()).value(jsonFile.getName())
          .key("encoding").value(encoding)
          .key("maxNumLines").value(maxNumLines)
          ;
     
     
      writer.endObject();
      pw.println(jsonStr.toString());
     
 
    } catch (JSONException e) {
      logger.error("Error occured while writing to JSON", e);
    }
View Full Code Here

Examples of org.json.JSONStringer

    private static QName _name = new QName("", "name");

    private static final QName c_body = new QName("c", XProcConstants.NS_XPROC_STEP, "body");

    public static String convert(XdmNode json) {
        JSONStringer js = new JSONStringer();

        json = S9apiUtils.getDocumentElement(json);

        if (c_body.equals(json.getNodeName())) {
            XdmNode jchild = null;
            XdmSequenceIterator iter = json.axisIterator(Axis.CHILD);
            while (iter.hasNext()) {
                XdmItem item = iter.next();
                if (item instanceof XdmNode) {
                    XdmNode child = (XdmNode) item;
                    if (child.getNodeKind() == XdmNodeKind.ELEMENT) {
                        if (jchild != null) {
                            throw new XProcException("Found c:body containing more than one JSON element?");
                        } else {
                            jchild = child;
                        }
                    }
                }
            }
            json = jchild;
        }

        try {
            build(json, js, ROOT);
        } catch (JSONException jse) {
            throw new XProcException(jse);
        }

        return js.toString();
    }
View Full Code Here

Examples of org.json.JSONStringer

    private String[] tokenSeparators;
    private Boolean dropdownAutoWidth;

    public CharSequence toJson() {
  try {
      JSONStringer writer = new JSONStringer();
      writer.object();
      Json.writeObject(writer, "minimumInputLength", minimumInputLength);
      Json.writeObject(writer, "minimumResultsForSearch", minimumResultsForSearch);
      Json.writeObject(writer, "maximumSelectionSize", maximumSelectionSize);
      Json.writeObject(writer, "placeholder", placeholder);
      Json.writeObject(writer, "allowClear", allowClear);
      Json.writeObject(writer, "multiple", multiple);
      Json.writeObject(writer, "closeOnSelect", closeOnSelect);
      Json.writeFunction(writer, "id", id);
      Json.writeFunction(writer, "matcher", matcher);
      Json.writeFunction(writer, "tokenizer", tokenizer);
      Json.writeFunction(writer, "sortResults", sortResults);
      Json.writeFunction(writer, "formatSelection", formatSelection);
      Json.writeFunction(writer, "formatResult", formatResult);
      Json.writeFunction(writer, "formatNoMatches", formatNoMatches);
      Json.writeFunction(writer, "formatInputTooShort", formatInputTooShort);
      Json.writeFunction(writer, "formatResultCssClass", formatResultCssClass);
      Json.writeFunction(writer, "formatSelectionTooBig", formatSelectionTooBig);
      Json.writeFunction(writer, "formatLoadMore", formatLoadMore);
      Json.writeFunction(writer, "formatSearching", formatSearching);
      Json.writeFunction(writer, "escapeMarkup", escapeMarkup);
      Json.writeFunction(writer, "createSearchChoice", createSearchChoice);
      Json.writeFunction(writer, "initSelection", initSelection);
      Json.writeFunction(writer, "query", query);
      Json.writeObject(writer, "width", width);
      Json.writeObject(writer, "openOnEnter", openOnEnter);
      Json.writeFunction(writer, "containerCss", containerCss);
      Json.writeObject(writer, "containerCssClass", containerCssClass);
      Json.writeFunction(writer, "dropdownCss", dropdownCss);
      Json.writeObject(writer, "dropdownCssClass", dropdownCssClass);
      Json.writeObject(writer, "separator", separator);
      Json.writeObject(writer, "tokenSeparators", tokenSeparators);
      Json.writeObject(writer, "dropdownAutoWidth", dropdownAutoWidth);
      if (ajax != null) {
    writer.key("ajax");
    ajax.toJson(writer);
      }
      Json.writeFunction(writer, "data", data);
      Json.writeFunction(writer, "tags", tags);
      writer.endObject();

      return writer.toString();
  } catch (JSONException e) {
      throw new RuntimeException("Could not convert Select2 settings object to Json", e);
  }
    }
View Full Code Here

Examples of org.json.JSONStringer

  }

  public static String createRequest()
  throws JSONException {
    float epoch = System.currentTimeMillis()/1000;
    JSONStringer msg = new JSONStringer();
    return msg
            .object()
            .key("client_name")
            .value("RPC Client 1.0")
            .key("time")
            .value(Float.toString(epoch))
View Full Code Here

Examples of org.json.JSONStringer

            prototype.name().set( name );
            prototype.entityType().set( first(Qi4j.FUNCTION_DESCRIPTOR_FOR.map( entity ).types()).getName() );
            prototype.entityId().set( entity.identity().get() );

            // JSON-ify parameters
            JSONStringer json = new JSONStringer();
            try
            {
                JSONWriter params = json.object();
                for (int i = 0; i < args.length; i++)
                {
                    params.key( "param" + i );
                    if (args[i] == null)
                        params.value( JSONObject.NULL );
                    else
                        params.value( args[i] );
                }
                json.endObject();
            } catch (JSONException e)
            {
                throw new IllegalArgumentException( "Could not create eventValue", e );
            }

            prototype.parameters().set( json.toString() );

            DomainEventValue eventValue = builder.newInstance();

            return eventValue;
        }
View Full Code Here

Examples of org.json.JSONStringer

            UnitOfWork uow = uowf.currentUnitOfWork();
            prototype.usecase().set( uow.usecase().name() );
            prototype.version().set( version );

            // JSON-ify parameters
            JSONStringer json = new JSONStringer();
            try
            {
                JSONWriter params = json.object();
                for (int i = 1; i < args.length; i++)
                {
                    params.key( "param" + i );
                    if (args[i] == null)
                        params.value( JSONObject.NULL );
                    else
                        params.value( args[i] );
                }
                json.endObject();
            } catch (JSONException e)
            {
                throw new IllegalArgumentException( "Could not create event", e );
            }

            prototype.parameters().set( json.toString() );

            ApplicationEvent event = builder.newInstance();

            return event;
        }
View Full Code Here

Examples of org.json.JSONStringer

*
*/
public final class JSONUtils {

    public static String buildJSON(Map<String, Object> params) throws JSONException {
        final JSONStringer stringer = new JSONStringer();
        stringer.object();

        for (Map.Entry<String, Object> param : params.entrySet()) {
            if (param.getKey() != null && !"".equals(param.getKey()) && param.getValue() != null && !""
                .equals(param.getValue())) {
                stringer.key(param.getKey()).value(param.getValue());
            }
        }

        return stringer.endObject().toString();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.