public void format( FormatterContext context, Collection<MetaObject> foreignKeys, String[] levels) { RetsVersion retsVersion = context.getRetsVersion(); if (foreignKeys.size() == 0) { return; } TagBuilder tag; // 1.7.2 DTD makes changes. if (retsVersion.equals(RetsVersion.RETS_1_0) || retsVersion.equals(RetsVersion.RETS_1_5) || retsVersion.equals(RetsVersion.RETS_1_7)) { /* * RETS 1.5 spec indicates that Version and Date should be * attributes of the METADATA-FOREIGNKEYS tag. However, the 1.5 DTD * does not list these in the attribute list. */ tag = new TagBuilder(context.getWriter(), "METADATA-FOREIGNKEYS") .beginContentOnNewLine() .appendColumns(COLUMNS); } else { // TODO: RETS 1.7.2 spec says tag should be METADATA-FOREIGN_KEYS // instead of METADATA-FOREIGNKEYS. tag = new TagBuilder(context.getWriter(), "METADATA-FOREIGNKEYS") .appendAttribute("Version", context.getVersion()) .appendAttribute("Date", context.getDate(), context.getRetsVersion()) .beginContentOnNewLine() .appendColumns(COLUMNS); } for (Iterator<?> iterator = foreignKeys.iterator(); iterator.hasNext(); ) { MForeignKey foreignKey = (MForeignKey) iterator.next(); appendDataRow(context, foreignKey); } tag.close(); }
public void testPrinting() { StringWriter formatted = new StringWriter(); TagBuilder tag = new TagBuilder(new PrintWriter(formatted), "test"); tag.beginContentOnNewLine(); // Print a string tag.print("a&b<c>d\"e"); tag.print((String) null); tag.print("\n"); // Print an object tag.print(new StringBuffer("f&g<h>i\"j")); tag.print((Object) null); tag.print("\n"); // Print an int tag.print(5); tag.print("\n"); // Print a collection List list = new ArrayList(); list.add("n\""); list.add("o"); list.add("l<"); list.add("k&"); list.add("m>"); tag.print(list); tag.print((Collection) null); tag.print("\n"); tag.close(); assertLinesEqual( "<test>\n" + "a&b<c>d"e\n" + "f&g<h>i"j\n" + "5\n" + "k&,l<,m>,n",o\n" + "</test>\n", formatted.toString()); }