[freenet-cvs] r15190 - in trunk/plugins/Echo/src: plugins/echo plugins/echo/block plugins/echo/i18n xml

fred at freenetproject.org fred at freenetproject.org
Sat Sep 15 17:49:19 UTC 2007


Author: fred
Date: 2007-09-15 17:49:19 +0000 (Sat, 15 Sep 2007)
New Revision: 15190

Removed:
   trunk/plugins/Echo/src/plugins/echo/Page.java
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/plugins/echo/ProjectManager.java
   trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java
   trunk/plugins/Echo/src/plugins/echo/block/BlockManager.java
   trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java
   trunk/plugins/Echo/src/xml/edit.xsl
Log:
Using a monolithic XSL for the editor was a bad idea.

Step 1 :
* Preparing the API
* Rewrite the XSL style sheet to handle the kind of content


Modified: trunk/plugins/Echo/src/plugins/echo/Echo.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/Echo.java	2007-09-15 16:14:35 UTC (rev 15189)
+++ trunk/plugins/Echo/src/plugins/echo/Echo.java	2007-09-15 17:49:19 UTC (rev 15190)
@@ -3,7 +3,9 @@
 import plugins.echo.i18n.I18n;
 import plugins.echo.block.BlockManager;
 import plugins.echo.block.Block;
+import plugins.echo.editor.*;
 
+
 import freenet.pluginmanager.FredPlugin;
 import freenet.pluginmanager.FredPluginHTTP;
 import freenet.pluginmanager.FredPluginHTTPAdvanced;
@@ -28,6 +30,7 @@
 import nu.xom.ParsingException;
 import nu.xom.xslt.XSLException;
 
+import java.util.HashMap;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
@@ -38,6 +41,8 @@
 
 // TODO
 //	* Exceptions !
+//	* var Project / projectManager
+// 	* var Page
 
 
 public class Echo implements FredPlugin, FredPluginHTTP, FredPluginHTTPAdvanced, FredPluginThreadless {
@@ -45,26 +50,21 @@
 	public static final File BASE_DIR = new File("plugins/Echo/");
 	public static final int PROJECT_ID_LENGTH = 3;
 	public static final int NODE_ID_LENGTH = 4;
-	public static final int CATEGORY_ID_LENGTH = 3;
 	
 	private static final int MAX_TITLE_LENGTH = 200;
 	private static final int MAX_BODY_LENGTH = 100000;
-	private static final int MAX_ID_LENGTH = Math.max(PROJECT_ID_LENGTH, Math.max(NODE_ID_LENGTH, CATEGORY_ID_LENGTH));
 	private static final int MAX_OBJECT_LENGTH = 8;
 	private static final int MAX_CATEGORY_NAME_LENGTH = 100;
-	private static final int MAX_KEY_LENGTH = 1024*1024;
 	
 	protected PluginRespirator respirator;
 	private Builder parser;
 	private XSLTransform transform;
 	private I18n i18n;
-	private Page page;
+	private HashMap<String,Page> pages;
 	private ProjectManager projectManager;
 	private Project project;
 	private NodesManager nodesManager;
 	private BlockManager blockManager;
-	private Node node;
-	private ClientPutDir clientPutDir;
 	
 	public Echo()
 	{
@@ -83,10 +83,9 @@
 
 			parser = new Builder();
 			
-			Document styleSheet = parser.build(getClass().getResourceAsStream("/xml/edit.xsl"));
+			Document styleSheet = parser.build(getClass().getResourceAsStream("/xml/edit2.xsl"));
 // 			Document styleSheet = parser.build("/home/fred/prog/soc/trunk/plugins/Echo/src/xml/edit.xsl");
 			i18n.translateXML(styleSheet);
-			
 			transform = new XSLTransform(styleSheet);
 
 			projectManager = new ProjectManager(BASE_DIR, respirator.getNode().random);
@@ -94,7 +93,28 @@
 				projectManager.newProject("My Flog");
 			
 			setProject(projectManager.loadProject("001"));
+			String formPsw = respirator.getNode().clientCore.formPassword;
+			
+			
+			pages = new HashMap<String,Page>();
 
+			pages.put("plugins.echo.Echo", StaticPage.createFromContentFile("Welcome", "welcome.xml"));
+			
+			Page nodePage = new NodePage(nodesManager, formPsw);
+			pages.put("newPost", nodePage);
+			pages.put("newPage", nodePage);
+			pages.put("edit", nodePage);
+			
+			pages.put("nodes", new NodesPage(project.getNodesManager()));
+			pages.put("blocks", new BlocksPage(blockManager, formPsw));
+			pages.put("categories", new CategoriesPage(nodesManager, formPsw));
+			pages.put("generate", new GeneratePage(projectManager));
+			pages.put("insert", new InsertPage(projectManager, respirator.getNode().clientCore.getFCPServer(), formPsw));
+			
+			pages.put("write", StaticPage.createFromContentFile(I18n.getString("echo.action.write"), "write.xml"));
+			pages.put("manage", StaticPage.createFromContentFile(I18n.getString("echo.action.manage"), "manage.xml"));
+			pages.put("publish",StaticPage.createFromContentFile(I18n.getString("echo.action.publish"), "publish.xml"));
+			
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
@@ -110,7 +130,6 @@
 
 	public void terminate() {
 		// TODO
-		// Bleh
 	}
 
 	private void setProject(Project p) {
@@ -122,40 +141,44 @@
 	
 	}
 	
-	private String transform(Page page) {
+
+	private String handleHTTPRequest(HTTPRequest request) {
+		
 		try {
+			String fileName = (new File(request.getPath())).getName();
+			Page p;
 			
-			return transform.transform(page.getDoc()).get(0).toXML();
+			if(pages.containsKey(fileName))
+				p = pages.get(fileName);
+			else
+				p = StaticPage.createFromContentFile("404 error", "http404error.xml");
 			
+			p.handleHTTPRequest(request);
+			
 			/*
 				Nice but input white space are not respected
-			
-			
+			*/
 			ByteArrayOutputStream baos = new ByteArrayOutputStream();
 			Serializer serializer = new Serializer(baos);
 			serializer.setIndent(4);
 			serializer.setMaxLength(128);
-			serializer.write(new Document((Element) transform.transform(page.getDoc()).get(0)));
+			serializer.write(new Document((Element) transform.transform(new Document(p.toXML())).get(0)));
 			return baos.toString();
 			
-			*/
-			
+
+// 			return t.transform(new Document(p.toXML())).get(0).toXML();
 		} catch (Exception e) {
-			return e.getMessage();
+			e.printStackTrace();
+			return e.toString();
 		}
 	}
 	
 	public String handleHTTPGet(HTTPRequest request) throws PluginHTTPException {
 
-		
 		if ("/plugins/plugins.echo.Echo".equals(request.getPath()))
 			throw new RedirectPluginHTTPException("", "/plugins/plugins.echo.Echo", "/plugins/plugins.echo.Echo/");
 			
-		
 		String fileName = (new File(request.getPath())).getName();
-		String nodeId = request.getParam("node");
-		String catId = request.getParam("category");
-		String blockId = request.getParam("block");
 		
 		if ("edit.css".equals(fileName) || "echo-logo-small-0.1.png".equals(fileName)) {
 			
@@ -175,155 +198,8 @@
 				return ioe.getMessage();
 			}
 			
-		} else if ("newPost".equals(fileName) || "newPage".equals(fileName) || ("edit".equals(fileName) && ! "".equals(nodeId))) {
-
-			page = new Page();
-			page.appendData(getFormPassword());
-			
-			if("edit".equals(fileName)) {
-				
-				page.setTitle("Edit");
-				try {
-					
-					node = nodesManager.getNodeById(nodeId);
-					if(node == null)
-						page.appendError("The node " + nodeId + "does not exist");
-					else 
-						page.appendData(node.getRoot());
-
-				} catch (IOException ioe) {
-					page.appendError(ioe.getMessage());
-				} catch (ParsingException pe) {
-					page.appendError("The node " + nodeId  + " is damaged : " + pe.getMessage());
-				}
-				
-			} else {
-				page.setTitle("New " + fileName.substring(3,7));
-				node = new Node(nodesManager.getFreeNodeId(),
-						"newPost".equals(fileName) ? Node.NodeType.POST_NODE : Node.NodeType.STATIC_PAGE_NODE);
-				page.appendData(node.getRoot());
-			}
-			
-		} else if ("renameCategory".equals(fileName) &&  ! "".equals(catId)) {
-
-			page = new Page();
-			page.setTitle(i18n.getString("echo.common.rename"));
-			Element rename = new Element("rename");
-			
-			Element category = new Element("category");
-			category.addAttribute(new Attribute("id", catId));
-			category.addAttribute(new Attribute("name", nodesManager.getCategoryNameById(catId)));
-			
-			rename.appendChild(category);
-			page.appendData(rename);
-			page.appendData(getFormPassword());
-			
-		} else if ("del".equals(fileName) && (! "".equals(nodeId) || ! "".equals(catId))) {
-
-			page = new Page();
-			page.setTitle(i18n.getString("echo.common.delete"));
-			
-			Element object;
-			if(!"".equals(nodeId)) {
-				object = new Element("node");
-				object.addAttribute(new Attribute("id", nodeId));
-			} else {
-				object = new Element("category");
-				object.addAttribute(new Attribute("id", catId));
-			}
-			
-			Element del = new Element("delete");
-			del.appendChild(object);
-			page.appendData(del);
-			page.appendData(getFormPassword());
-			
-		} else if ("configureBlock".equals(fileName) && ! "".equals(blockId) ) {
-			
-			Element configureBlock = new Element("configure-block");
-			page = new Page(configureBlock);
-			if(blockManager.blockExists(blockId)) {
-				Block block = blockManager.getBlockById(blockId);
-				page.setTitle(i18n.getString("echo.block." + block.getType().toString()));
-				
-				if(block.isConfigurable())
-					configureBlock.appendChild(block.toXMLElement());
-				else
-					page.appendError("This block is not configurable");
-				
-			} else {
-				page.setTitle("Block");
-				page.appendError("Block not found");
-			}			
-			
-		} else if ("write".equals(fileName) || "manage".equals(fileName)) {
-			
-			page = new Page();
-			page.setTitle(i18n.getString("echo.action." + fileName));
-			page.appendData(new Element(fileName));
-			
-			
-		} else if ("publish".equals(fileName)) {
-			
-			Element pub = new Element("publish");
-			page = new Page(pub);
-			page.setTitle(i18n.getString("echo.action.publish"));
-			
-		} else if ("configure".equals(fileName)) {
-			
-			Element configure = new Element("configure");
-			Element projects = new Element("projects");
-			configure.appendChild(projects);
-			
-			for(String id : projectManager.getProjectsIds()) {
-			
-				Element project = new Element("project");
-				project.addAttribute(new Attribute("id", id));
-				projects.appendChild(project);
-			
-			}
-			
-			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)) {
-			
-			setInsertPage();
-				
-		} else if ("nodes".equals(fileName)) {
-			
-			setNodesPage();
-			
-		} else if ("categories".equals(fileName)) {
-
-			setCategoriesPage();
-			
-		} else if ("blocks".equals(fileName)) {
-			
-			setBlocksPage();
-			
-		} else {	
-			
-			setDefaultPage();
-			
-		}
-
-		return transform(page);
+		} else
+			return handleHTTPRequest(request);
 	}
 	
 	public String handleHTTPPut(HTTPRequest request) throws PluginHTTPException {
@@ -331,243 +207,13 @@
 	}
 	
 	public String handleHTTPPost(HTTPRequest request) throws PluginHTTPException {
- 		try {
-			String passwd = request.getPartAsString("formPassword", 32);				//
-			if((passwd == null) || !passwd.equals(respirator.getNode().clientCore.formPassword))	// FIXME : useless ?
-				return "Wrong Password !!";							//
-			
-			if(request.isPartSet("confirmdelete") || request.isPartSet("cancel")) {	// TODO
-				
-				String object = request.getPartAsString("object", MAX_OBJECT_LENGTH);
-				
-				if(request.isPartSet("cancel")) {
-					if("node".equals(object))
-						setNodesPage();
-					else
-						setCategoriesPage();
-				}else {
-					
-					String id = request.getPartAsString("id", MAX_ID_LENGTH);
-					
-					if("node".equals(object)) {
-						
-						if(nodesManager.nodeExists(id)) {
-							nodesManager.deleteNode(id);
-							setNodesPage();
-						} else {
-							setNodesPage();
-							page.appendError("The node " + id + "does not exist");
-						}
-						
-					} else {
-						
-						setCategoriesPage();
-						if(nodesManager.categoryExists(id)) {
-							nodesManager.deleteCategory(id);
-							nodesManager.writeCategories();
-						} else
-							page.appendError("The category " + id + "does not exist");
-					}
-				}
-			} else if (request.isPartSet("category-name")) {
-				
-				String name = request.getPartAsString("category-name", MAX_CATEGORY_NAME_LENGTH).trim();
-				String catId = request.getPartAsString("category-id", CATEGORY_ID_LENGTH);
-				
-				if(! "".equals(name)) {
-					if(! nodesManager.renameCategory(catId, name))
-						nodesManager.newCategory(name);
-					
-					nodesManager.writeCategories();
-					
-					setCategoriesPage();
-					
-				} 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 if (request.isPartSet("insert-key")) {
-				setInsertPage();
-				
-				if(clientPutDir == null || clientPutDir.hasFinished()) {
-					FreenetURI insertURI = null;
-					FreenetURI requestURI = null;
-					
-					try {
-						insertURI = new FreenetURI(request.getPartAsString("insert-key", MAX_KEY_LENGTH));
-					} catch(MalformedURLException mue) {
-						page.appendError("Invalid insertion key : " + mue.getMessage());
-					}
-					
-					try {
-						requestURI = new FreenetURI(request.getPartAsString("request-key", MAX_KEY_LENGTH));
-					} catch(MalformedURLException mue) {
-						page.appendError("Invalid request key : " + mue.getMessage());
-					}
-					
-					if(insertURI != null && requestURI != null) {
-					
-						
-						if (! project.getInsertURI().equals(insertURI)){
-							project.setInsertURI(insertURI);
-							
-						}
-						
-						if (! project.getRequestURI().equals(requestURI)) {
-							project.setRequestURI(requestURI);
-							
-						}
-						
-						SiteGenerator generator = new SiteGenerator(project);
-						generator.generate();
-						
-						SimpleDirectoryInserter inserter = new SimpleDirectoryInserter(respirator.getNode().clientCore.getFCPServer());
-						clientPutDir = inserter.insert(new File(project.getProjectDir(), "out"), "index.html", insertURI);
-						
-						setInsertPage();					
-					}
-				}
-								
-			} else {
-			
-				String title = request.getPartAsString("title", MAX_TITLE_LENGTH).trim();
-				String body = request.getPartAsString("body", MAX_BODY_LENGTH).trim();
-
-				if("".equals(title))
-					page.appendError("Field \"title\" is empty");
-
-				if("".equals(body)) 
-					page.appendError("Field \"body\" is empty");
-
-				node.setTitle(title);
-				node.setBody(body);
-				
-				String[] cats = nodesManager.getCategoriesIds();
-				for(String cat : cats)
-					node.setCategory(cat, request.isPartSet("category-" + cat));
-					
-				if(page.countErrors() == 0) {
-					
-					setNodesPage();
-					
-					try {
-
-						nodesManager.writeNode(node);
-						
-					} catch (FileNotFoundException fnfe) {
-						page.appendError("fnfe" + fnfe.getMessage());
-					} catch (IOException ioe) {
-						page.appendError("Cannot write node " + node.getId() + " : " + ioe.getMessage());
-					} catch (Exception e) {
-						page.appendError(e.getMessage());
-					}
-				} else {
-
-					page.setTitle("Edit");
-					page.appendData(getFormPassword());
-					page.appendData(node.getRoot());
-				}
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-			return e.getMessage();
-		}
-
-		return transform(page);
-
-	}
-
-	private void setDefaultPage() {
-	
-		page = new Page();
-	
-	}
-
-	private void setNodesPage() {
-		page = new Page();
-		page.setTitle("My nodes");
-		page.appendData(nodesManager.getXMLNodesList());
-	}
-	
-	private void setCategoriesPage() {
-		page = new Page(new Element("categories"));
-		page.setTitle(i18n.getString("echo.common.categories"));
-		page.appendData(getFormPassword());
-	}
-
-	private void setBlocksPage() {
+		String passwd = request.getPartAsString("formPassword", 32);				//
+		if((passwd == null) || !passwd.equals(respirator.getNode().clientCore.formPassword))	// FIXME : useless ?
+			return "Wrong Password !!";							//
 		
-		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 void setInsertPage() {
-		
-			Element insert = new Element("insert");
-			page= new Page(insert);
-			page.setTitle("Insert");
-			page.appendData(getFormPassword());
-			
-			if(clientPutDir == null || clientPutDir.hasFinished()) {
-			
-				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 {
-				insert.addAttribute(new Attribute("running","true"));
-			}
-	
-	}
-	
-	private Element getFormPassword() {
-		
-		Element formPassword = new Element("formpassword");
-		formPassword.addAttribute(new Attribute("value", respirator.getNode().clientCore.formPassword));
+		return handleHTTPRequest(request);
 
-		return formPassword;
 	}
-
 }
\ No newline at end of file

Modified: trunk/plugins/Echo/src/plugins/echo/Node.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/Node.java	2007-09-15 16:14:35 UTC (rev 15189)
+++ trunk/plugins/Echo/src/plugins/echo/Node.java	2007-09-15 17:49:19 UTC (rev 15190)
@@ -16,6 +16,7 @@
 public class Node {
 
 	public enum NodeType { POST_NODE, STATIC_PAGE_NODE };
+	public static final int CATEGORY_ID_LENGTH = 3;
 	
 	private String id;
 	private NodeType type = null;

Modified: trunk/plugins/Echo/src/plugins/echo/NodesManager.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/NodesManager.java	2007-09-15 16:14:35 UTC (rev 15189)
+++ trunk/plugins/Echo/src/plugins/echo/NodesManager.java	2007-09-15 17:49:19 UTC (rev 15190)
@@ -74,6 +74,12 @@
 
 	}
 
+	public int size() {
+
+		return nodes.size();
+
+	} 
+
 	public Nodes getPosts() throws IOException, ParsingException {
 		
 		Nodes posts = new Nodes();
@@ -157,7 +163,8 @@
 		return nodes.keySet().toArray(new String[]{});
 		
 	}
-
+	
+	// Useless ??
 	public Element getXMLNodesList() {
 
 		String[] ids = this.getIds();
@@ -182,6 +189,12 @@
 		
 	}
 	
+	public int countCategories() {
+	
+		return categories.size();
+	
+	}
+	
 	public String getCategoryNameById(String id) {
 		
 		return categories.get(id);

Deleted: trunk/plugins/Echo/src/plugins/echo/Page.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/Page.java	2007-09-15 16:14:35 UTC (rev 15189)
+++ trunk/plugins/Echo/src/plugins/echo/Page.java	2007-09-15 17:49:19 UTC (rev 15190)
@@ -1,74 +0,0 @@
-package plugins.echo;
-
-import nu.xom.Document;
-import nu.xom.Node;
-import nu.xom.Nodes;
-import nu.xom.Element;
-
-import java.util.Vector;
-
-public class Page {
-
-	private String title = null;
-	private nu.xom.Nodes data;
-	private Vector<String> errors;
-	
-	public Page() {
-		data = new nu.xom.Nodes();
-		errors = new Vector<String> ();
-	}	
-
-	public Page(Element content) {
-		this();
-		this.appendData(content);
-	} 
-	
-	public void setTitle(String title) {
-		this.title = title;
-	}
-
-	public void setData(nu.xom.Nodes data) {
-		this.data = data;
-	}
-
-	public void appendData(nu.xom.Node data) {
-		this.data.append(data);
-	}
-	
-	public void appendError(String desc) {
-		errors.add(desc);
-	}
-
-	public Document getDoc() {
-		Element page = new Element("page");
-		
-		Element titleElement = new Element("title");
-		titleElement.appendChild(title);
-		page.appendChild(titleElement);
-
-		if(errors.size() != 0) {
-			Element errorsElement = new Element("errors");
-			for(String e : errors) {
-				Element error = new Element("error");
-				error.appendChild(e);
-				errorsElement.appendChild(error); 
-			}
-
-			page.appendChild(errorsElement);
-		}
-		
-		Element dataElement = new Element("data");
-		for(int i=0; i < data.size(); i++) {
-			data.get(i).detach();
-			dataElement.appendChild(data.get(i));
-		}
-		page.appendChild(dataElement);
-
-		return new Document(page);
-		
-	}
-
-	public int countErrors() {
-		return errors.size();
-	}
-}

Modified: trunk/plugins/Echo/src/plugins/echo/ProjectManager.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/ProjectManager.java	2007-09-15 16:14:35 UTC (rev 15189)
+++ trunk/plugins/Echo/src/plugins/echo/ProjectManager.java	2007-09-15 17:49:19 UTC (rev 15190)
@@ -18,6 +18,7 @@
 	private File baseDir;
 	private HashMap<String,File> projects;
 	private RandomSource randomSource;
+	private Project currentProject;
 
 	public ProjectManager(File baseDir, RandomSource randomSource) {
 	
@@ -37,12 +38,19 @@
 	
 		if(projects.containsKey(projectId)) {
 		
-			return new Project(projects.get(projectId));
+			currentProject = new Project(projects.get(projectId));
+			return getCurrentProject();
 		
 		}
 		
 		return null;
 	}
+
+	public Project getCurrentProject() {
+
+		return currentProject;
+
+	}
 	
 	public Project newProject(String projectTitle) throws IOException, ParsingException {
 	

Modified: trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java	2007-09-15 16:14:35 UTC (rev 15189)
+++ trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java	2007-09-15 17:49:19 UTC (rev 15190)
@@ -111,4 +111,10 @@
 		cssFile.close();
 		
 	}
+	
+	public File getOutDir() {
+		
+		return outDir;
+	
+	}
 }
\ No newline at end of file

Modified: trunk/plugins/Echo/src/plugins/echo/block/BlockManager.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/block/BlockManager.java	2007-09-15 16:14:35 UTC (rev 15189)
+++ trunk/plugins/Echo/src/plugins/echo/block/BlockManager.java	2007-09-15 17:49:19 UTC (rev 15190)
@@ -96,6 +96,7 @@
 		write(blogroll);
 		
 		Block categories = new CategoriesBlock("002");
+		categories.setPosition("right");
 		write(categories);
 	
 	}

Modified: trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java
===================================================================
--- trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java	2007-09-15 16:14:35 UTC (rev 15189)
+++ trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java	2007-09-15 17:49:19 UTC (rev 15190)
@@ -24,9 +24,9 @@
 	public static final String PREFIX = "echo.i18n.";
 	public static final String SUFFIX = ".properties";
 	
-	private String selectedLanguage;
-	private Properties translation;
-	private Properties defaultTranslation = null;
+	private static String selectedLanguage;
+	private static Properties translation;
+	private static Properties defaultTranslation = null;
 
 	public I18n(String language) throws MissingResourceException {
 		
@@ -39,15 +39,15 @@
 	* 	Set the language
 	* 	@param language the ISO code of the language 
 	*/
-	public void setLanguage(String language) throws MissingResourceException {
+	public static void setLanguage(String language) throws MissingResourceException {
 		
-			Logger.normal("I18n", "Changing the current language to : " + language);
-			loadTranslation(language, translation);
-			
-			if(! language.equals(DEFAULT_LANGUAGE))
-				loadTranslation(DEFAULT_LANGUAGE, defaultTranslation);
-			
-			selectedLanguage = language;
+		Logger.normal("I18n", "Changing the current language to : " + language);
+		loadTranslation(language, translation);
+		
+		if(! language.equals(DEFAULT_LANGUAGE))
+			loadTranslation(DEFAULT_LANGUAGE, defaultTranslation);
+		
+		selectedLanguage = language;
 	}
 	
 	/**
@@ -55,15 +55,15 @@
 	*	@param language the ISO code of the language
 	*	@param props the properties to load into 
 	*/
-	private void loadTranslation(String language, Properties props) throws MissingResourceException {
+	private static void loadTranslation(String language, Properties props) throws MissingResourceException {
 		
 		if(props == null)
 			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));
+// 			props.load(ClassLoader.getSystemClassLoader().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);
+			Logger.error("I18n", "IOException while accessing the " + language +"file" + ioe.getMessage(), ioe);
 			throw new MissingResourceException("Unable to load the translation file for " + language, "i18n", language);
 		}
 	}
@@ -73,7 +73,7 @@
 	*	@param key
 	*	@return the translated String in the selected language, the translated String in the default language or the key itself if the key is not found in the default language		
 	*/
-	public String getString(String key) {
+	public static String getString(String key) {
 	
 		String str = translation.getProperty(key);
 		if(str != null)
@@ -99,7 +99,7 @@
 	*	Translate a whole XML document, replace i18n elements by the translations of their keys
 	*	@param doc the nu.xom.Document to translate
 	*/
-	public void translateXML(Document doc) {
+	public static void translateXML(Document doc) {
 	
 		nu.xom.Nodes i18nNodes = doc.query("//i18n");	
 		

Modified: trunk/plugins/Echo/src/xml/edit.xsl
===================================================================
--- trunk/plugins/Echo/src/xml/edit.xsl	2007-09-15 16:14:35 UTC (rev 15189)
+++ trunk/plugins/Echo/src/xml/edit.xsl	2007-09-15 17:49:19 UTC (rev 15190)
@@ -11,17 +11,7 @@
 	doctype-public= "-//W3C//DTD XHTML 1.0 Strict//EN"
 	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
 	indent="yes" />
-	
-	<xsl:preserve-space  elements="content" />
-	
-	<xsl:param name="baseDir" />
 
-	<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:variable name="categoriesFile"><xsl:value-of select="$nodesDir" />categories.xml</xsl:variable>
-	
-<!-- 	<xsl:import href="block.xsl" />  -->
-
 	<xsl:template match="/page">
 		<html>
 			<head>
@@ -44,286 +34,17 @@
 					</div>
 
 					<div id="main">
-						<h1><xsl:value-of select="title/text()" /></h1>
+						<h1><xsl:value-of select="@title" /></h1>
 						<xsl:apply-templates select="errors" />
-						<xsl:apply-templates select="data" />
-<!--  						<div><xsl:copy-of select="/node()" /></div>  -->
-					
+						<xsl:apply-templates select="content" />	
 					</div>
 				</div>
 			</body>
 		</html>
 	</xsl:template>
 
-	<xsl:template match="data">
-		<!-- 	 otherwise nodes list ? (document(..))		-->
-		<xsl:choose>
-			<xsl:when test="write">
-				<dl>
-					<dt><a href="newPost"><i18n key="echo.common.blogPost" /></a></dt>
-					<dd><i18n key="echo.write.newPost" /></dd>
-					
-					<dt><a href="newPage"><i18n key="echo.common.staticPage" /></a></dt>
-					<dd><i18n key="echo.write.newPage" /></dd>
-				</dl>
-			</xsl:when>
-			
-			<xsl:when test="manage">
-				<dl>
-					<!-- Suxx ? -->
-					<dt><a href="nodes"><i18n key="echo.manage.myNodes" /></a></dt>
-					<dd><i18n key="echo.manage.myNodes.desc" /></dd>
-
-					<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="publish">
-				<dl>
-					<dt><a href="generate"><i18n key="echo.generate" /></a></dt>
-					<dd><i18n key="echo.generate.desc" /></dd>
-					
-					<dt><a href="insert"><i18n key="echo.insert" /></a></dt>
-					<dd><i18n key="echo.insert.desc" /></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">
-				<xsl:choose>
-					<xsl:when test="insert/@running='true'">
-						An insertion is already running, you can see its advancement on the <a href="/queue/">queue page</a>.
-					</xsl:when>
-					<xsl:otherwise>
-						<form name="insert" method="POST" action="">
-							<label for="insert-key">Insert key</label>
-							<input type="text" name="insert-key" id="insert-key" size="70">
-							<xsl:if test="insert/insertURI" >
-								<xsl:attribute name="value">
-									<xsl:value-of select="insert/insertURI" />
-								</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/requestURI">
-								<xsl:attribute name="value">
-									<xsl:value-of select="insert/requestURI" />
-								</xsl:attribute>
-							</xsl:if>
-							</input>
-							<input type="hidden" name="formPassword" value="{formpassword/@value}" />
-							<input type="submit" />
-						</form>
-					</xsl:otherwise>
-				</xsl:choose>
-			</xsl:when>
-			
-			<xsl:when test="configure">
-				<form name="" method="POST" action="">
-					<select name="project">
-					<xsl:for-each select="configure/projects/project">
-						<option value="@id"><xsl:value-of select="@id" /></option>
-					</xsl:for-each>
-					</select>
-					<input type="hidden" name="formPassword" value="{formpassword/@value}" class="inline" />
-					<input type="submit" value="Load" class="inline" />
-				</form>
-			</xsl:when>
-			
-			<xsl:when test="categories">
-				<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($categoriesFile)//category">
-					<xsl:sort select="text()" />
-					<tr>
-						<xsl:if test="(position() mod 2) = 0">
-							<xsl:attribute name="class">alternate</xsl:attribute>
-						</xsl:if>
-						
-						<td><xsl:value-of select="text()" /></td>
-						<td><a href="renameCategory?category={@id}"><i18n key="echo.common.rename" /></a></td>
-						<td><a href="del?category={@id}"><i18n key="echo.common.delete" /></a></td>
-					</tr>	
-					</xsl:for-each>
-				</table>
-				</xsl:if>
-
-				<form name="newCategory" method="POST" action="">
-					<label for="category-name" class="inline"><i18n key="echo.manage.newCategory" /></label>
-					<input type="text" id="category-name" name="category-name" class="inline" />
-					<input type="hidden" name="formPassword" value="{formpassword/@value}" class="inline" />
-					<input type="submit" value="Create" class="inline" />
-				</form>
-				
-			</xsl:when>
-			<xsl:when test="rename">
-				<form name="newCategory" method="POST" action="">
-					<label for="category-name" class="inline"><i18n key="echo.common.name" /></label>
-					<input type="text" id="category-name" name="category-name" value="{rename/category/@name}" class="inline" />
-					<input type="hidden" name="category-id" value="{rename/category/@id}" class="inline" />
-					<input type="hidden" name="formPassword" value="{formpassword/@value}" class="inline" />
-					<input type="submit" class="inline" />
-				</form>
-				
-			</xsl:when>
-			<xsl:when test="nodes">
-				<xsl:choose>
-				<xsl:when test="count(./nodes/node) > 0">
-				<table>
-				<tr>
-					<th>Id</th>
-					<th><i18n key="echo.common.date" /></th>
-					<th><i18n key="echo.common.title" /></th>
-					<th><i18n key="echo.common.nodeType" /></th>
-					<th colspan="2"><i18n key="echo.common.action" /></th>
-				</tr>
-				<xsl:for-each select="nodes/node">
-				<xsl:sort select="@id" />
-				<tr>
-					<xsl:if test="(position() mod 2) = 0">
-						<xsl:attribute name="class">alternate</xsl:attribute>
-					</xsl:if>
-					
-					<td><xsl:value-of select="@id" /></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>
-				</xsl:for-each>
-				</table>
-				</xsl:when>
-				<xsl:otherwise>
-					You don't have any node, <a href="./write">create a new one</a>.
-				</xsl:otherwise>
-				</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="configure-block">
-				<xsl:if test="configure-block/block/@type='blog-roll'">
-					<xsl:call-template name="block-blog-roll">
-						<xsl:with-param name="block" select="configure-block/block" />
-					</xsl:call-template>
-				</xsl:if>
-			</xsl:when>
-			
-			<xsl:when test="./node">
-			<form name="edit" method="POST" action="">
-				<label for="edit-title"><i18n key="echo.common.title" /></label>
-				<input type="text" id="edit-title" name="title" size="100" value="{node/title/text()}"/>
-				<label for="edit-body"><i18n key="echo.write.nodeBody" /></label>
-				<textarea id="edit-body" name="body" cols="100" rows="50">
-					<xsl:choose>
-						<xsl:when test="node/content/text()">
-							<xsl:text><xsl:value-of select="node/content" /></xsl:text>
-						</xsl:when>
-						<xsl:otherwise>
-							<xsl:text> </xsl:text>
-						</xsl:otherwise>
-					</xsl:choose>
-				</textarea>
-				<xsl:if test="count(document($categoriesFile)/categories/category) > 0">
-				<fieldset>
-					<legend><i18n key="echo.common.categories" /></legend>
-					<xsl:call-template name="categoriesCheckbox">
-						<xsl:with-param name="nodeCategories" select="node/categories" />
-					</xsl:call-template>
-				</fieldset>
-				</xsl:if>
-				<input type="hidden" name="formPassword" value="{formpassword/@value}" />
-				<input type="submit" />
-			</form>
-			</xsl:when>
-			
-			<xsl:when test="./delete">
-			Are you sure you want to delete the
-				<xsl:value-of select="name(delete/*)" />
-				<xsl:text> </xsl:text>
-				<xsl:value-of select="delete/*/@id" /> ?
-				
- 			<form name="del" method="POST" action=""> 
- 				<input type="hidden" name="object" value="{name(delete/*)}" />
- 				<input type="hidden" name="id" value="{delete/*/@id}" />
- 				<input type="hidden" name="formPassword" value="{formpassword/@value}" />
- 				<input type="submit" name="confirmdelete" value="Delete" class="inline" />
- 				<input type="submit" name="cancel" value="Cancel" class="inline" />
-			</form>
-			</xsl:when>
-			
-			<xsl:otherwise>
-				Welcome
-			</xsl:otherwise>
-			
-		</xsl:choose>
+	<xsl:template match="content">
+		<xsl:copy-of select="./node()" />
 	</xsl:template> 
 
 	<xsl:template match="errors">
@@ -344,84 +65,4 @@
 		</div>
 	</xsl:template>
 	
-	<xsl:template name="categoriesCheckbox">
-		<xsl:param name="nodeCategories" />
-		<xsl:for-each select="document($categoriesFile)/categories/category">
-		<xsl:sort select="text()" />
-			<xsl:variable name="id"><xsl:value-of select="@id" /></xsl:variable>
-			
-			<input type="checkbox" id="category-{@id}" name="category-{@id}" class="inline">
-			<xsl:if test="$nodeCategories/category[@id=$id]">
-				<xsl:attribute name="checked">checked</xsl:attribute>
-			</xsl:if>
-			</input>
-			<label for="category-{@id}" class="inline"><xsl:value-of select="text()" /></label>
-		</xsl:for-each>
-		
-	</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:template name="block-blog-roll">
-		<xsl:param name="block" />
-		TODO
-	</xsl:template>
-	
 </xsl:stylesheet>
\ No newline at end of file




More information about the cvs mailing list