Exemplo n.º 1
0
        private static void ConvertEachBibTexPairIntoWord2007Pair(XmlDocument doc, XmlNode node_source, string fields)
        {
            List <string> field_list = SplitFields(fields);

            foreach (string field in field_list)
            {
                string[] field_split = field.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries);
                if (2 != field_split.Length)
                {
                    Logging.Warn("Unable to process BibTex field '{0}'", field);
                }
                else
                {
                    string key = field_split[0].Trim();
                    string val = field_split[1].Trim();
                    val = val.TrimStart('{').TrimEnd('}');
                    val = BibTexCharacterMap.BibTexToASCII(val);

                    string  field_type_word2007 = TranslateFieldType(key);
                    XmlNode node_record         = doc.CreateElement(NS_TAG, field_type_word2007, NS);

                    // Process authors specifically
                    if (key.Equals("author"))
                    {
                        XmlNode node_name_list = doc.CreateElement(NS_TAG, "NameList", NS);

                        XmlNode node_author = doc.CreateElement(NS_TAG, "Author", NS);
                        node_author.AppendChild(node_name_list);

                        node_record.AppendChild(node_author);

                        string[] authors = NameTools.SplitAuthors_LEGACY(val);
                        foreach (string author in authors)
                        {
                            string first_name;
                            string last_name;
                            NameTools.SplitName_LEGACY(author, out first_name, out last_name);

                            XmlNode node_last = doc.CreateElement(NS_TAG, "Last", NS);
                            node_last.AppendChild(doc.CreateTextNode(last_name));

                            XmlNode node_first = doc.CreateElement(NS_TAG, "First", NS);
                            node_first.AppendChild(doc.CreateTextNode(first_name));

                            XmlNode node_person = doc.CreateElement(NS_TAG, "Person", NS);
                            node_person.AppendChild(node_last);
                            node_person.AppendChild(node_first);

                            node_name_list.AppendChild(node_person);
                        }
                    }
                    else
                    {
                        node_record.AppendChild(doc.CreateTextNode(val));
                    }

                    node_source.AppendChild(node_record);
                }
            }
        }
Exemplo n.º 2
0
        private static void ExpandAuthors(PDFDocument doc, NodeControl node_control)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();
            ASSERT.Test(doc != null);

            FeatureTrackingManager.Instance.UseFeature(Features.Brainstorm_ExploreLibrary_Document_Authors);

            if (doc != null)
            {
                string authors = doc.AuthorsCombined;
                if (String.IsNullOrEmpty(authors) || Constants.UNKNOWN_AUTHORS == authors)
                {
                    return;
                }

                WPFDoEvents.InvokeInUIThread(() =>
                {
                    WPFDoEvents.AssertThisCodeIsRunningInTheUIThread();

                    List <NameTools.Name> names = new List <NameTools.Name>();
                    string[] authors_split      = NameTools.SplitAuthors_LEGACY(authors);
                    foreach (string author_split in authors_split)
                    {
                        string first_names, last_name;
                        NameTools.SplitName_LEGACY(author_split, out first_names, out last_name);
                        string initial = String.IsNullOrEmpty(first_names) ? null : first_names.Substring(0, 1);
                        PDFAuthorNodeContent pdf_author = new PDFAuthorNodeContent(doc.LibraryRef.Id, last_name, initial);
                        NodeControlAddingByKeyboard.AddChildToNodeControl(node_control, pdf_author, false);
                    }
                });
            }
        }
        public static bool DoesBibTeXMatchDocument(BibTexItem bibtex_item, PDFDocument pdf_document, out PDFSearchResultSet search_result_set)
        {
            try
            {
                string authors_string = BibTexTools.GetAuthor(bibtex_item);
                if (!String.IsNullOrEmpty(authors_string))
                {
                    List <NameTools.Name> names = NameTools.SplitAuthors(authors_string, PDFDocument.UNKNOWN_AUTHORS);
                    StringBuilder         sb    = new StringBuilder();
                    foreach (NameTools.Name name in names)
                    {
                        sb.AppendFormat("\"{0}\" ", name.last_name);
                    }

                    string names_search_string = sb.ToString();
                    if (!String.IsNullOrEmpty(names_search_string))
                    {
                        search_result_set = PDFSearcher.Search(pdf_document, 1, names_search_string, PDFSearcher.MATCH_CONTAINS);
                        if (0 < search_result_set.Count)
                        {
                            return(true);
                        }
                    }
                }
            }
            catch (Exception) { }

            search_result_set = new PDFSearchResultSet();
            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the pages in the selected namespace.
        /// </summary>
        /// <returns>The pages.</returns>
        private IList <PageInfo> GetPages()
        {
            NamespaceInfo   nspace      = Pages.FindNamespace(lstNamespace.SelectedValue);
            List <PageInfo> pages       = Pages.GetPages(nspace);
            var             orphanPages = Pages.GetOrphanedPages(pages);

            var result = new List <PageInfo>(pages.Count);

            var filter = txtFilter.Text.Trim().ToLower(System.Globalization.CultureInfo.CurrentCulture);

            foreach (PageInfo page in pages)
            {
                if (NameTools.GetLocalName(page.FullName).ToLower(System.Globalization.CultureInfo.CurrentCulture).Contains(filter))
                {
                    if (chkOrphansOnly.Checked && !orphanPages.Contains(page.FullName))
                    {
                        continue;
                    }
                    else
                    {
                        result.Add(page);
                    }
                }
            }

            result.Sort(new PageNameComparer());

            return(result);
        }
Exemplo n.º 5
0
        public static string MakeExportFilename(PDFDocument pdf_document)
        {
            string year = pdf_document.YearCombined;
            if (year == Constants.UNKNOWN_YEAR)
            {
                year = "";
            }

            string authors = "";
            List<NameTools.Name> author_names = NameTools.SplitAuthors(pdf_document.AuthorsCombined);
            if (0 < author_names.Count)
            {
                authors = author_names[0].last_name;
            }

            string title = pdf_document.TitleCombined;

            string filename = String.Format("{0}{1} - {2}", authors, year, title);

            filename = filename.Trim();
            filename = FileTools.MakeSafeFilename(filename);
            filename = filename + ".pdf";

            return filename;
        }
Exemplo n.º 6
0
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        NameTools window = (NameTools)EditorWindow.GetWindow(typeof(NameTools));

        window.Show();
    }
Exemplo n.º 7
0
        /// <summary>
        /// Loads the available pages and selects the current one.
        /// </summary>
        private void LoadDefaultPages()
        {
            // Populate default page, if there is a namespace selected
            if (!string.IsNullOrEmpty(txtCurrentNamespace.Value))
            {
                NamespaceInfo nspace = Pages.FindNamespace(
                    txtCurrentNamespace.Value != RootName ? txtCurrentNamespace.Value : null);

                List <PageInfo> pages = Pages.GetPages(nspace);

                string currentDefaultPage = nspace != null ? nspace.DefaultPage.FullName : Settings.DefaultPage;

                lstDefaultPage.Items.Clear();
                foreach (PageInfo page in pages)
                {
                    ListItem item = new ListItem(NameTools.GetLocalName(page.FullName), page.FullName);
                    if (page.FullName == currentDefaultPage)
                    {
                        item.Selected = true;
                    }

                    lstDefaultPage.Items.Add(item);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Populates the namespaces list for migration.
        /// </summary>
        /// <param name="page">The selected page.</param>
        /// <returns><c>true</c> if there is at least one valid target namespace, <c>false</c> otherwise.</returns>
        private bool PopulateTargetNamespaces(PageInfo page)
        {
            string currentUser = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames();

            lstTargetNamespace.Items.Clear();

            NamespaceInfo pageNamespace = Pages.FindNamespace(NameTools.GetNamespace(page.FullName));

            if (pageNamespace != null)
            {
                // Try adding Root as target namespace
                bool canManagePages = AuthChecker.CheckActionForNamespace(null, Actions.ForNamespaces.ManagePages, currentUser, currentGroups);
                if (canManagePages)
                {
                    lstTargetNamespace.Items.Add(new ListItem("<root>", ""));
                }
            }

            // Try adding all other namespaces
            foreach (NamespaceInfo nspace in Pages.GetNamespaces().FindAll(n => n.Provider == page.Provider))
            {
                if (pageNamespace == null || (pageNamespace != null && nspace.Name != pageNamespace.Name))
                {
                    bool canManagePages = AuthChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.ManagePages, currentUser, currentGroups);
                    if (canManagePages)
                    {
                        lstTargetNamespace.Items.Add(new ListItem(nspace.Name, nspace.Name));
                    }
                }
            }

            return(lstTargetNamespace.Items.Count > 0);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Adds a new Navigation Path.
        /// </summary>
        /// <param name="nspace">The target namespace (<c>null</c> for the root).</param>
        /// <param name="name">The Name.</param>
        /// <param name="pages">The Pages.</param>
        /// <param name="provider">The Provider to use for the new Navigation Path, or <c>null</c> for the default provider.</param>
        /// <returns>True if the Path is added successfully.</returns>
        public static bool AddNavigationPath(NamespaceInfo nspace, string name, List <PageInfo> pages, IPagesStorageProviderV30 provider)
        {
            var namespaceName = nspace != null ? nspace.Name : null;
            var fullName      = NameTools.GetFullName(namespaceName, name);

            if (Exists(fullName))
            {
                return(false);
            }

            if (provider == null)
            {
                provider = Collectors.PagesProviderCollector.GetProvider(Settings.DefaultPagesProvider);
            }

            NavigationPath newPath = provider.AddNavigationPath(namespaceName, name, pages.ToArray());

            if (newPath != null)
            {
                Log.LogEntry("Navigation Path " + fullName + " added", EntryType.General, Log.SystemUsername);
            }
            else
            {
                Log.LogEntry("Creation failed for Navigation Path " + fullName, EntryType.Error, Log.SystemUsername);
            }
            return(newPath != null);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Gets the categories for the current page, already formatted for display.
 /// </summary>
 /// <returns>The categories, formatted for display.</returns>
 private string GetFormattedPageCategories()
 {
     CategoryInfo[] categories = Pages.GetCategoriesForPage(currentPage);
     if (categories.Length == 0)
     {
         return(string.Format(@"<i><a href=""{0}"" title=""{1}"">{2}</a></i>",
                              GetCategoryLink("-"),
                              Properties.Messages.Uncategorized, Properties.Messages.Uncategorized));
     }
     else
     {
         StringBuilder sb = new StringBuilder(categories.Length * 10);
         for (int i = 0; i < categories.Length; i++)
         {
             sb.AppendFormat(@"<a href=""{0}"" title=""{1}"">{2}</a>",
                             GetCategoryLink(categories[i].FullName),
                             NameTools.GetLocalName(categories[i].FullName),
                             NameTools.GetLocalName(categories[i].FullName));
             if (i != categories.Length - 1)
             {
                 sb.Append(", ");
             }
         }
         return(sb.ToString());
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Appends a breadbrumb trail element.
        /// </summary>
        /// <param name="sb">The destination <see cref="T:StringBuilder" />.</param>
        /// <param name="page">The page to append.</param>
        /// <param name="dpPrefix">The drop-down menu ID prefix.</param>
        private void AppendBreadcrumb(StringBuilder sb, PageInfo page, string dpPrefix)
        {
            PageNameComparer comp = new PageNameComparer();
            PageContent      pc   = Content.GetPageContent(page, true);

            string id = AppendBreadcrumbDropDown(sb, page, dpPrefix);

            string nspace = NameTools.GetNamespace(page.FullName);

            sb.Append("&raquo; ");
            if (comp.Compare(page, currentPage) == 0)
            {
                sb.Append("<b>");
            }

            sb.AppendFormat(@"<a href=""{0}"" title=""{1}""{2}{3}{4}>{1}</a>",
                            Tools.UrlEncode(page.FullName) + Settings.PageExtension,
                            FormattingPipeline.PrepareTitle(pc.Title, false, FormattingContext.PageContent, currentPage) + (string.IsNullOrEmpty(nspace) ? "" : (" (" + NameTools.GetNamespace(page.FullName) + ")")),
                            (id != null ? @" onmouseover=""javascript:return __ShowDropDown(event, '" + id + @"', this);""" : ""),
                            (id != null ? @" id=""lnk" + id + @"""" : ""),
                            (id != null ? @" onmouseout=""javascript:return __HideDropDown('" + id + @"');""" : ""));
            if (comp.Compare(page, currentPage) == 0)
            {
                sb.Append("</b>");
            }

            sb.Append(" ");
        }
Exemplo n.º 12
0
        /// <summary>
        /// Activates the page editor.
        /// </summary>
        private void ActivatePageEditor()
        {
            lblCurrentPage.Text = txtCurrentPage.Value;
            txtNewName.Text     = NameTools.GetLocalName(txtCurrentPage.Value);

            // Enable/disable page sections
            PageContent   page        = Pages.FindPage(currentWiki, txtCurrentPage.Value);
            NamespaceInfo nspace      = Pages.FindNamespace(currentWiki, NameTools.GetNamespace(page.FullName));
            string        currentUser = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki);

            AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));

            bool canApproveReject    = AdminMaster.CanApproveDraft(page.Provider.CurrentWiki, page.FullName, currentUser, currentGroups);
            bool canDeletePages      = authChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.DeletePages, currentUser, currentGroups);
            bool canManageAllPages   = authChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.ManagePages, currentUser, currentGroups);
            bool canManagePage       = authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ManagePage, currentUser, currentGroups);
            bool canManageDiscussion = authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ManageDiscussion, currentUser, currentGroups);
            bool namespaceAvailable  = PopulateTargetNamespaces(page);

            // Approve/reject
            // Rename
            // Migrate
            // Rollback
            // Delete Backups
            // Clear discussion
            // Delete

            pnlApproveRevision.Enabled = canApproveReject;
            pnlRename.Enabled          = canDeletePages;
            pnlMigrate.Enabled         = canManageAllPages && namespaceAvailable;
            pnlRollback.Enabled        = canManagePage;
            pnlDeleteBackups.Enabled   = canManagePage;
            pnlClearDiscussion.Enabled = canManageDiscussion;
            pnlDelete.Enabled          = canDeletePages;

            // Disable rename, migrate, delete for default page
            NamespaceInfo currentNamespace   = Pages.FindNamespace(currentWiki, lstNamespace.SelectedValue);
            string        currentDefaultPage = currentNamespace != null ? currentNamespace.DefaultPageFullName : Settings.GetDefaultPage(currentWiki);

            if (txtCurrentPage.Value == currentDefaultPage)
            {
                btnRename.Enabled     = false;
                btnMigrate.Enabled    = false;
                btnDeletePage.Enabled = false;
            }

            LoadDraft(txtCurrentPage.Value);

            LoadBackups(txtCurrentPage.Value);

            btnRollback.Enabled      = lstRevision.Items.Count > 0;
            btnDeleteBackups.Enabled = lstBackup.Items.Count > 0;

            pnlList.Visible     = false;
            pnlEditPage.Visible = true;

            ClearResultLabels();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the pages in the selected namespace.
        /// </summary>
        /// <returns>The pages.</returns>
        private IList <PageContent> GetPages(NamespaceInfo nspace)
        {
            List <PageContent> pages = Pages.GetPages(currentWiki, nspace);

            var orphanPages           = new List <string>(Pages.GetOrphanedPages(currentWiki, nspace));
            List <PageContent> result = new List <PageContent>(pages.Count);

            string filter = txtFilter.Text.Trim().ToLower(System.Globalization.CultureInfo.CurrentCulture);

            foreach (PageContent page in pages)
            {
                if (NameTools.GetLocalName(page.FullName).ToLower(System.Globalization.CultureInfo.CurrentCulture).Contains(filter))
                {
                    if (chkOrphansOnly.Checked && !orphanPages.Contains(page.FullName))
                    {
                        continue;
                    }
                    else
                    {
                        result.Add(page);
                    }
                }
            }

            result.Sort(new PageNameComparer());

            return(result);
        }
Exemplo n.º 14
0
        protected void btnDeletePage_Click(object sender, EventArgs e)
        {
            PageInfo page = Pages.FindPage(txtCurrentPage.Value);

            if (!AuthChecker.CheckActionForNamespace(Pages.FindNamespace(NameTools.GetNamespace(page.FullName)), Actions.ForNamespaces.DeletePages,
                                                     SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames()))
            {
                return;
            }

            Log.LogEntry("Page deletion requested for " + txtCurrentPage.Value, EntryType.General, Log.SystemUsername);

            bool done = Pages.DeletePage(page);

            if (done)
            {
                ResetPageList();

                RefreshList();
                lblDeleteResult.CssClass = "resultok";
                lblDeleteResult.Text     = Properties.Messages.PageDeleted;
                ReturnToList();
            }
            else
            {
                lblDeleteResult.CssClass = "resulterror";
                lblDeleteResult.Text     = Properties.Messages.CouldNotDeletePage;
            }
        }
Exemplo n.º 15
0
        private static void Export_Directories_Authors(WebLibraryDetail web_library_detail, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items)
        {
            WshShell shell = new WshShell();

            string authors_base_path = Path.GetFullPath(Path.Combine(base_path, @"authors"));

            Directory.CreateDirectory(authors_base_path);

            foreach (var item in pdf_document_export_items.Values)
            {
                try
                {
                    List <NameTools.Name> names = NameTools.SplitAuthors(item.pdf_document.AuthorsCombined);
                    foreach (var name in names)
                    {
                        string author_base_path = Path.GetFullPath(Path.Combine(authors_base_path, name.LastName_Initials));
                        Directory.CreateDirectory(author_base_path);
                        string filename = Path.GetFullPath(Path.Combine(author_base_path, FileTools.MakeSafeFilename(item.pdf_document.TitleCombined) + ".lnk"));
                        CreateShortcut(shell, item.filename, filename);
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "Error creating shortcut for " + item.filename);
                }
            }
        }
Exemplo n.º 16
0
        private static void Export_Directories_Authors(Library library, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items)
        {
            WshShell shell = new WshShell();

            string authors_base_path = base_path + @"authors\";

            Directory.CreateDirectory(authors_base_path);

            foreach (var item in pdf_document_export_items.Values)
            {
                try
                {
                    List <NameTools.Name> names = NameTools.SplitAuthors(item.pdf_document.AuthorsCombined, PDFDocument.UNKNOWN_AUTHORS);
                    foreach (var name in names)
                    {
                        string author_base_path = authors_base_path + name.LastName_Initials + @"\";
                        Directory.CreateDirectory(author_base_path);
                        string filename = author_base_path + FileTools.MakeSafeFilename(item.pdf_document.TitleCombined) + ".lnk";
                        CreateShortcut(shell, item.filename, filename);
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "Error creating shortcut for " + item.filename);
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Prints the content.
        /// </summary>
        public void PrintContent()
        {
            StringBuilder sb    = new StringBuilder(5000);
            string        title = FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page);

            if (Request["Discuss"] == null)
            {
                string[] categories =
                    (from c in Pages.GetCategoriesForPage(page)
                     select NameTools.GetLocalName(c.FullName)).ToArray();

                UserInfo user = Users.FindUser(content.User);

                sb.Append(@"<h1 class=""pagetitle"">");
                sb.Append(title);
                sb.Append("</h1>");
                sb.AppendFormat("<small>{0} {1} {2} {3} &mdash; {4}: {5}</small><br /><br />",
                                Properties.Messages.ModifiedOn,
                                Preferences.AlignWithTimezone(content.LastModified).ToString(Settings.DateTimeFormat),
                                Properties.Messages.By,
                                user != null ? Users.GetDisplayName(user) : content.User,
                                Properties.Messages.CategorizedAs,
                                categories.Length == 0 ? Properties.Messages.Uncategorized : string.Join(", ", categories));
                sb.Append(Content.GetFormattedPageContent(page, true));
            }
            else
            {
                sb.Append(@"<h1 class=""pagetitle"">");
                sb.Append(title);
                sb.Append(" - Discussion</h1>");
                PrintDiscussion(sb);
            }
            lblContent.Text = sb.ToString();
        }
Exemplo n.º 18
0
        private void ExpandAuthors()
        {
            FeatureTrackingManager.Instance.UseFeature(Features.Brainstorm_ExploreLibrary_Document_Authors);

            PDFDocument pdf_document = pdf_document_node_content.PDFDocument;

            string authors = pdf_document.AuthorsCombined;

            if (String.IsNullOrEmpty(authors) || 0 == PDFDocument.UNKNOWN_AUTHORS.CompareTo(authors))
            {
                return;
            }

            List <NameTools.Name> names = new List <NameTools.Name>();

            string[] authors_split = NameTools.SplitAuthors_LEGACY(authors);
            foreach (string author_split in authors_split)
            {
                string first_names, last_name;
                NameTools.SplitName_LEGACY(author_split, out first_names, out last_name);
                string initial = String.IsNullOrEmpty(first_names) ? null : first_names.Substring(0, 1);
                PDFAuthorNodeContent pdf_author = new PDFAuthorNodeContent(pdf_document.Library.WebLibraryDetail.Id, last_name, initial);
                NodeControlAddingByKeyboard.AddChildToNodeControl(node_control, pdf_author, false);
            }
        }
Exemplo n.º 19
0
 protected void Page_Load(object sender, EventArgs e)
 {
     for (int i = 0; i < 1000; i++)
     {
         PageContent page = Pages.SetPageContent("root", "", "pagetest" + i, "Title of Pahe Test " + i, "testuser", DateTime.UtcNow, "", "Content of the test page " + i, new string[0], "", SaveMode.Normal);
         for (int j = 0; j < 200; j++)
         {
             Pages.SetPageContent("root", "", NameTools.GetLocalName(page.FullName), page.Title, page.User, DateTime.UtcNow, "", "Content of test page" + i + " at revision " + j, page.Keywords, page.Description, SaveMode.Backup);
         }
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Sets the navigation paths label.
        /// </summary>
        private void SetupNavigationPaths()
        {
            string[] paths = NavigationPaths.PathsPerPage(currentPage);

            string currentPath = Request["NavPath"];

            if (!string.IsNullOrEmpty(currentPath))
            {
                currentPath = currentPath.ToLowerInvariant();
            }

            if (!discussMode && !viewCodeMode && paths.Length > 0)
            {
                StringBuilder sb = new StringBuilder(500);
                sb.Append(Properties.Messages.Paths);
                sb.Append(": ");
                for (int i = 0; i < paths.Length; i++)
                {
                    NavigationPath path = NavigationPaths.Find(paths[i]);
                    if (path != null)
                    {
                        if (currentPath != null && paths[i].ToLowerInvariant().Equals(currentPath))
                        {
                            sb.Append("<b>");
                        }

                        sb.Append(@"<a href=""");
                        sb.Append(UrlTools.BuildUrl("Default.aspx?Page=", Tools.UrlEncode(currentPage.FullName), "&amp;NavPath=", Tools.UrlEncode(paths[i])));
                        sb.Append(@""" title=""");
                        sb.Append(NameTools.GetLocalName(path.FullName));
                        sb.Append(@""">");
                        sb.Append(NameTools.GetLocalName(path.FullName));
                        sb.Append("</a>");

                        if (currentPath != null && paths[i].ToLowerInvariant().Equals(currentPath))
                        {
                            sb.Append("</b>");
                        }

                        if (i != paths.Length - 1)
                        {
                            sb.Append(", ");
                        }
                    }
                }

                lblNavigationPaths.Text = sb.ToString();
            }
            else
            {
                lblNavigationPaths.Visible = false;
            }
        }
Exemplo n.º 21
0
        public static List <NameTools.Name> GetAuthorsForPDFDocument(PDFDocument pdf_document)
        {
            string authors = pdf_document.AuthorsCombined;

            if (String.IsNullOrEmpty(authors) || Constants.UNKNOWN_AUTHORS == authors)
            {
                return(EMPTY_NAMES);
            }

            List <NameTools.Name> names = NameTools.SplitAuthors(authors);

            return(names);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Processes the renaming of a namespace.
        /// </summary>
        /// <param name="oldName">The old name of the namespace.</param>
        /// <param name="oldPages">The list of local names of the pages in the renamed namespace.</param>
        /// <param name="newName">The new name of the namespace.</param>
        /// <returns><c>true</c> if the operation completed successfully, <c>false</c> otherwise.</returns>
        public static bool ProcessNamespaceRenaming(string oldName, List <string> oldPages, string newName)
        {
            if (oldName == null)
            {
                throw new ArgumentNullException("oldName");
            }

            if (oldName.Length == 0)
            {
                throw new ArgumentException("Old Name cannot be empty", "oldName");
            }

            if (oldPages == null)
            {
                throw new ArgumentNullException("oldPages");
            }

            foreach (string p in oldPages)
            {
                if (p == null)
                {
                    throw new ArgumentNullException("oldPages");
                }

                if (p.Length == 0)
                {
                    throw new ArgumentException("Page cannot be empty", "oldPages");
                }
            }

            if (newName == null)
            {
                throw new ArgumentNullException("newName");
            }

            if (newName.Length == 0)
            {
                throw new ArgumentException("New Name cannot be empty", "newName");
            }

            foreach (string p in oldPages)
            {
                SettingsProvider.AclManager.RenameResource(
                    Actions.ForPages.ResourceMasterPrefix + NameTools.GetFullName(oldName, p),
                    Actions.ForPages.ResourceMasterPrefix + NameTools.GetFullName(newName, p));
            }

            return(SettingsProvider.AclManager.RenameResource(
                       Actions.ForNamespaces.ResourceMasterPrefix + oldName,
                       Actions.ForNamespaces.ResourceMasterPrefix + newName));
        }
Exemplo n.º 23
0
        /// <summary>
        /// Determines whether a page is the default page of its namespace.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <returns><c>true</c> if the page is the default namespace of its namespace, <c>false</c> otherwise.</returns>
        private bool IsDefaultPage(PageInfo page)
        {
            string localName, nspace;

            NameTools.ExpandFullName(page.FullName, out nspace, out localName);

            if (string.IsNullOrEmpty(nspace))
            {
                return(localName.ToLowerInvariant() == Settings.DefaultPage.ToLowerInvariant());
            }
            NamespaceInfo ns = Pages.FindNamespace(nspace);

            return(ns.DefaultPage != null && ns.DefaultPage.FullName.ToLowerInvariant() == page.FullName.ToLowerInvariant());
        }
Exemplo n.º 24
0
        /// <summary>
        /// Searches for pages with name or title similar to a specified value.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <param name="name">The name to look for (<c>null</c> for the root).</param>
        /// <param name="nspace">The namespace to search into.</param>
        /// <returns>The similar pages, if any.</returns>
        public static PageContent[] SearchSimilarPages(string wiki, string name, string nspace)
        {
            if (string.IsNullOrEmpty(nspace))
            {
                nspace = null;
            }

            var searchFields = new [] { SearchField.PageFullName };
            List <SearchResult> searchResults = Search(wiki, searchFields, name, SearchOptions.AtLeastOneWord);

            var result = new List <PageContent>(20);

            foreach (SearchResult res in searchResults)
            {
                var pageDoc = res.Document as PageDocument;
                if (pageDoc != null)
                {
                    string pageNamespace = NameTools.GetNamespace(pageDoc.PageFullName);
                    if (string.IsNullOrEmpty(pageNamespace))
                    {
                        pageNamespace = null;
                    }

                    if (pageNamespace == nspace)
                    {
                        var page = new PageContent(pageDoc.PageFullName, null, new DateTime(), pageDoc.Title, null, new DateTime(), null, pageDoc.Content, null, null);
                        result.Add(page);
                    }
                }
            }

            // Search page names for matches
            List <PageContent> allPages = Pages.GetPages(wiki, Pages.FindNamespace(wiki, nspace));
            var    comp        = new PageNameComparer();
            string currentName = name.ToLowerInvariant();

            foreach (PageContent page in allPages)
            {
                if (NameTools.GetLocalName(page.FullName).ToLowerInvariant().Contains(currentName))
                {
                    if (result.Find(p => comp.Compare(p, page) == 0) == null)
                    {
                        result.Add(page);
                    }
                }
            }

            return(result.ToArray());
        }
Exemplo n.º 25
0
        private static void Export_HTML_Authors(StringBuilder html, Library library, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items)
        {
            MultiMap <string, PDFDocumentExportItem> items_sliced = new MultiMap <string, PDFDocumentExportItem>(false);

            foreach (var item in pdf_document_export_items.Values)
            {
                List <NameTools.Name> names = NameTools.SplitAuthors(item.pdf_document.AuthorsCombined);
                foreach (var name in names)
                {
                    items_sliced.Add(name.LastName_Initials, item);
                }
            }

            Export_HTML_XXX(html, "Authors", items_sliced);
        }
Exemplo n.º 26
0
        protected void btnNewCategory_Click(object sender, EventArgs e)
        {
            if (!CanManageCategoriesInCurrentNamespace())
            {
                return;
            }

            lblNewCategoryResult.CssClass = "";
            lblNewCategoryResult.Text     = "";

            txtNewCategory.Text = txtNewCategory.Text.Trim();

            Page.Validate("newcat");
            if (!Page.IsValid)
            {
                return;
            }

            txtNewCategory.Text = txtNewCategory.Text.Trim();
            if (txtNewCategory.Text.Length == 0)
            {
                return;
            }

            if (Pages.FindCategory(NameTools.GetFullName(lstNamespace.SelectedValue, txtNewCategory.Text)) != null)
            {
                lblNewCategoryResult.CssClass = "resulterror";
                lblNewCategoryResult.Text     = Properties.Messages.CategoryAlreadyExists;
                return;
            }
            else
            {
                Log.LogEntry("Category creation requested for " + txtNewCategory.Text, EntryType.General, Log.SystemUsername);

                if (Pages.CreateCategory(lstNamespace.SelectedValue, txtNewCategory.Text))
                {
                    txtNewCategory.Text           = "";
                    lblNewCategoryResult.CssClass = "resultok";
                    lblNewCategoryResult.Text     = Properties.Messages.CategoryCreated;
                    RefreshList();
                }
                else
                {
                    lblNewCategoryResult.CssClass = "resulterror";
                    lblNewCategoryResult.Text     = Properties.Messages.CouldNotCreateCategory;
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Determines whether a page is the default page of its namespace.
        /// </summary>
        /// <param name="pageFullName">The page full name.</param>
        /// <returns><c>true</c> if the page is the default namespace of its namespace, <c>false</c> otherwise.</returns>
        private bool IsDefaultPage(string pageFullName)
        {
            string localName, nspace;

            NameTools.ExpandFullName(pageFullName, out nspace, out localName);

            if (string.IsNullOrEmpty(nspace))
            {
                return(localName.ToLowerInvariant() == Settings.GetDefaultPage(currentWiki).ToLowerInvariant());
            }
            else
            {
                NamespaceInfo ns = Pages.FindNamespace(currentWiki, nspace);
                return(ns.DefaultPageFullName != null && ns.DefaultPageFullName.ToLowerInvariant() == pageFullName.ToLowerInvariant());
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Searches for pages with name or title similar to a specified value.
        /// </summary>
        /// <param name="name">The name to look for (<c>null</c> for the root).</param>
        /// <param name="nspace">The namespace to search into.</param>
        /// <returns>The similar pages, if any.</returns>
        public static PageInfo[] SearchSimilarPages(string name, string nspace)
        {
            if (string.IsNullOrEmpty(nspace))
            {
                nspace = null;
            }

            SearchResultCollection searchResults = Search(name, false, false, SearchOptions.AtLeastOneWord);

            var result = new List <PageInfo>(20);

            foreach (SearchResult res in searchResults)
            {
                var pageDoc = res.Document as PageDocument;
                if (pageDoc != null)
                {
                    var pageNamespace = NameTools.GetNamespace(pageDoc.PageInfo.FullName);
                    if (string.IsNullOrEmpty(pageNamespace))
                    {
                        pageNamespace = null;
                    }

                    if (pageNamespace == nspace)
                    {
                        result.Add(pageDoc.PageInfo);
                    }
                }
            }

            // Search page names for matches
            List <PageInfo> allPages    = Pages.GetPages(Pages.FindNamespace(nspace));
            var             comp        = new PageNameComparer();
            var             currentName = name.ToLowerInvariant();

            foreach (PageInfo page in allPages)
            {
                if (NameTools.GetLocalName(page.FullName).ToLowerInvariant().Contains(currentName))
                {
                    if (result.Find(delegate(PageInfo p) { return(comp.Compare(p, page) == 0); }) == null)
                    {
                        result.Add(page);
                    }
                }
            }

            return(result.ToArray());
        }
Exemplo n.º 29
0
        /// <summary>
        /// Refreshes the bulk category list.
        /// </summary>
        private void RefreshBulkCategoryList()
        {
            lstBulkCategories.Items.Clear();

            string        cp         = providerSelector.SelectedProvider;
            NamespaceInfo nspace     = Pages.FindNamespace(lstNamespace.SelectedValue);
            var           categories =
                from c in Pages.GetCategories(nspace)
                where c.Provider.GetType().FullName == cp
                select c;

            foreach (CategoryInfo cat in categories)
            {
                ListItem item = new ListItem(NameTools.GetLocalName(cat.FullName), cat.FullName);
                lstBulkCategories.Items.Add(item);
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Finds all the Navigation Paths that include a Page.
        /// </summary>
        /// <param name="page">The Page.</param>
        /// <returns>The list of Navigation Paths.</returns>
        public static string[] PathsPerPage(PageInfo page)
        {
            NamespaceInfo pageNamespace = Pages.FindNamespace(NameTools.GetNamespace(page.FullName));

            var result = new List <string>(10);
            List <NavigationPath> allPaths = GetNavigationPaths(pageNamespace);

            for (var i = 0; i < allPaths.Count; i++)
            {
                var pages = new List <string>(allPaths[i].Pages);
                if (pages.Contains(page.FullName))
                {
                    result.Add(allPaths[i].FullName);
                }
            }
            return(result.ToArray());
        }