Index: xword/ContentFiltering/ContentFiltering.csproj
===================================================================
--- xword/ContentFiltering/ContentFiltering.csproj (revision 22283)
+++ xword/ContentFiltering/ContentFiltering.csproj (working copy)
@@ -31,6 +31,10 @@
4
+
+ False
+ ..\dependencies\CookComputing.XmlRpcV2.dll
+
False
..\dependencies\nunit.framework.dll
@@ -93,6 +97,7 @@
+
Index: xword/ContentFiltering/StyleSheetExtensions/SSXManager.cs
===================================================================
--- xword/ContentFiltering/StyleSheetExtensions/SSXManager.cs (revision 0)
+++ xword/ContentFiltering/StyleSheetExtensions/SSXManager.cs (revision 0)
@@ -0,0 +1,180 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using XWiki.XmlRpc;
+using System.Xml;
+using CookComputing.XmlRpc;
+using XWiki.Office.Word;
+using System.Collections.Specialized;
+using XWiki.Clients;
+
+namespace ContentFiltering.StyleSheetExtensions
+{
+ ///
+ /// StyleSheet Extensions management class.
+ /// A SSXManager builded from cleaned HTML of a local editing page can be used to
+ /// add StyleSheetExtensions objects coresponding to the CSS of that page.
+ /// A SSXManager builded from a remote wiki page can be used to get the CSS coresponding
+ /// to the StyleSheetExtensions objects of that page.
+ ///
+ public class SSXManager
+ {
+ const string SSX_CLASS_NAME = "XWiki.StyleSheetExtension";
+ const string XOFFICE_SSX = "XOfficeStyle";
+
+ ///
+ /// Creates a SSXManager
from the cleaned HTML of a local editing page.
+ ///
+ /// An instance of the ConversionManager
for this page.
+ /// Cleaned HTML of the local page.
+ /// An instance of a SSXManager
.
+ public static SSXManager BuildFromLocalHTML(ConversionManager pageConverter, string cleanHTML)
+ {
+ SSXManager ssxManager = new SSXManager();
+ XmlDocument xmlDoc = new XmlDocument();
+ xmlDoc.LoadXml(cleanHTML);
+ XmlNodeList styleNodes = xmlDoc.GetElementsByTagName("style");
+ string pageCSSContent = "";
+
+ foreach (XmlNode styleNode in styleNodes)
+ {
+ pageCSSContent += styleNode.InnerText;
+ }
+
+ XmlRpcStruct dictionary = new XmlRpcStruct();
+ dictionary.Add("code", pageCSSContent);
+ dictionary.Add("name", "XOfficeStyle");
+ dictionary.Add("use", "onDemand");
+ dictionary.Add("parse", "0");
+
+ XWikiObject ssxObject = new XWikiObject();
+ ssxObject.className = SSX_CLASS_NAME;
+ ssxObject.pageId = pageConverter.States.PageFullName;
+ ssxObject.objectDictionary = dictionary;
+
+ ssxManager.pageFullName = pageConverter.States.PageFullName;
+ ssxManager.pageCSSContent = pageCSSContent;
+ ssxManager.pageStyleSheetExtensions = new List();
+ ssxManager.pageStyleSheetExtensions.Add(ssxObject);
+ ssxManager.pageConverter = pageConverter;
+ return ssxManager;
+ }
+
+ ///
+ /// Builds a SSXManager
for a remote wiki page.
+ ///
+ /// An instance of the ConversionManager
for this page.
+ /// An instance of a SSXManager
.
+ public static SSXManager BuildFromServerPage(ConversionManager pageConverter)
+ {
+ SSXManager ssxManager = new SSXManager();
+ ssxManager.pageFullName = pageConverter.States.PageFullName;
+ ssxManager.pageConverter = pageConverter;
+
+ List ssxObjects = ssxManager.RetrieveStyleSheetExtensions();
+
+ ssxManager.pageStyleSheetExtensions = ssxObjects;
+ StringBuilder sb = new StringBuilder();
+ foreach (XWikiObject ssxObject in ssxObjects)
+ {
+ sb.Append(ssxObject.objectDictionary["code"]);
+ sb.Append(Environment.NewLine);
+ }
+ ssxManager.pageCSSContent = sb.ToString();
+
+ return ssxManager;
+ }
+
+
+ private ConversionManager pageConverter;
+ private string pageFullName;
+ private List pageStyleSheetExtensions;
+ private string pageCSSContent;
+
+
+ ///
+ /// An instance of SSXManager can be obtained only with its BuildFrom... methods.
+ ///
+ protected SSXManager()
+ {
+ }
+
+
+ ///
+ /// Gets the full name of the page.
+ ///
+ public string PageFullName
+ {
+ get { return pageFullName; }
+ }
+
+ ///
+ /// Gets the CSS content for the page.
+ ///
+ public string PageCSSContent
+ {
+ get { return pageCSSContent; }
+ }
+
+ ///
+ /// Gets a copy of the StyleSheetExtension XWikiObject list.
+ ///
+ public List PageStyleSheetExtensions
+ {
+ get { return pageStyleSheetExtensions.ToList(); }
+ }
+
+
+ ///
+ /// Adds to server SSX objects for the current page.
+ ///
+ public void AddStyleSheetExtensions()
+ {
+ IXWikiClient client = pageConverter.XWikiClient;
+ int i = 0;
+ foreach (XWikiObject ssxObject in pageStyleSheetExtensions)
+ {
+ NameValueCollection fieldsValues = new NameValueCollection();
+
+ fieldsValues.Add("code", ssxObject.objectDictionary["code"].ToString());
+ fieldsValues.Add("name", ssxObject.objectDictionary["name"].ToString());
+ fieldsValues.Add("use", ssxObject.objectDictionary["use"].ToString());
+ fieldsValues.Add("parse", ssxObject.objectDictionary["parse"].ToString());
+
+ //remove existing XOffice style sheet extensions for current page
+ List existingSSXObjects = RetrieveStyleSheetExtensions();
+ foreach (XWikiObject existingSSX in existingSSXObjects)
+ {
+ if (existingSSX.objectDictionary["name"] + "" == XOFFICE_SSX || existingSSX.prettyName == XOFFICE_SSX)
+ {
+ client.RemoveObject(pageFullName, SSX_CLASS_NAME, existingSSX.id);
+ }
+ }
+
+ client.AddObject(pageFullName, ssxObject.className, fieldsValues);
+ }
+
+ }
+
+ ///
+ /// Retrieve SSX object of the current page from the server.
+ ///
+ /// A list of XWikiObject
containing SSX objects for the current page.
+ protected List RetrieveStyleSheetExtensions()
+ {
+ XWikiObjectSummary[] objects = pageConverter.XWikiClient.GetObjects(pageFullName);
+ List ssxObjects = new List();
+ foreach (XWikiObjectSummary objSum in objects)
+ {
+ if (objSum.className == SSX_CLASS_NAME)
+ {
+ XWikiObject obj = pageConverter.XWikiClient.GetObject(pageFullName, SSX_CLASS_NAME, objSum.id);
+ ssxObjects.Add(obj);
+ }
+ }
+
+ return ssxObjects;
+ }
+ }
+}