MjAbuz / test

Automatically exported from code.google.com/p/json-template
0 stars 0 forks source link

Java version available #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, I translated the python implementation to Java. Maybe you're 
interested in including it?

http://codereview.appspot.com/33078

Original issue reported on code.google.com by william....@gmail.com on 5 Apr 2009 at 6:15

GoogleCodeExporter commented 9 years ago
Wow fantastic!  I patched it in and was able to get all the tests to pass.

Slight nit: add a second argument to getenv, so that the os.path.join() doesn't 
fail
when joining with None (the default value):

os.getenv('JAVA_HOME', '')

I would like to do a couple things before "releasing" it:

1) Make sure the public Java API is consistent with the Python/JavaScript 
versions. 
It looks like it is, but does the package export any symbols that are 
implementation
details, for example?  (e.g. _ScopedContext and such are private in both Python 
and
JavaScript)

I'm not a Java expert, but something I've seen recently in the Java world is to 
have
this chaining:

TemplateCompileOptions().setMeta('{}').setMoreFormatters()

This is like the optional named arguments in Python.  So just return 'this' from
each.  Not sure if that's desirable or not.

2) A short README about the requirements to use it?  (Java version, platform). 
Although I suspect there is not much to know here -- I just downloaded the 
default
sun-java6-jre for my Ubuntu and it worked fine.  (And I need to do the same for
Python, 2.4+ is the goal, but I think it should probably work 2.2+ easily)

I'll add you as a member of the project, and since the tests all pass you 
commit it
now if you like.  I would like to get some more feedback and tweak it before 
releasing.

Also, how does it handle Unicode?  I wrote a note that for Python, it's 
transparent
(it just depends on the inputs), which I think is the right behavior.

Thanks a lot!

Original comment by gtempacc...@yahoo.com on 5 Apr 2009 at 8:04

GoogleCodeExporter commented 9 years ago
OK, committed.

I deleted a few "public" tokens, added a README and TODO to the java directory.

Here are the public classes/interfaces currently exported by the package:

BadFormatterError.java
9:public class BadFormatterError extends CompilationError {
CompilationError.java
8:public class CompilationError extends JSONTemplateError {
ConfigurationError.java
4:public class ConfigurationError extends CompilationError {
DefaultFormatters.java
5:public class DefaultFormatters {
DefaultProgramBuilder.java
5:public class DefaultProgramBuilder implements IProgramBuilder {
EvaluationError.java
4:public class EvaluationError extends JSONTemplateError {
IFormatter.java
3:public interface IFormatter {
IFormatterResolver.java
3:public interface IFormatterResolver {
IProgramBuilder.java
4:public interface IProgramBuilder {
ITemplateRenderCallback.java
3:public interface ITemplateRenderCallback {
JSONTemplateError.java
8:public class JSONTemplateError extends RuntimeException {
MissingFormatter.java
4:public class MissingFormatter extends CompilationError {
Template.java
23:public class Template {
TemplateCompileOptions.java
3:public class TemplateCompileOptions {
TemplateCompiler.java
8:public class TemplateCompiler {
TemplateSyntaxError.java
4:public class TemplateSyntaxError extends CompilationError {
UndefinedVariable.java
4:public class UndefinedVariable extends EvaluationError {

So, basically the errors, TemplateCompiler, TemplateCompilerOptions, 
ProgramBuilder, 
and for extensibility, the interfaces IProgramBuilder, IFormatter, 
IFormatterResolver, and ITemplateRenderCallback.

The requirements are documented in the README. It's been tested with Apple's 
Java 5 
and 6. 

About Unicode, I must admit that I have no experience dealing with it. Do you 
have 
any test cases that check Unicode handling?

Original comment by william....@gmail.com on 6 Apr 2009 at 12:31

GoogleCodeExporter commented 9 years ago
I'm closing this issue since it's in... I haven't seen as much feedback as I'd 
like
on the Java version though.  Are you using it for any of your personal projects 
that
you could share as examples?

And I opened up a separate bug about unicode test cases.  We definitely need 
those.

In Python there are 2 different string types -- str() and unicode(), and it 
matters
to the *internal* API too.  The testy.py tests can unfortunately only test a 
byte
stream really.

Thanks again.

Original comment by gtempacc...@yahoo.com on 10 Apr 2009 at 12:28

GoogleCodeExporter commented 9 years ago

Original comment by gtempacc...@yahoo.com on 10 Apr 2009 at 12:28

GoogleCodeExporter commented 9 years ago
I'm not actually using it for any personal projects (although the recently 
released 
GAE/Java seems like a nice place to use it), just did it for fun. I'll try to 
restructure the directories / build process first then make some examples 
(probably 
as jUnit tests and some webapp/JSP example). 

Original comment by william....@gmail.com on 10 Apr 2009 at 1:30

GoogleCodeExporter commented 9 years ago
Hi, I just downloaded the Java implementation and I plan to start using it on a 
real project.
If you don't mind, I would like to reorganize the package structure and I'm 
happy to contribute with the TODOs.

I'll let you know how it goes.

Cheers!

Original comment by matias...@gmail.com on 19 Jan 2011 at 11:22

GoogleCodeExporter commented 9 years ago
I tried to run Test.java using the attached file and I got the following 
Exception:

EXCEPTION: EvaluationError
jsontemplate.EvaluationError: pushSection called when current cursor value is 
not a map (is: {   "url-base": "http://example.com/music/",    "playlist-name": 
"Epic Playlist",    "songs": [     {       "url": "1.mp3",        "artist": 
"Grayceon",        "title": "Sounds Like Thunder"     },      {       "url": 
"2.mp3",        "artist": "Thou",        "title": "Their Hooves Carve Craters 
in the Earth"     }   ] })
    at jsontemplate.ScopedContext.pushSection(ScopedContext.java:22)
    at jsontemplate.SectionStatement.execute(SectionStatement.java:14)
    at jsontemplate.TemplateExecutor.execute(TemplateExecutor.java:10)
    at jsontemplate.Template.render(Template.java:52)
    at jsontemplate.Template.expand(Template.java:65)
    at jsontemplate_test.Test.main(Test.java:65)

The contents of the template and the dictionary are exactly what is shown as 
example in the intro page.
Can you give me a hint on what I am doing wrong?

Thanks!

Original comment by matias...@gmail.com on 19 Jan 2011 at 12:24

Attachments:

GoogleCodeExporter commented 9 years ago
Hi Matias, the dictionary's value is supposed to be an actual dictionary, not a 
string representation of a dictionary, so:

"dictionary": {"url-base": "...", "playlist-name": "...", "songs": [ {...} ] }

that should work.

Hope this helps,
William

Original comment by william....@gmail.com on 24 Jan 2011 at 6:48