Skip to content

Commit

Permalink
javascript import paths and version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ErykKul committed May 9, 2024
1 parent c924b83 commit 6bea3aa
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.erykkul</groupId>
<artifactId>json-transformer</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>

<name>json-transformer</name>
<description>JSON Transformer is a small and expressive Java library that uses transformers defined in JSON documents for transformations of JSON structures (even complex structures containing nested arrays of objects) into other (complex) JSON structures.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* "https://github.com/ErykKul/json-transformer?tab=readme-ov-file#functions">Functions</a>
*
* @author Eryk Kulikowski
* @version 1.0.0
* @version 1.0.1
* @since 1.0.0
*/
@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* "https://github.com/ErykKul/json-transformer?tab=readme-ov-file#transformer">Transformer</a>
*
* @author Eryk Kulikowski
* @version 1.0.0
* @version 1.0.1
* @since 1.0.0
*/
public class Transformation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* "https://github.com/ErykKul/json-transformer?tab=readme-ov-file#transformer">Transformer</a>
*
* @author Eryk Kulikowski
* @version 1.0.0
* @version 1.0.1
* @since 1.0.0
*/
public class TransformerFactory {
Expand Down Expand Up @@ -90,12 +90,23 @@ private TransformerFactory() {
* @return the transformer
*/
public Transformer createFromJsonString(final String json) {
return createFromJsonString(json, "");
}

/**
*
* @param json the String representation of the JSON document of the
* transformer
* @param importPath the path where JavaScript files can be imported from
* @return the transformer
*/
public Transformer createFromJsonString(final String json, final String importPath) {
final String content = importPattern.matcher(json).replaceAll(x -> {
final String importFile = x.group()
.substring(importOpenTag.length(), x.group().length() - importEndTag.length())
.trim();
try {
return escapePattern.matcher(Files.readString(Paths.get(importFile)))
return escapePattern.matcher(Files.readString(Paths.get(importPath + importFile)))
.replaceAll(y -> escapeMap.get(y.group()));
} catch (final IOException e) {
logger.severe("Importing from file \"" + importFile + "\" failed: " + e);
Expand All @@ -114,10 +125,23 @@ public Transformer createFromJsonString(final String json) {
* Creates a new transformer from a file containing the JSON document of the
* transformer.
*
* @param file the path and name of the file
* @param file the path and name of the file
* @param importPath the path where JavaScript files can be imported from
* @return the transformer
* @throws IOException thrown when the file is not found
*/
public Transformer createFromFile(final String file, final String importPath) throws IOException {
final String content = Files.readString(Paths.get(file));
return createFromJsonString(content, importPath);
}

/**
* Creates a new Transformation object from the JsonValue of that transformation
* document.
*
* @param transformation the JsonValue of the transformation document
* @return the transformation object
*/
public Transformer createFromFile(final String file) throws IOException {
final String content = Files.readString(Paths.get(file));
return createFromJsonString(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* Transformer</a>
*
* @author Eryk Kulikowski
* @version 1.0.0
* @version 1.0.1
* @since 1.0.0
*/
public class Utils {
Expand Down

0 comments on commit 6bea3aa

Please sign in to comment.