[Yanel-commits] rev 27089 - in
public/yanel/contributions/realms/foaf/src/resources/findfriend:
. src/java/org/wyona/yanel/impl/resources/findfriend xslt
michi at wyona.com
michi at wyona.com
Sat Sep 1 00:19:43 CEST 2007
Author: michi
Date: 2007-09-01 00:19:43 +0200 (Sat, 01 Sep 2007)
New Revision: 27089
Added:
public/yanel/contributions/realms/foaf/src/resources/findfriend/xslt/
public/yanel/contributions/realms/foaf/src/resources/findfriend/xslt/foaf2xhtml.xsl
Modified:
public/yanel/contributions/realms/foaf/src/resources/findfriend/src/java/org/wyona/yanel/impl/resources/findfriend/FindFriendResource.java
Log:
XSLT added
Modified: public/yanel/contributions/realms/foaf/src/resources/findfriend/src/java/org/wyona/yanel/impl/resources/findfriend/FindFriendResource.java
===================================================================
--- public/yanel/contributions/realms/foaf/src/resources/findfriend/src/java/org/wyona/yanel/impl/resources/findfriend/FindFriendResource.java 2007-08-31 22:07:12 UTC (rev 27088)
+++ public/yanel/contributions/realms/foaf/src/resources/findfriend/src/java/org/wyona/yanel/impl/resources/findfriend/FindFriendResource.java 2007-08-31 22:19:43 UTC (rev 27089)
@@ -12,6 +12,13 @@
import org.wyona.meguni.parser.Parser;
import org.wyona.meguni.util.ResultSet;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.stream.StreamResult;
+
+import java.io.File;
+
/**
*
*/
@@ -47,8 +54,8 @@
/**
*
*/
- public View getView(String viewId) {
- StringBuffer sb = new StringBuffer("<foaf>");
+ public View getView(String viewId) throws Exception {
+ StringBuffer sb = new StringBuffer("<foaf xmlns=\"http://www.wyona.org/foaf/1.0\">");
try {
String qs = getRequest().getParameter("q");
ResultSet resultSet = getSearchResults(qs.replaceAll(" ", "+") + "+FOAF");
@@ -70,7 +77,14 @@
sb.append("</foaf>");
View view = new View();
- view.setInputStream(new java.io.StringBufferInputStream(sb.toString()));
+ if (viewId != null && viewId.equals("source")) {
+ view.setInputStream(new java.io.StringBufferInputStream(sb.toString()));
+ } else {
+ StreamSource source = new StreamSource(new java.io.StringBufferInputStream(sb.toString()));
+ java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
+ getTransformer().transform(source, new StreamResult(baos));
+ view.setInputStream(new java.io.ByteArrayInputStream(baos.toByteArray()));
+ }
view.setMimeType(getMimeType(viewId));
return view;
}
@@ -91,4 +105,16 @@
Parser parser = (Parser) Class.forName(className).newInstance();
return parser.parse(queryString);
}
+
+ /**
+ *
+ */
+ private Transformer getTransformer() throws Exception {
+ File xsltFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile().getAbsolutePath(), "xslt" + File.separator + "foaf2xhtml.xsl");
+ Transformer tf = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltFile));
+ if (getRequest().getParameter("q") != null) {
+ tf.setParameter("query", getRequest().getParameter("q"));
+ }
+ return tf;
+ }
}
Added: public/yanel/contributions/realms/foaf/src/resources/findfriend/xslt/foaf2xhtml.xsl
===================================================================
--- public/yanel/contributions/realms/foaf/src/resources/findfriend/xslt/foaf2xhtml.xsl (rev 0)
+++ public/yanel/contributions/realms/foaf/src/resources/findfriend/xslt/foaf2xhtml.xsl 2007-08-31 22:19:43 UTC (rev 27089)
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns:foaf="http://www.wyona.org/foaf/1.0"
+>
+
+<xsl:output method="xhtml"/>
+<!-- NOTE: Must correspond with the mime-type delivered by the server. See src/java/org/wyona/yanel/impl/resources/DirectoryResource.java -->
+<!--
+<xsl:output method="html"/>
+-->
+<xsl:param name="query" select="'QUERY_IS_NULL'"/>
+
+
+
+<xsl:template match="/">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>Find a friend</title>
+</head>
+
+<body>
+<h1>Find a friend</h1>
+<p>
+<a href="?q={$query}&yanel.resource.viewid=source">XML view</a>
+</p>
+</body>
+</html>
+</xsl:template>
+
+</xsl:stylesheet>
More information about the Yanel-commits
mailing list