public override void Process(ProcessWordElementArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Element, "args.Element");

            if (args.Element.Name != "p")
            {
                return;
            }

            string value = args.Element.GetAttributeValue("class", string.Empty);

            if (value == "heading1")
            {
                args.Element.Name = "h2";
                args.Element.Attributes.RemoveAll();
            }
            else if (value == "heading2")
            {
                args.Element.Name = "h3";
                args.Element.Attributes.RemoveAll();
            }
            else if (value == "heading3")
            {
                args.Element.Name = "h4";
                args.Element.Attributes.RemoveAll();
            }
            else if (value == "heading4")
            {
                args.Element.Name = "h5";
                args.Element.Attributes.RemoveAll();
            }
        }
        public override void Process(ProcessWordElementArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Element, "args.Element");

            if (args.Element.Name != "img")
            {
                return;
            }

            args.Element.SetAttributeValue("class", "documentimage");
        }
        public override void Process(ProcessWordElementArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Element, "args.Element");
            string value = args.Element.GetAttributeValue("class", string.Empty);

            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            args.Element.SetAttributeValue("class", value.ToLower());
        }
Ejemplo n.º 4
0
        public override void Process(ProcessWordElementArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Element, "args.Element");

            if (args.Element.Name != "table")
            {
                return;
            }

            foreach (HtmlNode tr in args.Element.SelectNodes(".//tr[1]"))
            {
                foreach (HtmlNode th in tr.Descendants("td"))
                {
                    th.Name = "th";
                }
            }
        }
        public override void Process(ProcessWordElementArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Element, "args.Element");

            if (args.Element.Name == "sitecoreemphasis")
            {
                args.Element.Name = "em";
                args.Element.Attributes.RemoveAll();
            }
            else if (args.Element.Name == "sitecorewindow")
            {
                args.Element.Name = "strong";
                args.Element.Attributes.RemoveAll();
            }
            else if (args.Element.Name == "sitecorecodechar")
            {
                args.Element.Name = "code";
                args.Element.Attributes.RemoveAll();
            }
        }
Ejemplo n.º 6
0
        public override void Process(ProcessWordElementArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Element, "args.Element");

            foreach (HtmlNode child in args.Element.ChildNodes)
            {
                HtmlTextNode text = child as HtmlTextNode;

                if (text == null)
                {
                    continue;
                }

                string trimmed = child.InnerText.TrimEnd();

                if (child.InnerText != trimmed && child.InnerText != " ")
                {
                    text.Text = trimmed;
                }
            }
        }
        public override void Process(ProcessWordElementArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Database, "args.Database");
            Assert.ArgumentNotNull(args.Element, "args.Element");
            Assert.ArgumentNotNull(args.Path, "args.Path");
            Assert.ArgumentNotNull(args.Name, "args.Name");

            if (args.Element.Name != "img")
            {
                return;
            }

            MediaCreatorOptions options = new MediaCreatorOptions();

            options.Database = args.Database;
            string src = args.Element.GetAttributeValue("src", string.Empty);

            Assert.IsNotNullOrEmpty(src, "src");
            string name = src;
            int    i    = name.IndexOf('/');

            if (i > -1)
            {
                name = name.Substring(i + 1);
            }

            i = name.IndexOf('\\');

            if (i > -1)
            {
                name = name.Substring(i + 1);
            }

            i = name.LastIndexOf('.');

            if (i > -1)
            {
                name = name.Substring(0, i);
            }

            ////TODO: determine and implement logic to determine path to new media item
            Item mediaFolder = args.Database.GetItem("/sitecore/media library/images");

            Assert.IsTrue(mediaFolder != null, "mediaFolder");
            MediaItem image = null;

            // path to file on disk
//      string fullPath = MainUtil.MapPath(Sitecore.IO.TempFolder.Folder + "/" + src);
            string fullPath = src;

            // attempt to locate existing media item with same binary content
            Stream compareFile  = null;
            Stream compareMedia = null;

            // Trying to ensure the streams get closed
            try
            {
                compareFile = File.OpenRead(fullPath);

                foreach (Item item in args.Database.SelectItems(
                             "fast:" + mediaFolder.Paths.FullPath + "//*[@size='" + compareFile.Length + "']"))
                {
                    compareFile.Seek(0, SeekOrigin.Begin);
                    MediaItem compare = new MediaItem(item);
                    compareMedia = compare.GetMediaStream();

                    do
                    {
                        if (compareMedia.ReadByte() != compareFile.ReadByte())
                        {
                            break;
                        }
                    }while (compareMedia.Position != compareMedia.Length && compareFile.Position != compareFile.Length);

                    if (compareMedia.Position == compareMedia.Length)
                    {
                        image = compare;
                        ////TODO: these lines are redundant. If it's OK to check Position on a closed stream,
                        //// move these lines before this if condition and remove the duplication that follows
                        compareMedia.Close();
                        compareMedia = null;
                        break;
                    }

                    compareMedia.Close();
                    compareMedia = null;
                }
            }
            finally
            {
                if (compareFile != null)
                {
                    compareFile.Close();
                }

                if (compareMedia != null)
                {
                    compareMedia.Close();
                }
            }

            // if a matching image media item does not exist, create it
            if (image == null)
            {
                if (name.Contains("/"))
                {
                    name = name.Substring(name.LastIndexOf("/") + 1);
                }

                if (name.Contains("\\"))
                {
                    name = name.Substring(name.LastIndexOf("\\") + 1);
                }

                name = args.Name + "." + name + "." + new Random().Next();

                ////TODO: determine and implement logic to determine path and name for new media item
                options.Destination = mediaFolder.Paths.FullPath + '/'
                                      + args.Path + '/'
                                      + name.Replace('.', '-');
                image = new MediaCreator().CreateFromFile(fullPath, options);
            }

            args.Element.SetAttributeValue("src", "~/media/" + image.ID.ToShortID() + ".ashx");
        }