ICEfaces
  1. ICEfaces
  2. ICE-5831

Sparkle: New utility method for building parameter strings

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-Alpha2
    • Fix Version/s: 2.0-Beta2, 2.0.0
    • Component/s: ICE-Components
    • Labels:
      None
    • Environment:
      ICEfaces 2.0, Sparkle component platform
    • Affects:
      Documentation (User Guide, Ref. Guide, etc.)

      Description

      Should have a utility API that builds the parameter strings, performs param escaping.

      - Yip suggests that the JSON "stringify" function would suffice, if we can implement one.
      - param builder API should not send parameters that have the default value
      - param builder API should not send parameters for disabled features
      - API should perform escaping for security and correctness

        Activity

        Ken Fyten created issue -
        Ken Fyten made changes -
        Field Original Value New Value
        Salesforce Case []
        Fix Version/s 2.0-Beta [ 10231 ]
        Affects [Documentation (User Guide, Ref. Guide, etc.)]
        Assignee Priority P2
        Assignee Yip Ng [ yip.ng ]
        Hide
        Mark Collette added a comment - - edited

        http://www.json.org/

        After discussing the pros and cons of (A) creating a Map of parameters and serialising that to a JSON string; and (B) programmatically calling methods on a ResponseWriter-esque helper object to generate the JSON string; we've chosen (B). Here is the suggestion for how to implement that idea.

        Say we want to output a string that creates a javascript map, with a nested map, as well as String, integer and boolean values:

        {a:

        {b:true,c:'hi'}

        ,d:25}

        Re-written with more white-space, for greater clarity:

        {
        a:

        { b:true, c:'hi' }

        ,
        d:25
        }

        We could make use of a utility object, that provides an API similar to StringBuilder, but javascript variable oriented, instead of char oriented:

        JSONBuilder builder = new JSONBuilder();
        builder.beginMap().
        beginMap("a").
        entry("b", true).
        entry("c", "hi").
        endMap().
        entry("d", 25).
        endMap();
        String json = builder.toString();

        Or, slightly more succinctly:

        String json = JSONBuilder.create().
        beginMap().
        beginMap("a").
        entry("b", true).
        entry("c", "hi").
        endMap().
        entry("d", 25).
        endMap().toString();

        All the methods in JSONBuilder return the reference to itself, to simplify further operations on it. JSONBuilder.create() just makes a new instance. Every JSONBuilder internally uses a StringBuilder, whose toString() is returned by JSONBuilder.toString().

        beginMap() just appends: "{"
        beginMap(String key) appends: key + "

        {" endMap() appends: "}

        "

        There would be versions of entry(String key, X value) that take: int, long, float, double, boolean, String. They basically append: key + ":" + value. The String one adds quotes and does JSON string escaping, like how the link above describes.

        beginMap(String key) and entry(String key, X value) need to use some internal state for managing when to append a comma.

        Show
        Mark Collette added a comment - - edited http://www.json.org/ After discussing the pros and cons of (A) creating a Map of parameters and serialising that to a JSON string; and (B) programmatically calling methods on a ResponseWriter-esque helper object to generate the JSON string; we've chosen (B). Here is the suggestion for how to implement that idea. Say we want to output a string that creates a javascript map, with a nested map, as well as String, integer and boolean values: {a: {b:true,c:'hi'} ,d:25} Re-written with more white-space, for greater clarity: { a: { b:true, c:'hi' } , d:25 } We could make use of a utility object, that provides an API similar to StringBuilder, but javascript variable oriented, instead of char oriented: JSONBuilder builder = new JSONBuilder(); builder.beginMap(). beginMap("a"). entry("b", true). entry("c", "hi"). endMap(). entry("d", 25). endMap(); String json = builder.toString(); Or, slightly more succinctly: String json = JSONBuilder.create(). beginMap(). beginMap("a"). entry("b", true). entry("c", "hi"). endMap(). entry("d", 25). endMap().toString(); All the methods in JSONBuilder return the reference to itself, to simplify further operations on it. JSONBuilder.create() just makes a new instance. Every JSONBuilder internally uses a StringBuilder, whose toString() is returned by JSONBuilder.toString(). beginMap() just appends: "{" beginMap(String key) appends: key + " {" endMap() appends: "} " There would be versions of entry(String key, X value) that take: int, long, float, double, boolean, String. They basically append: key + ":" + value. The String one adds quotes and does JSON string escaping, like how the link above describes. beginMap(String key) and entry(String key, X value) need to use some internal state for managing when to append a comma.
        Hide
        Mark Collette added a comment -

        We should consider putting this class in glimmer, for us to use beyond sparkle, since glimmer core is hand-rolling similar code in places like org.icefaces.event.BridgeSetup.

        Show
        Mark Collette added a comment - We should consider putting this class in glimmer, for us to use beyond sparkle, since glimmer core is hand-rolling similar code in places like org.icefaces.event.BridgeSetup.
        Mark Collette made changes -
        Salesforce Case []
        Security Private [ 10001 ]
        Mark Collette made changes -
        Link This issue blocks ICE-5847 [ ICE-5847 ]
        Hide
        Mark Collette added a comment -

        In ICE-5830, Mircea describes a new utility class he added called ScriptWriter. In theory, we could augment that, or just use this in conjunction with that, for outputting our escaped javascript.

        Show
        Mark Collette added a comment - In ICE-5830 , Mircea describes a new utility class he added called ScriptWriter. In theory, we could augment that, or just use this in conjunction with that, for outputting our escaped javascript.
        Repository Revision Date User Message
        ICEsoft Public SVN Repository #21852 Tue Jul 06 16:12:23 MDT 2010 yip.ng ICE-5831: Sparkle: New utility method for building parameter strings.
        Files Changed
        Commit graph ADD /icefaces/scratchpads/sparkle/component/src/org/icefaces/component/utils/JSONBuilder.java
        Commit graph MODIFY /icefaces/scratchpads/sparkle/component/src/org/icefaces/component/selectinputdate/SelectInputDateRenderer.java
        Hide
        yip.ng added a comment - - edited

        Usage:

        import org.icefaces.component.utils.JSONBuilder;

        JSONBuilder.create().
        beginMap().
        entry("dateStr", dateStr).
        beginMap("hrMin").
        entry("selectedHour", selectedHour).
        entry("selectedMinute", selectedMinute).
        endMap().
        entry("hourField", hourField).
        beginMap("amPm").
        entry("amPmStr", amPmStr).
        entry("amStr", amPmStrings[0]).
        entry("pmStr", amPmStrings[1]).
        endMap().
        entry("renderAsPopup", renderAsPopup).
        entry("renderInputField", renderInputField).
        entry("singleSubmit", singleSubmit).
        entry("ariaEnabled", ariaEnabled).
        endMap().toString();

        Output:

        {"dateStr":"Jul\/07\/2010 01:41 PM","hrMin":

        {"selectedHour":"01","selectedMinute":"41"}

        ,"hourField":"HOUR1","amPm":

        {"amPmStr":"PM","amStr":"AM","pmStr":"PM"}

        ,"renderAsPopup":false,"renderInputField":false,"singleSubmit":false,"ariaEnabled":true}

        Requirements for default values and disabled features in separate JIRA: ICE-5847.

        Show
        yip.ng added a comment - - edited Usage: import org.icefaces.component.utils.JSONBuilder; JSONBuilder.create(). beginMap(). entry("dateStr", dateStr). beginMap("hrMin"). entry("selectedHour", selectedHour). entry("selectedMinute", selectedMinute). endMap(). entry("hourField", hourField). beginMap("amPm"). entry("amPmStr", amPmStr). entry("amStr", amPmStrings [0] ). entry("pmStr", amPmStrings [1] ). endMap(). entry("renderAsPopup", renderAsPopup). entry("renderInputField", renderInputField). entry("singleSubmit", singleSubmit). entry("ariaEnabled", ariaEnabled). endMap().toString(); Output: {"dateStr":"Jul\/07\/2010 01:41 PM","hrMin": {"selectedHour":"01","selectedMinute":"41"} ,"hourField":"HOUR1","amPm": {"amPmStr":"PM","amStr":"AM","pmStr":"PM"} ,"renderAsPopup":false,"renderInputField":false,"singleSubmit":false,"ariaEnabled":true} Requirements for default values and disabled features in separate JIRA: ICE-5847.
        yip.ng made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Repository Revision Date User Message
        ICEsoft Public SVN Repository #21859 Wed Jul 07 15:32:18 MDT 2010 yip.ng ICE-5831: Sparkle: New utility method for building parameter strings.
        Files Changed
        Commit graph MODIFY /icefaces/scratchpads/sparkle/component/src/org/icefaces/component/utils/JSONBuilder.java
        Hide
        Ken Fyten added a comment -

        This class requires JavaDoc.

        Show
        Ken Fyten added a comment - This class requires JavaDoc.
        Ken Fyten made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Repository Revision Date User Message
        ICEsoft Public SVN Repository #21866 Thu Jul 08 09:50:05 MDT 2010 yip.ng ICE-5831: Sparkle: New utility method for building parameter strings.
        Files Changed
        Commit graph MODIFY /icefaces/scratchpads/sparkle/component/src/org/icefaces/component/utils/JSONBuilder.java
        yip.ng made changes -
        Attachment screenshot-01.png [ 12427 ]
        Attachment screenshot-02.png [ 12428 ]
        Hide
        yip.ng added a comment -

        Done. See screenshots 1 and 2.

        Show
        yip.ng added a comment - Done. See screenshots 1 and 2.
        yip.ng made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Repository Revision Date User Message
        ICEsoft Public SVN Repository #21876 Thu Jul 08 15:56:34 MDT 2010 judy.guglielmin update for ICE-5831 and ICE-5830
        Files Changed
        Commit graph MODIFY /icefaces/scratchpads/sparkle/component/src/org/icefaces/component/menubutton/MenuButtonRenderer.java
        Ken Fyten made changes -
        Fix Version/s 2.0-Beta2 [ 10242 ]
        Fix Version/s 2.0-Beta1 [ 10231 ]
        Ken Fyten made changes -
        Security Private [ 10001 ]
        Ken Fyten made changes -
        Fix Version/s 2.0.0 [ 10230 ]
        Ken Fyten made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Assignee Priority P2

          People

          • Assignee:
            yip.ng
            Reporter:
            Ken Fyten
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: