using System; using iTextSharp.text; using Spring.Objects; using Sleis.Utility; using iTextSharp.text.pdf; using log4net; namespace Sleis.Pdf { public class ObjectValueLabelParser : ElementWriter { //public readonly ILog LOG = LogManager.GetLogger(typeof(ObjectValueLabelParser)); public string Format { get; set; } //public string Select { get; set; } public string[] Selects { get; set; } public override void Init() { if (String.IsNullOrEmpty(Format)) { Format = "{0}"; } } public string ParseValue(ObjectWrapper context) { LOG.Debug("Init Make"); if (String.IsNullOrEmpty(Select) && (Selects == null || Selects.Length < 1)) { return String.Format(Format, Label); } else { System.Collections.Generic.List args = new System.Collections.Generic.List(); if (Selects != null && Selects.Length > 0) { //allow for null values if property is null foreach (string selection in Selects) { try { args.Add(context.GetPropertyValue(selection)); } catch(Exception err) { //args.Add(null); LOG.Debug(String.Format("Error getting accessing {0} : {1}", Select, err.Message)); } } } else { //allow for null values if property is null try { args.Add(context.GetPropertyValue(Select)); } catch(Exception err) { //args.Add(null); LOG.Debug(String.Format("Error getting accessing {0} : {1}", Select, err.Message)); } } return args.Count > 0 ? String.Format(Format, args.ToArray()) : null; } } } }