using System; using iTextSharp.text; using Spring.Objects; using Sleis.Utility; using iTextSharp.text.pdf; namespace Sleis.Pdf { public class ObjectElementWriter : ElementWriter { public string Label { get; set; } public string Format { get; set; } public string Select { get; set; } public bool SkipNulls { get; set; } public override void Init() { ArgumentValidationUtility.ThrowOnEmpty(Select, "Select"); if (String.IsNullOrEmpty(Format)) { Format = "{0}"; } } public override void Write(Document pdf, ObjectWrapper context) { LOG.Debug("Init Write"); BeforeWrite(pdf, context); object selectionValue = null; try { selectionValue = context.GetPropertyValue(Select); } catch(Exception err) { LOG.Debug(String.Format("Error getting accessing {0} : {1}", Select, err.Message)); }//swallowed if (selectionValue != null || !SkipNulls) { if (String.IsNullOrEmpty(Label)) { Write(pdf, String.Format(Format, selectionValue)); } else { Write(pdf, String.Format(Format, selectionValue), Label); } } } } }