[Yanel-commits] rev 50173 - in public/yanel/trunk/src/contributions/resources/yanel-user: src/java/org/wyona/yanel/impl/resources xslt

michi at wyona.com michi at wyona.com
Thu Jun 3 23:04:52 CEST 2010


Author: michi
Date: 2010-06-03 23:04:52 +0200 (Thu, 03 Jun 2010)
New Revision: 50173

Modified:
   public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/YanelUserResource.java
   public/yanel/trunk/src/contributions/resources/yanel-user/xslt/yanel-user-profile.xsl
Log:
XML generation refactored

Modified: public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/YanelUserResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/YanelUserResource.java	2010-06-03 18:44:45 UTC (rev 50172)
+++ public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/YanelUserResource.java	2010-06-03 21:04:52 UTC (rev 50173)
@@ -120,10 +120,7 @@
      * submitDelete - Result of deleting the user
      */
     public View getView(String viewId) throws Exception {
-
         View defaultView = new View();
-        File xmlFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile().getAbsolutePath(), "xml" + File.separator + "yanel-user-profile.xml");
-
         try {
 
             File xslFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile().getAbsolutePath(), "xslt" + File.separator + "yanel-user-profile.xsl");
@@ -197,14 +194,14 @@
             }
             defaultView.setMimeType(getMimeType(viewId));
             if (viewId != null && viewId.equals("xml")) {
-                defaultView.setInputStream(new java.io.FileInputStream(xmlFile));
+                defaultView.setInputStream(getXMLAsStream());
             } else {
                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
                 String backToRealm = org.wyona.yanel.core.util.PathUtil.backToRealm(getPath());
                 String reservedPrefix = yanel.getReservedPrefix();
                 transformer.setParameter("yanel.back2realm", backToRealm);
                 transformer.setParameter("yanel.reservedPrefix", reservedPrefix);
-                transformer.transform(new javax.xml.transform.stream.StreamSource(xmlFile), new StreamResult(baos));
+                transformer.transform(new javax.xml.transform.stream.StreamSource(getXMLAsStream()), new StreamResult(baos));
                 defaultView.setInputStream(new java.io.ByteArrayInputStream(baos.toByteArray()));
             }
         } catch (Exception e) {
@@ -219,8 +216,17 @@
      * @see org.wyona.yanel.core.api.attributes.ViewableV2#exists()
      */
     public boolean exists() throws Exception {
-        log.warn("Not implemented yet!");
-        return true;
+        String userId = getUserId();
+        if (userId != null) {
+            if (realm.getIdentityManager().getUserManager().getUser(userId) != null) {
+                return true;
+            } else {
+                log.error("No such user: " + userId);
+            }
+        } else {
+            log.error("No user ID!");
+        }
+        return false;
     }
 
     /**
@@ -618,4 +624,30 @@
 
         return success;
     }
+
+    /**
+     * Get XML as stream
+     */
+    private java.io.InputStream getXMLAsStream() throws Exception {
+        String userId = getUserId();
+        if (userId != null) {
+            User user = realm.getIdentityManager().getUserManager().getUser(userId);
+            StringBuilder sb = new StringBuilder();
+
+            sb.append("<?xml version=\"1.0\"?>");
+            sb.append("<user id=\"" + userId + "\" email=\"" + user.getEmail() + "\">");
+            sb.append("</user>");
+            //sb.append("<form name=\"user-profile-form\"/>");
+
+            return new java.io.StringBufferInputStream(sb.toString());
+        } else {
+            return new java.io.StringBufferInputStream("<no-user-id/>");
+        }
+
+
+/*
+        File xmlFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile().getAbsolutePath(), "xml" + File.separator + "yanel-user-profile.xml");
+        return new java.io.FileInputStream(xmlFile);
+*/
+    }
 }

Modified: public/yanel/trunk/src/contributions/resources/yanel-user/xslt/yanel-user-profile.xsl
===================================================================
--- public/yanel/trunk/src/contributions/resources/yanel-user/xslt/yanel-user-profile.xsl	2010-06-03 18:44:45 UTC (rev 50172)
+++ public/yanel/trunk/src/contributions/resources/yanel-user/xslt/yanel-user-profile.xsl	2010-06-03 21:04:52 UTC (rev 50173)
@@ -10,7 +10,9 @@
 
   <xsl:param name="userId" select="''"/>
   <xsl:param name="userName" select="''"/>
+<!-- DEPRECATED
   <xsl:param name="email" select="''"/>
+-->
   <xsl:param name="user-profile-language" select="'IS_NULL'"/>
   <xsl:param name="expiration-date" select="'IS_NULL'"/>
   <xsl:param name="description" select="'TODO'"/>
@@ -46,7 +48,10 @@
               User Profile of <xsl:value-of select="$userId"/>
             </h1>
               <xsl:call-template name="show-message"/>     
+<!--
               <xsl:apply-templates select="form"/>
+-->
+              <xsl:apply-templates select="user"/>
             </div></td></tr></table>
           </body>
         </xsl:otherwise>
@@ -54,7 +59,10 @@
     </html>
   </xsl:template>  
 
+  <xsl:template match="user">
+<!--
   <xsl:template match="form">
+-->
     <h2>Change Password</h2>
     <form name="user-password-form" method="post" action="#">
       <p>
@@ -99,7 +107,10 @@
           <tr>
             <td>E-Mail:</td>
             <td>
+              <input type="text" name="email" value="{@email}"/>
+<!-- DEPRECATED
               <input type="text" name="email" value="{$email}"/>
+-->
             </td>
           </tr>
           <tr>



More information about the Yanel-commits mailing list