/// <summary> /// Adapts the html source returned by the XWiki server and makes it usable by Word using a local html file. /// </summary> /// <param name="xmlDoc">A reference to the xml dom.</param> public void Filter(ref XmlDocument xmlDoc) { XmlNodeList images = xmlDoc.GetElementsByTagName("img"); foreach (XmlNode node in images) { if (node.NodeType == XmlNodeType.Element) { XmlAttribute vshapesAttr = node.Attributes["v:shapes"]; if (vshapesAttr != null) { node.Attributes.Remove(vshapesAttr); } //remove parameters from URLs String src = node.Attributes["src"].Value.Split('?')[0]; //Creating an additional attribute to help identifing the image in the html. XmlAttribute attr = xmlDoc.CreateAttribute(ImageInfo.XWORD_IMG_ATTRIBUTE); //Adding the attribute to the xhtml code. Guid imgId = Guid.NewGuid(); attr.Value = imgId.ToString(); node.Attributes.Append(attr); //Adding the image to the current image list. ImageInfo imgInfo = new ImageInfo(); imgInfo.imgWebSrc = src; if (node.Attributes["alt"] != null) { imgInfo.altText = node.Attributes["alt"].Value; } manager.States.Images.Add(imgId, imgInfo); //Downloading image if (src == "") continue; if (src[0] == '/') { src = serverURL + src; } ParameterizedThreadStart pts = new ParameterizedThreadStart(DownloadImage); String folder = localFolder + "\\" + localFilename + manager.AddinSettings.MetaDataFolderSuffix; Object param = new ImageDownloadInfo(src, folder, imgInfo); pts.Invoke(param); src = folder + "\\" + Path.GetFileName(src); src = "file:///" + src.Replace("\\", "/"); node.Attributes["src"].Value = src; } } }
/// <summary> /// Creates a new instance for the ImageInfo class. /// </summary> /// <param name="URI">The URI of the image.</param> /// <param name="downloadFolder">The folder where the image will be downloaded.</param> /// <param name="imageInfo">The states of the image on the server and on the local file system.</param> public ImageDownloadInfo(String URI, String downloadFolder, ImageInfo imageInfo) { this._URI = URI; this.downloadFolder = downloadFolder; this.ImageInfo = imageInfo; }