Index: Wiki/src/main/resources/MSOffice/GetEncodingService.xml =================================================================== --- Wiki/src/main/resources/MSOffice/GetEncodingService.xml (revision 0) +++ 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: XWikiLib/Clients/IXWikiClient.cs =================================================================== --- XWikiLib/Clients/IXWikiClient.cs (revision 18614) +++ XWikiLib/Clients/IXWikiClient.cs (working copy) @@ -20,6 +20,14 @@ { get; } + + /// + /// Specifies the encoding from the XWiki server. + /// + Encoding ServerEncoding + { + get; + } /// /// Basic authentification method. @@ -177,6 +185,6 @@ /// The full name of the xwiki page /// The struts action. /// The URL for the specified page and action. - String GetURL(String documentFullName, String xwikiAction); + String GetURL(String documentFullName, String xwikiAction); } } Index: XWikiLib/Clients/XWikiHTTPClient.cs =================================================================== --- XWikiLib/Clients/XWikiHTTPClient.cs (revision 18614) +++ 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. @@ -126,6 +127,14 @@ return false; } isLoggedIn = true; + try + { + encoding = GetEncoding(); + } + catch (InvalidEncodingNameException ex) + { + encoding = null; + } return true; } @@ -149,6 +158,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. @@ -317,6 +354,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. Index: XWikiLib/Clients/XWikiXMLRPCClient.cs =================================================================== --- XWikiLib/Clients/XWikiXMLRPCClient.cs (revision 18614) +++ 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. @@ -29,8 +30,19 @@ return isLoggedIn; } } - + /// + /// 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: XWikiLib/XWiki/XWikiURLFactory.cs =================================================================== --- XWikiLib/XWiki/XWikiURLFactory.cs (revision 18614) +++ 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: XWikiLib/XWikiLib.csproj =================================================================== --- XWikiLib/XWikiLib.csproj (revision 18614) +++ XWikiLib/XWikiLib.csproj (working copy) @@ -56,6 +56,7 @@ + Index: XWord/AddinActions.cs =================================================================== --- XWord/AddinActions.cs (revision 18614) +++ XWord/AddinActions.cs (working copy) @@ -406,7 +406,7 @@ addin.AddinStatus.Syntax = addin.DefaultSyntax; } //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); @@ -485,7 +485,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();