My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 6: Java version available
2 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Apr 2009


 
Reported by william....@gmail.com, Apr 5, 2009
Hi, I translated the python implementation to Java. Maybe you're 
interested in including it?

http://codereview.appspot.com/33078
Apr 5, 2009
Project Member #1 gtempacc...@yahoo.com
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!

Status: Accepted
Apr 6, 2009
#2 william....@gmail.com
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?
Apr 9, 2009
Project Member #3 gtempacc...@yahoo.com
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.

Apr 9, 2009
Project Member #4 gtempacc...@yahoo.com
(No comment was entered for this change.)
Status: Fixed
Apr 9, 2009
#5 william....@gmail.com
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). 
Jan 19, 2011
#6 matias...@gmail.com
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!
Jan 19, 2011
#7 matias...@gmail.com
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!

songs.json
729 bytes   View   Download
Jan 23, 2011
#8 william....@gmail.com
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

Powered by Google Project Hosting