protected Document read( InputStream stream ) throws IOException { return Json.read(stream, false); }
protected Document read( InputStream stream ) throws IOException { return Json.read(stream, false); }
/** * Reads document content from the stream. * * @param in input stream. * @throws IOException */ private void readFromStream(InputStream in) throws IOException { document = DocumentFactory.newDocument(Json.read(in)); }
/** * Returns a DB with reads the given input stream as a configuration document {@code Document}. This document is * expected to contain a {@link Schematic#TYPE_FIELD type field} to indicate the type * of DB. * * @see #getDb(Document, ClassLoader) * @throws ParsingException if the given input stream is not a valid JSON document */ public static <T extends SchematicDb> T getDb(InputStream configInputStream) throws ParsingException, RuntimeException { Document document = Json.read(configInputStream).withVariablesReplacedWithSystemProperties(); return getDb(document, Schematic.class.getClassLoader()); }
/** * Returns a DB with reads the given input stream as a configuration document {@code Document}. This document is * expected to contain a {@link Schematic#TYPE_FIELD type field} to indicate the type * of DB. * * @see #getDb(Document, ClassLoader) * @throws ParsingException if the given input stream is not a valid JSON document */ public static <T extends SchematicDb> T getDb(InputStream configInputStream) throws ParsingException, RuntimeException { Document document = Json.read(configInputStream).withVariablesReplacedWithSystemProperties(); return getDb(document, Schematic.class.getClassLoader()); }
protected static Document doc( String content ) throws ParsingException { Document doc = Json.read(content); if (print) System.out.println(doc); return doc; }
/** * Resolve the supplied URL to a JSON document, read the contents, and parse into a {@link RepositoryConfiguration}. * * @param url the URL; may not be null * @return the parsed repository configuration; never null * @throws ParsingException if the content could not be parsed as a valid JSON document */ public static RepositoryConfiguration read( URL url ) throws ParsingException { CheckArg.isNotNull(url, "url"); Document doc = Json.read(url); return new RepositoryConfiguration(doc, withoutExtension(url.getFile())); }
/** * Read the supplied JSON file and parse into a {@link RepositoryConfiguration}. * * @param file the file; may not be null * @return the parsed repository configuration; never null * @throws ParsingException if the content could not be parsed as a valid JSON document * @throws FileNotFoundException if the file could not be found */ public static RepositoryConfiguration read( File file ) throws ParsingException, FileNotFoundException { CheckArg.isNotNull(file, "file"); Document doc = Json.read(new FileInputStream(file)); return new RepositoryConfiguration(doc, withoutExtension(file.getName())); }
/** * Read the supplied JSON file and parse into a {@link RepositoryConfiguration}. * * @param file the file; may not be null * @return the parsed repository configuration; never null * @throws ParsingException if the content could not be parsed as a valid JSON document * @throws FileNotFoundException if the file could not be found */ public static RepositoryConfiguration read( File file ) throws ParsingException, FileNotFoundException { CheckArg.isNotNull(file, "file"); Document doc = Json.read(new FileInputStream(file)); return new RepositoryConfiguration(doc, withoutExtension(file.getName())); }
/** * Resolve the supplied URL to a JSON document, read the contents, and parse into a {@link RepositoryConfiguration}. * * @param url the URL; may not be null * @return the parsed repository configuration; never null * @throws ParsingException if the content could not be parsed as a valid JSON document */ public static RepositoryConfiguration read( URL url ) throws ParsingException { CheckArg.isNotNull(url, "url"); Document doc = Json.read(url); return new RepositoryConfiguration(doc, withoutExtension(url.getFile())); }
@Override protected void startRepositoryWithConfiguration( String configContent ) throws Exception { Document doc = Json.read(configContent); startRepositoryWithConfiguration(doc); }
/** * Read the supplied stream containing a JSON file, and parse into a {@link RepositoryConfiguration}. * * @param stream the file; may not be null * @param name the name of the resource; may not be null * @return the parsed repository configuration; never null * @throws ParsingException if the content could not be parsed as a valid JSON document * @throws FileNotFoundException if the file could not be found */ public static RepositoryConfiguration read( InputStream stream, String name ) throws ParsingException, FileNotFoundException { CheckArg.isNotNull(stream, "stream"); CheckArg.isNotNull(name, "name"); Document doc = Json.read(stream); return new RepositoryConfiguration(doc, withoutExtension(name)); }
/** * Read the supplied stream containing a JSON file, and parse into a {@link RepositoryConfiguration}. * * @param stream the file; may not be null * @param name the name of the resource; may not be null * @return the parsed repository configuration; never null * @throws ParsingException if the content could not be parsed as a valid JSON document * @throws FileNotFoundException if the file could not be found */ public static RepositoryConfiguration read( InputStream stream, String name ) throws ParsingException, FileNotFoundException { CheckArg.isNotNull(stream, "stream"); CheckArg.isNotNull(name, "name"); Document doc = Json.read(stream); return new RepositoryConfiguration(doc, withoutExtension(name)); }
@BeforeClass public static void beforeAll() throws Exception { docs = new InMemoryDocumentLibrary("tests"); docs.put("http://json-schema.org/draft-03/schema#", Json.read(resource("json/schema/draft-03/schema.json"))); docs.put("json/spec-example-doc.json", Json.read(resource("json/spec-example-doc.json"))); docs.put("json/schema/spec-example.json", Json.read(resource("json/schema/spec-example.json"))); docs.put("json/sample-repo-config.json", Json.read(resource("json/sample-repo-config.json"))); docs.put("json/empty.json", Json.read(resource("json/empty.json"))); docs.put("json/schema/repository-config-schema.json", Json.read(resource("json/schema/repository-config-schema.json"))); docs.put("json/schema/enum-example.json", Json.read(resource("json/schema/enum-example.json"))); docs.put("json/enum-example-doc.json", Json.read(resource("json/enum-example-doc.json"))); }
public static JcrRepository startClusteredRepositoryWithConfig(String configFile, String clusterNodeId) throws Exception { URL configUrl = TestingUtil.class.getClassLoader().getResource(configFile); Assert.assertNotNull(configFile + " not found", configFile); Properties properties = new Properties(); properties.put("clusterNode", clusterNodeId); Document configDoc = Json.read(configUrl).withVariablesReplaced(properties); JcrRepository repository = new JcrRepository(new RepositoryConfiguration(configDoc, configFile)); repository.start(); Thread.sleep(200); return repository; }
@Test public void shouldMergeTwoDocuments() throws Exception { Document doc1 = Json.read(stream("json/merge-1.json")); Document doc2 = Json.read(stream("json/merge-2.json")); Document doc3 = Json.read(stream("json/merge-3.json")); EditableDocument editor = new DocumentEditor((MutableDocument)doc1); assertThat(Json.writePretty(editor).equals(Json.writePretty(doc3)), is(false)); editor.merge(doc2); assertThat(Json.writePretty(editor).equals(Json.writePretty(doc3)), is(true)); } }
/** * Subclasses can call this method at the beginning of each test to shutdown any currently-running repository and to start up * a new repository with the given JSON configuration content. * * @param configContent the JSON string containing the configuration for the repository (note that single quotes can be used * in place of double quote, making it easier for to specify a JSON content as a Java string) * @throws Exception if there was a problem starting the repository * @see #startRepositoryWithConfiguration(Document) * @see #startRepositoryWithConfiguration(InputStream) * @see #startRepositoryWithConfiguration(RepositoryConfiguration) * @see #startRepositoryAutomatically */ protected void startRepositoryWithConfiguration( String configContent ) throws Exception { assertThat(configContent, is(notNullValue())); Document doc = Json.read(configContent); startRepositoryWithConfiguration(doc); }
@Test public void shouldRoundTripLargeModeShapeDocument() throws Exception { Document doc = Json.read(resource("json/sample-large-modeshape-doc.json")); // OutputStream os = new FileOutputStream("src/test/resources/json/sample-large-modeshape-doc2.json"); // Json.writePretty(doc, os); // os.flush(); // os.close(); assertRoundtrip(doc); }
@BeforeClass public static void beforeAll() throws Exception { schemas = Schematic.createSchemaLibrary(); schemas.put("http://json-schema.org/draft-03/schema#", Json.read(resource("json/schema/draft-03/schema.json"))); schemas.put(PARTS_SCHEMA_URI, Json.read(resource("json/schema/spec-example.json"))); // schemas.put("json/schema/repository-config-schema.json", // Json.read(resource("json/schema/repository-config-schema.json"))); }
/** * Reads the input stream to load the JSON data as a Document, and then loads all of the documents within the "data" array * field into the database. * * @param stream the stream containing the JSON data Document */ protected void loadJsonDocuments( InputStream stream ) { runInTransaction(() -> { Document document = Json.read(stream); List<?> data = document.getArray("data"); if (data != null) { for (Object value : data) { if (value instanceof Document) { Document dataDoc = (Document) value; // Get the key ... Document content = dataDoc.getDocument("content"); Document metadata = dataDoc.getDocument("metadata"); String key = metadata.getString("id"); schematicDb.put(key, content); } } } return null; }); }