-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
isayan
committed
Apr 21, 2020
1 parent
36d063c
commit ed8d8a6
Showing
11 changed files
with
625 additions
and
101 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package extend.util.external; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonSyntaxException; | ||
import java.io.IOException; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* | ||
* @author isayan | ||
*/ | ||
public class JsonpElement { | ||
|
||
private JsonpElement() { | ||
} | ||
|
||
private final static Pattern JSONP_TYPE = Pattern.compile("\\s*([\\w\\$\\.]+)\\s*\\(\\s*(\\{.*?\\})\\s*\\)", Pattern.DOTALL); | ||
|
||
public static JsonpElement parseJsonp(String jsonpString) throws JsonSyntaxException { | ||
Matcher m = JSONP_TYPE.matcher(jsonpString); | ||
if (m.lookingAt()) { | ||
JsonpElement jsonp = new JsonpElement(); | ||
jsonp.raw = m.group(0); | ||
jsonp.callbackName = m.group(1); | ||
jsonp.jsonElement = JsonUtil.parse(m.group(2)); | ||
return jsonp; | ||
} | ||
throw new JsonSyntaxException("jsonp invalid format"); | ||
} | ||
|
||
private String raw; | ||
|
||
public String getRaw() { | ||
return raw; | ||
} | ||
|
||
private String callbackName; | ||
|
||
public String getCallbackName() { | ||
return callbackName; | ||
} | ||
|
||
private JsonElement jsonElement; | ||
|
||
public JsonElement getJsonElement() { | ||
return jsonElement; | ||
} | ||
|
||
public String pretty() throws IOException { | ||
StringBuilder buff = new StringBuilder(); | ||
buff.append(callbackName); | ||
buff.append("(\n"); | ||
buff.append(JsonUtil.prettyJson(jsonElement, true)); | ||
buff.append("\n)"); | ||
return buff.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.