Index: xword/Wiki/src/main/resources/MSOffice/GetEncodingService.xml =================================================================== --- xword/Wiki/src/main/resources/MSOffice/GetEncodingService.xml (revision 0) +++ xword/Wiki/src/main/resources/MSOffice/GetEncodingService.xml (revision 0) @@ -0,0 +1,61 @@ + + + +MSOffice +GetEncodingService + +en +0 + +XWiki.Admin +XWiki.Admin + +XWiki.Admin +1239491696000 +1239493018000 +1239493018000 +2.1 +GetEncodingsService + + + + +false +xwiki/1.0 +false + + +XWiki.TagClass + + + + + + + + +0 +input +1 +tags +1 +Tags +1 + + ,| +30 +0 + +com.xpn.xwiki.objects.classes.StaticListClass + + +MSOffice.GetEncodingService +0 +XWiki.TagClass +9fd947e4-3ebe-41b0-ba90-2cd80b3c7df3 + + + + +$xwiki.getEncoding() + Index: xword/XWikiLib/Clients/InvalidEncodingNameException.cs =================================================================== --- xword/XWikiLib/Clients/InvalidEncodingNameException.cs (revision 0) +++ xword/XWikiLib/Clients/InvalidEncodingNameException.cs (revision 0) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace XWiki.Clients +{ + class InvalidEncodingNameException : Exception + { + } +} Index: xword/XWikiLib/Clients/IXWikiClient.cs =================================================================== --- xword/XWikiLib/Clients/IXWikiClient.cs (revision 18635) +++ xword/XWikiLib/Clients/IXWikiClient.cs (working copy) @@ -22,6 +22,14 @@ } /// + /// Specifies the encoding from the XWiki server. + /// + Encoding ServerEncoding + { + get; + } + + /// /// Basic authentification method. /// /// Index: xword/XWikiLib/Clients/XWikiHTTPClient.cs =================================================================== --- xword/XWikiLib/Clients/XWikiHTTPClient.cs (revision 18635) +++ xword/XWikiLib/Clients/XWikiHTTPClient.cs (working copy) @@ -28,6 +28,7 @@ "rememeberme", "validation"}; private bool isLoggedIn; + private Encoding encoding; /// The url of the server. /// The username used to authenticate. /// The passowrd used to authenticate. @@ -118,6 +119,14 @@ return false; } isLoggedIn = true; + try + { + encoding = GetEncoding(); + } + catch (InvalidEncodingNameException ex) + { + encoding = null; + } return true; } @@ -141,6 +150,34 @@ } /// + /// Gets the encoding of the wiki instance. + /// + /// The character encoding from the XWiki server. + private Encoding GetEncoding() + { + Encoding enc; + + InsertCookies(); + String uri = ServerURL + XWikiURLs.GetEncoding; + Stream data = webClient.OpenRead(uri); + StreamReader reader = new StreamReader(data); + String response = reader.ReadToEnd(); + data.Close(); + reader.Close(); + try + { + enc = Encoding.GetEncoding(response); + } + catch (ArgumentException e) + { + // TODO: Log this error + throw new InvalidEncodingNameException(); + + } + return enc; + } + + /// /// Starts reading from an address. /// /// The adress. @@ -309,6 +346,28 @@ } /// + /// Specifies if the current encoding from the XWiki server. + /// + public Encoding ServerEncoding + { + get + { + if (encoding == null) + { + try + { + encoding = GetEncoding(); + } + catch (InvalidEncodingNameException ex) + { + encoding = Encoding.GetEncoding("ISO-8859-1"); + } + } + return encoding; + } + } + + /// /// Authenticates the user to the server. /// /// The username. @@ -622,4 +681,5 @@ #endregion } -} \ No newline at end of file +} + Index: xword/XWikiLib/Clients/XWikiXMLRPCClient.cs =================================================================== --- xword/XWikiLib/Clients/XWikiXMLRPCClient.cs (revision 18635) +++ xword/XWikiLib/Clients/XWikiXMLRPCClient.cs (working copy) @@ -8,6 +8,7 @@ public class XWikiXMLRPCClient : IXWikiClient { private bool isLoggedIn; + private Encoding encoding; /// /// XML-RPC implementation of IXWikiCLient. /// Provides access to the main features of XWiki using the XML-RPC API. @@ -31,6 +32,17 @@ } /// + /// Specifies if the current encoding from the XWiki server. + /// + public Encoding ServerEncoding + { + get + { + return encoding; + } + } + + /// /// Authenticates the user to the server. /// /// True if the operation succedes. False if the operation fails. Index: xword/XWikiLib/XWiki/XWikiURLFactory.cs =================================================================== --- xword/XWikiLib/XWiki/XWikiURLFactory.cs (revision 18635) +++ xword/XWikiLib/XWiki/XWikiURLFactory.cs (working copy) @@ -16,6 +16,7 @@ static String wikiStructureURL = "/xwiki/bin/view/MSOffice/StructureService?xpage=plain"; static String attachmentServiceURL = "/xwiki/bin/view/MSOffice/AttachmentService?xpage=plain"; static String protectedPagesURL = "/xwiki/bin/view/MSOffice/ProtectedPages?xpage=plain"; + static String getEncoding = "/xwiki/bin/view/MSOffice/GetEncodingService?xpage=plain"; /// /// Gets or sets the URL of the service that handles attachments. @@ -72,5 +73,15 @@ get { return protectedPagesURL; } set { protectedPagesURL = value; } } + + /// + /// Gets the encoding of the wiki. + /// + public static String GetEncoding + { + get { return getEncoding; } + set { getEncoding = value; } + } + } } Index: xword/XWikiLib/XWikiLib.csproj =================================================================== --- xword/XWikiLib/XWikiLib.csproj (revision 18635) +++ xword/XWikiLib/XWikiLib.csproj (working copy) @@ -60,6 +60,7 @@ + Index: xword/XWord/AddinActions.cs =================================================================== --- xword/XWord/AddinActions.cs (revision 18635) +++ xword/XWord/AddinActions.cs (working copy) @@ -453,7 +453,7 @@ //Convert the source to the propper encoding. - Encoding iso = Encoding.GetEncoding("ISO-8859-1"); + Encoding iso = Client.ServerEncoding; byte[] content = Encoding.Unicode.GetBytes(cleanHTML); byte[] wikiContent = null; wikiContent = Encoding.Convert(Encoding.Unicode, iso, content); @@ -532,7 +532,7 @@ pageContent = pageContent + newPageText; FileStream stream = new FileStream(localFileName, FileMode.Create); //byte[] buffer = UTF8Encoding.UTF8.GetBytes(pageContent.ToString()); - Encoding iso = Encoding.GetEncoding("ISO-8859-1"); + Encoding iso = Client.ServerEncoding; byte[] buffer = iso.GetBytes(pageContent); stream.Write(buffer, 0, buffer.Length); stream.Close();