Author: fred
Date: 2007-07-13 11:07:16 +0000 (Fri, 13 Jul 2007)
New Revision: 14061
Added:
trunk/plugins/Echo/src/test/categories.xml
Modified:
trunk/plugins/Echo/src/plugins/echo/Echo.java
trunk/plugins/Echo/src/plugins/echo/Node.java
trunk/plugins/Echo/src/plugins/echo/NodesManager.java
trunk/plugins/Echo/src/xml/edit.xsl
Log:
Adding categories support
Modified: trunk/plugins/Echo/src/plugins/echo/Echo.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/Echo.java 2007-07-13 11:04:44 UTC
(rev 14060)
+++ trunk/plugins/Echo/src/plugins/echo/Echo.java 2007-07-13 11:07:16 UTC
(rev 14061)
@@ -57,8 +57,8 @@
NODES_DIR.mkdirs();
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");
transform = new XSLTransform(styleSheet);
transform.setParameter("contextprefix",
NODES_DIR.getAbsolutePath() + "/");
Modified: trunk/plugins/Echo/src/plugins/echo/Node.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/Node.java 2007-07-13 11:04:44 UTC
(rev 14060)
+++ trunk/plugins/Echo/src/plugins/echo/Node.java 2007-07-13 11:07:16 UTC
(rev 14061)
@@ -14,6 +14,7 @@
private String id;
private Document doc = null;
private Element nodeElement = null;
+ private Element categoriesElement = null;
private Element titleElement = null;
private Element contentElement = null;
@@ -24,6 +25,9 @@
nodeElement = new Element("node");
nodeElement.addAttribute(new Attribute("id", id));
+ categoriesElement = new Element("categories");
+ nodeElement.appendChild(categoriesElement);
+
titleElement = new Element("title");
nodeElement.appendChild(titleElement);
@@ -40,6 +44,24 @@
}
+ private Element getCategoriesElement() {
+ if(categoriesElement == null)
+ categoriesElement = (Element)
doc.query("/node/categories").get(0);
+ return categoriesElement;
+
+ }
+
+ public void setCategories(String[] Ids) {
+
+ getCategoriesElement().removeChildren();
+
+ for(String id : Ids) {
+ Element category = new Element("category");
+ category.addAttribute(new Attribute("id", id));
+ categoriesElement.appendChild(category);
+ }
+ }
+
private Element getTitleElement() {
if(titleElement == null)
titleElement = (Element)
doc.query("/node/title").get(0);
Modified: trunk/plugins/Echo/src/plugins/echo/NodesManager.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/NodesManager.java 2007-07-13
11:04:44 UTC (rev 14060)
+++ trunk/plugins/Echo/src/plugins/echo/NodesManager.java 2007-07-13
11:07:16 UTC (rev 14061)
@@ -1,6 +1,7 @@
package plugins.echo;
import nu.xom.Builder;
+import nu.xom.Document;
import nu.xom.Element;
import nu.xom.Attribute;
import nu.xom.Serializer;
@@ -15,11 +16,13 @@
public class NodesManager {
+ private Builder parser;
private File nodesDir;
private HashMap<String, File> nodes;
- private Builder parser;
+ private HashMap<String, String> categories;
+
- public NodesManager(File nodesDirectory) {
+ public NodesManager(File nodesDirectory) throws IOException,
ParsingException{
nodesDir = nodesDirectory;
nodes = new HashMap<String, File> ();
@@ -30,6 +33,13 @@
if(f.getName().matches("[0-9]{4}.xml"))
nodes.put(f.getName().substring(0,4), f);
}
+
+ categories = new HashMap<String, String> ();
+ Document categoriesDoc =
parser.build(nodesDirectory.getParent() + File.separator + "categories.xml");
+ nu.xom.Nodes cats = categoriesDoc.query("//category");
+ for(int i=0; i < cats.size(); i++) {
+ categories.put(((Element)
cats.get(i)).getAttribute("id").getValue() , ((Element)
cats.get(i)).getValue());
+ }
}
public Node getNodeById(String nodeId) throws IOException,
ParsingException {
@@ -113,4 +123,55 @@
}
return nodesElement;
}
+
+ public void newCategory(String name) {
+
+ String id = "";
+ for(int i=1; i < 1000; i++) {
+ id = String.valueOf(i);
+ while(id.length() < 3)
+ id = "0" + id;
+
+ if(! categories.containsKey(id))
+ break;
+ }
+
+ categories.put(id, name);
+ }
+
+ /**
+ * Rename a category
+ * @param id The id of the category
+ * @param newName The new name to set
+ * @return true if the category was successfully , false if the
category 'id' does not exists.
+ *
+ */
+ public boolean renameCategory(String id, String newName) {
+
+ if(! categories.containsKey(id))
+ return false;
+
+ categories.put(id, newName);
+ return true;
+
+ }
+
+ public boolean deleteCategory(String id) throws IOException,
ParsingException {
+
+ if(! categories.containsKey(id))
+ return false;
+
+
+ String[] ids = getIds();
+ for(String i : ids) {
+ Node node = getNodeById(i);
+ nu.xom.Nodes c =
node.getDoc().query("/node/categories/category[@id = '" + id + "']");
+ if(c.size() != 0)
+ c.get(0).detach();
+ }
+
+ categories.remove(id);
+
+ return true;
+ }
}
Added: trunk/plugins/Echo/src/test/categories.xml
===================================================================
--- trunk/plugins/Echo/src/test/categories.xml (rev 0)
+++ trunk/plugins/Echo/src/test/categories.xml 2007-07-13 11:07:16 UTC (rev
14061)
@@ -0,0 +1,5 @@
+<categories>
+ <category id="001">Freenet"</category>
+ <category id="002">Linux</category>
+ <category id="003">My life</category>
+</categories>
Modified: trunk/plugins/Echo/src/xml/edit.xsl
===================================================================
--- trunk/plugins/Echo/src/xml/edit.xsl 2007-07-13 11:04:44 UTC (rev 14060)
+++ trunk/plugins/Echo/src/xml/edit.xsl 2007-07-13 11:07:16 UTC (rev 14061)
@@ -30,8 +30,9 @@
<div id="left">
<ul id="menu">
+ <li><a href="./new">New
node</a></li>
<li><a
href="./nodes">My nodes</a></li>
- <li><a href="./new">New
node</a></li>
+ <li><a
href="./categories">Categories</a></li>
<li><a
href="./generate">Generate</a></li>
</ul>
</div>
@@ -40,7 +41,7 @@
<h1><xsl:value-of
select="title/text()" /></h1>
<xsl:apply-templates
select="errors" />
<xsl:apply-templates
select="data" />
-<!-- <div><xsl:copy-of
select="/node()" /></div> -->
+ <div><xsl:copy-of
select="/node()" /></div>
</div>
</div>
@@ -99,7 +100,21 @@
</xsl:otherwise>
</xsl:choose>
</textarea>
- <!--del ?--> <input type="hidden" name="node-id"
value="{node/@id}" />
+ <xsl:if
test="count(document(concat($contextprefix,
'../categories.xml'))/categories/category) > 0">
+ <fieldset>
+ <legend>Categories</legend>
+ <xsl:for-each
select="document(concat($contextprefix,
'../categories.xml'))/categories/category">
+<!-- <input type="checkbox"
id="category-{@id}" name="category-{@id}"> -->
+<!-- <xsl:for-each
select="node/categories/category[@id = '001']"> -->
+<!--<xsl:if test="count(node/categories/category[@id='001']) > 0">
+ <xsl:attribute
name="checked">checked</xsl:attribute>
+ </xsl:if>-->
+<!-- </input> -->
+ <xsl:value-of
select="node/categories/category[@id = '001']/@id" />
+<!-- <label
for="category-{@id}"><xsl:value-of select="@name" /></label> -->
+ </xsl:for-each>
+ </fieldset>
+ </xsl:if>
<input type="hidden" name="formPassword"
value="{formpassword/@value}" />
<input type="submit" />
</form>