Changeset 4898 for trunk/src/clients/web/net/sf/basedb
- Timestamp:
- Apr 21, 2009, 11:29:09 AM (14 years ago)
- Location:
- trunk/src/clients/web/net/sf/basedb/clients/web/plugins
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/plugins/ExportTemplate.java
r4548 r4898 23 23 24 24 import java.io.IOException; 25 import java.util.Collection; 25 26 import java.util.List; 26 27 … … 84 85 85 86 /** 87 Write the values in a collection 88 @param ep Exported property the values belong to 89 @param values The values to be written 90 @since 2.12 91 */ 92 public void writeCollection(ExportedProperty ep, Collection<?> values) 93 throws IOException; 94 95 /** 86 96 End writing an item 87 97 @throws IOException If there is an error -
trunk/src/clients/web/net/sf/basedb/clients/web/plugins/ExportedProperty.java
r4896 r4898 41 41 public final Unit unit; 42 42 public final Formatter formatter; 43 public final DataLoader dataloader; 43 44 44 45 public static ExportedProperty parse(DbControl dc, String column, boolean annotatable, Formatter formatter) … … 60 61 public static ExportedProperty parse(DbControl dc, String column, String columnPrefix, 61 62 boolean annotatable, Formatter formatter, boolean sameUnits) 63 { 64 return parse(dc, column, columnPrefix, annotatable, formatter, sameUnits, null); 65 } 66 67 /** 68 @since 2.12 69 */ 70 @SuppressWarnings("unchecked") 71 public static ExportedProperty parse(DbControl dc, String column, String columnPrefix, 72 boolean annotatable, Formatter formatter, boolean sameUnits, DataLoader dataloader) 62 73 { 63 74 String[] p = column.split(":"); … … 81 92 if (columnPrefix != null) title = columnPrefix + title; 82 93 if (columnSuffix != null) title += columnSuffix; 83 return new ExportedProperty(name, title, at, unit, formatter );94 return new ExportedProperty(name, title, at, unit, formatter, dataloader); 84 95 } 85 96 … … 95 106 AnnotationType annotationType, Unit unit, Formatter formatter) 96 107 { 108 this(name, title, annotationType, unit, formatter, null); 109 } 110 111 public ExportedProperty(String name, String title, 112 AnnotationType annotationType, Unit unit, Formatter formatter, DataLoader dataloader) 113 { 97 114 this.name = name; 98 115 this.title = title; … … 100 117 this.formatter = formatter; 101 118 this.unit = unit; 119 this.dataloader = dataloader; 102 120 } 103 104 121 } -
trunk/src/clients/web/net/sf/basedb/clients/web/plugins/PlainTextTemplate.java
r4548 r4898 24 24 import java.io.IOException; 25 25 import java.io.Writer; 26 import java.util.Collection; 26 27 import java.util.List; 27 28 import java.util.regex.Pattern; … … 122 123 exportStream.write(escape(ep.formatter.format(data))); 123 124 } 125 126 /** 127 Writes a collection of values. 128 @since 2.12 129 */ 130 @Override 131 @SuppressWarnings("unchecked") 132 public void writeCollection(ExportedProperty ep, Collection<?> values) 133 throws IOException 134 { 135 if (colNum > 0) exportStream.write("\t"); 136 colNum++; 137 exportStream.write(escape(Values.getString(values, ",", true, ep.formatter))); 138 } 124 139 125 140 /** -
trunk/src/clients/web/net/sf/basedb/clients/web/plugins/QueryWrapper.java
r4512 r4898 32 32 @base.modified $Date$ 33 33 */ 34 interface QueryWrapper<T> 34 interface QueryWrapper<T> extends DataLoader<T> 35 35 { 36 36 /** … … 47 47 public int getId(T item); 48 48 49 /**50 Get the value for the specified property.51 @param exportedProperty The property to get the value for52 @param item The item that holds the value53 * @throws Exception If failing to get the data.54 */55 public Object getData(ExportedProperty exportedProperty, T item)56 throws Exception;57 58 49 } -
trunk/src/clients/web/net/sf/basedb/clients/web/plugins/SimpleExport.java
r4896 r4898 76 76 import java.util.ArrayList; 77 77 import java.util.Arrays; 78 import java.util.Collection; 78 79 import java.util.Date; 79 80 import java.util.List; … … 252 253 MultiFormatter defaultFormatter = new MultiFormatter(new ToStringFormatter<Object>(), true); 253 254 defaultFormatter.registerFormatter(Date.class, FormatterFactory.getDateFormatter(sc)); 255 DataLoader dataloader = null; 254 256 for (String column : columns) 255 257 { … … 265 267 formatter = (Formatter<?>)possibleFormatter; 266 268 } 269 // Get the registered dataloader for current column, if any, and clear it. 270 Object possibleDataloader = cc.setObject("export.dataloader." + property, null); 271 if (possibleDataloader instanceof DataLoader) 272 { 273 dataloader = (DataLoader<?>)possibleDataloader; 274 } 267 275 } 268 276 ExportedProperty ep = ExportedProperty.parse(dc, column, columnPrefix, 269 annotatable, formatter, sameUnits );277 annotatable, formatter, sameUnits, dataloader); 270 278 exportedProperties.add(ep); 271 279 properties.add(ep.name); … … 569 577 else 570 578 { 571 Object data = queryWrapper.getData(ep, item); 572 template.writeProperty(ep, data); 579 Object data = ep.dataloader == null ? 580 queryWrapper.getData(ep, item) : ep.dataloader.getData(ep, item); 581 582 if (data instanceof Collection) 583 { 584 template.writeCollection(ep, (Collection)data); 585 } 586 else 587 { 588 template.writeProperty(ep, data); 589 } 573 590 } 574 591 } -
trunk/src/clients/web/net/sf/basedb/clients/web/plugins/XMLTemplate.java
r4548 r4898 24 24 import java.io.IOException; 25 25 import java.io.Writer; 26 import java.util.Collection; 26 27 import java.util.List; 27 28 import java.util.regex.Pattern; … … 138 139 /** 139 140 Add the property value to the current item element. 141 @since 2.12 140 142 */ 141 143 @SuppressWarnings("unchecked") … … 149 151 150 152 /** 153 Add collection values to the current item element. 154 */ 155 @Override 156 @SuppressWarnings("unchecked") 157 public void writeCollection(ExportedProperty ep, Collection<?> values) 158 throws IOException 159 { 160 161 Element property = new Element("property-value"); 162 property.setAttribute("ref", ep.name); 163 if (values != null) 164 { 165 for (Object value : values) 166 { 167 Element valueElement = new Element("value"); 168 valueElement.setText(escape(ep.formatter.format(value))); 169 property.addContent(valueElement); 170 } 171 } 172 itemElement.addContent(property); 173 } 174 175 /** 151 176 Write the current item element to the export stream. 152 177 */
Note: See TracChangeset
for help on using the changeset viewer.