Update of /var/cvs/applications/richtext/src/org/mmbase/richtext/processors/xml
In directory 
james.mmbase.org:/tmp/cvs-serv10525/src/org/mmbase/richtext/processors/xml

Modified Files:
        MmxfGetString.java Util.java Wiki.java 
Log Message:
functionalaty to (handyer) maintain links in wiki-syntax


See also: 
http://cvs.mmbase.org/viewcvs/applications/richtext/src/org/mmbase/richtext/processors/xml


Index: MmxfGetString.java
===================================================================
RCS file: 
/var/cvs/applications/richtext/src/org/mmbase/richtext/processors/xml/MmxfGetString.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- MmxfGetString.java  14 Feb 2008 15:32:22 -0000      1.8
+++ MmxfGetString.java  1 Apr 2008 14:52:41 -0000       1.9
@@ -30,7 +30,7 @@
  * This class implements the `get' for `mmxf' fields.
  *
  * @author Michiel Meeuwissen
- * @version $Id: MmxfGetString.java,v 1.8 2008/02/14 15:32:22 michiel Exp $
+ * @version $Id: MmxfGetString.java,v 1.9 2008/04/01 14:52:41 michiel Exp $
  * @since MMBase-1.8
  */
 
@@ -106,6 +106,7 @@
                 StringWriter res = new StringWriter();
                 // TODO: XSL transformation parameter stuff must be 
generalized (not only cloud, but only e.g. request specific stuff must be dealt 
with).
                 Map params = new HashMap();
+                params.putAll(node.getCloud().getProperties());
                 params.put("cloud", node.getCloud());
                 XSLTransformer.transform(new DOMSource(xml), u, new 
StreamResult(res), params);
                 return res.toString();
@@ -116,6 +117,7 @@
                 java.net.URL u = 
ResourceLoader.getConfigurationRoot().getResource("xslt/2rich.xslt");
                 StringWriter res = new StringWriter();
                 Map params = new HashMap();
+                params.putAll(node.getCloud().getProperties());
                 params.put("cloud", node.getCloud());
                 XSLTransformer.transform(new DOMSource(xml), u, new 
StreamResult(res), params);
                 return res.toString();
@@ -128,6 +130,7 @@
                 java.net.URL u = 
ResourceLoader.getConfigurationRoot().getResource("xslt/mmxf2rich.xslt");
                 StringWriter res = new StringWriter();
                 Map params = new HashMap();
+                params.putAll(node.getCloud().getProperties());
                 params.put("cloud", node.getCloud());
                 XSLTransformer.transform(new DOMSource(xml), u, new 
StreamResult(res), params);
                 return res.toString();


Index: Util.java
===================================================================
RCS file: 
/var/cvs/applications/richtext/src/org/mmbase/richtext/processors/xml/Util.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Util.java   25 Mar 2008 18:00:14 -0000      1.2
+++ Util.java   1 Apr 2008 14:52:41 -0000       1.3
@@ -30,7 +30,7 @@
 /**
  * Utility functions, used by various classes in the package.
  * @author Michiel Meeuwissen
- * @version $Id: Util.java,v 1.2 2008/03/25 18:00:14 michiel Exp $
+ * @version $Id: Util.java,v 1.3 2008/04/01 14:52:41 michiel Exp $
  */
 
 public abstract class Util {
@@ -47,7 +47,9 @@
     public static Document parse(Object value)  throws 
javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException,  
java.io.IOException {
         if (value instanceof Document) return (Document) value;
         try {
-            log.info("Parsing " + value);
+            if (log.isDebugEnabled()) {
+                log.debug("Parsing " + value);
+            }
             return parse(new java.io.ByteArrayInputStream(("" + 
value).getBytes("UTF-8")));
         } catch (java.io.UnsupportedEncodingException uee) {
             // cannot happen, UTF-8 is supported..


Index: Wiki.java
===================================================================
RCS file: 
/var/cvs/applications/richtext/src/org/mmbase/richtext/processors/xml/Wiki.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Wiki.java   25 Mar 2008 18:00:14 -0000      1.1
+++ Wiki.java   1 Apr 2008 14:52:41 -0000       1.2
@@ -13,6 +13,7 @@
 import org.mmbase.bridge.Node;
 import org.mmbase.bridge.NodeList;
 import org.mmbase.bridge.util.Queries;
+import org.mmbase.util.xml.XMLWriter;
 import org.mmbase.util.*;
 import org.w3c.dom.*;
 import javax.xml.transform.dom.*;
@@ -21,22 +22,93 @@
 import org.mmbase.util.logging.*;
 
 /**
- * Set-processing for an `mmxf' field. This is the counterpart and inverse of 
[EMAIL PROTECTED] MmxfGetString}, for more
- * information see the javadoc of that class.
+ * Setting like wiki. A property of wiki-editing is, that you cannot point 
more then one idrel to
+ * the same anchor. Depending on this, the id's of the idrel can be left 
unfilled, and in the
+ * wiki-text, a user can simple refer to the node-number (or perhaps in later 
refinement some other
+ * id of the node).
+ *
  * @author Michiel Meeuwissen
- * @version $Id: Wiki.java,v 1.1 2008/03/25 18:00:14 michiel Exp $
+ * @version $Id: Wiki.java,v 1.2 2008/04/01 14:52:41 michiel Exp $
+ * @todo something goes wrong if same node relation multiple times.
  */
 
 class Wiki {
     private static final Logger log = Logging.getLoggerInstance(Wiki.class);
     private static final long serialVersionUID = 1L;
 
+
+    Node findById(NodeList links, String id) {
+        NodeIterator ni = links.nodeIterator();
+        while (ni.hasNext()) {
+            Node relation = ni.nextNode();
+            String relId = relation.getStringValue("id");
+            if (! "".equals(relId)) {
+                if (relId.equals(id)) {
+                    return relation;
+                }
+            } else {
+                Node destination = relation.getNodeValue("dnumber");
+                log.info("Found " + destination);
+                if (destination == null) {
+                    log.warn("dnumber null in " + relation);
+                } else {
+                    if (destination.getStringValue("number").equals(id)) {
+                        log.debug("Setting relation id of " + 
relation.getNumber() + " to " + destination.getNumber());
+                        relation.setStringValue("id", "" + 
destination.getNumber());
+                        relation.commit();
+                        log.debug("relation " + relation + " " + 
relation.getCloud());
+                        return relation;
+                    }
+                }
+            }
+        }
+        return null; // not found
+    }
+
     /**
+     * Simply considers the id the node-number, but this could be 
sophisitcated on.
+     */
+    Node getNode(Cloud cloud, String id) {
+        return cloud.getNode(id);
+    }
+
+    /**
+     * @param editedNode Node that is edited. Anchors will be either changed, 
or idrels will be
+     * created/modified to be in order
+     * @param source
      *
      */
     Document parse(Node editedNode, Document source) {
 
-        // TODO reolve anchors. Allow to use nodenumber as anchor.
+
+        Map<Integer, Node> usedLinks = new HashMap<Integer, Node>();
+        // reolve anchors. Allow to use nodenumber as anchor.
+        if (log.isDebugEnabled()) {
+            log.debug("Resolving " + editedNode + " " + 
XMLWriter.write(source, true));
+        }
+
+        Cloud cloud = editedNode.getCloud();
+        NodeManager objects = cloud.getNodeManager("object");
+        NodeQuery q = Queries.createRelationNodesQuery(editedNode, objects, 
"idrel", "destination");
+        NodeList links = cloud.getNodeManager("idrel").getList(q);
+
+        // search all anchors
+        org.w3c.dom.NodeList as = source.getElementsByTagName("a");
+        for (int i = 0; i < as.getLength(); i++) {
+            Element a = (Element) as.item(i);
+            String id = a.getAttribute("id");
+            if (log.isDebugEnabled()) {
+                log.debug("Found " + XMLWriter.write(a, true));
+            }
+            Node link = findById(links, id);
+            if (link != null) {
+                // odd, so never mind, we simply suppose it a node, and create 
the relation implicitely
+                Node node = getNode(cloud, id);
+                Relation newRel = editedNode.createRelation(node, 
cloud.getRelationManager(editedNode.getNodeManager(), node.getNodeManager(), 
"idrel"));
+                newRel.setStringValue("id", id);
+                newRel.commit();
+            }
+        }
 
         return source;
     }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to