[rfc][icedtea-web] bringing applets out of browser (part1)

Jacob Wisor gitne at gmx.de
Wed Dec 17 08:16:17 UTC 2014


Hello again! :-)

On 12/16/2014 04:37 PM, Jiri Vanek wrote:
> On 12/12/2014 07:55 PM, gitne at gmx.de wrote:
> 
> Hi!
> 
> I have included fixes for your nits to original thread - 
> http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2014-December/030245.html

Okay, thanks.

> >> […]
>>> +            s.append("  </resources>\n");
>>> +            s.append("  <applet-desc\n");
>>> +            s.append("    name='").append(getTitle()).append("'\n");
>>> +         s.append("    main-class='").append(getStrippedMain()).append("'\n");
>>> +         s.append("    width='").append(getApplet().getWidth()).append("'\n");
>>> +         s.append("    height='").append(getApplet().getHeight()).append("'>\n");
>>
>> Try merging strings into one string where possible here.
>>
>>> +         if (!getApplet().getParameters().isEmpty()){
>>> +             Set<Map.Entry<String,String>>  prms = getApplet().getParameters().entrySet();
>>> +             for (Map.Entry<String, String> entry : prms) {
>>> +                 s.append("    <param name='").append(entry.getKey()).append("' value='").append(entry.getValue
>>> ()).append("'/>\n");
>>> +             }
>>> +         }
>>> +           s.append("  </applet-desc>\n");
>>> +            s.append("</jnlp>\n");
>>
>> The strings in these last two statements here can be merged into one too.
> 
> Hm:( If you wont something like:
> 
>   -           s.append("  </applet-desc>\n");
>   -            s.append("</jnlp>\n");
>   +           s.append("  </applet-desc>\n</jnlp>\n");
> 
> Then I'm quite against. The original paragraphs seems much more readable to me:(

Well, you can still do this:

-           s.append("  </applet-desc>\n");
-           s.append("</jnlp>\n");
+           s.append("  </applet-desc>\n" +
+                    "</jnlp>\n");

This is how you do multi-line strings in Java. It works because final (or literal) string concatenations are processed at compile-time by the compiler. In your example, the string is concatenated or rather built (appended) by StringBuilder at run-time. These two notations are functionally equivalent but do have a different impact at run-time.

> 
>> Also, please concatenate the append operations with the derefenrence operator where possible. You can still group the
>> string building process into logical chunks using line breaks for better readability. ;-) This produces much better code
>> quality utilizing the stack which leads to higher performance. StringBuilder and the append() method have been developed
>> exactly for this kind of purpose.
> 
> Yah! Fixed. thank you for this reminder!
> 
> 
> Shortly:
> 
> public String toJnlp(boolean needSecurity, boolean useHref, boolean fix) {
> +        if (useJNLPHref && debugJnlp != null && useHref) {
> +            OutputController.getLogger().log("Using debugjnlp as return value toJnlp");
> +            if (fix) {
> +                return fixCommonIsuses(needSecurity, debugJnlp);
> +            } else {
> +                return debugJnlp;
> +            }
> +        } else {
> +            StringBuilder s = new StringBuilder();
> +            s.append("<?xml version='1.0' encoding='UTF-8'?>\n")
> +                    .append("<jnlp codebase='").append(getCodeBase().toString()).append("'")
> +                    .append(">\n")
> +                    .append("  <information>\n")
> +                    .append("    <title>").append(createJnlpTitle()).append("</title>\n")
> +                    .append("    <vendor>").append(createJnlpVendor()).append("</vendor>\n")
> +                    .append("  </information>\n");
> +            if (needSecurity) {
> +                s.append(getSecurityElement());
> +            }
> +            s.append("  <resources>\n");
> +            for (String i : getArchiveJars()) {
> +                s.append("    <jar href='").append(i).append("' />\n");
> +            }
> +            s.append("  </resources>\n")
> +                    .append("  <applet-desc\n")
> +                    .append("    name='").append(getTitle()).append("'\n")
> +                    .append("    main-class='").append(getStrippedMain()).append("'\n")
> +                    .append("    width='").append(getApplet().getWidth()).append("'\n")
> +                    .append("    height='").append(getApplet().getHeight()).append("'>\n");
> +            if (!getApplet().getParameters().isEmpty()) {
> +                Set<Map.Entry<String, String>> prms = getApplet().getParameters().entrySet();
> +                for (Map.Entry<String, String> entry : prms) {
> +                    s.append("    <param name='").append(entry.getKey()).append("' 
> value='").append(entry.getValue()).append("'/>\n");
> +                }
> +            }
> +            s.append("  </applet-desc>\n")
> +                    .append("</jnlp>\n");
> +            OutputController.getLogger().log("toJnlp generated:");
> +            OutputController.getLogger().log(s.toString());
> +            return s.toString();
> +        }
> +
> +    }
> +
> 
> 
> Is current version. Multilines kept, references fixed.

Yep, looks much nicer now. ;-)

Jacob


More information about the distro-pkg-dev mailing list