Пример #1
0
        public DreamMessage PostTidyXHmlt(DreamContext context, DreamMessage message)
        {
            string baseHref = context.Uri.GetParam("base", "");
            string pageID   = context.Uri.GetParam("context", "");
            bool   toEdit   = context.Uri.GetParam <bool>("toEdit", false);
            XDoc   doc      = XDoc.FromHtml(new StreamReader(message.Stream, message.ContentEncoding));

            XHTMLConverter.Convert(doc, baseHref, pageID, toEdit);
            return(DreamMessage.Ok(MimeType.XHTML, doc.Root.ToXHtml()));
        }
Пример #2
0
        public DreamMessage PostEditHandler(DreamContext context, DreamMessage message)
        {
            XDoc xhtml = message.ContentType.Contains("/html")
                ? XDoc.FromHtml(new StreamReader(message.Stream, message.ContentEncoding))
                : message.Document;

            if (xhtml == null || xhtml.IsEmpty)
            {
                LogUtils.LogWarning(_log, "PostEditHandler: null/empty input document");
                throw new DreamAbortException(DreamMessage.BadRequest("null/empty input document"));
            }
            string baseHref = context.Uri.GetParam("baseHref", 0, "http://mos/");
            string pageID   = context.Uri.GetParam("context", "");

            XHTMLConverter.Convert(xhtml, baseHref, pageID, true);
            ConvertAllWidgets("PostEditHandler", xhtml, "edit", pageID);
            return(DreamMessage.Ok(MimeType.XHTML, xhtml.ToXHtml()));
        }
Пример #3
0
        public DreamMessage PostPasteHandler(DreamContext context, DreamMessage message)
        {
            XDoc xhtml = message.ContentType.Contains("/html")
                ? XDoc.FromHtml(new StreamReader(message.Stream, message.ContentEncoding))
                : message.Document;

            if (xhtml == null || xhtml.IsEmpty)
            {
                LogUtils.LogWarning(_log, "PostEditHandler: null/empty input document");
                throw new DreamAbortException(DreamMessage.BadRequest("null/empty input document"));
            }
            string baseHref = context.Uri.GetParam("baseHref", 0, "http://mos/");
            string pageID   = context.Uri.GetParam("context", "");

            XHTMLConverter.Convert(xhtml, baseHref, pageID, true);

            MindTouch.Dream.Plug plug = MindTouch.Dream.Plug.New(Env.RootUri);
            foreach (XDoc nodeWithClass in xhtml["//*[@class='vcard']"])
            {
                XDoc replacement = plug.At("wiki-data", "dekibizcard", "hcardtoedit").Post(nodeWithClass).Document;
                if (replacement != null && !replacement.IsEmpty)
                {
                    nodeWithClass.Replace(replacement);
                }
            }

            bool insertMagic = context.Uri.GetParam <bool>("insertMagic", false);

            if (insertMagic)
            {
                Plug widgetStorage = Plug.New(Env.RootUri).At("mount", "deki-widgets");
                Plug widgetToEdit  = Plug.New(Env.RootUri.At("wiki-data", "dekibizcard", "edit"));
                XDoc files         = widgetStorage.With("pattern", "*.vcf").Get().Document;
                foreach (XDoc fileName in files["file/name"])
                {
                    XDoc vcard       = XDoc.FromVersit(widgetStorage.At(fileName.Contents).Get().Text, "dekibizcard");
                    XDoc widgetXhtml = widgetToEdit.Post(vcard).Document;
                    xhtml["//body"].Add(widgetXhtml);
                }
            }
            return(DreamMessage.Ok(MimeType.HTML, xhtml.ToString()));
        }