Beispiel #1
0
        /// <summary>
        /// Creates the guide entry from the given text and relvant attributes
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="hiddenStatus"></param>
        /// <param name="style"></param>
        /// <param name="editing"></param>
        /// <returns></returns>
        static public XmlElement CreateGuideEntry(string text, int hiddenStatus, GuideEntryStyle style, int canRead)
        {

            XmlDocument doc = new XmlDocument();
            if (hiddenStatus > 0 && canRead == 0)
            {
                doc.LoadXml("<GUIDE><BODY>This article has been hidden pending moderation.</BODY></GUIDE>");
            }
            else
            {
                try
                {
                    switch (style)
                    {
                        case GuideEntryStyle.GuideML:
                            text = text.Trim();
                            text = Entities.ReplaceEntitiesWithNumericValues(text);
                            //text = HtmlUtils.ReplaceCRsWithBRs(text);
                            text = HtmlUtils.EscapeNonEscapedAmpersands(text);
                            doc.PreserveWhitespace = true;
                            doc.LoadXml(text);
                            AdjustFootnotes(doc);
                            //doc["GUIDE"]["BODY"].InnerXml = HtmlUtils.ReplaceCRsWithBRs(doc["GUIDE"]["BODY"].InnerXml);
                            break;

                        case GuideEntryStyle.PlainText:
                            doc.LoadXml(StringUtils.PlainTextToGuideML(text));
                            break;

                        case GuideEntryStyle.Html:
                            doc.LoadXml("<GUIDE><BODY><PASSTHROUGH><![CDATA[" + text + "]]></PASSTHROUGH></BODY></GUIDE>");
                            break;

                        default:
                            goto case GuideEntryStyle.GuideML;//null styles are generally guideml...
                        //throw new NotImplementedException("Don't know what type of entry we've got here!");
                    }
                }
                catch (XmlException e)
                {
                    //If something has gone wrong log stuff
                    DnaDiagnostics.Default.WriteExceptionToLog(e);

                    var errorMessage = Regex.Replace(e.Message, "position +[0-9][0-9]* ", "", RegexOptions.IgnoreCase);

                    var xmlException = new XmlException(errorMessage, e);

                    throw new ApiException("GuideML Transform Failed", xmlException);
                }
            }

            return doc.DocumentElement;
        }
Beispiel #2
0
        private Article SetWritableArticleProperties(Article article, GuideEntryStyle style, string subject, string guideML,  int[] researcherUserIds)
        {
            //Need to set this before processing the guideML
            article.Style = style;

            // populate the writable parts of the object graph with the input article
            if (guideML != String.Empty)
            {
                article.GuideMLAsString = guideML;
                article.ArticleInfo.GetReferences(readerCreator, article.OriginalGuideMLAsXmlElement);
                
                if (!article.IsGuideMLWellFormed) 
                { 
                    article.XmlError = "GuideML is badly formed2";
                    throw new Exception("GuideML is badly formed"); 
                }
            }


            if (subject != String.Empty)
            {
                article.Subject = subject;
            }
            
            if (researcherUserIds != null)
            {
                article.ArticleInfo.PageAuthor.Researchers.Clear();
                foreach (int researcherId in researcherUserIds)
                {
                    BBC.Dna.Objects.User user = new BBC.Dna.Objects.User();
                    user.UserId = researcherId;
                    article.ArticleInfo.PageAuthor.Researchers.Add(user);
                }
            }

            return article;
        }
Beispiel #3
0
 private Article SetWritableArticleProperties(Article article, GuideEntryStyle style, string subject, string guideML, string researcherUserIdsAsCSV)
 {
     int[] researchIds = new int[0];
     if (researcherUserIdsAsCSV != null)
     {
         // convert comma seperate string into array of ints
         researchIds = new List<string>(researcherUserIdsAsCSV.Split(',')).ConvertAll<int>(x => Convert.ToInt32(x)).ToArray<int>();
     }
     return SetWritableArticleProperties(article, style, subject, guideML,  researchIds);
 }
Beispiel #4
0
 private Article SetWritableArticleProperties(Article article, GuideEntryStyle style, string subject, string guideML,  List<BBC.Dna.Objects.User> researchersIdsAsCSV)
 {
     int[] researchIds = new int[0];
     if (researchersIdsAsCSV != null)
     {
         researchIds = (from r in researchersIdsAsCSV select r.UserId).ToArray<int>();
     }
     return SetWritableArticleProperties(article, style, subject, guideML,  researchIds);
 }
Beispiel #5
0
        private Article BuildNewArticleObject(int siteId, int userid, GuideEntryStyle style, string subject, string guideML, string submittable, int hidden)
        {
            // validate the inputs. Has the required fields been supplied?
            if (String.IsNullOrEmpty(subject)) {  throw ApiException.GetError(ErrorType.MissingSubject); }
            if (String.IsNullOrEmpty(guideML)) {  throw ApiException.GetError(ErrorType.MissingGuideML); }
            
            // default submittable if it's not supplied
            if (String.IsNullOrEmpty(submittable))  { submittable = "YES";}

            Article article = new Article();
            article.ArticleInfo = new BBC.Dna.Objects.ArticleInfo();
            article.ArticleInfo.CatgoriesList = new List<CrumbTrail>();
            article.ArticleInfo.CrumbTrails = new CrumbTrails();
            article.ArticleInfo.CrumbTrails.CrumbTrail = new List<CrumbTrail>();
            article.ArticleInfo.DateCreated = new DateElement(DateTime.Now);
            article.ArticleInfo.ModerationStatus = BBC.Dna.Moderation.Utils.ModerationStatus.ArticleStatus.Undefined;
            article.ArticleInfo.PageAuthor = new ArticleInfoPageAuthor();
            article.ArticleInfo.PageAuthor.Editor = new UserElement();
            article.ArticleInfo.PageAuthor.Editor.user = new BBC.Dna.Objects.User();
            article.ArticleInfo.RelatedMembers = new ArticleInfoRelatedMembers();
            article.ArticleInfo.Site = new ArticleInfoSite();
            article.ArticleInfo.Status = new ArticleStatus();
            article.ArticleInfo.Status.Value = "User entry, public";
            article.ArticleInfo.Status.Type = 3;
            article.Type = Article.ArticleType.Article;

            article.Style = style;
            article.Subject = subject;
            article.GuideMLAsString = guideML;

            article.ArticleInfo.CrumbTrails = new CrumbTrails();
            article.ArticleInfo.CrumbTrails.CrumbTrail = new List<CrumbTrail>();

            article.ArticleInfo.Site.Id = siteId;
            article.ArticleInfo.SiteId = siteId;
            article.ArticleInfo.PageAuthor.Editor.user.UserId = userid;
            article.ArticleInfo.Submittable = new ArticleInfoSubmittable();
            article.ArticleInfo.Submittable.Type = submittable;

            article.CanRead = 1;
            article.DefaultCanRead = 1;
            article.CanWrite = 0;
            article.DefaultCanWrite = 0;
            article.CanChangePermissions = 0;
            article.DefaultCanChangePermissions = 0;

            article.HiddenStatus = hidden;

            return article;
        }