[freenet-cvs] r14484 - in trunk/plugins/Echo/src: plugins/echo plugins/echo/i18n test xml
fred at freenetproject.org
fred at freenetproject.org
Sun Aug 5 14:01:11 UTC 2007
Author: fred
Date: 2007-08-05 14:01:10 +0000 (Sun, 05 Aug 2007)
New Revision: 14484
Removed:
trunk/plugins/Echo/src/test/blocks.xml
Modified:
trunk/plugins/Echo/src/plugins/echo/Echo.java
trunk/plugins/Echo/src/plugins/echo/NodesManager.java
trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java
trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java
trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties
trunk/plugins/Echo/src/xml/edit.xsl
Log:
blocks management
Modified: trunk/plugins/Echo/src/plugins/echo/Echo.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/Echo.java 2007-08-05 03:28:31 UTC (rev 14483)
+++ trunk/plugins/Echo/src/plugins/echo/Echo.java 2007-08-05 14:01:10 UTC (rev 14484)
@@ -1,6 +1,8 @@
package plugins.echo;
import plugins.echo.i18n.I18n;
+import plugins.echo.block.BlockManager;
+import plugins.echo.block.Block;
import freenet.pluginmanager.FredPlugin;
import freenet.pluginmanager.FredPluginHTTP;
@@ -41,6 +43,7 @@
public static final File BASE_DIR = new File("plugins/Echo/");
public static final File NODES_DIR = new File(BASE_DIR.getPath() + File.separator + "nodes");
+ public static final File BLOCKS_DIR = new File(BASE_DIR.getPath() + File.separator + "blocks");
public static final int NODE_ID_LENGTH = 4;
public static final int CATEGORY_ID_LENGTH = 3;
@@ -56,6 +59,7 @@
private I18n i18n;
private Page page;
private NodesManager nodesManager;
+ private BlockManager blockManager;
private Node node;
public Echo() throws PluginHTTPException
@@ -71,9 +75,11 @@
i18n.translateXML(styleSheet);
transform = new XSLTransform(styleSheet);
- transform.setParameter("contextprefix", NODES_DIR.getAbsolutePath() + "/");
+ transform.setParameter("baseDir", BASE_DIR.getAbsolutePath() + "/");
nodesManager = new NodesManager(BASE_DIR);
+ blockManager = new BlockManager(BLOCKS_DIR);
+
} catch (Exception e) {
e.printStackTrace(System.err);
}
@@ -99,11 +105,11 @@
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);
@@ -111,9 +117,9 @@
serializer.write(new Document((Element) transform.transform(page.getDoc()).get(0)));
return baos.toString();
- */
+
} catch (Exception e) {
return e.getMessage();
}
@@ -241,6 +247,10 @@
setCategoriesPage();
+ } else if ("blocks".equals(fileName)) {
+
+ setBlocksPage();
+
} else {
setDefaultPage();
@@ -309,6 +319,24 @@
} else {
page.appendError("Fied \"name\" is empty");
}
+
+ } else if (request.isPartSet("blocks")) {
+
+ String[] blocksIds = blockManager.getIds();
+ for(String id : blocksIds) {
+ Block block = blockManager.getBlockById(id);
+
+ String position = request.getPartAsString("position-" + id, 8);
+ block.setPosition(position);
+
+ String weight = request.getPartAsString("weight-" + id, 2);
+ block.setWeight(Integer.parseInt(weight));
+
+ blockManager.write(block);
+ }
+
+ setBlocksPage();
+
} else {
String title = request.getPartAsString("title", MAX_TITLE_LENGTH).trim();
@@ -375,6 +403,28 @@
page.appendData(getFormPassword());
}
+ private void setBlocksPage() {
+
+ Element blocksElement = new Element("blocks");
+ Block[] blocks = blockManager.getBlocks();
+ for(Block b : blocks) {
+ Element block = new Element("block");
+ block.addAttribute(new Attribute("id", b.getId()));
+ block.addAttribute(new Attribute("type", i18n.getString("echo.block." + b.getType().toString())));
+ block.addAttribute(new Attribute("position", b.getPosition()));
+ block.addAttribute(new Attribute("weight", String.valueOf(b.getWeight())));
+
+ if(b.isConfigurable())
+ block.addAttribute(new Attribute("configurable", "true"));
+
+ blocksElement.appendChild(block);
+ }
+
+ page = new Page(blocksElement);
+ page.setTitle(i18n.getString("echo.common.blocks"));
+ page.appendData(getFormPassword());
+ }
+
private Element getFormPassword() {
Element formPassword = new Element("formpassword");
Modified: trunk/plugins/Echo/src/plugins/echo/NodesManager.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/NodesManager.java 2007-08-05 03:28:31 UTC (rev 14483)
+++ trunk/plugins/Echo/src/plugins/echo/NodesManager.java 2007-08-05 14:01:10 UTC (rev 14484)
@@ -38,7 +38,7 @@
File[] files = nodesDir.listFiles();
for(File f : files) {
- if(f.getName().matches("[0-9]{4}.xml"))
+ if(f.getName().matches("[0-9]{" + Echo.NODE_ID_LENGTH + "}.xml"))
nodes.put(f.getName().substring(0,4), f);
}
Modified: trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java 2007-08-05 03:28:31 UTC (rev 14483)
+++ trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java 2007-08-05 14:01:10 UTC (rev 14484)
@@ -80,7 +80,5 @@
writeToFile(transform.transform(new Document(index)), "category-" + category + ".html");
}
-
-
}
}
\ No newline at end of file
Modified: trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java 2007-08-05 03:28:31 UTC (rev 14483)
+++ trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java 2007-08-05 14:01:10 UTC (rev 14484)
@@ -12,6 +12,8 @@
import nu.xom.Text;
import nu.xom.Document;
+import java.io.*; // FIXME
+
/**
* This class provides a trivial internationalization framework
*/
@@ -59,6 +61,7 @@
props = new Properties();
try {
props.load(getClass().getResourceAsStream("/i18n/" + PREFIX + language + SUFFIX));
+// props.load(new FileInputStream("/home/fred/prog/soc/trunk/plugins/Echo/src/plugins/echo/i18n/" + PREFIX + language + SUFFIX));
} catch (IOException ioe) {
Logger.error(this, "IOException while accessing the " + language +"file" + ioe.getMessage(), ioe);
throw new MissingResourceException("Unable to load the translation file for " + language, "i18n", language);
Modified: trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties 2007-08-05 03:28:31 UTC (rev 14483)
+++ trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties 2007-08-05 14:01:10 UTC (rev 14484)
@@ -14,6 +14,9 @@
echo.common.date=Date
echo.common.title=Title
echo.common.nodeType=Type
+echo.common.blocks=Blocks
+echo.common.position=Position
+echo.common.weight=Weight
echo.write.newPost=Create a new post
echo.write.newPage=Create a new page
Deleted: trunk/plugins/Echo/src/test/blocks.xml
===================================================================
--- trunk/plugins/Echo/src/test/blocks.xml 2007-08-05 03:28:31 UTC (rev 14483)
+++ trunk/plugins/Echo/src/test/blocks.xml 2007-08-05 14:01:10 UTC (rev 14484)
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<blocks>
- <block id="menu.002" align="left" order="2" />
- <block id="menu.001" align="left" order="1" />
- <block id="recent-posts.001" align="right" order="1" />
-</blocks>
-
Modified: trunk/plugins/Echo/src/xml/edit.xsl
===================================================================
--- trunk/plugins/Echo/src/xml/edit.xsl 2007-08-05 03:28:31 UTC (rev 14483)
+++ trunk/plugins/Echo/src/xml/edit.xsl 2007-08-05 14:01:10 UTC (rev 14484)
@@ -14,8 +14,14 @@
<xsl:preserve-space elements="content" />
- <xsl:param name="contextprefix" />
+ <xsl:param name="baseDir" />
+ <xsl:variable name="categoriesFile"><xsl:value-of select="$baseDir" />categories.xml</xsl:variable>
+ <xsl:variable name="nodesDir"><xsl:value-of select="$baseDir" />nodes/</xsl:variable>
+ <xsl:variable name="blocksDir"><xsl:value-of select="$baseDir" />blocks/</xsl:variable>
+
+<!-- <xsl:import href="block.xsl" /> -->
+
<xsl:template match="/page">
<html>
<head>
@@ -70,18 +76,21 @@
<dt><a href="categories"><i18n key="echo.common.categories" /></a></dt>
<dd><i18n key="echo.manage.categories.desc" /></dd>
+ <dt><a href="blocks"><i18n key="echo.common.blocks" /></a></dt>
+ <dd><i18n key="echo.manage.blocks.desc" /></dd>
+
</dl>
</xsl:when>
<xsl:when test="categories">
- <xsl:if test="count(document(concat($contextprefix, '../categories.xml'))//category) > 0">
+ <xsl:if test="count(document($categoriesFile)//category) > 0">
<table>
<tr>
<th><i18n key="echo.common.name" /></th>
<th colspan="2"><i18n key="echo.common.action" /></th>
</tr>
- <xsl:for-each select="document(concat($contextprefix, '../categories.xml'))//category">
+ <xsl:for-each select="document($categoriesFile)//category">
<xsl:sort select="text()" />
<tr>
<xsl:if test="(position() mod 2) = 0">
@@ -133,9 +142,9 @@
</xsl:if>
<td><xsl:value-of select="@id" /></td>
- <td><xsl:value-of select="document(concat($contextprefix, @id, '.xml'))/node/modified" /></td>
- <td><xsl:value-of select="document(concat($contextprefix, @id, '.xml'))/node/title" /></td>
- <td><xsl:value-of select="document(concat($contextprefix, @id, '.xml'))/node/@type" /></td>
+ <td><xsl:value-of select="document(concat($nodesDir, @id, '.xml'))/node/modified" /></td>
+ <td><xsl:value-of select="document(concat($nodesDir, @id, '.xml'))/node/title" /></td>
+ <td><xsl:value-of select="document(concat($nodesDir, @id, '.xml'))/node/@type" /></td>
<td><a href="edit?node={@id}"><i18n key="echo.common.edit" /></a></td>
<td><a href="del?node={@id}"><i18n key="echo.common.delete" /></a></td>
</tr>
@@ -148,6 +157,57 @@
</xsl:choose>
</xsl:when>
+ <xsl:when test="./blocks">
+ <!-- <xsl:for-each select="'aa' 'bb'">
+ j
+ </xsl:for-each>-->
+ <form name="blocks" method="POST" action="">
+ <table>
+ <tr>
+ <th><i18n key="echo.common.name" /></th>
+ <th><i18n key="echo.common.position" /></th>
+ <th><i18n key="echo.common.weight" /></th>
+ <th><i18n key="echo.common.action" /></th>
+ </tr>
+ <xsl:for-each select="blocks/block">
+ <xsl:sort select="@postion" />
+ <tr>
+ <xsl:if test="(position() mod 2) = 0">
+ <xsl:attribute name="class">alternate</xsl:attribute>
+ </xsl:if>
+
+ <td><xsl:value-of select="@type" /></td>
+ <td>
+ <select name="position-{@id}">
+ <xsl:call-template name="blockPosition">
+ <xsl:with-param name="blockPosition" select="@position" />
+ </xsl:call-template>
+ </select>
+ </td>
+ <td>
+ <select name="weight-{@id}">
+ <xsl:call-template name="blockWeightOption">
+ <xsl:with-param name="start" select="0" />
+ <xsl:with-param name="end" select="5" />
+ <xsl:with-param name="blockWeight" select="@weight" />
+ </xsl:call-template>
+ </select>
+ </td>
+ <td>
+ <xsl:if test="@configurable">
+ <a href="configureBlock?block={@id}">configure</a>
+
+ </xsl:if>
+ </td>
+ </tr>
+ </xsl:for-each>
+ </table>
+ <input type="hidden" name="blocks" value="bleh" />
+ <input type="hidden" name="formPassword" value="{formpassword/@value}" />
+ <input type="submit" />
+ </form>
+ </xsl:when>
+
<xsl:when test="./node">
<form name="edit" method="POST" action="">
<label for="edit-title"><i18n key="echo.common.title" /></label>
@@ -165,7 +225,7 @@
</xsl:otherwise>
</xsl:choose>
</textarea>
- <xsl:if test="count(document(concat($contextprefix, '../categories.xml'))/categories/category) > 0">
+ <xsl:if test="count(document($categoriesFile)/categories/category) > 0">
<fieldset>
<legend><i18n key="echo.common.categories" /></legend>
<xsl:call-template name="categoriesCheckbox">
@@ -224,7 +284,7 @@
<xsl:template name="categoriesCheckbox">
<xsl:param name="nodeCategories" />
- <xsl:for-each select="document(concat($contextprefix, '../categories.xml'))/categories/category">
+ <xsl:for-each select="document($categoriesFile)/categories/category">
<xsl:sort select="text()" />
<xsl:variable name="id"><xsl:value-of select="@id" /></xsl:variable>
@@ -238,4 +298,63 @@
</xsl:template>
+ <xsl:template name="blockPosition">
+ <xsl:param name="blockPosition" />
+
+ <xsl:call-template name="blockPositionOption">
+ <xsl:with-param name="position">top</xsl:with-param>
+ <xsl:with-param name="blockPosition" select="$blockPosition" />
+ </xsl:call-template>
+ <xsl:call-template name="blockPositionOption">
+ <xsl:with-param name="position">bottom</xsl:with-param>
+ <xsl:with-param name="blockPosition" select="$blockPosition" />
+ </xsl:call-template>
+ <xsl:call-template name="blockPositionOption">
+ <xsl:with-param name="position">left</xsl:with-param>
+ <xsl:with-param name="blockPosition" select="$blockPosition" />
+ </xsl:call-template>
+ <xsl:call-template name="blockPositionOption">
+ <xsl:with-param name="position">right</xsl:with-param>
+ <xsl:with-param name="blockPosition" select="$blockPosition" />
+ </xsl:call-template>
+ <xsl:call-template name="blockPositionOption">
+ <xsl:with-param name="position">disabled</xsl:with-param>
+ <xsl:with-param name="blockPosition" select="$blockPosition" />
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template name="blockPositionOption">
+ <xsl:param name="position" />
+ <xsl:param name="blockPosition" />
+
+ <option value="{$position}">
+ <xsl:if test="$position = $blockPosition">
+ <xsl:attribute name="selected">selected</xsl:attribute>
+ </xsl:if>
+ <xsl:value-of select="$position" />
+ </option>
+ </xsl:template>
+
+ <xsl:template name="blockWeightOption">
+ <xsl:param name="start" select="0" />
+ <xsl:param name="end" select="0" />
+ <xsl:param name="blockWeight" />
+
+ <option value="{$start}">
+ <xsl:if test="$start = $blockWeight">
+ <xsl:attribute name="selected">selected</xsl:attribute>
+ </xsl:if>
+ <xsl:value-of select="$start" />
+ </option>
+
+ <xsl:if test="$start != $end">
+ <xsl:call-template name="blockWeightOption">
+ <xsl:with-param name="start" select="$start+1" />
+ <xsl:with-param name="end" select="$end" />
+ <xsl:with-param name="blockWeight" select="$blockWeight" />
+ </xsl:call-template>
+ </xsl:if>
+
+ </xsl:template>
+
</xsl:stylesheet>
\ No newline at end of file
More information about the cvs
mailing list