Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 68831 invoked from network); 3 Nov 2009 23:32:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 3 Nov 2009 23:32:48 -0000 Received: (qmail 18750 invoked by uid 500); 3 Nov 2009 23:32:48 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 18700 invoked by uid 500); 3 Nov 2009 23:32:48 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 18691 invoked by uid 99); 3 Nov 2009 23:32:48 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Nov 2009 23:32:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Nov 2009 23:32:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EB8C823888D8; Tue, 3 Nov 2009 23:32:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r832603 - /sling/trunk/contrib/scripting/jst/src/main/java/org/apache/sling/scripting/jst/HtmlCodeGenerator.java Date: Tue, 03 Nov 2009 23:32:15 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091103233215.EB8C823888D8@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Tue Nov 3 23:32:14 2009 New Revision: 832603 URL: http://svn.apache.org/viewvc?rev=832603&view=rev Log: Remove redundant null check Modified: sling/trunk/contrib/scripting/jst/src/main/java/org/apache/sling/scripting/jst/HtmlCodeGenerator.java Modified: sling/trunk/contrib/scripting/jst/src/main/java/org/apache/sling/scripting/jst/HtmlCodeGenerator.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/jst/src/main/java/org/apache/sling/scripting/jst/HtmlCodeGenerator.java?rev=832603&r1=832602&r2=832603&view=diff ============================================================================== --- sling/trunk/contrib/scripting/jst/src/main/java/org/apache/sling/scripting/jst/HtmlCodeGenerator.java (original) +++ sling/trunk/contrib/scripting/jst/src/main/java/org/apache/sling/scripting/jst/HtmlCodeGenerator.java Tue Nov 3 23:32:14 2009 @@ -46,15 +46,15 @@ import org.w3c.dom.Document; import org.xml.sax.InputSource; -/** Generates HTML code for JST templates */ +/** Generates HTML code for JST templates */ class HtmlCodeGenerator { private final List libraryScripts = new LinkedList(); private final HtmlContentRenderer htmlRenderer; private final Logger log = LoggerFactory.getLogger(getClass()); - + // TODO should be configurable or synced with the actual location public final static String SLING_JS_PATH = "/system/sling.js"; - + /** Property names to use to build the page title, in order of preference */ public final static String [] TITLE_PROPERTY_NAMES = { "title", @@ -66,21 +66,21 @@ libraryScripts.add(SLING_JS_PATH); htmlRenderer = new HtmlContentRenderer(); } - - /** Generate HTML code for the given request and script path */ - void generateHtml(SlingHttpServletRequest request, String scriptPath, - InputStream scriptStream, PrintWriter output) + + /** Generate HTML code for the given request and script path */ + void generateHtml(SlingHttpServletRequest request, String scriptPath, + InputStream scriptStream, PrintWriter output) throws RepositoryException, JSONException, ScriptException, IOException { - + // access our data (need a Node) final Resource r = request.getResource(); final Node n = r.adaptTo(Node.class); final String pageTitle = getTitle(r, n); - - // Parse script using the NekoHTML permissive HTML parser + + // Parse script using the NekoHTML permissive HTML parser final DOMParser parser = new DOMParser(); try { - parser.setFeature("http://xml.org/sax/features/namespaces", false); + parser.setFeature("http://xml.org/sax/features/namespaces", false); parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower"); parser.setProperty("http://cyberneko.org/html/properties/names/attrs", "lower"); parser.parse(new InputSource(scriptStream)); @@ -90,7 +90,7 @@ throw se; } final Document template = parser.getDocument(); - + // compute default rendering final StringWriter defaultRendering = new StringWriter(); if(n!=null) { @@ -98,7 +98,7 @@ htmlRenderer.render(pw, r, n, pageTitle); pw.flush(); } - + // compute currentNode values in JSON format final StringWriter jsonData = new StringWriter(); if(n != null) { @@ -106,15 +106,11 @@ final JsonItemWriter j = new JsonItemWriter(null); final int maxRecursionLevels = 1; pw.print("var currentNode="); - if(n!=null) { - j.dump(n, pw, maxRecursionLevels); - } else { - pw.print("{}"); - } + j.dump(n, pw, maxRecursionLevels); pw.print(";"); pw.flush(); } - + // run XSLT transform on script, passing parameter // for our computed values final String xslt = "/xslt/script-transform.xsl"; @@ -133,26 +129,26 @@ final Result result = new StreamResult(output); final DOMSource source = new DOMSource(template); t.transform(source, result); - + } catch (Exception e) { final ScriptException se = new ScriptException("Error in XSLT transform for " + scriptPath); se.initCause(e); throw se; - + } finally { xslTransform.close(); } } - + /** Return the full path to supplied resource */ static String fullPath (SlingHttpServletRequest request, String path) { return SlingRequestPaths.getContextPath(request) + SlingRequestPaths.getServletPath(request) + path; } - - /** Return the title to use for the generated page */ + + /** Return the title to use for the generated page */ protected String getTitle(Resource r, Node n) { String title = null; - + if(n != null) { for(String name : TITLE_PROPERTY_NAMES) { try { @@ -162,20 +158,20 @@ title = s; break; } - } + } } catch(RepositoryException re) { log.warn("RepositoryException in getTitle()", re); } } } - + if(title == null) { title = r.getPath(); if(title.startsWith("/")) { title = title.substring(1); } } - + return title; } }