Author: fred
Date: 2007-08-20 17:00:45 +0000 (Mon, 20 Aug 2007)
New Revision: 14807
Modified:
trunk/plugins/Echo/src/plugins/echo/Echo.java
trunk/plugins/Echo/src/plugins/echo/Page.java
trunk/plugins/Echo/src/plugins/echo/Project.java
trunk/plugins/Echo/src/plugins/echo/ProjectManager.java
trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java
trunk/plugins/Echo/src/xml/edit.xsl
trunk/plugins/Echo/src/xml/test.xsl
Log:
- generate & insert pages
- Use the project title as blog title
Modified: trunk/plugins/Echo/src/plugins/echo/Echo.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/Echo.java 2007-08-20 16:55:23 UTC
(rev 14806)
+++ trunk/plugins/Echo/src/plugins/echo/Echo.java 2007-08-20 17:00:45 UTC
(rev 14807)
@@ -14,6 +14,7 @@
import freenet.pluginmanager.DownloadPluginHTTPException;
import freenet.pluginmanager.RedirectPluginHTTPException;
+import freenet.keys.FreenetURI;
import freenet.support.api.HTTPRequest;
import freenet.support.HTMLNode;
@@ -35,8 +36,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
-import freenet.keys.*;
-
// TODO
// * Exceptions !
@@ -65,7 +64,7 @@
private BlockManager blockManager;
private Node node;
-// private InsertTest test;
+ private InsertTest test;
public Echo() throws PluginHTTPException
{
@@ -74,8 +73,8 @@
parser = new Builder();
- Document styleSheet =
parser.build(getClass().getResourceAsStream("/xml/edit.xsl"));
-// Document styleSheet =
parser.build("/home/fred/prog/soc/trunk/plugins/Echo/src/xml/edit.xsl");
+// Document styleSheet =
parser.build(getClass().getResourceAsStream("/xml/edit.xsl"));
+ Document styleSheet =
parser.build("/home/fred/prog/soc/trunk/plugins/Echo/src/xml/edit.xsl");
i18n.translateXML(styleSheet);
transform = new XSLTransform(styleSheet);
@@ -100,10 +99,10 @@
public void runPlugin(PluginRespirator p) {
this.respirator = p;
- /*
- test = new InsertTest(respirator.getNode(), new
File("/home/fred/test.jpg"));
- System.err.println("Test.isNull ?? : " + (test == null));*/
+// test = new InsertTest(respirator.getNode(), new
File("/home/fred/test.jpg"));
+// System.err.println("Test.isNull ?? : " + (test == null));
+
}
public void terminate() {
@@ -123,11 +122,12 @@
private String transform(Page page) {
try {
- return
transform.transform(page.getDoc()).get(0).toXML();
+// return
transform.transform(page.getDoc()).get(0).toXML();
/*
Nice but input white space are not respected
+ */
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
Serializer serializer = new Serializer(baos);
serializer.setIndent(4);
@@ -135,7 +135,6 @@
serializer.write(new Document((Element)
transform.transform(page.getDoc()).get(0)));
return baos.toString();
- */
} catch (Exception e) {
@@ -264,19 +263,8 @@
Element pub = new Element("publish");
page = new Page(pub);
-
page.setTitle(i18n.getString("echo.action.publish"));
- try {
- SiteGenerator test = new SiteGenerator();
- test.generate();
-
- pub.addAttribute(new Attribute("outputdir",(new
File(BASE_DIR.getPath() + File.separator + "out")).getAbsolutePath() + "/"));
-
- } catch (Exception e) {
- e.printStackTrace();
- page.appendError(e.getMessage());
- }
} else if ("configure".equals(fileName)) {
Element configure = new Element("configure");
@@ -293,7 +281,43 @@
page = new Page(configure);
page.setTitle(i18n.getString("echo.action.configure"));
+
+ } else if ("generate".equals(fileName)) {
+
+ Element generate = new Element("generate");
+ page= new Page(generate);
+ page.setTitle("Generate");
+ try {
+ SiteGenerator test = new SiteGenerator(project);
+ test.generate();
+
+ generate.addAttribute(new
Attribute("outputdir",(new File(BASE_DIR.getPath() + File.separator +
"out")).getAbsolutePath() + "/"));
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ page.appendError(e.getMessage());
+ }
+ } else if ("insert".equals(fileName)) {
+
+ Element insert = new Element("insert");
+ page= new Page(insert);
+ page.setTitle("Insert");
+
+ FreenetURI uri = project.getInsertURI();
+ if(uri != null){
+ Element insertURI = new Element("insertURI");
+ insertURI.appendChild(uri.toString());
+ insert.appendChild(insertURI);
+ }
+
+ uri = project.getRequestURI();
+ if(uri != null){
+ Element requestURI = new Element("requestURI");
+ requestURI.appendChild(uri.toString());
+ insert.appendChild(requestURI);
+ }
+
} else if ("nodes".equals(fileName)) {
setNodesPage();
@@ -314,7 +338,7 @@
return transform(page);
}
-
+
public String handleHTTPPut(HTTPRequest request) throws
PluginHTTPException {
return "Put";
}
Modified: trunk/plugins/Echo/src/plugins/echo/Page.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/Page.java 2007-08-20 16:55:23 UTC
(rev 14806)
+++ trunk/plugins/Echo/src/plugins/echo/Page.java 2007-08-20 17:00:45 UTC
(rev 14807)
@@ -19,8 +19,7 @@
}
public Page(Element content) {
- data = new nu.xom.Nodes();
- errors = new Vector<String> ();
+ this();
this.appendData(content);
}
Modified: trunk/plugins/Echo/src/plugins/echo/Project.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/Project.java 2007-08-20 16:55:23 UTC
(rev 14806)
+++ trunk/plugins/Echo/src/plugins/echo/Project.java 2007-08-20 17:00:45 UTC
(rev 14807)
@@ -2,11 +2,14 @@
import plugins.echo.block.BlockManager;
+import freenet.keys.FreenetURI;
+
import java.util.Properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.net.MalformedURLException;
import nu.xom.ParsingException;
@@ -35,12 +38,50 @@
}
- public String getName() {
+ public String getTitle() {
- return projectConfig.getProperty("name");
+ return projectConfig.getProperty("title");
}
+ public FreenetURI getInsertURI() {
+
+ return getURI("inserturi");
+
+ }
+
+ public FreenetURI getRequestURI() {
+
+ return getURI("requesturi");
+
+ }
+
+ public void setInsertURI(FreenetURI uri) {
+
+ projectConfig.setProperty("inserturi", uri.toString());
+
+ }
+
+ public void setRequestURI(FreenetURI uri) {
+
+ projectConfig.setProperty("requesturi", uri.toString());
+
+ }
+
+ private FreenetURI getURI(String key) {
+
+ String str = projectConfig.getProperty(key);
+ if(str == null)
+ return null;
+
+ try {
+ return new FreenetURI(str);
+
+ } catch (MalformedURLException mue) {
+ return null;
+ }
+ }
+
public NodesManager getNodesManager() {
return nodesManager;
Modified: trunk/plugins/Echo/src/plugins/echo/ProjectManager.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/ProjectManager.java 2007-08-20
16:55:23 UTC (rev 14806)
+++ trunk/plugins/Echo/src/plugins/echo/ProjectManager.java 2007-08-20
17:00:45 UTC (rev 14807)
@@ -38,7 +38,7 @@
return null;
}
- public Project newProject(String name) throws IOException,
ParsingException {
+ public Project newProject(String projectTitle) throws IOException,
ParsingException {
String id = "";
for(int i=1; i < Math.pow(10, Echo.PROJECT_ID_LENGTH); i++) {
@@ -58,7 +58,7 @@
FileOutputStream configFile = new
FileOutputStream(projectDir.getPath() + File.separator + "conf.xml");
Properties conf = new Properties();
- conf.setProperty("name", name);
+ conf.setProperty("title", projectTitle);
conf.storeToXML(configFile, null);
configFile.close();
Modified: trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java 2007-08-20
16:55:23 UTC (rev 14806)
+++ trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java 2007-08-20
17:00:45 UTC (rev 14807)
@@ -8,8 +8,6 @@
public class SiteGenerator {
// public static final File BASE_DIR = new
File("/home/fred/Freenet/plugins/Echo");
- public static final File BASE_DIR = Echo.BASE_DIR;
- public static final File OUT_DIR = new File(BASE_DIR.getAbsolutePath()
+ File.separator + "out");
public static final int POSTS_PER_PAGE = 5;
private NodesManager nodesManager;
@@ -18,16 +16,22 @@
private XSLTransform rssTransform;
private Serializer serializer;
private Document template;
+ private Project project;
+ private File outDir;
- public SiteGenerator() throws IOException, ParsingException,
XSLException {
+ public SiteGenerator(Project project) throws IOException,
ParsingException, XSLException {
- nodesManager = new NodesManager(BASE_DIR);
+ this.project = project;
+ this.outDir = new File(project.getProjectDir(), "out/");
+ nodesManager = project.getNodesManager();
parser = new Builder();
+
template =
parser.build(getClass().getResourceAsStream("/xml/test.xsl"));
// template =
parser.build("/home/fred/prog/soc/trunk/plugins/Echo/src/xml/test.xsl");
transform = new XSLTransform(template);
- transform.setParameter("basedir", BASE_DIR.getAbsolutePath() +
"/");
+ transform.setParameter("basedir",
project.getProjectDir().getAbsolutePath() + "/");
+ transform.setParameter("project-title", project.getTitle());
// rssTransform = new
XSLTransform(parser.build("/home/fred/prog/soc/trunk/plugins/Echo/src/xml/rss.xsl"));
@@ -39,14 +43,14 @@
public void writeToFile(nu.xom.Nodes result, String fileName) throws
XSLException, IOException {
- serializer.setOutputStream(new
FileOutputStream(OUT_DIR.getPath() + File.separator + fileName));
+ serializer.setOutputStream(new
FileOutputStream(outDir.getPath() + File.separator + fileName));
serializer.write(new Document((Element) result.get(0)));
}
public void generate() throws Exception{ // TODO : Pfouille !!
- OUT_DIR.mkdirs();
+ outDir.mkdirs();
Nodes nodes = nodesManager.getNodes();
for(Node node : nodes) {
@@ -82,7 +86,7 @@
InputStream in = getClass().getResourceAsStream("/style.css");
- FileOutputStream cssFile = new
FileOutputStream(OUT_DIR.getPath() + File.separator + "style.css");
+ FileOutputStream cssFile = new
FileOutputStream(outDir.getPath() + File.separator + "style.css");
byte[] buffer = new byte[1024];
int read;
Modified: trunk/plugins/Echo/src/xml/edit.xsl
===================================================================
--- trunk/plugins/Echo/src/xml/edit.xsl 2007-08-20 16:55:23 UTC (rev 14806)
+++ trunk/plugins/Echo/src/xml/edit.xsl 2007-08-20 17:00:45 UTC (rev 14807)
@@ -84,9 +84,45 @@
</xsl:when>
<xsl:when test="publish">
- <a href="file://{publish/@outputdir}">Output
dir</a>
+ <dl>
+ <dt><a href="generate">Generate the
site</a></dt>
+ <dd>Bleh bleh</dd>
+
+ <dt><a href="insert">Insert</a></dt>
+ <dd>Generate the site and insert it on
Freenet</dd>
+ </dl>
</xsl:when>
+ <xsl:when test="generate">
+ <xsl:if test="not(/page/errors)">
+ <a
href="file://{generate/@outputdir}">Output dir</a>
+ </xsl:if>
+ </xsl:when>
+
+ <xsl:when test="insert">
+ <form name="insert">
+ <label for="insert-key">Insert
key</label>
+ <input type="text" name="insert-key"
id="insert-key" size="70">
+ <xsl:if test="insert/insertKey" >
+ <xsl:attribute name="value">
+ <xsl:value-of
select="insert/insertKey" />
+ </xsl:attribute>
+ </xsl:if>
+ </input>
+
+ <label for="request-key">Request
key</label>
+ <input type="text" name="request-key"
id="request-key" size="70">
+ <xsl:if test="insert/requestKey">
+ <xsl:attribute name="value">
+ <xsl:value-of
select="insert/requestKey" />
+ </xsl:attribute>
+ </xsl:if>
+ </input>
+ <input type="hidden"
name="formPassword" value="{formpassword/@value}" />
+ <input type="submit" />
+ </form>
+ </xsl:when>
+
<xsl:when test="configure">
<form name="" method="POST" action="">
<select name="project">
Modified: trunk/plugins/Echo/src/xml/test.xsl
===================================================================
--- trunk/plugins/Echo/src/xml/test.xsl 2007-08-20 16:55:23 UTC (rev 14806)
+++ trunk/plugins/Echo/src/xml/test.xsl 2007-08-20 17:00:45 UTC (rev 14807)
@@ -13,6 +13,7 @@
indent="yes" />
<xsl:param name="basedir" />
+ <xsl:param name="project-title" />
<xsl:variable name="blocksdir"><xsl:value-of select="$basedir"
/>/blocks/</xsl:variable>
<xsl:variable name="categoriesFile"><xsl:value-of select="$basedir"
/>/categories.xml</xsl:variable>
@@ -26,7 +27,7 @@
<body>
<div id="container">
<div id="header">
- <h1 id="blog-title"><a
href="index.html">My Flog</a></h1>
+ <h1 id="blog-title"><a
href="index.html"><xsl:value-of select="$project-title" /></a></h1>
</div>
<!--<div id="left">