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) { return(null); } if (componentPart.Elements == null || componentPart.Elements.Count == 0) { return(null); } var hasDOI = !string.IsNullOrEmpty(citation.Reference.Doi); var hasOnlineAddress = !string.IsNullOrEmpty(citation.Reference.OnlineAddress); if (!hasDOI && !hasOnlineAddress) { return(null); //Suppress output of this literal } //Still here? OK, so there's an online address handled = false; return(null); }
private FieldElement GetDateFieldElement(ComponentPart componentPart) { if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } FieldElement dateFieldElement = componentPart.Elements.Where(element => { DateTimeFieldElement dateTimeFieldElement = element as DateTimeFieldElement; if (dateTimeFieldElement != null) { return(true); } TextFieldElement textFieldElement = element as TextFieldElement; if (textFieldElement != null) { return(true); } return(false); }).FirstOrDefault() as FieldElement; return(dateFieldElement); }
public static void Start() { RuntimeObject.Init(); RigidBody.Init(); CollisionBody.Init(); CollisionSensor.Init(); TransportSurface.Init(); CollisionMaterial.Init(); HingeJoint.Init(); SlidingJoint.Init(); CylindricalJoint.Init(); FixedJoint.Init(); BallJoint.Init(); AngularLimit.Init(); LinearLimit.Init(); AngularSpring.Init(); LinearSpring.Init(); SpeedControl.Init(); PositionControl.Init(); BreakingConstraint.Init(); GearCoupling.Init(); CamCoupling.Init(); ElecCamCoupling.Init(); PreventCollision.Init(); ChangeMaterial.Init(); ComponentPart.Init(); SourceBehavior.Init(); SinkBehavior.Init(); GraphControl.Init(); ExternalConnection.Init(); SignalAdapter.Init(); Signal.Init(); ProxyObject.Init(); RuntimeParameters.Init(); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } PersonFieldElement personFieldElement = componentPart.Elements.OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } if (personFieldElement.SuppressOutput) { return(null); } #region BeforeFormatPerson: BeforeFormatPersonEventArgs bfp; personFieldElement.PersonFormatter.BeforeFormatPerson += (sender, e) => { bfp = (BeforeFormatPersonEventArgs)e; if (bfp.Person == null) { return; } if (string.IsNullOrEmpty(bfp.Person.FullName)) { return; } if (bfp.Person.FullName.Any(c => IsChinese(c))) { // if required, Chinese names can have a different name order than other persons in the group // otherwise, pls. comment out the following line using to slashes // bfp.NameOrder = PersonNameOrder.FirstNameLastName; bfp.SpaceBetwenLastAndFirstnames = ""; // used for PersonNameOrder = FirstNameLastName bfp.LastNameFirstNameSeparator = ""; // used for PersonNameOrder = LastNameFirstName or LastNameFirstNameCompact; } }; #endregion return(null); }
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); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = true; if (citation == null) { return(null); } var citationManager = citation.CitationManager; if (citationManager == null) { return(null); } var bibliographyCitation = citation as BibliographyCitation; if (bibliographyCitation == null) { return(null); } int countCites = ( from cite in citationManager.PlaceholderCitations where cite.YearOnly == false && cite.BibOnly == false && cite.Reference == citation.Reference select cite ).Count(); if (countCites == 0) { return(null); } if (componentPart == null) { return(null); } if (componentPart.Elements == null || componentPart.Elements.Count == 0) { return(null); } LiteralElement countCitesLiteralElement = componentPart.Elements.OfType <LiteralElement>().FirstOrDefault(element => element.Text == "CITE COUNT"); if (countCitesLiteralElement == null) { return(null); } countCitesLiteralElement.Text = countCites.ToString(); handled = false; return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //suppresses the output of the component, if a CitationKey field element is present and if the current citation key was automatically created handled = false; if (componentPart == null) { return(null); } if (componentPart.Elements == null) { return(null); } if (citation == null || citation.Reference == null) { return(null); } if (componentPart.Scope == ComponentPartScope.ParentReference && citation.Reference.ParentReference == null) { return(null); } var citationKeyFieldElement = componentPart.Elements.OfType <CitationKeyFieldElement>().FirstOrDefault(); if (citationKeyFieldElement == null) { return(null); } string citationKeyResolved; UpdateType citationKeyUpdateTypeResolved; if (componentPart.Scope == ComponentPartScope.ParentReference) { citationKeyResolved = citation.Reference.ParentReference.CitationKey; citationKeyUpdateTypeResolved = citation.Reference.ParentReference.CitationKeyUpdateType; } else { citationKeyResolved = citation.Reference.CitationKey; citationKeyUpdateTypeResolved = citation.Reference.CitationKeyUpdateType; } if (citationKeyUpdateTypeResolved == UpdateType.Automatic || string.IsNullOrWhiteSpace(citationKeyResolved)) { handled = true; return(null); } return(null); }
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); } TextFieldElement textFieldElement = componentPart.Elements.OfType <TextFieldElement>().FirstOrDefault(); //SwissAcademic.Citavi.Citations.TextFieldElement if (textFieldElement == null) { return(null); } bool found = false; TextUnitCollection textUnits = textFieldElement.GetTextUnits(citation, template); if (textUnits == null) { return(null); } foreach (ITextUnit textUnit in textUnits) { if (textUnit.Text.Contains("-")) { found = true; textUnit.Text = textUnit.Text.Replace("-", "\u2011"); } } if (found) { componentPart.Elements.ReplaceItem(textFieldElement, textUnits.TextUnitsToLiteralElements(componentPart)); } return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (componentPart == null) { return(null); } if (citation == null || citation.Reference == null) { return(null); } var dateString = citation.Reference.Date; if (string.IsNullOrWhiteSpace(dateString)) { return(null); } var dateFieldElement = componentPart.GetFieldElements().FirstOrDefault <FieldElement>(item => item.PropertyId == ReferencePropertyId.Date); if (dateFieldElement == null) { return(null); } var output = new TextUnitCollection(); DateTime dateValue; if (!DateTime.TryParse(dateString, out dateValue)) { return(null); } var day = dateValue.Day; //int var month = dateValue.Month; //ditto var year = dateValue.Year; //ditto var monthStringRoman = NumeralSystemConverter.ToRomanNumber(arabicNumber: month.ToString(), lowerCase: false); var dayString = day.ToString("D2"); //2-digit day, padded with leading 0 if necessary, so 08 instead of 8 var yearString = dateValue.ToString("yyyy"); //4-digit year var newDatePattern = "{0}. {1} {2}"; dateString = string.Format(newDatePattern, dayString, monthStringRoman, yearString); var dateStringTextUnit = new LiteralTextUnit(dateString); output.Add(dateStringTextUnit); handled = true; return(output); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (componentPart == null) { return(null); } if (citation == null || citation.Reference == null) { return(null); } var periodical = citation.Reference.Periodical; if (periodical == null) { return(null); } var notesString = periodical.Notes; if (string.IsNullOrWhiteSpace(notesString)) { return(null); } var periodicalFieldElement = componentPart.GetFieldElements().FirstOrDefault <FieldElement>(item => item.PropertyId == ReferencePropertyId.Periodical); if (periodicalFieldElement == null) { return(null); } var output = componentPart.GetTextUnitsUnfiltered(citation, template); var notesPrefixTextUnit = new LiteralTextUnit(" ["); notesPrefixTextUnit.FontStyle = FontStyle.Neutral; var notesTextUnit = new LiteralTextUnit(notesString); notesTextUnit.FontStyle = FontStyle.Neutral; var notesSuffixTextUnit = new LiteralTextUnit("]"); notesSuffixTextUnit.FontStyle = FontStyle.Neutral; output.Add(notesPrefixTextUnit); output.Add(notesTextUnit); output.Add(notesSuffixTextUnit); handled = true; return(output); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { bool doSuppressOnPages = false; //Seitennummern bool doSuppressOnColumns = false; //Spaltennummern bool doSuppressOnParagraphs = false; //Paragraphen bool doSuppressOnMargins = true; //Randnummern bool doSuppressOnOthers = false; //Andere //do not edit handled = false; if (citation == null) { return(null); } if (componentPart == null) { return(null); } if (componentPart.Elements == null) { return(null); } if (!componentPart.Elements.Any()) { return(null); } PlaceholderCitation placeholderCitation = citation as PlaceholderCitation; if (placeholderCitation == null) { return(null); } if (placeholderCitation.Entry == null) { return(null); } if ( (doSuppressOnPages && placeholderCitation.Entry.PageRange.NumberingType == NumberingType.Page) || (doSuppressOnColumns && placeholderCitation.Entry.PageRange.NumberingType == NumberingType.Column) || (doSuppressOnParagraphs && placeholderCitation.Entry.PageRange.NumberingType == NumberingType.Paragraph) || (doSuppressOnMargins && placeholderCitation.Entry.PageRange.NumberingType == NumberingType.Margin) || (doSuppressOnOthers && placeholderCitation.Entry.PageRange.NumberingType == NumberingType.Other) ) { handled = true; return(null); } return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //Version 1.1 Filter can handle both Edition and EditionNumberResolved, can be part of a multi-element component part //Version 1.0 Filter handles Edition only (no EditionNumberResolved) handled = false; if (componentPart == null) { return(null); } if (componentPart.Elements == null) { return(null); } if (citation == null || citation.Reference == null) { return(null); } if (componentPart.Scope == ComponentPartScope.ParentReference && citation.Reference.ParentReference == null) { return(null); } var editionFieldElement = componentPart.GetFieldElements().FirstOrDefault <FieldElement>(item => item.PropertyId == ReferencePropertyId.Edition || item.PropertyId == ReferencePropertyId.EditionNumberResolved); if (editionFieldElement == null) { return(null); } string editionNumberResolved; if (componentPart.Scope == ComponentPartScope.ParentReference) { editionNumberResolved = citation.Reference.ParentReference.EditionNumberResolved; } else { editionNumberResolved = citation.Reference.EditionNumberResolved; } //now suppress the output ONLY if edition number is 1 if (editionNumberResolved == "1") { componentPart.Elements.Remove(editionFieldElement); } return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { bool doSuppressOnComments = true; //Kommentare bool doSuppressOnIndirectQuotations = true; //Indirekte Zitate bool doSuppressOnSummaries = true; //Zusammenfassungen bool doSuppressOnNonQuotations = false; //Nachweis ohne Wissenselement (auch Bildzitate) bool doSuppressOnDirectQuotations = false; //Wörtliche Zitate //do not edit handled = false; if (citation == null) { return(null); } if (componentPart == null) { return(null); } if (componentPart.Elements == null) { return(null); } if (!componentPart.Elements.Any()) { return(null); } PlaceholderCitation placeholderCitation = citation as PlaceholderCitation; if (placeholderCitation == null) { return(null); } if (placeholderCitation.Entry == null) { return(null); } if ( (doSuppressOnComments && placeholderCitation.Entry.QuotationType == QuotationType.Comment) || (doSuppressOnIndirectQuotations && placeholderCitation.Entry.QuotationType == QuotationType.IndirectQuotation) || (doSuppressOnSummaries && placeholderCitation.Entry.QuotationType == QuotationType.Summary) || (doSuppressOnNonQuotations && placeholderCitation.Entry.QuotationType == QuotationType.None) || (doSuppressOnDirectQuotations && placeholderCitation.Entry.QuotationType == QuotationType.DirectQuotation) ) { handled = true; return(null); } return(null); }
internal override List <ComponentLine> BuildLines() { List <ComponentLine> lines = new List <ComponentLine>(); lines.Add(new ComponentLine("SUMMARY:", Summary.Coalesce(Description.ToDescriptionString(), "Onbekend").ToSummary())); if (IsAllDayEvent) { lines.Add(new ComponentLine("DTSTART;VALUE=DATE:", StartEvent.ToCalendarDateUTC())); lines.Add(new ComponentLine("DTEND;VALUE=DATE:", EndEvent.ToCalendarDateUTC())); } else { var tz = new ComponentPart("TZID", TimeZone.ToOlsonName()); lines.Add(new ComponentLine($"DTSTART;{tz}:", StartEvent, false)); lines.Add(new ComponentLine($"DTEND;{tz}:", EndEvent, false)); } DateTime now = DateTime.Now; //lines.Add(new ComponentLine("DTSTAMP:", now, true)); lines.Add(new ComponentLine("UID:", $"{Code}@icalendarAPI")); //lines.Add(new ComponentLine("CLASS:", Class)); //lines.Add(new ComponentLine("CATEGORIES:", Categories)); lines.Add(new ComponentLine("STATUS:", Status)); //lines.Add(new ComponentLine("TRANSP:", Transparancy)); lines.Add(new ComponentLine("LOCATION:", Location.ToPascalCase())); //lines.Add(new ComponentLine("URL:", UrlNormalization.Instance.Normalize(Url))); //lines.Add(new ComponentLine("LAST-MODIFIED:", LastModified.Coalesce(now), true)); //lines.Add(new ComponentLine("CREATED:", now, true)); lines.Add(new ComponentLine("SEQUENCE:", Sequence)); //lines.Add(new ComponentLine("DESCRIPTION:", Description.ToDescriptionString())); //lines.Add(new ComponentLine("PRIORITY:", Priority.ForceToRange<int>(0, 9))); //lines.Add(new ComponentLine("RESOURCES:", Resources)); //lines.Add(new ComponentLine("REQUEST-STATUS:", RequestStatus)); //lines.Add(new ComponentLine("X-ALT-DESC;FMTTYPE=text/html:", string.Empty)); //Description.ToHtml(true, 30) //lines.Add(new ComponentLine("X-MICROSOFT-CDO-BUSYSTATUS:", MicrosoftBusyStatus.Busy)); //lines.Add(new ComponentLine("X-MICROSOFT-CDO-IMPORTANCE:", (int)MS_CDO_Importance.Normal)); lines.AddRange(Attachments.Select(attachment => attachment.BuildLine())); //if (!string.IsNullOrEmpty(Description) || !string.IsNullOrEmpty(HtmlDescription)) // output.AppendLine("X-ALT-DESC;" + FileMimeType.Html.ToCalendarString() + ";" + HtmlDescription.ToHtmlString(true).Coalesce(Description.ToHtml())); if (Alarm != null) { lines.AddRange(Alarm.BuildLines()); } return(BuildComponent(lines)); }
private static PersonFieldElement GetFirstPersonFieldElement(ComponentPart componentPart) { if (componentPart == null) { return(null); } if (componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } return(componentPart.Elements.OfType <PersonFieldElement>().FirstOrDefault() as PersonFieldElement); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (componentPart == null) { return(null); } if (citation == null || citation.Reference == null) { return(null); } PersonFieldElement personFieldElement = componentPart.GetFieldElements().OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } IEnumerable <Person> persons = personFieldElement.GetPersons(citation.Reference); if (persons == null || !persons.Any()) { return(null); } bool found = false; TextUnitCollection textUnits = personFieldElement.GetTextUnits(citation, template); if (textUnits == null) { return(null); } foreach (ITextUnit textUnit in textUnits) { if (textUnit.Text.Contains(" ")) { found = true; textUnit.Text = textUnit.Text.Replace(" ", "\u00A0"); } } if (found) { componentPart.Elements.ReplaceItem(personFieldElement, textUnits.TextUnitsToLiteralElements(componentPart)); } return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null) { return(null); } if (componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } PersonFieldElement personFieldElement = componentPart.Elements.OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } #region BeforeFormatPerson BeforeFormatPersonEventArgs b; personFieldElement.PersonFormatter.BeforeFormatPerson += (sender, e) => { b = (BeforeFormatPersonEventArgs)e; if (b.Person == null) { return; } if (string.IsNullOrEmpty(b.Person.LastNameForSorting)) { return; } var sortNamePerson = new Person(b.Person.Project, b.Person.LastNameForSorting); b.Person = sortNamePerson; }; #endregion return(null); }
void RemoveAllButElement(ComponentPart componentPart, IElement elementToKeep) { if (componentPart == null || componentPart.Elements == null || componentPart.Elements.Count == 0) { return; } var elements = componentPart.Elements.ToList(); foreach (IElement element in elements) { if (element == elementToKeep) { continue; } componentPart.Elements.Remove(element); } }
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 || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } PersonFieldElement authorsOrEditorsOrOrganizationsFieldElement = componentPart.Elements.OfType <PersonFieldElement>() .Where(element => element.PropertyId == ReferencePropertyId.AuthorsOrEditorsOrOrganizations) .FirstOrDefault() as PersonFieldElement; if (authorsOrEditorsOrOrganizationsFieldElement == null) { return(null); } if ( citation.Reference.AuthorsOrEditorsOrOrganizationsPersonRoleResolved != PersonRole.Editor && citation.Reference.AuthorsOrEditorsOrOrganizationsPersonRoleResolved != PersonRole.Organization ) { return(null); } authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixSingular.Text = " (Hrsg.)"; //authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixSingular.FontStyle = FontStyle.Bold; authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixPlural.Text = " (Hrsg.)"; //authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixPlural.FontStyle = FontStyle.Bold; handled = false; return(null); }
private Reference GetReferenceInScope(ComponentPart componentPart, Citation citation) { if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null) { return(null); } Reference referenceInScope = citation.Reference; if (componentPart.Scope == ComponentPartScope.ParentReference) { referenceInScope = citation.Reference.ParentReference; } return(referenceInScope); }
private static List <Person> GetPersonsDisplayed(ComponentPart componentPart, Reference reference) { if (reference == null) { return(null); } if (componentPart == null) { return(null); } //check for 1st PersonFieldElement in ComponentPart PersonFieldElement firstPersonFieldElement = componentPart.Elements.FirstOrDefault(item => item is PersonFieldElement) as PersonFieldElement; if (firstPersonFieldElement == null) { return(null); } return(GetPersonsDisplayed(firstPersonFieldElement, reference)); }
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 = true; TextUnitCollection output = new TextUnitCollection(); LiteralTextUnit text; string referenceType = citation.Reference.ReferenceType.ToString(); text = new LiteralTextUnit(referenceType, FontStyle.Neutral); // text = new LiteralTextUnit(referenceType, FontStyle.Bold | FontStyle.SmallCaps); output.Add(new LiteralTextUnit("[", FontStyle.Neutral)); output.Add(text); output.Add(new LiteralTextUnit("]", FontStyle.Neutral)); return(output); }
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; }
Citation GetCitationForComponentPartScope(ComponentPart componentPart, Citation citation) { Citation citationInScope; switch (componentPart.Scope) { #region ComponentPartScope.ParentReference case ComponentPartScope.ParentReference: { var parentReference = citation.Reference.ParentReference; if (parentReference == null) { return(null); } citationInScope = new PreviewCitation(parentReference, componentPart.CitationStyle, RuleSetType.Bibliography); } break; #endregion ComponentPartScope.ParentReference #region ComponentPartScope.Reference case ComponentPartScope.Reference: default: { citationInScope = citation; } break; #endregion ComponentPartScope.Reference } return(citationInScope); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = true; var output = new TextUnitCollection(); if (citation == null) { return(output); } if (citation.Reference == null) { return(output); } if (!citation.Reference.HasCoreField(ReferenceTypeCoreFieldId.Editors)) { return(output); //empty string } var editors = citation.Reference.Editors; if (editors == null || editors.Count == 0) { return(output); //empty string } if (editors.Count == 1) { output.Add(new LiteralTextUnit("ed.")); } else { output.Add(new LiteralTextUnit("eds.")); } return(output); }
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; Reference referenceResolved = null; if (componentPart.Scope == ComponentPartScope.ParentReference && citation.Reference.ParentReference != null) referenceResolved = citation.Reference.ParentReference; else referenceResolved = citation.Reference; if (referenceResolved == null) return null; var organizationsFieldElement = componentPart.Elements.OfType<PersonFieldElement>().FirstOrDefault() as PersonFieldElement; if (organizationsFieldElement == null) return null; IList<Person> personsAndOrganizations = referenceResolved.GetValue(organizationsFieldElement.PropertyId) as IList<Person>; if (personsAndOrganizations == null || personsAndOrganizations.Count == 0) return null; if (organizationsFieldElement.OrganizationNameOrder == OrganizationNameOrder.AbbreviationName) { //"UN [United Nations]" organizationsFieldElement.OrganizationTextBeforeNameApplyCondition = TextBeforeAfterApplyCondition.AllAttributesHaveData; organizationsFieldElement.OrganizationTextAfterNameApplyCondition = TextBeforeAfterApplyCondition.AllAttributesHaveData; } else if (organizationsFieldElement.OrganizationNameOrder == OrganizationNameOrder.NameAbbreviation) { //"United Nations [UN]" organizationsFieldElement.OrganizationTextBeforeAbbreviationApplyCondition = TextBeforeAfterApplyCondition.AllAttributesHaveData; organizationsFieldElement.OrganizationTextAfterAbbreviationApplyCondition = TextBeforeAfterApplyCondition.AllAttributesHaveData; } return null; }
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 || citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } #region ThisPersonFieldElement PersonFieldElement thisPersonFieldElement = GetFirstPersonFieldElement(componentPart); if (thisPersonFieldElement == null || thisPersonFieldElement.SuppressOutput) { return(null); } #endregion #region ThesePersons IEnumerable <Person> thesePersons = thisPersonFieldElement.GetPersons(citation); if (thesePersons == null || !thesePersons.Any()) { return(null); } #endregion #region PreviousPersonFieldElement PersonFieldElement previousPersonFieldElement = GetPreviousPersonFieldElement(thisPersonFieldElement, template, citation); if (previousPersonFieldElement == null) { return(null); } #endregion #region PreviousPersons IEnumerable <Person> previousPersons = previousPersonFieldElement.GetPersons(citation); if (previousPersons == null || !previousPersons.Any()) { return(null); } #endregion PersonTeamsCompareResult compareResult = GetPersonTeamsIdentityAndGenderStructure(thesePersons, previousPersons); if (compareResult.Identity == PersonTeamsIdentity.None) { return(null); } bool handleAlsoPartialIdentity = true; //if true, both of the following cases (1) and (2) will be treated. Otherwise, //if false, only case (1) will be treated //(1) Watson, Mary / Smith, Emma, »An interesting contribution«, in: iidem (Eds.), Edited book with 2 editors, London 2012. //(2) Watson, Mary / Smith, Emma, »A rather boring contribution«, in: iidem / Green, Peter (Eds.), Edited book with 3 editors, London 2012. if (compareResult.Identity == PersonTeamsIdentity.Partial && !handleAlsoPartialIdentity) { return(null); } //if you want "ders."/"dies." written in italics or other font styles, choose the desired option, for example FontStyle.Italic, FontStyle.Bold or FontStyle.SmallCaps LiteralTextUnit idemSingularMaleLiteral = new LiteralTextUnit("ders.", FontStyle.Neutral); LiteralTextUnit idemSingularFemaleLiteral = new LiteralTextUnit("dies.", FontStyle.Neutral); LiteralTextUnit idemSingularNeutralLiteral = new LiteralTextUnit("dass.", FontStyle.Neutral); LiteralTextUnit idemPluralLiteral = new LiteralTextUnit("dies.", FontStyle.Neutral); //NOTE: If you want a prefix such as "In: " and a suffix " (Hrsg.)", you can define them as group prefix and suffix on the field element inside the component part editor //CAUTION: This script will get more complex, if the separators between persons differ from group to group of for the last person LiteralTextUnit personSeparator = new LiteralTextUnit(thisPersonFieldElement.FirstGroupPersonSeparator.Text, thisPersonFieldElement.FirstGroupPersonSeparator.FontStyle); //we remove all separators, because some person names will have to be suppressed and we want to avoid excess separators such as the /'s in idem///John Smith thisPersonFieldElement.FirstGroupPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupLastPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupToSecondGroupSeparator.Text = ""; thisPersonFieldElement.SecondGroupPersonSeparator.Text = ""; thisPersonFieldElement.SecondGroupLastPersonSeparator.Text = ""; AfterFormatPersonEventArgs afp; thisPersonFieldElement.PersonFormatter.AfterFormatPerson += (sender, e) => { afp = (AfterFormatPersonEventArgs)e; #region Full Identity if (compareResult.Identity == PersonTeamsIdentity.Full) { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else { afp.TextUnits.Clear(); } } #endregion #region Partial Identity else { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else if (afp.Index < compareResult.IdenticalPersonsCount) { afp.TextUnits.Clear(); } else { afp.TextUnits.Insert(0, personSeparator); } } #endregion }; return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; //make sure, the important variables have data if (citation == null) { return(null); } Reference reference = citation.Reference; if (reference == null || reference.Project == null) { return(null); } if (reference.ReferenceType != ReferenceType.JournalArticle) { return(null); } if (!string.IsNullOrEmpty(reference.TitleSupplement)) { return(null); //Diese Zeile ggf. durch // auskommentieren, falls auch bereits gefüllte Titelzusätze-Felder überschrieben werden sollen } if (reference.Periodical == null) { return(null); } //find the other reference via entity links if (reference.Project.EntityLinks == null || !reference.Project.EntityLinks.Any()) { return(null); } List <Reference> referencesLinkedFromThis = (from link in reference.Project.EntityLinks.FindLinksForSource((ICitaviEntity)reference) where link.Target is Reference select(Reference) link.Target).ToList(); if (referencesLinkedFromThis == null || !referencesLinkedFromThis.Any()) { return(null); } List <Reference> referencesLinkingToThis = (from link in reference.Project.EntityLinks.FindLinksForTarget((ICitaviEntity)reference) where link.Source is Reference select(Reference) link.Source).ToList(); if (referencesLinkingToThis == null || !referencesLinkingToThis.Any()) { return(null); } //find first reference with a bidirectional link and treat that as the parrallel publication Reference otherReference = referencesLinkedFromThis.Intersect(referencesLinkingToThis).FirstOrDefault(); if (otherReference == null) { return(null); } if (otherReference.Periodical == null || string.IsNullOrEmpty(otherReference.Periodical.FullName)) { return(null); } //prepare this component's output var output = new TextUnitCollection(); StringBuilder outputTagged = new StringBuilder(); #region title of the article //wird für den Stil "Angewandte Chemie" nicht benötigt /** if (!string.IsNullOrEmpty(otherReference.Title)) * { * if (output.Count > 0) * { * outputTagged.Append(", "); * output.Add(new LiteralTextUnit("; ", FontStyle.Neutral)); * } * outputTagged.Append("<i>"); * outputTagged.Append(otherReference.Title); * outputTagged.Append("</i>"); * output.Add(new LiteralTextUnit(otherReference.Title, FontStyle.Neutral)); * } **/ #endregion #region periodical name if (!string.IsNullOrEmpty(otherReference.Periodical.StandardAbbreviation)) { /** if (output.Count > 0) //wird benötigt, falls zuvor noch der Aufsatztitel ausgegeben wird * { * outputTagged.Append(", "); * output.Add(new LiteralTextUnit(", ", FontStyle.Neutral)); * }**/ outputTagged.Append("<i>"); outputTagged.Append(otherReference.Periodical.StandardAbbreviation); outputTagged.Append("</i>"); output.Add(new LiteralTextUnit(otherReference.Periodical.StandardAbbreviation, FontStyle.Italic)); } else if (!string.IsNullOrEmpty(otherReference.Periodical.Name)) { /** if (output.Count > 0) //wird benötigt, falls zuvor noch der Aufsatztitel ausgegeben wird * { * outputTagged.Append(", "); * output.Add(new LiteralTextUnit(", ", FontStyle.Neutral)); * }**/ outputTagged.Append("<i>"); outputTagged.Append(otherReference.Periodical.Name); outputTagged.Append("</i>"); output.Add(new LiteralTextUnit(otherReference.Periodical.Name, FontStyle.Italic)); } #endregion #region year if (!string.IsNullOrEmpty(otherReference.YearResolved)) { if (output.Count > 0) { outputTagged.Append(", "); output.Add(new LiteralTextUnit(", ", FontStyle.Neutral)); // output.Add(new LiteralTextUnit(" (", FontStyle.Bold)); } outputTagged.Append("<b>"); // outputTagged.Append(" ("); outputTagged.Append(otherReference.YearResolved); // outputTagged.Append(")"); outputTagged.Append("</b>"); output.Add(new LiteralTextUnit(otherReference.YearResolved, FontStyle.Bold)); // output.Add(new LiteralTextUnit(")", FontStyle.Bold)); } #endregion #region volumne number if (!string.IsNullOrEmpty(otherReference.Volume)) { if (output.Count > 0) { outputTagged.Append(", "); output.Add(new LiteralTextUnit(", ", FontStyle.Neutral)); } outputTagged.Append("<i>"); outputTagged.Append(otherReference.Volume); outputTagged.Append("</i>"); output.Add(new LiteralTextUnit(otherReference.Volume, FontStyle.Italic)); } #endregion #region page range if (!string.IsNullOrEmpty(otherReference.PageRange.ToString())) { if (output.Count > 0) { outputTagged.Append(", "); output.Add(new LiteralTextUnit(", ", FontStyle.Neutral)); } outputTagged.Append(otherReference.PageRange.ToString()); output.Add(new LiteralTextUnit(otherReference.PageRange.ToString(), FontStyle.Neutral)); } #endregion #region DOI //wird für den Stil "Angewandte Chemie" nicht benötigt /** if (!string.IsNullOrEmpty(otherReference.Doi)) * { * if (output.Count > 0) * { * outputTagged.Append(", https://doi.org/"); * output.Add(new LiteralTextUnit(", https://doi.org/", FontStyle.Neutral)); * } * // outputTagged.Append("<i>"); * outputTagged.Append(otherReference.Doi); * // outputTagged.Append("</i>"); * output.Add(new LiteralTextUnit(otherReference.Doi, FontStyle.Neutral)); * } **/ #endregion if (reference.Project.DesktopProjectConfiguration != null && reference.Project.DesktopProjectConfiguration.Permissions != null && reference.Project.DesktopProjectConfiguration.Permissions.DbPermission != null && reference.Project.DesktopProjectConfiguration.Permissions.DbPermission == ProjectDbPermission.Write) { reference.TitleSupplementTagged = outputTagged.ToString(); } handled = true; return(output); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (componentPart == null) { return(null); } if (citation == null) { return(null); } if (citation.Reference == null) { return(null); } if (componentPart.Scope == ComponentPartScope.ParentReference && citation.Reference.ParentReference == null) { return(null); } var referenceInScopeOfComponentPart = componentPart.Scope == ComponentPartScope.ParentReference ? citation.Reference.ParentReference : citation.Reference; //check for the first custom field in the componentPart ... we expect this to be the field where the publication media type ist stored ReferencePropertyId[] customFieldProperties = new ReferencePropertyId[] { ReferencePropertyId.CustomField1, ReferencePropertyId.CustomField2, ReferencePropertyId.CustomField3, ReferencePropertyId.CustomField4, ReferencePropertyId.CustomField5, ReferencePropertyId.CustomField6, ReferencePropertyId.CustomField7, ReferencePropertyId.CustomField8, ReferencePropertyId.CustomField9 }; TextFieldElement customFieldElement = componentPart.GetFieldElements().OfType <TextFieldElement>().FirstOrDefault(fieldElement => customFieldProperties.Contains(fieldElement.PropertyId)); if (customFieldElement == null) { return(null); } //check if corresponding reference field contains data var mediaType = referenceInScopeOfComponentPart.GetValue(customFieldElement.PropertyId) as string; if (string.IsNullOrEmpty(mediaType)) { return(null); } //the following words should be output in italics var specialMediaTypes = new string[] { "iPad", "Kindle", "Microsoft", "Word", "PowerPoint", "Excel", "Nook", "Sony", "Adobe" }; var regEx = new Regex(@"\b(" + string.Join("|", specialMediaTypes) + @")\b", RegexOptions.IgnoreCase); if (regEx.IsMatch(mediaType)) { var words = mediaType.Split(' '); var newLiteralElements = new List <LiteralElement>(); for (int i = 0; i < words.Count(); i++) { var word = words[i]; if (string.IsNullOrWhiteSpace(word)) { continue; } LiteralElement newLiteralElement = null; if (i < words.Count() - 1) { newLiteralElement = new LiteralElement(componentPart, word + " "); } else { newLiteralElement = new LiteralElement(componentPart, word); } if (specialMediaTypes.Contains(word)) { newLiteralElement.FontStyle = SwissAcademic.Drawing.FontStyle.Italic; } else { newLiteralElement.FontStyle = SwissAcademic.Drawing.FontStyle.Neutral; } newLiteralElements.Add(newLiteralElement); } var index = componentPart.Elements.IndexOf(customFieldElement); componentPart.Elements.RemoveAt(index); componentPart.Elements.InsertElements(index, newLiteralElements); foreach (var element in componentPart.Elements.OfType <LiteralElement>()) { element.ApplyCondition = ElementApplyCondition.Always; } //componentPart.Elements.ReplaceItem(customFieldElement, newLiteralElements); } return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //Name of filter: Outputs a dash "---" instead of names in case of repetition //Version 3.2: Refactored for C6 to make use of AfterFormatPerson event handler //Version 3.1: //- set font style of dashes to neutral //Version 3.0: //- allow either one dash if all persons are the same (lookForRepetitionOfIndividualPersons = false) or various dashes for each repeated person (lookForRepetitionOfIndividualPersons = true) //- allow mix of dashes and written names and again dashes (exitLookForRepetitionIfFailedOnce = false) or not (exitLookForRepetitionIfFailedOnce = true) //Version 2.2: //- GetPreviousVisibleCitation() method gets first previous citation where nobib = false //Version 2.1: //- filter deactivates itself, if the bibliography is NOT YET completely sorted (see below) //Version 2: //- filter deactivates itself, if the person field component it is attached to is NOT the first inside the template //- filter works on ALL kinds of person fields (Authors, Editors, Organizations, AuthorsEditorsOrOrganizations etc.) //- filter compares ALL kinds of person fields of this citation with the ones of its predecessor (e.g. authors with authors, authors with editors etc.) //- filter considers group prefices for singular and plural already defined on the field element itself: // --- (Hrsg.) or ---, eds. etc. I.e. it checks, if ", eds." has already been defined and uses it with the dash. //- you can customize the dash in line 34 below //NOTE: Set the following to true, if you want one dash if all persons are repeated, or none, //set it to false, if you want to compare person by person and set individual dashes per repeated person bool lookForRepetitionOfIndividualPersons = true; bool exitLookForRepetitionIfFailedOnce = true; //only applicable if previous was set to true /* * lookForRepetitionOfIndividualPersons = FALSE: * * A, B (2010) * - (2010) * A, B, C (2010) * A, B, D (2010) * A, B, C (2010) * A, D, C (2010) * * lookForRepetitionOfIndividualPersons = TRUE, exitLookForRepetitionIfFailedOnce = TRUE * * A, B (2010) * -, - (2010) * A, B, C (2010) * -, -, D (2010) * A, B, C (2010) * -, D, C (2010) * * lookForRepetitionOfIndividualPersons = TRUE, exitLookForRepetitionIfFailedOnce = FALSE * * A, B (2010) * -, - (2010) * A, B, C (2010) * -, -, D (2010) * A, B, C (2010) * -, D, - (2010) * */ handled = false; if (citation == null || citation.Reference == null || citation.CitationManager == null) { return(null); } if (template == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } //define the dashes string emdashes = "———"; LiteralTextUnit emDashesTextUnit = new LiteralTextUnit(emdashes); //filter deactivates itself, if the bibliography is NOT YET completely sorted //this is necessary to avoid that this filter in turn changes the sort order, that it depends upon if (citation.CitationManager.BibliographyCitations.IsSorted == false) { return(null); } //make sure the current componentPart is the FIRST inside the template if (template.ComponentParts == null || template.ComponentParts.Count == 0) { return(null); } if (template.ComponentParts[0].Id != componentPart.Id) { return(null); } #region ThisBibliographyCitation var thisBibliographyCitation = citation as BibliographyCitation; if (thisBibliographyCitation == null) { return(null); } #endregion ThisBibliographyCitation #region PreviousBibliographyCitation var previousBibliographyCitation = GetPreviousVisibleBibliographyCitation(thisBibliographyCitation); if (previousBibliographyCitation == null) { return(null); } if (previousBibliographyCitation.Reference == null) { return(null); } if (previousBibliographyCitation.NoBib == true) { return(null); } #endregion PreviousBibliographyCitation #region ThisTemplate var thisTemplate = thisBibliographyCitation.Template; if (thisTemplate == null) { return(null); } #endregion ThisTemplate #region PreviousTemplate var previousTemplate = previousBibliographyCitation.Template; if (previousTemplate == null) { return(null); } #endregion PreviousTemplate #region ThisPersonFieldElement var thisPersonFieldElement = ( componentPart.Elements != null && componentPart.Elements.Count > 0 ? componentPart.Elements[0] : null ) as PersonFieldElement; if (thisPersonFieldElement == null) { return(null); } #endregion ThisPersonFieldElement #region PreviousPersonFieldElement var previousPersonFieldElement = ( previousTemplate.ComponentParts != null && previousTemplate.ComponentParts.Count > 0 && previousTemplate.ComponentParts[0].Elements != null && previousTemplate.ComponentParts[0].Elements.Count > 0 ? previousTemplate.ComponentParts[0].Elements[0] : null ) as PersonFieldElement; if (previousPersonFieldElement == null) { return(null); } #endregion PreviousPersonFieldElement #region ThesePersons //we DO have a valid citation/reference a previous citation/reference, so we can compare their persons IEnumerable <Person> thesePersons = thisBibliographyCitation.Reference.GetValue(thisPersonFieldElement.PropertyId) as IEnumerable <Person>; if (thesePersons == null || thesePersons.Count() == 0) { return(null); } #endregion ThesePersons #region PreviousPersons IEnumerable <Person> previousPersons = previousBibliographyCitation.Reference.GetValue(previousPersonFieldElement.PropertyId) as IEnumerable <Person>; if (previousPersons == null || previousPersons.Count() == 0) { return(null); } bool failedOnce = false; #endregion PreviousPersons //we DO have authors in both cases to compare #region LookForRepetitionOfIndividualPersons = TRUE if (lookForRepetitionOfIndividualPersons) { /* * A, B (2010) * -, - (2010) * A, B, C (2010) * -, -, D (2010) */ AfterFormatPersonEventArgs afp; thisPersonFieldElement.PersonFormatter.AfterFormatPerson += (sender, e) => { if (exitLookForRepetitionIfFailedOnce && failedOnce) { return; } afp = (AfterFormatPersonEventArgs)e; Person thisPerson = afp.Person; if (thisPerson == null) { failedOnce = true; return; } Person previousPerson = previousPersons.ElementAtOrDefault(afp.Index); if (previousPerson == null) { failedOnce = true; return; } if (!thisPerson.Equals(previousPerson)) { failedOnce = true; return; } //same person afp.TextUnits.Clear(); afp.TextUnits.Add(emDashesTextUnit); }; } #endregion LookForRepetitionOfIndividualPersons = TRUE #region LookForRepetitionOfIndividualPersons = FALSE else { if (!thesePersons.SequenceEqual(previousPersons)) { return(null); } //check if there are group suffixe defined LiteralTextUnit thisGroupSuffixSingularTextUnit = thisPersonFieldElement.GroupSuffixSingular != null ? new LiteralTextUnit(thisPersonFieldElement.GroupSuffixSingular) : null; LiteralTextUnit thisGroupSuffixPluralTextUnit = thisPersonFieldElement.GroupSuffixPlural != null ? new LiteralTextUnit(thisPersonFieldElement.GroupSuffixPlural) : null; //we are dealing the the same author(s), so we handle the output now: TextUnitCollection output = new TextUnitCollection(); if (thesePersons.Count() > 1 && thisGroupSuffixPluralTextUnit != null) { output.Add(emDashesTextUnit); output.Add(thisGroupSuffixSingularTextUnit); } else if (thesePersons.Count() == 1 && thisGroupSuffixSingularTextUnit != null) { output.Add(emDashesTextUnit); output.Add(thisGroupSuffixSingularTextUnit); } else { output.Add(emDashesTextUnit); } //Set dashes to neutral font style foreach (ITextUnit unit in output) { if (!unit.Text.Equals(emdashes)) { continue; } unit.FontStyle = SwissAcademic.Drawing.FontStyle.Neutral; } handled = true; return(output); } #endregion LookForRepetitionOfIndividualPersons = FALSE return(null); }