adrnsoh / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

RFE: integrated Expression Language for JSON #95

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice to have sun's old "Expression Language for Java ME" integrated 
in C1.  

http://meapplicationdevelopers.java.net/mobileajax.html

Original issue reported on code.google.com by 1815...@coolman.ca on 15 Mar 2012 at 4:18

GoogleCodeExporter commented 9 years ago
Since we have our own JSON parser that would be somewhat of a duplication, 
integrating that library with our parser would probably be impractical since 
our JSON parser is quite different.

Original comment by shai.almog on 15 Mar 2012 at 6:47

GoogleCodeExporter commented 9 years ago
If you change your mind, I converted the Sun expression language library to 
work with Codename One's json parser.  Attached is the updated source with a 
demo.  I just despise traversing trees so this thing makes it much friendlier, 
like XSLT is to DOMs

Original comment by 1815...@coolman.ca on 16 Mar 2012 at 8:44

Attachments:

GoogleCodeExporter commented 9 years ago
That's great ;-)

I'd like to add it but since the original authors didn't quite document it and 
I'm not really familiar with it can you write a couple of short documentation 
blurbs for the package/class explaining the purpose and a common use case?
I would probably refactor it into the io.util package for consistency.

Is XML supported or only JSON?

Original comment by shai.almog on 16 Mar 2012 at 9:19

GoogleCodeExporter commented 9 years ago
Sure, will do. 

It doesn't support XML, personally I'd love to find a ME compatible XPath 
processor for that.  This Expression Language utility is a very minimal subset 
of what XPath does.  It should also work against any deeply nested Hashtable 
where arrays are stored as vectors,

One feature I just remembered I didn't convert was their 'pretty printer' which 
lets you select a fragment of a JSON document... will include that with the 
update.

Original comment by 1815...@coolman.ca on 16 Mar 2012 at 5:06

GoogleCodeExporter commented 9 years ago
Here's the updated source, documented, refactored, and with the pretty printer 
included.  Use cases documented at the method level.  Added a demo of the 
pretty printer output to the console.

Original comment by 1815...@coolman.ca on 16 Mar 2012 at 10:05

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks! This will land in the next update, I'll commit it in my next checkin.

Original comment by shai.almog on 17 Mar 2012 at 7:10

GoogleCodeExporter commented 9 years ago
Cool, thanks.  I've updated it to support both the XML and JSON parsers, and 
also supports much more of XPath syntax,ie. almost everything on this page 
works now:

http://www.w3schools.com/xpath/xpath_syntax.asp

Would you consider the package name: com.codename1.path?

Original comment by 1815...@coolman.ca on 17 Mar 2012 at 7:57

GoogleCodeExporter commented 9 years ago
I don't mind changing the package name but looking a bit at the code we have 3 
public classes of which I would probably remove the ResultException since it 
seems redundant (why not use a generic IOException?).
Does it warrant a dedicated package?

Original comment by shai.almog on 18 Mar 2012 at 4:27

GoogleCodeExporter commented 9 years ago
The ResultException was Sun's class, IOException works for me.  
There's a number of new (private implementation) classes now to handle all 
types of predicate expressions. There will only be one public class.   The 
reason I suggested moving to com.codename1.path is because it's not really an 
IO tool, it's for processing structured data, and also no longer specific to 
either JSON or XML. 

Original comment by 1815...@coolman.ca on 18 Mar 2012 at 6:23

GoogleCodeExporter commented 9 years ago
There are right now two public classes with the pretty printer (or was that 
intended as a private class?).
I committed a version to SVN, still under the IO package. 
I was thinking about moving it to something like a "processing" package, which 
can be used in the future for features such as regular expressions, validation 
language etc.
Will that work for you?

Original comment by shai.almog on 18 Mar 2012 at 7:09

GoogleCodeExporter commented 9 years ago
The processing package idea sounds perfect.  The pretty printer is a private 
class and the util class is gone now.  I moved all private classes to a 
subpackage of *.processing.impl.

Original comment by 1815...@coolman.ca on 18 Mar 2012 at 8:04

GoogleCodeExporter commented 9 years ago
If the private classes are in a separate package they have to be public which 
means they will appear in code completion. We generally prefer having package 
private classes rather than an impl package except in the special case of the 
implementation classes. I'll refactor to processing.

Original comment by shai.almog on 18 Mar 2012 at 8:11

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Oh right, good point, I moved them back and made them all package scope.  
Attached is the updated source with comments, included the theme.res which has 
the data files for the demo.

Original comment by 1815...@coolman.ca on 18 Mar 2012 at 10:36

Attachments:

GoogleCodeExporter commented 9 years ago
Forgot to update the comments in the main Result class to reflect changing path 
separator from dot to slash.

Original comment by 1815...@coolman.ca on 18 Mar 2012 at 11:19

Attachments:

GoogleCodeExporter commented 9 years ago
I'm getting the following compilation errors with your latest version:
Compiling 11 source files to /Users/user2/dev/cn1/CodenameOne/build/classes
/Users/user2/dev/cn1/CodenameOne/src/com/codename1/processing/TextEvaluator.java
:47: cannot find symbol
symbol  : method fromContent(com.codename1.processing.StructuredContent)
location: class com.codename1.processing.Result
        Result result = Result.fromContent(element.getChild(0));
                              ^
/Users/user2/dev/cn1/CodenameOne/src/com/codename1/processing/TextEvaluator.java
:72: cannot find symbol
symbol  : method fromContent(com.codename1.processing.StructuredContent)
location: class com.codename1.processing.Result
        Result result = Result.fromContent(element.getChild(0));
                              ^
/Users/user2/dev/cn1/CodenameOne/src/com/codename1/processing/TextEvaluator.java
:98: cannot find symbol
symbol  : method fromContent(com.codename1.processing.StructuredContent)
location: class com.codename1.processing.Result
        Result result = Result.fromContent(element.getChild(0));
                              ^
/Users/user2/dev/cn1/CodenameOne/src/com/codename1/processing/TextEvaluator.java
:122: cannot find symbol
symbol  : method fromContent(com.codename1.processing.StructuredContent)
location: class com.codename1.processing.Result
        Result result = Result.fromContent(element.getChild(0));
                              ^
4 errors

Original comment by shai.almog on 19 Mar 2012 at 4:31

GoogleCodeExporter commented 9 years ago
That's strange, that method is package private (because StructuredContent is 
private), yet I just tried again and it still compiles clean on my machine.  
Can you change the static method fromPublic(StructuredContent) to public and 
try compiling again?

Original comment by 1815...@coolman.ca on 19 Mar 2012 at 4:52

GoogleCodeExporter commented 9 years ago
Are you sync'd with the current SVN that I committed?
I noticed your package didn't include the package.html file

Original comment by shai.almog on 19 Mar 2012 at 5:16

GoogleCodeExporter commented 9 years ago
No, my svn access is read-only so my workspace project wasn't in sync with it, 
didn't notice it was committed.  I just noticed as well the message said it was 
compiling 11 source files, there should be 13 (11 classes, 2 interfaces, not 
including the demo).

Original comment by 1815...@coolman.ca on 19 Mar 2012 at 5:31

GoogleCodeExporter commented 9 years ago
I think you removed/renamed files which is fine. The compilation issue didn't 
come from one of those files though.
Can you sync the changes I made (mostly docs, and exceptions). Even with a read 
only SVN you can still diff to see the changes between local and remote.

Original comment by shai.almog on 19 Mar 2012 at 6:00

GoogleCodeExporter commented 9 years ago
Here's a diff patch against the latest in svn, hopefully that works better. For 
some reason the patch won't pick up the one deletion.. ResultUtil class should 
be deleted.

Original comment by 1815...@coolman.ca on 19 Mar 2012 at 10:23

Attachments:

GoogleCodeExporter commented 9 years ago
The patch file you generated includes the trunk directory I don't have. Can you 
just zip up the files like before only make sure they are up to date with SVN?
Thanks.

Original comment by shai.almog on 19 Mar 2012 at 11:28

GoogleCodeExporter commented 9 years ago
Hopefully we've got it this time - this is taking more effort than writing it :)

Original comment by 1815...@coolman.ca on 19 Mar 2012 at 10:18

Attachments:

GoogleCodeExporter commented 9 years ago
That is usually the bigger problem with these sort of projects... You have no 
idea how bad this was in Sun/Oracle.

This now compiles fine and seems OK to commit, but I noticed allot of the files 
have no copyright or attribution of any sort. Did you take them from somewhere 
or did you write them yourself?
You didn't remove an existing copyright clause by any chance?

Original comment by shai.almog on 20 Mar 2012 at 6:24

GoogleCodeExporter commented 9 years ago
I wrote all code except for Result, ResultTokenizer and PrettyPrinter, in which 
I left Sun's copyright intact and made note of the derivative work in those 3 
files.  All other files are usable standalone of the Sun code, and I contribute 
them under the same GPL2+Classpath exception to ensure compatibility with CN1.  
I'm not restricted by any company for contributing to OSS at this time.

Original comment by 1815...@coolman.ca on 20 Mar 2012 at 6:40

GoogleCodeExporter commented 9 years ago
I'm just sticking this slightly modified copyright clause at the top with your 
name prepended to our brand.

/*
 * Copyright (c) 2012, Eric Coolman, Codename One and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Codename One designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *  
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 * 
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 * Please contact Codename One through http://www.codenameone.com/ if you 
 * need additional information or have any questions.
 */

Original comment by shai.almog on 20 Mar 2012 at 7:02

GoogleCodeExporter commented 9 years ago
Perfect, thanks Shai!

Original comment by 1815...@coolman.ca on 20 Mar 2012 at 7:32