[Yanel-commits] rev 20302 - in public/yanel/trunk: conf src/contributions/resources/contact-form src/contributions/resources/contact-form/src src/contributions/resources/contact-form/src/build src/contributions/resources/contact-form/src/java src/contributions/resources/contact-form/src/java/org src/contributions/resources/contact-form/src/java/org/wyona src/contributions/resources/contact-form/src/java/org/wyona/yanel src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources src/realms/yanel-website/content src/realms/yanel-website/content/contact-form src/realms/yanel-website/content/rtd src/realms/yanel-website/paths/en src/realms/yanel-website/paths/en/contact.html src/realms/yanel-website/paths/en/contact.html.yanel-rti

josias at wyona.com josias at wyona.com
Fri Nov 24 12:20:58 CET 2006


Author: josias
Date: 2006-11-24 12:20:56 +0100 (Fri, 24 Nov 2006)
New Revision: 20302

Added:
   public/yanel/trunk/src/contributions/resources/contact-form/build.xml
   public/yanel/trunk/src/contributions/resources/contact-form/resource.xml
   public/yanel/trunk/src/contributions/resources/contact-form/src/
   public/yanel/trunk/src/contributions/resources/contact-form/src/build/
   public/yanel/trunk/src/contributions/resources/contact-form/src/build/build.properties
   public/yanel/trunk/src/contributions/resources/contact-form/src/build/dependencies.xml
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactBean.java
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/SendMail.java
   public/yanel/trunk/src/realms/yanel-website/content/contact-form/
   public/yanel/trunk/src/realms/yanel-website/content/contact-form/en.xhtml
   public/yanel/trunk/src/realms/yanel-website/content/introspection-contact-form.xml
   public/yanel/trunk/src/realms/yanel-website/content/rtd/contact-form.rtd
   public/yanel/trunk/src/realms/yanel-website/paths/en/contact.html.yanel-rti/
   public/yanel/trunk/src/realms/yanel-website/paths/en/contact.html.yanel-rti/.yarep-uid
   public/yanel/trunk/src/realms/yanel-website/paths/en/contact.html/
   public/yanel/trunk/src/realms/yanel-website/paths/en/contact.html/.yarep-uid
Modified:
   public/yanel/trunk/conf/yanel.xml
Log:
applied patch for bug #5056: contact form resource

Modified: public/yanel/trunk/conf/yanel.xml
===================================================================
--- public/yanel/trunk/conf/yanel.xml	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/conf/yanel.xml	2006-11-24 11:20:56 UTC (rev 20302)
@@ -13,6 +13,7 @@
   <resource src="../src/resources/invoice/"                     compile="true"/>
   <resource src="../src/contributions/resources/atom/"          compile="true"/>
   <resource src="../src/contributions/resources/atom-entry/"    compile="true"/>
+  <resource src="../src/contributions/resources/contact-form/"  compile="true"/>
   <resource src="../src/contributions/resources/wiki/"          compile="true"/>
   <resource src="../src/contributions/resources/zip/"           compile="true"/>
   <resource src="../src/resources/websearch/"                   compile="true"/>

Added: public/yanel/trunk/src/contributions/resources/contact-form/build.xml
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/build.xml	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/contributions/resources/contact-form/build.xml	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+
+<project name="yanel-resource" default="compile">
+
+  <import file="src/build/dependencies.xml"/>
+
+  <target name="init" description="Initialize build" depends="dependencies">
+    <echo>Initialize build</echo>
+
+    <dirname property="resource.home.dir" file="${ant.file}"/>
+    <echo>Resource Home Directory: ${resource.home.dir}</echo>
+
+    <property file="${resource.home.dir}/src/build/local.build.properties"/>
+    <property file="${resource.home.dir}/src/build/build.properties"/>
+
+    <path id="classpath">
+      <pathelement path="${maven2.cp}"/>
+      <pathelement path="${maven2.resource.cp}"/>
+    </path>
+    <property name="resource.build.dir" value="${resource.home.dir}/build"/>
+    <property name="resource.classes.dir" value="${resource.build.dir}/classes"/>
+    <property name="resource.lib.dir" value="${resource.build.dir}/lib"/>
+    <property name="resource.java.dir" value="${resource.home.dir}/src/java"/>
+  </target>
+
+  <target name="compile" description="Compile Java classes" depends="init">
+
+    <mkdir dir="${resource.classes.dir}"/>
+    <javac srcdir="${resource.java.dir}" destdir="${resource.classes.dir}"
+      classpathref="classpath"
+      debug="true"
+    />
+    <mkdir dir="${resource.lib.dir}"/>
+    <jar destfile="${resource.lib.dir}/yanel-resource-${resource.name}-${resource.version}.jar"
+      basedir="${resource.classes.dir}"
+    />
+  </target>
+
+  <target name="clean" depends="init">
+    <delete dir="${resource.build.dir}"/>
+  </target>
+
+  <target name="copy-dependencies" depends="init">
+    <copy todir="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/lib">
+      <fileset refid="maven2.resource.fileset"/>
+      <mapper type="flatten"/>
+    </copy>
+  </target>
+</project>


Property changes on: public/yanel/trunk/src/contributions/resources/contact-form/build.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/contact-form/resource.xml
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/resource.xml	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/contributions/resources/contact-form/resource.xml	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+
+<resource xmlns="http://www.wyona.org/yanel/1.0"
+  name="contact-form"
+  namespace="http://www.wyona.org/yanel/resource/1.0"
+  class="org.wyona.yanel.impl.resources.ContactResource"
+  >
+<description>
+Contact Form for sending email
+</description>
+
+<!--
+<rtd>
+  <property name="xslt"/>
+  <property name="mime-type"/>
+  <property name="feed-title"/>
+  <property name="entries-path"/>
+</rtd>
+-->
+</resource>


Property changes on: public/yanel/trunk/src/contributions/resources/contact-form/resource.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/contact-form/src/build/build.properties
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/src/build/build.properties	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/contributions/resources/contact-form/src/build/build.properties	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1,2 @@
+resource.name=contact-form
+resource.version=0.0.1-dev-rXXX


Property changes on: public/yanel/trunk/src/contributions/resources/contact-form/src/build/build.properties
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/contact-form/src/build/dependencies.xml
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/src/build/dependencies.xml	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/contributions/resources/contact-form/src/build/dependencies.xml	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+
+<project name="contact-form-dependencies" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
+
+  <target name="dependencies" description="Dependencies">
+    <!-- INFO: http://maven.apache.org/ant-tasks.html -->
+    <artifact:remoteRepository id="wyona.remote.repository" url="http://www.wyona.org/maven2/"/>
+
+    <artifact:dependencies pathId="maven2.classpath" filesetId="maven2.fileset">
+      <remoteRepository refid="wyona.remote.repository"/>
+      <dependency groupId="javax.servlet" artifactId="servlet-api" version="2.3"
+        scope="provided"/>
+      <dependency groupId="log4j" artifactId="log4j" version="1.2.8"/>
+      <dependency groupId="wyona-org-yanel" artifactId="yanel-core"
+        version="${yanel.source.version}"/>
+      <dependency groupId="yarep" artifactId="yarep" version="0.0.1-dev-r17381"/>
+      <dependency groupId="wyona-org-commons" artifactId="wyona-org-commons"
+        version="0.0.1-dev-r17376"/>
+    </artifact:dependencies>
+
+    <artifact:dependencies pathId="maven2.resource.classpath" filesetId="maven2.resource.fileset">
+      <remoteRepository refid="wyona.remote.repository"/>
+      <dependency groupId="javax.activation" artifactId="activation" version="1.1"/>
+      <dependency groupId="javax.mail" artifactId="mail" version="1.4"/>
+    </artifact:dependencies>
+
+    <property name="maven2.cp" refid="maven2.classpath"/>
+    <!--<echo>Maven2 classpath: ${maven2.cp}</echo>-->
+     <property name="maven2.resource.cp" refid="maven2.resource.classpath"/>
+  </target>
+
+</project>


Property changes on: public/yanel/trunk/src/contributions/resources/contact-form/src/build/dependencies.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactBean.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactBean.java	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactBean.java	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1,38 @@
+package org.wyona.yanel.impl.resources;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class ContactBean {
+    String company, lastName, firstName, address, city, email, message;
+    
+    public String getAddress() {
+        return address;
+    }
+    public String getEmail() {
+        return email;
+    }
+    public String getCompany() {
+        return company;
+    }
+    public String getMessage() {
+        return message;
+    }
+    public String getFirstName() {
+        return firstName;
+    }
+    public String getCity() {
+        return city;
+    }
+    public String getLastName() {
+        return lastName;
+    }
+    public ContactBean(HttpServletRequest request) {
+        company = request.getParameter("company");
+        firstName  = request.getParameter("firstName");
+        lastName = request.getParameter("lastName");
+        address  = request.getParameter("address");
+        city  = request.getParameter("city");
+        email  = request.getParameter("email");
+        message = request.getParameter("message");
+    }
+}


Property changes on: public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactBean.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1,423 @@
+/*
+ * Copyright 2006 Wyona
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.wyona.org/licenses/APACHE-LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.wyona.yanel.impl.resources;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.StringReader;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.log4j.Category;
+import org.wyona.yanel.core.Path;
+import org.wyona.yanel.core.Resource;
+import org.wyona.yanel.core.api.attributes.ViewableV1;
+import org.wyona.yanel.core.attributes.viewable.View;
+import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
+import org.wyona.yarep.core.NoSuchNodeException;
+import org.wyona.yarep.core.Repository;
+import org.wyona.yarep.core.RepositoryFactory;
+import org.wyona.yarep.util.RepoPath;
+import org.wyona.yarep.util.YarepUtil;
+
+/**
+ * 
+ */
+public class ContactResource extends Resource implements ViewableV1 {
+
+    private static final String SMTP_HOST = "smtpHost:";
+
+    private static final String SMTP_PORT = "smtpPort:";
+
+    private static final String TO = "to:";
+
+    private static Category log = Category.getInstance(ContactResource.class);
+
+    private String smtpHost;
+
+    private int smtpPort = 0;
+
+    private String to;
+
+    private String from;
+
+    private String subject;
+
+    private String content;
+
+    /**
+     * 
+     */
+    public ContactResource() {
+    }
+
+    /**
+     * 
+     */
+    public ViewDescriptor[] getViewDescriptors() {
+        return null;
+    }
+    
+    /**
+     * 
+     */
+    public View getView(Path path, String viewId) {
+        View defaultView = new View();
+        defaultView.setMimeType("application/xml");
+        StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
+        defaultView.setInputStream(new java.io.StringBufferInputStream(sb
+                .toString()));
+        return defaultView;
+    }
+
+    /**
+     * @throws Exception
+     * 
+     */
+    public View getView(HttpServletRequest request, String viewId)
+            throws Exception {
+        Path path = new Path(request.getServletPath());
+        Enumeration enumeration = request.getParameterNames();
+        boolean submit = enumeration.hasMoreElements();
+        // if submit null just return the file
+        if (!submit) {
+            View defaultView = new View();
+            return plainRequest(path, defaultView);
+        }
+        String uri = request.getRequestURI();
+
+        boolean success = false;
+        Map status = null;
+        if (!getProperties(path)) {
+            log.warn("SetupException: ");
+            status = new HashMap(3);
+            status.put(SendMail.STATUS, "user-error");
+            status.put(SendMail.MESSAGE, "Please verify your setup of the rti!");
+            return computeForward(path, status);
+        } else {
+            // getting the form values
+            ContactBean contact = new ContactBean(request);
+            verifyContact(contact);
+            try {
+                SendMail.send(smtpHost, smtpPort, from, to, subject, content);
+                success = true;
+                status = new HashMap(3);
+                status.put(SendMail.STATUS, "success");
+            } catch (AddressException e) {
+                log.warn("AddressException: ", e);
+                status = new HashMap(3);
+                status.put(SendMail.STATUS, "user-error");
+                status.put(SendMail.MESSAGE, e.getMessage());
+            } catch (MessagingException e) {
+                log.warn("MessagingException: "
+                        + "An error occured while sending email.", e);
+
+                status = new HashMap(3);
+                status.put(SendMail.STATUS, "server-error");
+                status.put(SendMail.MESSAGE,
+                        "An error occured while sending email: "
+                                + e.getMessage());
+            } finally {
+                return computeForward(path, status);
+            }
+        }
+    }
+
+    private View plainRequest(Path path, View defaultView) throws Exception,
+            TransformerConfigurationException,
+            TransformerFactoryConfigurationError, NoSuchNodeException,
+            TransformerException {
+        Repository contentRepo;
+        RepoPath rp = contentRepo(path);
+        contentRepo = rp.getRepo();
+
+        Transformer transformer = TransformerFactory.newInstance()
+                .newTransformer(getXSLTStreamSource(path, contentRepo));
+        transformer.setParameter("yanel.path.name", path.getName());
+        transformer.setParameter("yanel.path", path.toString());
+        // transformer.setParameter("yanel.back2context", backToRoot(path,
+        // ""));
+        // transformer.setParameter("yarep.back2realm", backToRoot(new
+        // org.wyona.yanel.core.Path(rp.getPath().toString()), ""));
+        // TODO: Is this the best way to generate an InputStream from an
+        // OutputStream?
+        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
+        transformer.transform(new StreamSource(rp.getRepo().getInputStream(
+                new org.wyona.yarep.core.Path(rp.getPath().toString()))),
+                new StreamResult(baos));
+        defaultView.setInputStream(new java.io.ByteArrayInputStream(baos
+                .toByteArray()));
+        defaultView.setMimeType(getMimeType(path));
+        defaultView.setInputStream(new java.io.ByteArrayInputStream(baos
+                .toByteArray()));
+
+        return defaultView;
+    }
+
+    private RepoPath contentRepo(Path path) throws Exception {
+        return new YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(
+                path.toString()), getRepositoryFactory());
+    }
+
+    private String getMimeType(Path path, String viewId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    private View computeForward(Path path, Map status) throws Exception {
+        View defaultView = new View();
+        defaultView.setMimeType("application/xml");
+        StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
+        sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
+        sb.append("<head>");
+        // here we need to test the status of the mail
+        String statusCode = (String) status.get(SendMail.STATUS);
+        if (statusCode.equals("success")) {
+            sb.append("<title>Your message has been sent successfully.</title>");
+            sb.append("</head>");
+            sb.append("<body>");
+            sb.append("<div id=\"contenBody\">");
+            sb.append("<h1>Success</h1>");
+            sb.append("<p>Following message has been sent:</p>");
+            // decoding content of the message body
+            StringReader stringReader = new StringReader(content);
+            BufferedReader reader = new BufferedReader(stringReader);
+            String line = null;
+            while ((line = reader.readLine()) != null) {
+                sb.append("<p>" + line + "</p>");
+            }
+            // finishing
+            sb.append("</div>");
+            sb.append("</body>");
+        } else {
+            sb.append("<title>Your message has not been sent.</title>");
+            sb.append("</head>");
+            sb.append("<body>");
+            sb.append("<div id=\"contenBody\">");
+            sb.append("<h1>" + status.get(SendMail.STATUS) + "</h1>");
+            sb.append("<p>Your message has not been sent.</p>");
+            sb.append("<p>" + status.get(SendMail.MESSAGE) + "</p>");
+            sb.append("</div>");
+            sb.append("</body>");
+        }
+        sb.append("</html>");
+        computeView(path, defaultView, sb);
+        return defaultView;
+    }
+
+    private void computeView(Path path, View defaultView, StringBuffer sb)
+            throws Exception, TransformerConfigurationException,
+            TransformerFactoryConfigurationError, NoSuchNodeException,
+            TransformerException {
+        Transformer transformer = prepareTransformer(path);
+        // transformer.setParameter("yanel.back2context", backToRoot(path, ""));
+        // transformer.setParameter("yarep.back2realm", backToRoot(new
+        // org.wyona.yanel.core.Path(rp.getPath().toString()), ""));
+        // TODO: Is this the best way to generate an InputStream from an
+        // OutputStream?
+        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
+        transformer.transform(new StreamSource(
+                new java.io.StringBufferInputStream(sb.toString())),
+                new StreamResult(baos));
+        defaultView.setInputStream(new java.io.ByteArrayInputStream(baos
+                .toByteArray()));
+        defaultView.setMimeType(getMimeType(path));
+        defaultView.setInputStream(new java.io.ByteArrayInputStream(baos
+                .toByteArray()));
+    }
+
+    private Transformer prepareTransformer(Path path) throws Exception,
+            TransformerConfigurationException,
+            TransformerFactoryConfigurationError, NoSuchNodeException {
+        Repository contentRepo;
+        RepoPath rp = contentRepo(path);
+        contentRepo = rp.getRepo();
+        Transformer transformer = TransformerFactory.newInstance()
+                .newTransformer(getXSLTStreamSource(path, contentRepo));
+        transformer.setParameter("yanel.path.name", path.getName());
+        transformer.setParameter("yanel.path", path.toString());
+        return transformer;
+    }
+
+    /**
+     * Here we need to verify whether we have all props that we need for the
+     * SendMail class.
+     */
+    private boolean verifyContact(ContactBean contact) {
+        boolean success = false;
+        if (null != contact.email & null != contact.message) {
+
+            from = contact.email;
+            subject = "Yanel feedback";
+            content = "Company: " + contact.getCompany() + "\n" + "Firstname: "
+                    + contact.getFirstName() + "\n" + "Lastname: "
+                    + contact.getLastName() + "\n" + "Address: "
+                    + contact.getAddress() + "\n" + "City: " + contact.getCity()
+                    + "\n" + "Email: " + contact.getEmail() + "\n" + "\n"
+                    + "Message:\n" + contact.message;
+            success = true;
+        }
+        return success;
+
+    }
+
+    /**
+     * 
+     */
+    private StreamSource getXSLTStreamSource(Path path, Repository repo)
+            throws NoSuchNodeException {
+        Path xsltPath = getXSLTPath(path);
+        if (xsltPath != null) {
+            return new StreamSource(repo
+                    .getInputStream(new org.wyona.yarep.core.Path(getXSLTPath(
+                            path).toString())));
+        } else {
+            File xsltFile = org.wyona.commons.io.FileUtil.file(rtd
+                    .getConfigFile().getParentFile().getAbsolutePath(), "xslt"
+                    + File.separator + "dir2xhtml.xsl");
+            log.error("DEBUG: XSLT file: " + xsltFile);
+            return new StreamSource(xsltFile);
+        }
+    }
+
+    /**
+     * 
+     */
+    private Path getXSLTPath(Path path) {
+        String xsltPath = null;
+        try {
+            // TODO: Get yanel RTI yarep properties file name from framework
+            // resp. use MapFactory ...!
+            RepoPath rpRTI = new org.wyona.yarep.util.YarepUtil()
+                    .getRepositoryPath(new org.wyona.yarep.core.Path(path
+                            .toString()), getRTIRepositoryFactory());
+            java.io.BufferedReader br = new java.io.BufferedReader(rpRTI
+                    .getRepo().getReader(
+                            new org.wyona.yarep.core.Path(new Path(rpRTI
+                                    .getPath().toString()).getRTIPath()
+                                    .toString())));
+
+            while ((xsltPath = br.readLine()) != null) {
+                if (xsltPath.indexOf("xslt:") == 0) {
+                    xsltPath = xsltPath.substring(6);
+                    log.debug("XSLT Path: " + xsltPath);
+                    return new Path(xsltPath);
+                }
+            }
+            log.error("No XSLT Path within: " + rpRTI.getPath());
+        } catch (Exception e) {
+            log.warn(e);
+        }
+
+        return null;
+    }
+
+    /**
+     * Here we need to verify that all default information like mail host, port,
+     * etc. are set. If not we can directly abort the processing and report an
+     * error.
+     */
+    private boolean getProperties(Path path) {
+        boolean success = false;
+        String line = null;
+        try {
+            // TODO: Get yanel RTI yarep properties file name from framework
+            // resp. use MapFactory ...!
+            RepoPath rpRTI = new org.wyona.yarep.util.YarepUtil()
+                    .getRepositoryPath(new org.wyona.yarep.core.Path(path
+                            .toString()), getRTIRepositoryFactory());
+            java.io.BufferedReader br = new java.io.BufferedReader(rpRTI
+                    .getRepo().getReader(
+                            new org.wyona.yarep.core.Path(new Path(rpRTI
+                                    .getPath().toString()).getRTIPath()
+                                    .toString())));
+
+            while ((line = br.readLine()) != null) {
+                if (line.indexOf(SMTP_HOST) == 0) {
+                    smtpHost = line.substring(SMTP_HOST.length() + 1);
+                }
+                if (line.indexOf(SMTP_PORT) == 0) {
+                    smtpPort = Integer.parseInt(line.substring(SMTP_PORT
+                            .length() + 1));
+                }
+                if (line.indexOf(TO) == 0) {
+                    to = line.substring(TO.length() + 1);
+                }
+            }
+        } catch (Exception e) {
+            log.warn(e);
+        }
+        if (null != smtpHost & 0 < smtpPort & null != to) {
+            success = true;
+        }
+        return success;
+    }
+
+    /**
+     * 
+     */
+    private String getMimeType(Path path) {
+        String mimeType = null;
+        try {
+            // TODO: Get yanel RTI yarep properties file name from framework
+            // resp. use MapFactory ...!
+            RepoPath rpRTI = new org.wyona.yarep.util.YarepUtil()
+                    .getRepositoryPath(new org.wyona.yarep.core.Path(path
+                            .toString()), getRTIRepositoryFactory());
+            java.io.BufferedReader br = new java.io.BufferedReader(rpRTI
+                    .getRepo().getReader(
+                            new org.wyona.yarep.core.Path(new Path(rpRTI
+                                    .getPath().toString()).getRTIPath()
+                                    .toString())));
+
+            while ((mimeType = br.readLine()) != null) {
+                if (mimeType.indexOf("mime-type:") == 0) {
+                    mimeType = mimeType.substring(11);
+                    log.info("*" + mimeType + "*");
+                    // TODO: Maybe validate mime-type ...
+                    return mimeType;
+                }
+            }
+        } catch (Exception e) {
+            log.warn(e);
+        }
+
+        // NOTE: Assuming fallback re dir2xhtml.xsl ...
+        return "application/xhtml+xml";
+    }
+    
+    protected RepositoryFactory getRepositoryFactory() {
+        return yanel.getRepositoryFactory("DefaultRepositoryFactory");
+    }
+    
+    protected RepositoryFactory getRTIRepositoryFactory() {
+        return yanel.getRepositoryFactory("RTIRepositoryFactory");
+    }
+    
+}


Property changes on: public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/SendMail.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/SendMail.java	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/SendMail.java	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1,34 @@
+package org.wyona.yanel.impl.resources;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
+public class SendMail {
+    public static final String STATUS = "status";
+    public static final String MESSAGE = "message";
+    
+    public static void send(String smtpHost, int smtpPort, String from,
+            String to, String subject, String content) throws AddressException,
+            MessagingException {
+        // Create a mail session
+        java.util.Properties props = new java.util.Properties();
+        props.put("mail.smtp.host", smtpHost);
+        props.put("mail.smtp.port", "" + smtpPort);
+        Session session = Session.getDefaultInstance(props, null);
+
+        // Construct the message
+        Message msg = new MimeMessage(session);
+        msg.setFrom(new InternetAddress(from));
+        msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
+        msg.setSubject(subject);
+        msg.setText(content);
+
+        // Send the message
+        Transport.send(msg);
+    }
+}
\ No newline at end of file


Property changes on: public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/SendMail.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/realms/yanel-website/content/contact-form/en.xhtml
===================================================================
--- public/yanel/trunk/src/realms/yanel-website/content/contact-form/en.xhtml	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/realms/yanel-website/content/contact-form/en.xhtml	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1,94 @@
+<?xml version="1.0"?>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <title>Yanel :: Contact</title>
+    
+  </head>
+  
+  <body>
+    <div id="boxBody"> 
+      <strong>Yanel</strong>
+      <br/>Wyona AG
+      <br/>Hardstrasse 219
+      <br/>
+      <br/>phone: +41 44 272 91 61 
+      <br/>fax: +41 44 272 91 62 
+      <br/>skype: <a href="callto:wyona-switzerland">wyona-switzerland</a>
+      <br/>email: <a href="mailto:contact at wyona.com">contact at wyona.com</a>
+      <br/>8005
+      <br/>Zürich 
+      <br/>Switzerland 
+    </div>
+    
+    <div id="contenBody">
+      
+      <form method="post" action="#">
+        <table cellpadding="0" cellspacing="0" border="0">
+          <tr>
+            <td colspan="2">
+              <h1>Contact</h1>
+              <h2>Please contact us via this form or call us </h2>
+            </td>
+          </tr>
+          <tr>
+            <td colspan="2"></td>
+          </tr>
+          
+          <tr>
+            <td align="right" valign="top" class="contentfield">Company</td>
+            <td>
+              <input type="text" name="company" class="box" size="40" value=""/>
+            </td>
+          </tr>
+          <tr>
+            <td align="right" valign="top" class="contentfield">Firstname</td>
+            <td>
+              <input type="text" name="firstName" class="box" size="40" value=""/>
+            </td>
+          </tr>
+          <tr>
+            <td align="right" valign="top" class="contentfield">Lastname</td>
+            <td>
+              <input type="text" name="lastName" class="box" size="40" value=""/>
+            </td>
+          </tr>
+          <tr>
+            <td align="right" valign="top" class="contentfield">Address</td>
+            <td>
+              <input type="text" name="address" class="box" size="40" value=""/>
+            </td>
+          </tr>
+          <tr>
+            <td align="right" valign="top" class="contentfield">ZIP / City</td>
+            <td>
+              <input type="text" name="city" class="box" size="40" value=""/>
+            </td>
+          </tr>
+          <tr>
+            <td align="right" valign="top" class="contentfield">E-Mail</td>
+            <td>
+              <input type="text" name="email" class="box" size="40" value=""/>
+            </td>
+          </tr>
+          <tr>
+            <td align="right" valign="top" class="contentfield">Message</td>
+            <td>
+              <textarea rows="8" name="message" cols="30" class="box">&#160;</textarea>
+            </td>
+          </tr>
+          <tr>
+            <td>&#160;
+            </td>
+            <td>
+              <input type="submit" value="send "/>
+            </td>
+          </tr>
+        </table>
+      </form>
+    </div>
+  </body>
+</html>

Added: public/yanel/trunk/src/realms/yanel-website/content/introspection-contact-form.xml
===================================================================
--- public/yanel/trunk/src/realms/yanel-website/content/introspection-contact-form.xml	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/realms/yanel-website/content/introspection-contact-form.xml	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+
+<introspection xmlns="http://www.wyona.org/neutron/1.0">
+
+<edit mime-type="application/xhtml+xml" name="contact-form">
+  <open url="contact-form.xhtml" method="GET"/>
+  <save url="contact-form.xhtml?yanel.resource.usecase=save" method="PUT"/>
+</edit>
+
+</introspection>


Property changes on: public/yanel/trunk/src/realms/yanel-website/content/introspection-contact-form.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/realms/yanel-website/content/rtd/contact-form.rtd
===================================================================
--- public/yanel/trunk/src/realms/yanel-website/content/rtd/contact-form.rtd	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/realms/yanel-website/content/rtd/contact-form.rtd	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1,6 @@
+<{http://www.wyona.org/yanel/resource/1.0}contact-form/>
+mime-type: application/xhtml+xml
+xslt: /xslt/global.xsl
+to: contact at localhost
+smtpHost: localhost
+smtpPort: 25

Added: public/yanel/trunk/src/realms/yanel-website/paths/en/contact.html/.yarep-uid
===================================================================
--- public/yanel/trunk/src/realms/yanel-website/paths/en/contact.html/.yarep-uid	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/realms/yanel-website/paths/en/contact.html/.yarep-uid	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1 @@
+contact-form/en.xhtml

Added: public/yanel/trunk/src/realms/yanel-website/paths/en/contact.html.yanel-rti/.yarep-uid
===================================================================
--- public/yanel/trunk/src/realms/yanel-website/paths/en/contact.html.yanel-rti/.yarep-uid	2006-11-24 11:09:03 UTC (rev 20301)
+++ public/yanel/trunk/src/realms/yanel-website/paths/en/contact.html.yanel-rti/.yarep-uid	2006-11-24 11:20:56 UTC (rev 20302)
@@ -0,0 +1 @@
+rtd/contact-form.rtd




More information about the Yanel-commits mailing list