This method retrieves a globally defined {@link ComponentType} (a @@ -756,16 +845,6 @@ _debug = Boolean.valueOf(flag); } - protected static void closeStream(InputStream is) { - if (is != null) { - try { - is.close(); - } catch (Exception e) { - // ignore - } - } - } - /** *
This map contains sub-class specific attributes that may be needed * by specific implementations of cvs diff: src/java/com/sun/jsftemplating/layout/facelets/DbFactory.java is a new entry, no comparison available cvs diff: src/java/com/sun/jsftemplating/layout/facelets/FaceletsClasspathEntityResolver.java is a new entry, no comparison available Index: src/java/com/sun/jsftemplating/layout/facelets/FaceletsLayoutDefinitionReader.java =================================================================== RCS file: /cvs/jsftemplating/src/java/com/sun/jsftemplating/layout/facelets/FaceletsLayoutDefinitionReader.java,v retrieving revision 1.14 diff -u -r1.14 FaceletsLayoutDefinitionReader.java --- src/java/com/sun/jsftemplating/layout/facelets/FaceletsLayoutDefinitionReader.java 19 Apr 2007 01:26:03 -0000 1.14 +++ src/java/com/sun/jsftemplating/layout/facelets/FaceletsLayoutDefinitionReader.java 25 Apr 2007 19:40:50 -0000 @@ -27,14 +27,11 @@ import java.net.URL; import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; /** * @author Jason Lee @@ -46,252 +43,220 @@ private Document document; public FaceletsLayoutDefinitionReader(String key, URL url) { - try{ - this.key = key; - this.url = url; - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - dbf.setValidating(false); - dbf.setIgnoringComments(true); - dbf.setIgnoringElementContentWhitespace(false); - dbf.setCoalescing(false); - // The opposite of creating entity ref nodes is expanding inline - dbf.setExpandEntityReferences(true); - - DocumentBuilder builder = dbf.newDocumentBuilder(); - builder.setErrorHandler(new ParsingErrorHandler()); - InputStream is = new BufferedInputStream(this.url.openStream()); - document = builder.parse(is); - is.close(); - } catch (Exception e) { - throw new LayoutDefinitionException(e); - } + InputStream is = null; + try{ + this.key = key; + this.url = url; + + DocumentBuilder builder = DbFactory.getInstance(); + builder.setErrorHandler(new ParsingErrorHandler()); + is = new BufferedInputStream(this.url.openStream()); + document = builder.parse(is); + is.close(); + } catch (Exception e) { + throw new LayoutDefinitionException(e); + } finally { + LayoutDefinitionManager.closeStream(is); + } } public LayoutDefinition read() throws IOException { - LayoutDefinition layoutDefinition = new LayoutDefinition(key); - NodeList nodeList = document.getChildNodes(); - boolean abortProcessing = false; - for (int i = 0; i < nodeList.getLength() && (abortProcessing != true); i++) { - abortProcessing = process(layoutDefinition, nodeList.item(i), false); - } - return layoutDefinition; + LayoutDefinition layoutDefinition = new LayoutDefinition(key); + NodeList nodeList = document.getChildNodes(); + boolean abortProcessing = false; + for (int i = 0; i < nodeList.getLength() && (abortProcessing != true); i++) { + abortProcessing = process(layoutDefinition, nodeList.item(i), false); + } + return layoutDefinition; } public boolean process(LayoutElement parent, Node node, boolean nested) throws IOException { - boolean abortProcessing = false; - LayoutElement element = null; - LayoutElement newParent = parent; - boolean endElement = false; - - String value = node.getNodeValue(); -// System.out.println(node.getNodeName() + ": '" + node.getNodeType() + "' = '" + value + "'"); - // TODO: find out what "name" should be in the ctors - switch (node.getNodeType()) { - case Node.TEXT_NODE : - if (!value.trim().equals("")) { - element = new LayoutStaticText(parent, - LayoutElementUtil.getGeneratedId(node.getNodeName()), - value); - } - break; - case Node.ELEMENT_NODE: - element = createComponent(parent, node, nested); + boolean abortProcessing = false; + LayoutElement element = null; + LayoutElement newParent = parent; + boolean endElement = false; + + String value = node.getNodeValue(); +// System.out.println(node.getNodeName() + ": '" + node.getNodeType() + "' = '" + value + "'"); +// TODO: find out what "name" should be in the ctors + switch (node.getNodeType()) { + case Node.TEXT_NODE : + if (!value.trim().equals("")) { + element = new LayoutStaticText(parent, + LayoutElementUtil.getGeneratedId(node.getNodeName()), + value); + } + break; + case Node.ELEMENT_NODE: + element = createComponent(parent, node, nested); if (element instanceof LayoutStaticText) { // We have a element node that needs to be static text endElement = true; } else if (element instanceof LayoutComponent) { nested = true; newParent = element; - } else if (element instanceof LayoutComposition) { + } else if (element instanceof LayoutComposition) { abortProcessing = true; newParent = element; - } else if (element instanceof LayoutDefine) { + } else if (element instanceof LayoutDefine) { newParent = element; - } else if (element instanceof LayoutInsert) { + } else if (element instanceof LayoutInsert) { newParent = element; - } -// FIXME: Jason, this code may need to be refactored. I think almost -// FIXME: everything should have newParent = element. The problem comes when -// FIXME: you are turning and into 2 separate staticText -// FIXME: components. This should be a single component, then it could contain -// FIXME: children also. You may want a to create a component like Woodstock's -// FIXME: "markup" component to do this. - break; - default: - // just because... :P - } - - if (element != null) { - parent.addChildLayoutElement(element); - - NodeList nodeList = node.getChildNodes(); - boolean abortChildProcessing = false; - for (int i = 0; i < nodeList.getLength() && (abortChildProcessing != true); i++) { - abortChildProcessing = process(newParent, nodeList.item(i), nested); - } - if (abortChildProcessing == true) { - abortProcessing = abortChildProcessing; - }else { - - if (endElement) { - String nodeName = node.getNodeName(); - element = new LayoutStaticText(parent, LayoutElementUtil.getGeneratedId(nodeName), "" + nodeName + ">"); - parent.addChildLayoutElement(element); - } - } - } + } +// FIXME: Jason, this code may need to be refactored. I think almost +// FIXME: everything should have newParent = element. The problem comes when +// FIXME: you are turning and into 2 separate staticText +// FIXME: components. This should be a single component, then it could contain +// FIXME: children also. You may want a to create a component like Woodstock's +// FIXME: "markup" component to do this. + break; + default: + // just because... :P + } + + if (element != null) { + parent.addChildLayoutElement(element); + + NodeList nodeList = node.getChildNodes(); + boolean abortChildProcessing = false; + for (int i = 0; i < nodeList.getLength() && (abortChildProcessing != true); i++) { + abortChildProcessing = process(newParent, nodeList.item(i), nested); + } + if (abortChildProcessing == true) { + abortProcessing = abortChildProcessing; + }else { + + if (endElement) { + String nodeName = node.getNodeName(); + element = new LayoutStaticText(parent, LayoutElementUtil.getGeneratedId(nodeName), "" + nodeName + ">"); + parent.addChildLayoutElement(element); + } + } + } - return abortProcessing; + return abortProcessing; } private LayoutElement createComponent(LayoutElement parent, Node node, boolean nested) { - LayoutElement element = null; - String nodeName = node.getNodeName(); + LayoutElement element = null; + String nodeName = node.getNodeName(); NamedNodeMap attrs = node.getAttributes(); Node nameNode = attrs.getNamedItem("id"); String id = (nameNode != null) ? nameNode.getNodeValue() : LayoutElementUtil.getGeneratedId(nodeName); - if ("ui:composition".equals(nodeName)) { - parent = parent.getLayoutDefinition(); // parent to the LayoutDefinition - parent.getChildLayoutElements().clear(); // a ui:composition clears everything outside of it - LayoutComposition lc = new LayoutComposition(parent, id); - String template = attrs.getNamedItem("template").getNodeValue(); - lc.setTemplate(template); - element = lc; - } else if ("ui:define".equals(nodeName)) { - String name = attrs.getNamedItem("name").getNodeValue(); - element = new LayoutDefine(parent, name); - } else if ("ui:insert".equals(nodeName)) { - LayoutInsert li = new LayoutInsert(parent, id); - String name = attrs.getNamedItem("name").getNodeValue(); - li.setName(name); - element = li; - } else if ("ui:component".equals(nodeName)) { - } else if ("ui:debug".equals(nodeName)) { - } else if ("ui:decorate".equals(nodeName)) { - LayoutComposition lc = new LayoutComposition(parent, id, true); - String template = attrs.getNamedItem("template").getNodeValue(); - lc.setTemplate(template); - element = lc; - } else if ("ui:fragment".equals(nodeName)) { - } else if ("ui:include".equals(nodeName)) { - } else if ("ui:param".equals(nodeName)) { - } else if ("ui:remove".equals(nodeName)) { - // Let the element remain null - } else if ("ui:repeat".equals(nodeName)) { - } else if ("ui:event".equals(nodeName)) { - // per Ken, we need to append "/>" to allow the handler parser code - // to end correctly - //String body = node.getNodeValue() +"/>"; - String body = node.getTextContent(); + if ("ui:composition".equals(nodeName)) { + parent = parent.getLayoutDefinition(); // parent to the LayoutDefinition + parent.getChildLayoutElements().clear(); // a ui:composition clears everything outside of it + LayoutComposition lc = new LayoutComposition(parent, id); + String template = attrs.getNamedItem("template").getNodeValue(); + lc.setTemplate(template); + element = lc; + } else if ("ui:define".equals(nodeName)) { + String name = attrs.getNamedItem("name").getNodeValue(); + element = new LayoutDefine(parent, name); + } else if ("ui:insert".equals(nodeName)) { + LayoutInsert li = new LayoutInsert(parent, id); + Node nameAttr = attrs.getNamedItem("name"); + String name = (nameAttr != null) ? nameAttr.getNodeValue() : null; + li.setName(name); + element = li; + } else if ("ui:component".equals(nodeName)) { + } else if ("ui:debug".equals(nodeName)) { + } else if ("ui:decorate".equals(nodeName)) { + LayoutComposition lc = new LayoutComposition(parent, id, true); + String template = attrs.getNamedItem("template").getNodeValue(); + lc.setTemplate(template); + element = lc; + } else if ("ui:fragment".equals(nodeName)) { + } else if ("ui:include".equals(nodeName)) { + } else if ("ui:param".equals(nodeName)) { + } else if ("ui:remove".equals(nodeName)) { + // Let the element remain null + } else if ("ui:repeat".equals(nodeName)) { + } else if ("ui:event".equals(nodeName)) { + // per Ken, we need to append "/>" to allow the handler parser code + // to end correctly + String body = node.getTextContent(); body = (body == null) ? "/>" : (body.trim() + "/>"); - String eventName = node.getAttributes().getNamedItem("type").getNodeValue(); - InputStream is = new ByteArrayInputStream(body.getBytes()); - EventParserCommand command = new EventParserCommand(); - try { - TemplateParser parser = new TemplateParser(is); - parser.open(); // Needed to initialize things. - // Setup the reader... - TemplateReader reader = new TemplateReader("foo", parser); // TODO: get a real ID - reader.pushTag("event"); // The tag will be popped at the end - // Read the handlers... - command.process(new BaseProcessingContext(), - new ProcessingContextEnvironment(reader, parent, true), eventName); - // Clean up - parser.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } finally { - if (is != null) { - try { - is.close(); - } catch (Exception e) { - // ignore - } - } - } - } else { + String eventName = node.getAttributes().getNamedItem("type").getNodeValue(); + InputStream is = new ByteArrayInputStream(body.getBytes()); + EventParserCommand command = new EventParserCommand(); + try { + TemplateParser parser = new TemplateParser(is); + parser.open(); // Needed to initialize things. + // Setup the reader... + TemplateReader reader = new TemplateReader("foo", parser); // TODO: get a real ID + reader.pushTag("event"); // The tag will be popped at the end + // Read the handlers... + command.process(new BaseProcessingContext(), + new ProcessingContextEnvironment(reader, parent, true), eventName); + // Clean up + parser.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + if (is != null) { + try { + is.close(); + } catch (Exception e) { + // ignore + } + } + } + } else { LayoutComponent lc = null; - ComponentType componentType = LayoutDefinitionManager.getGlobalComponentType(nodeName); - if (componentType == null) { - String value = node.getNodeValue(); - if (value == null) { - value = ""; - } -// FIXME: This needs to account for beginning and ending tags.... - lc = new LayoutStaticText(parent, id, - "<" + nodeName + buildAttributeList(node) + ">"); - } else { - lc = new LayoutComponent(parent, id, componentType); - addAttributesToComponent(lc, node); -// FIXME: Because of the way pages are composed in facelets, the parent -// FIXME: LayoutComponent may not exist in this LD. In that case it is not -// FIXME: a "facet child", but it appears to be according to the following -// FIXME: method. We need a better way to mark children as facets or real -// FIXME: children. This may even require diverging the LD into 1 for -// FIXME: components and 1 for pages. :( For now I am commenting it out and -// FIXME: defaulting to false. -// LayoutElementUtil.checkForFacetChild(parent, lc); - } + ComponentType componentType = LayoutDefinitionManager.getGlobalComponentType(nodeName); + if (componentType == null) { + String value = node.getNodeValue(); + if (value == null) { + value = ""; + } +// FIXME: This needs to account for beginning and ending tags.... + lc = new LayoutStaticText(parent, id, + "<" + nodeName + buildAttributeList(node) + ">"); + } else { + lc = new LayoutComponent(parent, id, componentType); + addAttributesToComponent(lc, node); +// FIXME: Because of the way pages are composed in facelets, the parent +// FIXME: LayoutComponent may not exist in this LD. In that case it is not +// FIXME: a "facet child", but it appears to be according to the following +// FIXME: method. We need a better way to mark children as facets or real +// FIXME: children. This may even require diverging the LD into 1 for +// FIXME: components and 1 for pages. :( For now I am commenting it out and +// FIXME: defaulting to false. +// LayoutElementUtil.checkForFacetChild(parent, lc); + } lc.setFacetChild(false); lc.setNested(nested); element = lc; - } + } - return element; + return element; } private void addAttributesToComponent (LayoutComponent lc, Node node) { - NamedNodeMap map = node.getAttributes(); - for (int i = 0; i < map.getLength(); i++) { - Node attr = map.item(i); - lc.addOption(attr.getNodeName(), attr.getNodeValue()); - } + NamedNodeMap map = node.getAttributes(); + for (int i = 0; i < map.getLength(); i++) { + Node attr = map.item(i); + lc.addOption(attr.getNodeName(), attr.getNodeValue()); + } } private String buildAttributeList(Node node) { - StringBuilder attrs = new StringBuilder(); + StringBuilder attrs = new StringBuilder(); - NamedNodeMap map = node.getAttributes(); - for (int i = 0; i < map.getLength(); i++) { - Node attr = map.item(i); - attrs.append(" ") - .append(attr.getNodeName()) - .append("=\"") - .append(attr.getNodeValue()) - .append("\""); - } + NamedNodeMap map = node.getAttributes(); + for (int i = 0; i < map.getLength(); i++) { + Node attr = map.item(i); + attrs.append(" ") + .append(attr.getNodeName()) + .append("=\"") + .append(attr.getNodeValue()) + .append("\""); + } - return attrs.toString(); + return attrs.toString(); } -} - - -class ParsingErrorHandler implements org.xml.sax.ErrorHandler { - //Log logger = LogFactory.getLog(this.getClass()); - - public ParsingErrorHandler() { - super(); - // TODO Auto-generated constructor stub - } - - public void warning(SAXParseException arg0) throws SAXException { -// logger.warn(arg0.getMessage()); - } - - public void error(SAXParseException arg0) throws SAXException { - //logger.error(arg0.getMessage()); - fatalError(arg0); - } - - public void fatalError(SAXParseException arg0) throws SAXException { -// logger.error(arg0.getMessage()); - System.err.println (arg0.getMessage()); -// System.exit(-1); - } - -} +} \ No newline at end of file cvs diff: src/java/com/sun/jsftemplating/layout/facelets/ParsingErrorHandler.java is a new entry, no comparison available cvs diff: src/java/com/sun/jsftemplating/layout/facelets/facelet-taglib_1_0.dtd is a new entry, no comparison available cvs diff: src/java/com/sun/jsftemplating/layout/facelets/xhtml-lat1.ent is a new entry, no comparison available cvs diff: src/java/com/sun/jsftemplating/layout/facelets/xhtml-special.ent is a new entry, no comparison available cvs diff: src/java/com/sun/jsftemplating/layout/facelets/xhtml-symbol.ent is a new entry, no comparison available cvs diff: src/java/com/sun/jsftemplating/layout/facelets/xhtml1-transitional.dtd is a new entry, no comparison available Index: src/java/com/sun/jsftemplating/util/Util.java =================================================================== RCS file: /cvs/jsftemplating/src/java/com/sun/jsftemplating/util/Util.java,v retrieving revision 1.11 diff -u -r1.11 Util.java --- src/java/com/sun/jsftemplating/util/Util.java 19 Apr 2007 23:00:30 -0000 1.11 +++ src/java/com/sun/jsftemplating/util/Util.java 25 Apr 2007 19:43:51 -0000 @@ -22,6 +22,7 @@ */ package com.sun.jsftemplating.util; +import java.io.InputStream; import java.util.Locale; import java.util.Map; import java.util.Properties; @@ -201,21 +202,37 @@ } /** *
This method strips leading delimeter.
- * + * */ - protected static String stripLeadingDelimeter(String str, char ch) { - if(str == null || str.equals("")) { - return str; - } - int j = 0; - char[] strArr = str.toCharArray(); - for(int i=0; i < strArr.length; i++) { - j=i; - if(strArr[i] != ch) { - break; - } - } - return str.substring(j); - - } + protected static String stripLeadingDelimeter(String str, char ch) { + if(str == null || str.equals("")) { + return str; + } + int j = 0; + char[] strArr = str.toCharArray(); + for(int i=0; i < strArr.length; i++) { + j=i; + if(strArr[i] != ch) { + break; + } + } + return str.substring(j); + + } + + /** + * Closes an InputStream if it is non-null, throwing away any Exception + * that may occur + * @param is + */ + public static void closeStream(InputStream is) { + if (is != null) { + try { + is.close(); + } catch (Exception e) { + // ignore + } + } + } + } Index: test/java/com/sun/jsftemplating/layout/LayoutDefinitionManagerTest.java =================================================================== RCS file: /cvs/jsftemplating/test/java/com/sun/jsftemplating/layout/LayoutDefinitionManagerTest.java,v retrieving revision 1.5 diff -u -r1.5 LayoutDefinitionManagerTest.java --- test/java/com/sun/jsftemplating/layout/LayoutDefinitionManagerTest.java 2 Apr 2007 23:31:28 -0000 1.5 +++ test/java/com/sun/jsftemplating/layout/LayoutDefinitionManagerTest.java 25 Apr 2007 18:07:30 -0000 @@ -22,11 +22,7 @@ */ package com.sun.jsftemplating.layout; -import com.sun.jsftemplating.component.factory.basic.StaticTextFactory; -import com.sun.jsftemplating.layout.descriptors.ComponentType; -import com.sun.jsftemplating.layout.descriptors.handler.HandlerDefinition; - -import junit.framework.*; +import com.sun.jsftemplating.component.factory.basic.StaticTextFactory;import com.sun.jsftemplating.layout.descriptors.ComponentType;import com.sun.jsftemplating.layout.descriptors.handler.HandlerDefinition;import java.util.Map;import junit.framework.TestCase; /** @@ -55,7 +51,7 @@ ex.printStackTrace(); fail(ex.getMessage()); } - } + } public void testReadFaceletsTagLibXml() { assertNotNull(LayoutDefinitionManager.getGlobalComponentTypes().get("http://java.sun.com/jsf/extensions/dynafaces:scripts")); } /** *Test to ensure we can read global {@link HandlerDefinition}s.
Index: test/java/com/sun/jsftemplating/layout/facelets/FaceletsLayoutDefinitionReaderTest.java =================================================================== RCS file: /cvs/jsftemplating/test/java/com/sun/jsftemplating/layout/facelets/FaceletsLayoutDefinitionReaderTest.java,v retrieving revision 1.3 diff -u -r1.3 FaceletsLayoutDefinitionReaderTest.java --- test/java/com/sun/jsftemplating/layout/facelets/FaceletsLayoutDefinitionReaderTest.java 3 Apr 2007 19:24:07 -0000 1.3 +++ test/java/com/sun/jsftemplating/layout/facelets/FaceletsLayoutDefinitionReaderTest.java 25 Apr 2007 19:55:53 -0000 @@ -20,10 +20,14 @@ * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. */ + package com.sun.jsftemplating.layout.facelets; + import java.net.URL; import junit.framework.TestCase; + import com.sun.jsftemplating.layout.descriptors.LayoutDefinition; + /** * *@@ -31,14 +35,18 @@ *
* */ + public class FaceletsLayoutDefinitionReaderTest extends TestCase { + /** * * * */ protected void setUp() { + } + /** * ******************************************************************** * SECTION: New Files ******************************************************************* SEE ATTACHMENTS