001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.core.engine.util;
034:
035: import org.libresource.so6.core.WsConnection;
036: import org.libresource.so6.core.command.xml.DeleteAttribute;
037: import org.libresource.so6.core.command.xml.DeleteNode;
038: import org.libresource.so6.core.command.xml.InsertAttribute;
039: import org.libresource.so6.core.command.xml.InsertNode;
040: import org.libresource.so6.core.command.xml.UpdateAttribute;
041:
042: import java.util.ArrayList;
043: import java.util.Collection;
044: import java.util.Iterator;
045:
046: /**
047: * @author smack
048: */
049: public class XmlUtil {
050: private static final String VALID_CHAR = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/\"\'*-+.,;:!#{}[]()|`\\ _=?";
051:
052: public static String replaceInvalideXmlChar(String src) {
053: StringBuffer result = new StringBuffer();
054:
055: for (int i = 0; i < src.length(); i++) {
056: if (VALID_CHAR.indexOf(src.charAt(i)) != -1) {
057: result.append(src.charAt(i));
058: } else {
059: result.append("?");
060: }
061: }
062:
063: return result.toString();
064: }
065:
066: public static Collection convertToSo6Commands(WsConnection wsc,
067: String path, Collection xyDiffCmds) {
068: // TEMPO
069: // Replace the move command by delete/insert
070:
071: /*
072: * Vector tempo = new Vector(); for (Iterator i = xyDiffCmds.iterator();
073: * i.hasNext();) { XMLCommand cmd = (XMLCommand) i.next(); if
074: * (cmd.getType() == XMLCommand.MOVE_NODE) {
075: * fr.loria.ecoo.so6.xml.xydiff.MoveNode m =
076: * (fr.loria.ecoo.so6.xml.xydiff.MoveNode) cmd; tempo.addElement(new
077: * fr.loria.ecoo.so6.xml.xydiff.DeleteNode(m.getSourcePath(),
078: * m.getMovedNode())); tempo.addElement(new
079: * fr.loria.ecoo.so6.xml.xydiff.InsertNode(m.getDestPath(),
080: * m.getMovedNode())); } else { tempo.addElement(cmd); } }
081: */
082:
083: // Sort the commands
084: //Object[] cmds = xyDiffCmds.toArray();
085: //Object[] cmds = tempo.toArray();
086: //Arrays.sort(cmds);
087: //
088: ArrayList result = new ArrayList();
089:
090: for (Iterator i = xyDiffCmds.iterator(); i.hasNext();) {
091: //for (int i = 0; i < cmds.length; i++) {
092: Object xyCmd = i.next();
093:
094: //Object xyCmd = cmds[i];
095: if (xyCmd instanceof fr.loria.ecoo.so6.xml.xydiff.InsertNode) {
096: fr.loria.ecoo.so6.xml.xydiff.InsertNode in = (fr.loria.ecoo.so6.xml.xydiff.InsertNode) xyCmd;
097: result.add(new InsertNode(path, wsc, in.getNodePath(),
098: in.getNode()));
099: } else if (xyCmd instanceof fr.loria.ecoo.so6.xml.xydiff.DeleteNode) {
100: fr.loria.ecoo.so6.xml.xydiff.DeleteNode dn = (fr.loria.ecoo.so6.xml.xydiff.DeleteNode) xyCmd;
101: result.add(new DeleteNode(path, wsc, dn.getNodePath(),
102: dn.getNode()));
103: } else if (xyCmd instanceof fr.loria.ecoo.so6.xml.xydiff.InsertAttribute) {
104: fr.loria.ecoo.so6.xml.xydiff.InsertAttribute ia = (fr.loria.ecoo.so6.xml.xydiff.InsertAttribute) xyCmd;
105: result.add(new InsertAttribute(path, wsc, ia
106: .getNodePath(), ia.getName(), ia.getValue()));
107: } else if (xyCmd instanceof fr.loria.ecoo.so6.xml.xydiff.DeleteAttribute) {
108: fr.loria.ecoo.so6.xml.xydiff.DeleteAttribute da = (fr.loria.ecoo.so6.xml.xydiff.DeleteAttribute) xyCmd;
109: result.add(new DeleteAttribute(path, wsc, da
110: .getNodePath(), da.getName()));
111: } else if (xyCmd instanceof fr.loria.ecoo.so6.xml.xydiff.UpdateAttribute) {
112: fr.loria.ecoo.so6.xml.xydiff.UpdateAttribute ua = (fr.loria.ecoo.so6.xml.xydiff.UpdateAttribute) xyCmd;
113: result.add(new UpdateAttribute(path, wsc, ua
114: .getNodePath(), ua.getAttributeName(), ua
115: .getOldValue(), ua.getNewValue()));
116: }
117: }
118:
119: return result;
120: }
121: }
|