[Yanel-commits] rev 21834 - in public/yanel/trunk/src: core/java/org/wyona/yanel/servlet webapp/xslt

michi at wyona.com michi at wyona.com
Wed Jan 17 12:31:55 CET 2007


Author: michi
Date: 2007-01-17 12:31:54 +0100 (Wed, 17 Jan 2007)
New Revision: 21834

Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java
   public/yanel/trunk/src/webapp/xslt/xmlInfo2xhtml.xsl
Log:
namespace added

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java	2007-01-17 11:26:25 UTC (rev 21833)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java	2007-01-17 11:31:54 UTC (rev 21834)
@@ -78,6 +78,7 @@
     File xsltLoginScreen;
 
     private static String IDENTITY_KEY = "identity";
+    private static String NAMESPACE = "http://www.wyona.org/yanel/1.0";
 
     private static final String METHOD_PROPFIND = "PROPFIND";
     private static final String METHOD_OPTIONS = "OPTIONS";
@@ -179,11 +180,12 @@
 
         org.w3c.dom.Document doc = null;
         javax.xml.parsers.DocumentBuilderFactory dbf= javax.xml.parsers.DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
         try {
             javax.xml.parsers.DocumentBuilder parser = dbf.newDocumentBuilder();
             org.w3c.dom.DOMImplementation impl = parser.getDOMImplementation();
             org.w3c.dom.DocumentType doctype = null;
-            doc = impl.createDocument("http://www.wyona.org/yanel/1.0", "yanel", doctype);
+            doc = impl.createDocument(NAMESPACE, "yanel", doctype);
         } catch(Exception e) {
             log.error(e.getMessage(), e);
             throw new ServletException(e.getMessage());
@@ -200,9 +202,9 @@
         //log.debug("contextPath: " + request.getContextPath());
         //log.debug("servletPath: " + request.getServletPath());
         
-        Element requestElement = (Element) rootElement.appendChild(doc.createElement("request"));
-        requestElement.setAttribute("uri", request.getRequestURI());
-        requestElement.setAttribute("servlet-path", request.getServletPath());
+        Element requestElement = (Element) rootElement.appendChild(doc.createElementNS(NAMESPACE, "request"));
+        requestElement.setAttributeNS(NAMESPACE, "uri", request.getRequestURI());
+        requestElement.setAttributeNS(NAMESPACE, "servlet-path", request.getServletPath());
 
         HttpSession session = request.getSession(true);
         Element sessionElement = (Element) rootElement.appendChild(doc.createElement("session"));
@@ -310,9 +312,9 @@
                             String message = "No such node exception: " + e;
                             log.warn(e);
                             //log.error(e.getMessage(), e);
-                            Element exceptionElement = (Element) rootElement.appendChild(doc.createElement("exception"));
+                            Element exceptionElement = (Element) rootElement.appendChild(doc.createElementNS(NAMESPACE, "exception"));
                             exceptionElement.appendChild(doc.createTextNode(message));
-                            exceptionElement.setAttribute("status", "404");
+                            exceptionElement.setAttributeNS(NAMESPACE, "status", "404");
                             response.setStatus(javax.servlet.http.HttpServletResponse.SC_NOT_FOUND);
                             setYanelOutput(request, response, doc);
                             return;
@@ -1340,7 +1342,7 @@
             javax.xml.parsers.DocumentBuilder parser = dbf.newDocumentBuilder();
             org.w3c.dom.DOMImplementation impl = parser.getDOMImplementation();
             org.w3c.dom.DocumentType doctype = null;
-            doc = impl.createDocument("http://www.wyona.org/yanel/1.0", "yanel", doctype);            
+            doc = impl.createDocument(NAMESPACE, "yanel", doctype);            
             
             Element rootElement = doc.getDocumentElement();
             

Modified: public/yanel/trunk/src/webapp/xslt/xmlInfo2xhtml.xsl
===================================================================
--- public/yanel/trunk/src/webapp/xslt/xmlInfo2xhtml.xsl	2007-01-17 11:26:25 UTC (rev 21833)
+++ public/yanel/trunk/src/webapp/xslt/xmlInfo2xhtml.xsl	2007-01-17 11:31:54 UTC (rev 21834)
@@ -3,10 +3,13 @@
 <xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xhtml="http://www.w3.org/1999/xhtml"
+  xmlns="http://www.w3.org/1999/xhtml"
+  xmlns:yanel="http://www.wyona.org/yanel/1.0"
   xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
-  xmlns="http://www.w3.org/1999/xhtml"
 >
 
+  <!-- TODO: Isn't there a more standardized i18n namespace? -->
+
   <xsl:output method="xhtml" encoding="UTF-8"/>
 
   <xsl:template match="/">
@@ -15,10 +18,10 @@
             <title>
               Yanel
               <xsl:choose>
-                <xsl:when test="/yanel/exception/@status = '404'">
+                <xsl:when test="/yanel:yanel/yanel:exception/@yanel:status = '404'">
                   - 404
                 </xsl:when>
-                <xsl:when test="child::node()/exception">
+                <xsl:when test="child::node()/yanel:exception">
                   <i18n:text>- An error occurred</i18n:text>
                 </xsl:when>
                 <xsl:otherwise>
@@ -31,7 +34,10 @@
 
               <h1>Yanel
               <xsl:choose>
-                <xsl:when test="child::node()/exception">
+                <xsl:when test="/yanel:yanel/yanel:exception/@yanel:status = '404'">
+                  <i18n:text>- 404</i18n:text>
+                </xsl:when>
+                <xsl:when test="child::node()/yanel:exception">
                   <i18n:text>- An error occurred</i18n:text>
                 </xsl:when>
                 <xsl:otherwise>
@@ -41,7 +47,7 @@
               </h1>
 
               <xsl:choose>
-                <xsl:when test="child::node()/exception">
+                <xsl:when test="child::node()/yanel:exception">
                   <p><a href="?yanel.format=xml">Show XML source</a> </p>
                 </xsl:when>
                 <xsl:otherwise>
@@ -49,14 +55,14 @@
                 </xsl:otherwise>
               </xsl:choose>
 
-              <xsl:apply-templates select="child::node()/exception"/>
+              <xsl:apply-templates select="child::node()/yanel:exception"/>
 
             <p>
               <h4>Servlet Context Real Path</h4>
               <xsl:value-of select="child::node()/@servlet-context-real-path"/>
             </p>
 
-            <xsl:apply-templates select="child::node()/request"/>
+            <xsl:apply-templates select="child::node()/yanel:request"/>
             <xsl:apply-templates select="child::node()/session"/>
             <xsl:apply-templates select="child::node()/resource-type-identifier"/>
             <xsl:apply-templates select="child::node()/no-resource-type-identifier"/>
@@ -66,12 +72,12 @@
         </html>
   </xsl:template>
   
-  <xsl:template match="request">
+  <xsl:template match="yanel:request">
     <p>
     <h4>Request:</h4>
     <ul>
-      <li>Servlet Path: <xsl:value-of select="@servlet-path"/></li>
-      <li>URI: <xsl:value-of select="@uri"/></li>
+      <li>Servlet Path: <xsl:value-of select="@yanel:servlet-path"/></li>
+      <li>URI: <xsl:value-of select="@yanel:uri"/></li>
     </ul>
     </p>
   </xsl:template>
@@ -150,16 +156,16 @@
       </p>     
   </xsl:template>
   
-  <xsl:template match="exception">
+  <xsl:template match="yanel:exception">
     <p>
       <xsl:choose>
-        <xsl:when test="@status = '404'">
-        No such page:  <xsl:value-of select="../request/@uri"/>
+        <xsl:when test="@yanel:status = '404'">
+        No such page:  <xsl:value-of select="/yanel:yanel/yanel:request/@yanel:uri"/>
         </xsl:when>
         <xsl:otherwise>
       <h4>Exception</h4>
       <ul>
-        <xsl:if test="@status"><li>Status: <xsl:value-of select="@status"/></li></xsl:if>
+        <xsl:if test="@yanel:status"><li>Status: <xsl:value-of select="@yanel:status"/></li></xsl:if>
         <li>Error Message: 
           <ul>
             <li><xsl:value-of select="."/></li>




More information about the Yanel-commits mailing list