コード例 #1
0
        public static string NewShortTitle(Reference reference)
        {
            try
            {
                if (reference == null)
                {
                    return(null);
                }

                string newShortTitle = string.Empty;

                Project project = Program.ActiveProjectShell.Project;

                string styleName = "ShortTitleGenerator.ccs";
                string folder    = project.Addresses.GetFolderPath(CitaviFolder.UserData).ToString();
                string fullPath  = folder + @"\Custom Citation Styles\" + styleName;
                if (!System.IO.File.Exists(fullPath))
                {
                    System.Windows.Forms.MessageBox.Show(ShortTitleGeneratorLocalization.CitationStyleNotFound);
                    return(null);
                }
                Uri uri = new Uri(fullPath);

                CitationStyle citationStyle = CitationStyle.Load(uri.AbsoluteUri);

                List <Reference> references = new List <Reference>();
                references.Add(reference);

                CitationManager citationManager = new CitationManager(Program.ActiveProjectShell.Project.Engine, citationStyle, references);
                if (citationManager == null)
                {
                    return(null);
                }

                BibliographyCitation bibliographyCitation = citationManager.BibliographyCitations.FirstOrDefault();
                if (bibliographyCitation == null)
                {
                    return(null);
                }

                List <ITextUnit> textUnits = bibliographyCitation.GetTextUnits();
                if (textUnits == null)
                {
                    return(null);
                }

                var output = new TextUnitCollection();

                foreach (ITextUnit textUnit in textUnits)
                {
                    output.Add(textUnit);
                }

                newShortTitle = output.ToString();
                return(newShortTitle);
            }
            catch { return(null); }
        }
コード例 #2
0
        public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled)
        {
            //return handled = true if this macro generates the output (as an IEnumerable<ITextUnit>); the standard output will be suppressed
            //return handled = false if you want Citavi to produce the standard output;

            handled = false;

            if (citation == null)
            {
                return(null);
            }
            Reference reference = citation.Reference;

            if (reference == null)
            {
                return(null);
            }

            if (citation.CitationManager == null)
            {
                return(null);
            }
            CitationManager citationManager = citation.CitationManager;


            BibliographyCitation bibliographyCitation = citation as BibliographyCitation;

            if (bibliographyCitation == null)
            {
                return(null);
            }

            int counter = 0;

            foreach (PlaceholderCitation placeholderCitation in citationManager.PlaceholderCitations)
            {
                if (placeholderCitation == null || placeholderCitation.Reference == null)
                {
                    continue;
                }
                if (placeholderCitation.Reference.Equals(reference))
                {
                    counter++;
                }
            }

            if (counter == 1)
            {
                handled = true;
                return(null);
            }

            return(null);
        }
        private static BibliographyCitation GetPreviousVisibleBibliographyCitation(BibliographyCitation bibliographyCitation)
        {
            if (bibliographyCitation == null)
            {
                return(null);
            }
            BibliographyCitation previousBibliographyCitation = bibliographyCitation;

            //consider nobib
            do
            {
                previousBibliographyCitation = previousBibliographyCitation.PreviousBibliographyCitation;
                if (previousBibliographyCitation == null)
                {
                    return(null);
                }
            } while (previousBibliographyCitation.NoBib == true);

            //still here? found one!
            return(previousBibliographyCitation);
        }
コード例 #4
0
        public IEnumerable<ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled)
        {
            handled = true;

            if (citation == null) return null;
            if (citation.Reference == null) return null;

            if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) return null;
            if (componentPart.Elements.Count != 1) return null;

            CitationKeyFieldElement citationKeyFieldElement = componentPart.Elements.ElementAt(0) as CitationKeyFieldElement;
            if (citationKeyFieldElement == null) return null;

            PlaceholderCitation placeholderCitation = citation as PlaceholderCitation;
            if (placeholderCitation != null)
            {
                if (placeholderCitation.CorrespondingBibliographyCitation == null) return null;
                if (placeholderCitation.IsAmbiguityTest) return null;

                if (placeholderCitation.AmbiguityFound && !placeholderCitation.AmbiguityResolved)
                {
                    handled = false; //this will display the citation key
                    return null;
                }
            }

            if (citation.CitationManager == null) return null;

            BibliographyCitation bibliographyCitation = citation as BibliographyCitation;
            if (bibliographyCitation != null)
            {
                if (bibliographyCitation.AmbiguityFound && !bibliographyCitation.AmbiguityResolved)
                {
                    handled = false; //this will display the citation key
                    return null;
                }
            }

            return null;
        }
コード例 #5
0
        private static Citation GetPreviousVisibleCitation(Citation citation)
        {
            if (citation == null)
            {
                return(null);
            }

            #region Bibliography

            if (citation.CitationType == CitationType.Bibliography)
            {
                BibliographyCitation previousBibliographyCitation = citation as BibliographyCitation;
                if (previousBibliographyCitation == null)
                {
                    return(null);
                }

                //consider nobib
                do
                {
                    previousBibliographyCitation = previousBibliographyCitation.PreviousBibliographyCitation;
                    if (previousBibliographyCitation == null)
                    {
                        return(null);
                    }
                } while (previousBibliographyCitation.NoBib == true);

                //still here? found one!
                return(previousBibliographyCitation);
            }

            #endregion Bibliography

            #region InText

            if (citation.CitationType == CitationType.InText)
            {
                InTextCitation previousInTextCitation = citation as InTextCitation;
                if (previousInTextCitation == null)
                {
                    return(null);
                }

                //consider bibonly
                do
                {
                    previousInTextCitation = previousInTextCitation.PreviousInTextCitation;
                    if (previousInTextCitation == null)
                    {
                        return(null);
                    }
                } while (previousInTextCitation.BibOnly == true);

                //still here? found one!
                return(previousInTextCitation);
            }

            #endregion InText

            #region Footnote

            if (citation.CitationType == CitationType.Footnote)
            {
                FootnoteCitation previousFootnoteCitation = citation as FootnoteCitation;
                if (previousFootnoteCitation == null)
                {
                    return(null);
                }

                //consider bibonly
                do
                {
                    previousFootnoteCitation = previousFootnoteCitation.PreviousFootnoteCitation;
                    if (previousFootnoteCitation == null)
                    {
                        return(null);
                    }
                } while (previousFootnoteCitation.BibOnly == true);

                //still here? found one!
                return(previousFootnoteCitation);
            }

            #endregion Footnote

            //still here? no visible previous citation found!
            return(null);
        }
        public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled)
        {
            handled = true;

            if (citation == null)
            {
                return(null);
            }
            if (citation.Reference == null)
            {
                return(null);
            }

            PlaceholderCitation placeholderCitation = citation as PlaceholderCitation;

            if (placeholderCitation != null)
            {
                if (placeholderCitation.CorrespondingBibliographyCitation == null)
                {
                    return(null);
                }

                if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any())
                {
                    return(null);
                }
                if (componentPart.Elements.Count != 1)
                {
                    return(null);
                }

                CitationKeyFieldElement citationKeyFieldElement = componentPart.Elements.ElementAt(0) as CitationKeyFieldElement;
                if (citationKeyFieldElement == null)
                {
                    return(null);
                }
                if (placeholderCitation.IsAmbiguityTest)
                {
                    return(null);
                }

                if (placeholderCitation.AmbiguityFound && !placeholderCitation.AmbiguityResolved)
                {
                    handled = false;                     //this will display the citation key
                }
            }

            if (citation.CitationManager == null)
            {
                return(null);
            }

            BibliographyCitation bibliographyCitation = citation as BibliographyCitation;

            if (bibliographyCitation != null)
            {
                var placeholderCitations = citation.CitationManager.PlaceholderCitations;
                if (placeholderCitations
                    .Where(item => item.Reference == bibliographyCitation.Reference)
                    .Any(item2 => item2.AmbiguityFound == true && item2.AmbiguityResolved == false))
                {
                    handled = false;                     //this will display the citation key
                }
            }


            return(null);
        }
コード例 #7
0
        public int Compare(Citation x, Citation y)
        {
            /*
             *                  This is an example of a custom sort macro that sorts all references of type 'internet document' on top of the bibliography.
             *                  The internet documents themselves are sorted according to a different logic than the rest of the cited documents.
             *                  Return values:
             *                  0:               x is considered the same as y sorting-wise, so we cannot tell a difference based on the algorithm below
             *                  > 0 (positive):      x should go after y, x is greater than y
             *                  < 0 (negative):      x should go before y, x is less than
             */


            if (x == null || y == null)
            {
                return(0);
            }

            Reference xReference = x.Reference;
            Reference yReference = y.Reference;

            if (xReference == null || yReference == null)
            {
                return(0);
            }

            ReferenceType xReferenceType = xReference.ReferenceType;
            ReferenceType yReferenceType = yReference.ReferenceType;

            BibliographyCitation xBibliographyCitation = x as BibliographyCitation;
            BibliographyCitation yBibliographyCitation = y as BibliographyCitation;

            if (xBibliographyCitation == null || yBibliographyCitation == null)
            {
                return(0);
            }


            Template xTemplate = x.GetTemplateForCitation();
            Template yTemplate = y.GetTemplateForCitation();

            if (xTemplate == null || yTemplate == null)
            {
                return(0);
            }

            PersonFieldElement xPersonFieldElement = xTemplate.StructuralPersonFieldElement;
            PersonFieldElement yPersonFieldElement = yTemplate.StructuralPersonFieldElement;

            IEnumerable <Person> xPersons = xPersonFieldElement != null?xPersonFieldElement.GetPersonsCited(x) : Enumerable.Empty <Person>();

            IEnumerable <Person> yPersons = yPersonFieldElement != null?yPersonFieldElement.GetPersonsCited(y) : Enumerable.Empty <Person>();

            int xPersonsCount = 0;
            int yPersonsCount = 0;

            if (xPersons != null)
            {
                xPersonsCount = xPersons.Count();
            }
            if (yPersons != null)
            {
                yPersonsCount = yPersons.Count();
            }

            string xTitleForSorting = GetTitleForSorting(xReference);
            string yTitleForSorting = GetTitleForSorting(yReference);

            string xVolume = xReference.Volume;
            string yVolume = yReference.Volume;

            string xSeriesTitleForSorting = GetSeriesTitleForSorting(xReference);
            string ySeriesTitleForSorting = GetSeriesTitleForSorting(yReference);

            string xNumber = xReference.Number;
            string yNumber = yReference.Number;

            StringComparer defaultStringComparer     = StringComparer.Create(_cultureForSorting, true);
            int            personsCompareResult      = 0;
            int            personsCountCompareResult = 0;
            int            titleCompareResult        = 0;
            int            seriesTitleCompareResult  = 0;
            int            volumeCompareResult       = 0;
            int            numberCompareResult       = 0;
            int            yearCompareResult         = 0;
            int            editionCompareResult      = 0;


            if (xPersonsCount == 0 && yPersonsCount == 0)
            {
                //compare Titles
                titleCompareResult = xTitleForSorting.CompareTo(yTitleForSorting);
                if (titleCompareResult != 0)
                {
                    return(titleCompareResult);
                }

                seriesTitleCompareResult = xSeriesTitleForSorting.CompareTo(ySeriesTitleForSorting);
                if (seriesTitleCompareResult != 0)
                {
                    return(seriesTitleCompareResult);
                }
            }
            else if (xPersonsCount == 0 && yPersonsCount > 0)
            {
                //compare xTitle with yFirstAuthor
                titleCompareResult = defaultStringComparer.Compare(xTitleForSorting, yPersons.ElementAt(0).FullName);
                if (titleCompareResult != 0)
                {
                    return(titleCompareResult);
                }
            }
            else if (xPersonsCount > 0 && yPersonsCount == 0)
            {
                //compare xFirstAuthor with yTitle
                titleCompareResult = defaultStringComparer.Compare(xPersons.ElementAt(0).FullName, yTitleForSorting);
                if (titleCompareResult != 0)
                {
                    return(titleCompareResult);
                }
            }
            else
            {
                /*
                 *              1. Single Author Group
                 *              2. Author + Single Co-Author Group
                 *              3. Author + Multiple-Co-Authors Group
                 */

                //compare by first author
                personsCompareResult = ComparePersons(xPersons.ElementAt(0), yPersons.ElementAt(0));
                if (personsCompareResult != 0)
                {
                    return(personsCompareResult);
                }

                //still here? then both have same first author
                if ((xPersonsCount == 1 && yPersonsCount > 1) || (xPersonsCount == 2 && yPersonsCount > 2))
                {
                    //x before y
                    return(-1);
                }
                if ((xPersonsCount > 1 && yPersonsCount == 1) || (xPersonsCount > 2 && yPersonsCount == 2))
                {
                    //x after y
                    return(1);
                }
                if (xPersonsCount == 2 && yPersonsCount == 2)
                {
                    //compare by co-author
                    personsCompareResult = ComparePersons(xPersons.ElementAt(1), yPersons.ElementAt(1));
                    if (personsCompareResult != 0)
                    {
                        return(personsCompareResult);
                    }
                }

                //still here?
                //both have either exactly one identical author OR
                //both have exactly two identical authors OR
                //more than 2 authors with identical first author

                //we continue with year comparison
            }


            #region Year

            yearCompareResult = YearComparer.Compare(x, y);
            if (yearCompareResult != 0)
            {
                return(yearCompareResult);
            }

            #endregion Year

            #region Title

            titleCompareResult = defaultStringComparer.Compare(xTitleForSorting, yTitleForSorting);
            if (titleCompareResult != 0)
            {
                return(titleCompareResult);
            }


            #endregion Title

            #region Volume

            if
            (
                xReferenceType == yReferenceType &&
                xReference.HasCoreField(ReferenceTypeCoreFieldId.Volume) &&
                yReference.HasCoreField(ReferenceTypeCoreFieldId.Volume) &&
                HasFieldElement(xTemplate, ReferencePropertyId.Volume) &&
                HasFieldElement(yTemplate, ReferencePropertyId.Volume)
            )
            {
                NumberStringComparer volumeComparer = new NumberStringComparer()
                {
                    CompareMode            = NumberStringCompareMode.ByTextAndNumbersSegmentwise,
                    UseAbsoluteNumbersOnly = true
                };

                volumeCompareResult = volumeComparer.Compare(xVolume, yVolume);
                if (volumeCompareResult != 0)
                {
                    return(volumeCompareResult);
                }
            }

            #endregion Volume

            #region Number

            if
            (
                xReferenceType == yReferenceType &&
                xReference.HasCoreField(ReferenceTypeCoreFieldId.Number) &&
                yReference.HasCoreField(ReferenceTypeCoreFieldId.Number) &&
                HasFieldElement(xTemplate, ReferencePropertyId.Number) &&
                HasFieldElement(yTemplate, ReferencePropertyId.Number)
            )
            {
                NumberStringComparer numberComparer = new NumberStringComparer()
                {
                    CompareMode            = NumberStringCompareMode.ByTextAndNumbersSegmentwise,
                    UseAbsoluteNumbersOnly = true
                };

                numberCompareResult = numberComparer.Compare(xNumber, yNumber);
                if (numberCompareResult != 0)
                {
                    return(numberCompareResult);
                }
            }

            #endregion

            #region Edition

            if
            (
                xReference.HasCoreField(ReferenceTypeCoreFieldId.Edition) &&
                yReference.HasCoreField(ReferenceTypeCoreFieldId.Edition) &&
                HasFieldElement(xTemplate, ReferencePropertyId.Edition) &&
                HasFieldElement(yTemplate, ReferencePropertyId.Edition)
            )
            {
                var xEdition = xReference.EditionNumberResolved;
                var yEdition = yReference.EditionNumberResolved;

                bool xHasEdition = !string.IsNullOrEmpty(xEdition);
                bool yHasEdition = !string.IsNullOrEmpty(yEdition);


                if (xHasEdition && yHasEdition)
                {
                    NumberStringComparer editionComparer = new NumberStringComparer()
                    {
                        CompareMode            = NumberStringCompareMode.ByTextAndNumbersSegmentwise,
                        UseAbsoluteNumbersOnly = true
                    };

                    editionCompareResult = editionComparer.Compare(xEdition, yEdition);
                    if (editionCompareResult != 0)
                    {
                        return(editionCompareResult);
                    }
                }
                else if (xHasEdition && !yHasEdition) //y before x
                {
                    return(1);
                }
                else if (!xHasEdition && yHasEdition) //x before y
                {
                    return(-1);
                }
            }

            #endregion

            return(0);
        }
コード例 #8
0
        public bool IsTemplateForReference(ConditionalTemplate template, Citation citation)
        {
            if (citation == null)
            {
                return(false);
            }

            IReference currentReference = citation.Reference;

            if (currentReference == null)
            {
                return(false);
            }

            IReference currentParentReference = currentReference.ParentReference;

            if (currentParentReference == null)
            {
                return(false);
            }

            CitationManager citationManager = citation.CitationManager;

            if (citationManager == null)
            {
                return(false);
            }

            #region Bibliography

            BibliographyCitation currentBibliographyCitation = citation as BibliographyCitation;
            if (currentBibliographyCitation != null)
            {
                if (!citationManager.BibliographyCitations.IsSorted)
                {
                    return(false);
                }
                foreach (BibliographyCitation otherBibliographyCitation in citationManager.BibliographyCitations)
                {
                    if (otherBibliographyCitation == null)
                    {
                        continue;
                    }
                    if (otherBibliographyCitation == currentBibliographyCitation)
                    {
                        break;
                    }

                    IReference otherReference = otherBibliographyCitation.Reference;
                    if (otherReference == null)
                    {
                        continue;
                    }
                    if (otherReference == currentReference)
                    {
                        return(true);
                    }
                    if (otherReference == currentParentReference)
                    {
                        return(true);
                    }

                    IReference otherParentReference = otherReference.ParentReference;
                    if (otherParentReference == null)
                    {
                        continue;
                    }
                    if (otherParentReference == currentParentReference)
                    {
                        return(true);
                    }
                    if (otherParentReference == currentReference)
                    {
                        return(true);
                    }
                }
                return(false);
            }

            #endregion Bibliography

            #region Footnotes

            FootnoteCitation currentFootnoteCitation = citation as FootnoteCitation;
            if (currentFootnoteCitation != null)
            {
                foreach (FootnoteCitation otherFootnoteCitation in citationManager.FootnoteCitations)
                {
                    if (otherFootnoteCitation == null)
                    {
                        continue;
                    }
                    if (otherFootnoteCitation == currentFootnoteCitation)
                    {
                        break;
                    }

                    IReference otherReference = otherFootnoteCitation.Reference;
                    if (otherReference == null)
                    {
                        continue;
                    }
                    if (otherReference == currentReference)
                    {
                        return(true);
                    }
                    if (otherReference == currentParentReference)
                    {
                        return(true);
                    }

                    IReference otherParentReference = otherReference.ParentReference;
                    if (otherParentReference == null)
                    {
                        continue;
                    }
                    if (otherParentReference == currentParentReference)
                    {
                        return(true);
                    }
                    if (otherParentReference == currentReference)
                    {
                        return(true);
                    }
                }
                return(false);
            }

            #endregion Footnotes

            //not implmented for InTextCitations
            return(false);
        }
コード例 #9
0
        //Other reference of same author(s)/editor(s)/organization(s) cited BEFORE
        public bool IsTemplateForReference(ConditionalTemplate template, Citation citation)
        {
            var testEqualityBy = PersonIdentityTest.ByInternalID;             //adjust here to your needs
            //e.g. PersonIdentityTest.ByLastNameFirstName
            //e.g. PersonIdentityText.ByFullName
            //e.g. PersonIdentityTest.ByInternalID <- recommended for most cases

            bool considerNoBibInBibliographyCitations = false;
            bool considerNoBibInInTextCitations       = false;
            bool considerNoBibInFootnoteCitations     = false;

            if (citation == null)
            {
                return(false);
            }

            CitationManager citationManager = citation.CitationManager;

            if (citationManager == null)
            {
                return(false);
            }

            Reference currentReference = citation.Reference;

            if (currentReference == null)
            {
                return(false);
            }

            IEnumerable <Person> currentPersons = currentReference.AuthorsOrEditorsOrOrganizations;

            if (currentPersons == null || currentPersons.Count() == 0)
            {
                return(false);
            }

            IEnumerable <PublicationCitation> allCitations = null;

            PublicationCitation currentPublicationCitation = citation as PublicationCitation;

            if (currentPublicationCitation == null)
            {
                return(false);
            }

            #region InTextCitations

            InTextCitation currentInTextCitation = citation as InTextCitation;
            if (currentInTextCitation != null)
            {
                if (currentInTextCitation.BibOnly)
                {
                    return(false);
                }
                allCitations = considerNoBibInInTextCitations ?
                               citationManager.InTextCitations.Where(item => !item.BibOnly).Cast <PublicationCitation>() :
                               citationManager.InTextCitations.Where(item => !item.BibOnly && item.CorrespondingBibliographyCitation != null && !item.CorrespondingBibliographyCitation.NoBib.GetValueOrDefault(false));
            }

            #endregion

            #region FootnoteCitations

            if (allCitations == null)
            {
                FootnoteCitation currentFootnoteCitation = citation as FootnoteCitation;
                if (currentFootnoteCitation != null)
                {
                    if (currentFootnoteCitation.BibOnly)
                    {
                        return(false);
                    }
                    allCitations = considerNoBibInFootnoteCitations ?
                                   citationManager.FootnoteCitations.Where(item => !item.BibOnly).Cast <PublicationCitation>() :
                                   citationManager.FootnoteCitations.Where(item => !item.BibOnly && item.CorrespondingBibliographyCitation != null && !item.CorrespondingBibliographyCitation.NoBib.GetValueOrDefault(false));
                }
            }

            #endregion

            #region BibliographyCitations

            if (allCitations == null)
            {
                BibliographyCitation currentBibliographyCitation = citation as BibliographyCitation;
                if (currentBibliographyCitation.NoBib.GetValueOrDefault(false))
                {
                    return(false);
                }
                if (currentBibliographyCitation != null)
                {
                    allCitations = citationManager.BibliographyCitations.Where(item => !item.NoBib.GetValueOrDefault(false)).Cast <PublicationCitation>();
                }
            }

            #endregion


            IEnumerable <string> currentIdentifiers = GetPersonIdentifiers(currentPersons, testEqualityBy);

            foreach (PublicationCitation otherPublicationCitation in allCitations)
            {
                if (otherPublicationCitation == null)
                {
                    continue;
                }

                if (otherPublicationCitation == currentPublicationCitation)
                {
                    break;
                }

                var otherReference = otherPublicationCitation.Reference;
                if (otherReference == null)
                {
                    continue;
                }
                if (otherReference == currentReference)
                {
                    continue;
                }

                var otherPersons = otherReference.AuthorsOrEditorsOrOrganizations;
                if (otherPersons == null || otherPersons.Count() == 0)
                {
                    continue;
                }


                var otherIdentifiers = GetPersonIdentifiers(otherPersons, testEqualityBy);

                if (testEqualityBy == PersonIdentityTest.ByInternalID)
                {
                    //object identity
                    if (otherPersons.SequenceEqual(currentPersons))
                    {
                        return(true);
                    }
                }
                else
                {
                    if (otherIdentifiers.SequenceEqual(currentIdentifiers))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #10
0
        public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled)
        {
            handled = false;
            bool   addAmbiguityResolvingLetter = true;
            string noYearString   = "o.J.";
            string noYearTemplate = "{0}{1}";                   //add a space if you do not want the ambiguity resolving letter to "stick" to the no-year-string: "{0} {1}"

            if (citation == null)
            {
                return(null);
            }

            if (componentPart == null)
            {
                return(null);
            }
            if (componentPart.Elements == null || componentPart.Elements.Count == 0)
            {
                return(null);
            }

            Reference reference = citation.Reference;

            if (reference == null)
            {
                return(null);
            }

            //Reference in Scope of ComponentPart
            Reference referenceInScope = componentPart.Scope == ComponentPartScope.Reference ? citation.Reference : citation.Reference.ParentReference;

            if (referenceInScope == null)
            {
                return(null);
            }

            var yearFieldElement = componentPart.Elements
                                   .OfType <DateTimeFieldElement>()
                                   .Where(item => item.PropertyId == ReferencePropertyId.Year || item.PropertyId == ReferencePropertyId.YearResolved)
                                   .FirstOrDefault() as DateTimeFieldElement;

            if (yearFieldElement == null)
            {
                return(null);
            }


            string yearValue = referenceInScope.GetValue(yearFieldElement.PropertyId) as string;

            if (!string.IsNullOrEmpty(yearValue))
            {
                return(null);
            }


            //for the identifying letter we need a corresponding bibliography citation
            BibliographyCitation correspondingBibliographyCitationInScope = null;
            BibliographyCitation thisBibliographyCitation = citation as BibliographyCitation;

            if (componentPart.Scope == ComponentPartScope.Reference)
            {
                #region ComponentPartScope.Reference

                if (thisBibliographyCitation == null)
                {
                    PlaceholderCitation placeholderCitation = citation as PlaceholderCitation;
                    if (placeholderCitation != null)
                    {
                        correspondingBibliographyCitationInScope = placeholderCitation.CorrespondingBibliographyCitation;
                    }
                }
                else
                {
                    correspondingBibliographyCitationInScope = thisBibliographyCitation;
                }

                #endregion
            }
            else
            {
                #region ComponentPartScope.ParentReference

                if (citation.CitationManager != null)
                {
                    foreach (BibliographyCitation otherBibliographyCitation in citation.CitationManager.BibliographyCitations)
                    {
                        if (otherBibliographyCitation == null)
                        {
                            continue;
                        }
                        if (otherBibliographyCitation == thisBibliographyCitation)
                        {
                            continue;
                        }

                        if (otherBibliographyCitation.Reference == null)
                        {
                            continue;
                        }
                        if (otherBibliographyCitation.Reference == referenceInScope)
                        {
                            correspondingBibliographyCitationInScope = otherBibliographyCitation;
                        }
                    }
                }

                #endregion
            }
            string identifyingLetter = string.Empty;
            if (correspondingBibliographyCitationInScope != null)
            {
                identifyingLetter = correspondingBibliographyCitationInScope.IdentifyingLetter;
            }

            string         outputString         = string.Format(noYearTemplate, noYearString, identifyingLetter);
            LiteralElement outputLiteralElement = new LiteralElement(componentPart, outputString);
            outputLiteralElement.FontStyle = yearFieldElement.FontStyle;
            componentPart.Elements.ReplaceItem(yearFieldElement, outputLiteralElement);

            //all literal elements should always be output:
            foreach (LiteralElement literalElement in componentPart.Elements.OfType <LiteralElement>())
            {
                literalElement.ApplyCondition = ElementApplyCondition.Always;
            }

            return(null);
        }
コード例 #11
0
        //Version 3.0: complete overhaul, script considers different output for placehoder citations and bibliography citations
        //Version 2.0: script can be attached to both date/time field element as well as text field element

        public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled)
        {
            //enter the culture the date info has been formatted and entered in, e.g. 12/05/2017 would be December, 12th in en-UK and May, 5th in en-US
            CultureInfo targetCulture = CultureInfo.CreateSpecificCulture("en-US");

            //list all possible date formats for this script to check; the scripts tries to parse the date beginning from left to right
            string[] formats = new string[] { "yyyy-MM-dd", "yyyy/MM/dd", "dd/MM/yyyy", "yyyy/dd/MM", "dd.MM.yyyy", "d.M.yyyy", "d.MM.yyyy", "dd.M.yyyy", "dd.MM.yy", "d.M.yy", "d.MM.yy", "dd.M.yy" };

            bool usePeriodAfterAbbreviatedMonthName = true;                     //if true, month names will be: Jan. Feb. Mar. Apr. May (!) Jun. Jul. Aug. Sept. Oct. Nov. Dec.

            ///IMPORTANT: Use the following indexed placeholders {n} and format strings xxxx as in {n:xxxx} for the templates.
            ///You can ommit placeholders and/or place them freely inside the templates below. Yet, it is not recommended to use the same placeholder more than once,
            ///because this script is not optimized for this.
            ///
            ///{0}: letter for ambiguity resolving
            ///{1}: year	of start or single date
            ///{2}: month	of start or single date
            ///{3}: day     of start or single date
            ///{4}: year	of end date
            ///{5}: month	of end date
            ///{6}: day     of end date
            ///use the following formatting for "6 June 2018"
            ///YEAR:	yyyy = 2018, yy = 18
            ///MONTH:	MMMM = June, MMM = Jun, MM = 06, %M = 6
            ///DAY:		dd = 06, %d = 6, %do = 6th

            //SINGLE DATE - output format templates
            string outputFormatSingleDatePlaceholder  = "{1:yyyy}{0}";                                                                                                                                                          //e.g. 2013a
            string outputFormatSingleDateBibliography = "{1:yyyy}{0}, {2:MMMM} {3:%do}";                                                                                                                                        //e.g. 2013a, January 6th

            //DATE RANGE - output format templates
            //same year, same month
            string outputFormatDateRangeSameYearSameMonthPlaceholder  = "{1:yyyy}{0}";                                                                                                                  //e.g. 2013a
            string outputFormatDateRangeSameYearSameMonthBibliography = "{1:yyyy}{0}, {2:MMMM} {3:%do} - {6:%do}";                                                                                      //e.g. 2013a, January 6th - 9th

            //same year, different month
            string outputFormatDateRangeSameYearDifferentMonthPlaceholder  = "{1:yyyy}{0}";                                                                                             //e.g. 2013a
            string outputFormatDateRangeSameYearDifferentMonthBibliography = "{1:yyyy}{0}, {2:MMMM} {3:%do} - {5:MMMM} {6:%do}";                                                        //e.g. 2013a, September 28th - October 3rd

            //different years
            string outputFormatDateRangeDifferentYearsPlaceholder  = "{1:yyyy}/{4:yyyy}{0}";                                                                            //e.g. 2013/2014a
            string outputFormatDateRangeDifferentYearsBibliography = "{1:yyyy}/{4:yyyy}{0}; {1:yyyy}, {2:MMMM} {3:%do} - {4:yyyy}, {5:MMMM} {6:%do}";                   //e.g. 2013/2014a; 2013, December 29th - 2014, January 4th

            handled = false;

            if (citation == null)
            {
                return(null);
            }

            Reference referenceInScope = GetReferenceInScope(componentPart, citation);

            if (referenceInScope == null)
            {
                return(null);
            }

            FieldElement dateFieldElement = GetDateFieldElement(componentPart);

            if (dateFieldElement == null)
            {
                return(null);
            }

            ReferencePropertyId referencePropertyId = dateFieldElement.PropertyId;
            string dateString = referenceInScope.GetValue(referencePropertyId) as string;

            if (string.IsNullOrEmpty(dateString))
            {
                return(null);
            }

            TextUnitCollection output = null;

            PlaceholderCitation placeholderCitation = citation as PlaceholderCitation;
            bool isPlaceholderCitation = placeholderCitation != null;

            PreviewCitation previewCitation = citation as PreviewCitation;
            bool            isPreviewBibliographyCitation = previewCitation != null && citation.CitationType == CitationType.Bibliography;

            BibliographyCitation bibliographyCitation = citation as BibliographyCitation;
            bool isBibliographyCitation = bibliographyCitation != null;

            if (bibliographyCitation == null && placeholderCitation != null)
            {
                bibliographyCitation = placeholderCitation.CorrespondingBibliographyCitation;
            }
            if (bibliographyCitation == null && !isPreviewBibliographyCitation)
            {
                return(null);
            }


            string          identifyingLetter         = bibliographyCitation != null ? bibliographyCitation.IdentifyingLetter : string.Empty;
            LiteralTextUnit identifyingLetterTextUnit = new LiteralTextUnit(identifyingLetter, Drawing.FontStyle.Neutral);
            bool            hasIdentifyingLetter      = !string.IsNullOrEmpty(identifyingLetter);

            #region Tread n.d. + letter for disambiguation ("IdentifyingLetter")

            if (hasIdentifyingLetter && ContainsND(dateString))
            {
                //we make sure the IdentifyingLetter is separated from n.d. by a space char or hyphen: Smith n.d.-a, Smith n.d.-b
                //go to method SeparateIdentifyingLetterFromND below to customize
                output = componentPart.GetTextUnitsUnfiltered(citation, template);
                if (output == null || !output.Any())
                {
                    return(null);
                }

                handled = true;
                return(SeparateIdentifyingLetterFromND(output, identifyingLetter));
            }

            #endregion

            FontStyle fontStyle = dateFieldElement is DateTimeFieldElement ? ((DateTimeFieldElement)dateFieldElement).FontStyle : ((TextFieldElement)dateFieldElement).FontStyle;

            DateTime dateSingle;
            DateTime dateStart;
            DateTime dateEnd;

            string outputText = string.Empty;

            #region Check for Single Date

            if (TryParseSingleDate(dateString, formats, targetCulture, out dateSingle))
            {
                #region BibliographyCitation

                if (isBibliographyCitation || isPreviewBibliographyCitation)
                {
                    outputText = FormatDate(dateSingle, outputFormatSingleDateBibliography, targetCulture, identifyingLetter, usePeriodAfterAbbreviatedMonthName);
                }

                #endregion

                #region PlaceholderCitation

                else if (isPlaceholderCitation)
                {
                    outputText = FormatDate(dateSingle, outputFormatSingleDatePlaceholder, targetCulture, identifyingLetter, usePeriodAfterAbbreviatedMonthName);
                }

                #endregion

                #region Other

                else
                {
                    handled = false;
                    return(null);
                }

                #endregion
            }

            #endregion

            #region Check for Date Range

            else if (TryParseDateRange(dateString, formats, targetCulture, out dateStart, out dateEnd))
            {
                #region BibliographyCitation

                if (isBibliographyCitation || isPreviewBibliographyCitation)
                {
                    #region same year, same month

                    if (dateStart.Year == dateEnd.Year && dateStart.Month == dateEnd.Month && dateStart.Day != dateEnd.Day)
                    {
                        outputText = FormatDateRange(dateStart, dateEnd, outputFormatDateRangeSameYearSameMonthBibliography, targetCulture, identifyingLetter, usePeriodAfterAbbreviatedMonthName);
                    }

                    #endregion

                    #region same year, different months

                    else if (dateStart.Year == dateEnd.Year && dateStart.Month != dateEnd.Month)
                    {
                        outputText = FormatDateRange(dateStart, dateEnd, outputFormatDateRangeSameYearDifferentMonthBibliography, targetCulture, identifyingLetter, usePeriodAfterAbbreviatedMonthName);
                    }

                    #endregion

                    #region different years

                    else
                    {
                        outputText = FormatDateRange(dateStart, dateEnd, outputFormatDateRangeDifferentYearsBibliography, targetCulture, identifyingLetter, usePeriodAfterAbbreviatedMonthName);
                    }

                    #endregion
                }

                #endregion

                #region PlaceholderCitation

                else if (isPlaceholderCitation)
                {
                    #region same year, same month

                    if (dateStart.Year == dateEnd.Year && dateStart.Month == dateEnd.Month && dateStart.Day != dateEnd.Day)
                    {
                        outputText = FormatDateRange(dateStart, dateEnd, outputFormatDateRangeSameYearSameMonthPlaceholder, targetCulture, identifyingLetter, usePeriodAfterAbbreviatedMonthName);
                    }

                    #endregion

                    #region same year, different months

                    else if (dateStart.Year == dateEnd.Year && dateStart.Month != dateEnd.Month)
                    {
                        outputText = FormatDateRange(dateStart, dateEnd, outputFormatDateRangeSameYearDifferentMonthPlaceholder, targetCulture, identifyingLetter, usePeriodAfterAbbreviatedMonthName);
                    }

                    #endregion

                    #region different years

                    else
                    {
                        outputText = FormatDateRange(dateStart, dateEnd, outputFormatDateRangeDifferentYearsPlaceholder, targetCulture, identifyingLetter, usePeriodAfterAbbreviatedMonthName);
                    }

                    #endregion
                }

                #endregion

                #region Other

                else
                {
                    handled = false;
                    return(null);
                }

                #endregion
            }

            #endregion

            #region Do the output

            if (!string.IsNullOrEmpty(outputText))
            {
                var outputTextUnits = new TextUnitCollection();
                outputTextUnits = TextUnitCollectionUtility.TaggedTextToTextUnits(dateFieldElement, outputText, fontStyle);

                if (outputTextUnits.Any())
                {
                    List <ITextUnit> componentPartOutput = new List <ITextUnit>();
                    foreach (IElement element in componentPart.Elements)
                    {
                        if (element == dateFieldElement)
                        {
                            componentPartOutput.AddRange(outputTextUnits);
                        }
                        else
                        {
                            componentPartOutput.AddRange(element.GetTextUnits(citation, template));
                        }
                    }
                    handled = true;
                    return(componentPartOutput);
                }
            }

            #endregion

            handled = false;
            return(null);
        }
        public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled)
        {
            handled = false;

            bool   addInPrintNote       = true;                                 //only if set to true you are able to separate the in-print-note and the ambiguity resolving letter by a space, if required.
            bool   addInPrintNoteCustom = false;                                //only applicable if addInPrintNote = true, if set to false, the output well be as specified on the date/time field element in component
            string noYearString         = "o.\u00A0J.";                         //"o.J.", "n.d." - \u00A0 = non-breaking space (geschütztes Leerzeichen)
            string noYearTemplate       = "{0}\u00A0{1}";                       //add a space if you do not want the ambiguity resolving letter to "stick" to the no-year-string:	"{0} {1}" -> o. J. a
            //remove the space if you want the ambiguity resolving letter to "stick" to the no-year-string:		"{0}{1}"  -> o.J.a
            string noYearNoIdentifyingLetterTemplate = "{0}";
            string inPrintTemplate = "{0}\u00A0{1}";                            //add a space if you do not want the ambiguity resolving letter to "stick" to the in-print-note:	"{0} {1}" -> in press a
            //remove the space if you want the ambiguity resolving letter to "stick" to the in-print-note:		"{0}{1}"  -> in pressa
            string inPrintNoIdentifyingLetterTemplate = "{0}";
            string inPrintNoteCustom = "im\u00A0Druck";                         //"im Druck", ", in press"

            if (citation == null)
            {
                return(null);
            }

            if (componentPart == null)
            {
                return(null);
            }
            if (componentPart.Elements == null || componentPart.Elements.Count == 0)
            {
                return(null);
            }

            Reference reference = citation.Reference;

            if (reference == null)
            {
                return(null);
            }

            //Reference in Scope of ComponentPart
            Reference referenceInScope = componentPart.Scope == ComponentPartScope.Reference ? citation.Reference : citation.Reference.ParentReference;

            if (referenceInScope == null)
            {
                return(null);
            }

            var yearFieldElement = componentPart.Elements
                                   .OfType <DateTimeFieldElement>()
                                   .Where(item => item.PropertyId == ReferencePropertyId.Year || item.PropertyId == ReferencePropertyId.YearResolved)
                                   .FirstOrDefault() as DateTimeFieldElement;

            if (yearFieldElement == null)
            {
                return(null);
            }

            string inPrintNoteStandard = yearFieldElement.InPrintReplacement.Text;

            string yearValue = referenceInScope.GetValue(yearFieldElement.PropertyId) as string;

            //for the identifying letter we need a corresponding bibliography citation
            BibliographyCitation correspondingBibliographyCitationInScope = null;
            BibliographyCitation thisBibliographyCitation = citation as BibliographyCitation;

            if (componentPart.Scope == ComponentPartScope.Reference)
            {
                #region ComponentPartScope.Reference

                if (thisBibliographyCitation == null)
                {
                    PlaceholderCitation placeholderCitation = citation as PlaceholderCitation;
                    if (placeholderCitation != null)
                    {
                        correspondingBibliographyCitationInScope = placeholderCitation.CorrespondingBibliographyCitation;
                    }
                }
                else
                {
                    correspondingBibliographyCitationInScope = thisBibliographyCitation;
                }

                #endregion
            }
            else
            {
                #region ComponentPartScope.ParentReference

                if (citation.CitationManager != null)
                {
                    foreach (BibliographyCitation otherBibliographyCitation in citation.CitationManager.BibliographyCitations)
                    {
                        if (otherBibliographyCitation == null)
                        {
                            continue;
                        }
                        if (otherBibliographyCitation == thisBibliographyCitation)
                        {
                            continue;
                        }

                        if (otherBibliographyCitation.Reference == null)
                        {
                            continue;
                        }
                        if (otherBibliographyCitation.Reference == referenceInScope)
                        {
                            correspondingBibliographyCitationInScope = otherBibliographyCitation;
                        }
                    }
                }

                #endregion
            }
            string identifyingLetter = string.Empty;
            if (correspondingBibliographyCitationInScope != null)
            {
                identifyingLetter = correspondingBibliographyCitationInScope.IdentifyingLetter;
            }

            string outputString = string.Empty;


            if (string.IsNullOrEmpty(yearValue))
            {
                //"o.J." or "n.d."
                if (string.IsNullOrEmpty(identifyingLetter))
                {
                    outputString = string.Format(noYearNoIdentifyingLetterTemplate, noYearString);
                }
                else
                {
                    outputString = string.Format(noYearTemplate, noYearString, identifyingLetter);
                }
            }

            else if (addInPrintNote && StringUtility.ContainsInPrintInformation(yearValue))
            {
                if (addInPrintNoteCustom)
                {
                    //"im Druck" or "in print"
                    if (string.IsNullOrEmpty(identifyingLetter))
                    {
                        outputString = string.Format(inPrintNoIdentifyingLetterTemplate, inPrintNoteCustom);
                    }
                    else
                    {
                        outputString = string.Format(inPrintTemplate, inPrintNoteCustom, identifyingLetter);
                    }
                }
                else
                {
                    //"im Druck" or "in print" as specified on the date/time field element in component
                    if (string.IsNullOrEmpty(inPrintNoteStandard))
                    {
                        return(null);
                    }

                    if (string.IsNullOrEmpty(identifyingLetter))
                    {
                        outputString = string.Format(inPrintNoIdentifyingLetterTemplate, inPrintNoteStandard);
                    }
                    else
                    {
                        outputString = string.Format(inPrintTemplate, inPrintNoteStandard, identifyingLetter);
                    }
                }
            }

            else
            {
                //if neither "o.J."/"n.d." nor "im Druck"/"in print" applies
                return(null);
            }

            LiteralElement outputLiteralElement = new LiteralElement(componentPart, outputString);
            outputLiteralElement.FontStyle = yearFieldElement.FontStyle;
            componentPart.Elements.ReplaceItem(yearFieldElement, outputLiteralElement);

            //all literal elements should always be output:
            foreach (LiteralElement literalElement in componentPart.Elements.OfType <LiteralElement>())
            {
                literalElement.ApplyCondition = ElementApplyCondition.Always;
            }

            return(null);
        }
コード例 #13
0
		public IEnumerable<ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled)
		{
			handled = false;

			if (citation == null) return null;
			if (citation.Reference == null) return null;
			if (componentPart == null) return null;
			if (componentPart.Elements == null || componentPart.Elements.Count == 0) return null;
			
			bool ambiguityFound = false;
			BibliographyCitation bibliographyCitation = citation as BibliographyCitation;
			if (bibliographyCitation == null)
			{
				PlaceholderCitation placeholderCitation = citation as PlaceholderCitation;
				if (placeholderCitation != null)
				{
					bibliographyCitation = placeholderCitation.CorrespondingBibliographyCitation;
				}
			}
			if (bibliographyCitation != null && 
				bibliographyCitation.AmbiguityFound && 
				!string.IsNullOrEmpty(bibliographyCitation.IdentifyingLetter)
			) ambiguityFound = true;
			
			#region Find field elements of type DateTime

			IEnumerable<DateTimeFieldElement> dateTimeFieldElements = componentPart.Elements.OfType<DateTimeFieldElement>();
			if (dateTimeFieldElements == null || dateTimeFieldElements.Count() != 1) return null;

			DateTimeFieldElement dateTimeFieldElement = dateTimeFieldElements.ElementAt(0);
			if (dateTimeFieldElement == null) return null;
			
			#endregion
			
			#region Determine reference to look at
			
			Reference reference;
			if (componentPart.Scope == ComponentPartScope.ParentReference)
			{
				if (citation.Reference.ParentReference == null) return null;
				reference = citation.Reference.ParentReference as Reference;
			}
			else
			{
				reference = citation.Reference as Reference;
			}
			if (reference == null) return null;			
			
			#endregion Determine reference to look at
			
			#region Determine reference language
			
			Language language;
			if (String.Equals(reference.LanguageCode, CultureInfo.GetCultureInfo("en").TwoLetterISOLanguageName, StringComparison.OrdinalIgnoreCase))
			{
				language = Language.English;
			}
			else if (String.Equals(reference.LanguageCode, CultureInfo.GetCultureInfo("de").TwoLetterISOLanguageName, StringComparison.OrdinalIgnoreCase))
			{
				language = Language.German;
			}
			else
			{
				language = Language.Other;
			}
			
			#endregion Determine reference language

			var propertyId = dateTimeFieldElement.PropertyId;
			var dateTimeStringValue = reference.GetValue(propertyId) as string;
			if (string.IsNullOrEmpty(dateTimeStringValue)) return null;


			//das folgende geht nicht, da DateTimeFieldFormatter leider "internal" ist
			//TextUnitCollection textUnits = DateTimeFieldFormatter.Format(citation, dateTimeFieldElement, dateTimeStringValue);

			List<Segment> segments = GetSegments(dateTimeStringValue);


			List<LiteralElement> literalElements = new List<LiteralElement>();

			TextUnitCollection debug = new TextUnitCollection();
			//int counter = 1;
			foreach (Segment segment in segments)
			{
				switch (segment.type)
				{
					case SegmentType.Text:
						{
							var literalElement = new LiteralElement(componentPart, segment.text);
							literalElement.FontStyle = dateTimeFieldElement.FontStyle;
							literalElements.Add(literalElement);
						}
						break;

					case SegmentType.DateTime:
						{
							string newDateString;
							
							#region YEAR information only
							
							if (!segment.ContainsMonthInformation && !segment.ContainsDayInformation)
							{
								switch (language)
								{
									default:
									case (Language.English):
									{
										newDateString = segment.dateTime.ToString("yyyy", new CultureInfo("en-US")); //or "en-UK"
									}
									break;
									
									case (Language.German):
									{
										newDateString = segment.dateTime.ToString("yyyy", new CultureInfo("de-DE")); // or "de-CH" or "de-AT"
									}
									break;
									
									case (Language.Other):
									{
										newDateString = segment.dateTime.ToString("yyyy", new CultureInfo("en-US"));
									}
									break;	
								}
							}
							
							#endregion
							
							#region YEAR and MONTH
							
							else if (!segment.ContainsDayInformation)
							{
								switch (language)
								{
									default:
									case (Language.English):
									{
										newDateString = segment.dateTime.ToString("MM/yyyy", new CultureInfo("en-US")); //or "en-UK"
									}
									break;
									
									case (Language.German):
									{
										newDateString = segment.dateTime.ToString("MMM yyyy", new CultureInfo("de-DE")); // or "de-CH" or "de-AT"
									}
									break;
									
									case (Language.Other):
									{
										newDateString = segment.dateTime.ToString("MM/yyyy", new CultureInfo("en-US"));
									}
									break;	
								}
							}
							
							#endregion
							
							#region YEAR and MONTH and DAY
							
							else
							{
								switch (language)
								{
									default:
									case (Language.English):
									{
										newDateString = segment.dateTime.ToString("d", new CultureInfo("en-US")); //or "en-UK"
									}
									break;
									
									case (Language.German):
									{
										newDateString = segment.dateTime.ToString("dd. MM yyyy", new CultureInfo("de-DE")); // or "de-CH" or "de-AT"
									}
									break;
									
									case (Language.Other):
									{
										newDateString = segment.dateTime.ToString("MM/dd/yyyy", new CultureInfo("en-US"));
									}
									break;	
								}
							}
							
							#endregion
							
							var literalElement = new LiteralElement(componentPart, newDateString);
							literalElement.FontStyle = dateTimeFieldElement.FontStyle;
							literalElements.Add(literalElement);
						}
						break;

				}
			}

			if (ambiguityFound) 
			{
				var literalElement = new LiteralElement(componentPart, bibliographyCitation.IdentifyingLetter);
				literalElement.FontStyle = dateTimeFieldElement.FontStyle;
				literalElements.Add(literalElement);
			}

			//replace the DateTimeFieldElement by the LiteralElements
			componentPart.Elements.ReplaceItem(dateTimeFieldElement, literalElements);


			//and Citavi handles the rest, therefore we say handled = false && return null
			handled = false;
			return null;
		}
コード例 #14
0
        public bool IsTemplateForReference(ConditionalTemplate template, Citation citation)
        {
            if (citation == null)
            {
                return(false);
            }
            if (citation.CitationManager == null)
            {
                return(false);
            }
            if (citation.Reference == null)
            {
                return(false);
            }
            if (citation.Reference.Periodical == null)
            {
                return(false);
            }


            FootnoteCitation currentFootnoteCitation = citation as FootnoteCitation;

            if (currentFootnoteCitation != null)
            {
                if (currentFootnoteCitation.RuleSetOverride != RuleSetOverride.None)
                {
                    return(false);
                }
                if (currentFootnoteCitation.YearOnly || currentFootnoteCitation.PersonOnly)
                {
                    return(false);
                }

                foreach (FootnoteCitation otherFootnoteCitation in citation.CitationManager.FootnoteCitations)
                {
                    if (otherFootnoteCitation == currentFootnoteCitation)
                    {
                        break;
                    }
                    if (otherFootnoteCitation.Reference == null)
                    {
                        continue;
                    }
                    if (otherFootnoteCitation.Reference.Periodical == null)
                    {
                        continue;
                    }
                    if (otherFootnoteCitation.Reference.Periodical.Equals(currentFootnoteCitation.Reference.Periodical))
                    {
                        return(true);
                    }
                }

                //still here?
                return(false);
            }


            InTextCitation currentInTextCitation = citation as InTextCitation;

            if (currentInTextCitation != null)
            {
                if (currentInTextCitation.RuleSetOverride != RuleSetOverride.None)
                {
                    return(false);
                }
                if (currentInTextCitation.YearOnly || currentInTextCitation.PersonOnly)
                {
                    return(false);
                }

                foreach (InTextCitation otherInTextCitation in citation.CitationManager.InTextCitations)
                {
                    if (otherInTextCitation == currentInTextCitation)
                    {
                        break;
                    }
                    if (otherInTextCitation.Reference == null)
                    {
                        continue;
                    }
                    if (otherInTextCitation.Reference.Periodical == null)
                    {
                        continue;
                    }
                    if (otherInTextCitation.Reference.Periodical.Equals(currentInTextCitation.Reference.Periodical))
                    {
                        return(true);
                    }
                }

                //still here?
                return(false);
            }


            BibliographyCitation currentBibliographyCitation = citation as BibliographyCitation;

            if (currentBibliographyCitation != null)
            {
                foreach (BibliographyCitation otherBibliographyCitation in citation.CitationManager.BibliographyCitations)
                {
                    if (otherBibliographyCitation == currentBibliographyCitation)
                    {
                        break;
                    }
                    if (otherBibliographyCitation.Reference == null)
                    {
                        continue;
                    }
                    if (otherBibliographyCitation.Reference.Periodical == null)
                    {
                        continue;
                    }
                    if (otherBibliographyCitation.Reference.Periodical.Equals(currentBibliographyCitation.Reference.Periodical))
                    {
                        return(true);
                    }
                }

                //still here
                return(false);
            }

            return(false);
        }