1 2 17 18 19 package org.apache.poi.poifs.dev; 20 21 import java.io.*; 22 23 import java.util.*; 24 25 30 31 public class POIFSViewEngine 32 { 33 private static final String _EOL = System.getProperty("line.separator"); 34 35 48 49 public static List inspectViewable(final Object viewable, 50 final boolean drilldown, 51 final int indentLevel, 52 final String indentString) 53 { 54 List objects = new ArrayList(); 55 56 if (viewable instanceof POIFSViewable) 57 { 58 POIFSViewable inspected = ( POIFSViewable ) viewable; 59 60 objects.add(indent(indentLevel, indentString, 61 inspected.getShortDescription())); 62 if (drilldown) 63 { 64 if (inspected.preferArray()) 65 { 66 Object [] data = inspected.getViewableArray(); 67 68 for (int j = 0; j < data.length; j++) 69 { 70 objects.addAll(inspectViewable(data[ j ], drilldown, 71 indentLevel + 1, 72 indentString)); 73 } 74 } 75 else 76 { 77 Iterator iter = inspected.getViewableIterator(); 78 79 while (iter.hasNext()) 80 { 81 objects.addAll(inspectViewable(iter.next(), 82 drilldown, 83 indentLevel + 1, 84 indentString)); 85 } 86 } 87 } 88 } 89 else 90 { 91 objects.add(indent(indentLevel, indentString, 92 viewable.toString())); 93 } 94 return objects; 95 } 96 97 private static String indent(final int indentLevel, 98 final String indentString, final String data) 99 { 100 StringBuffer finalBuffer = new StringBuffer (); 101 StringBuffer indentPrefix = new StringBuffer (); 102 103 for (int j = 0; j < indentLevel; j++) 104 { 105 indentPrefix.append(indentString); 106 } 107 LineNumberReader reader = 108 new LineNumberReader(new StringReader(data)); 109 110 try 111 { 112 String line = reader.readLine(); 113 114 while (line != null) 115 { 116 finalBuffer.append(indentPrefix).append(line).append(_EOL); 117 line = reader.readLine(); 118 } 119 } 120 catch (IOException e) 121 { 122 finalBuffer.append(indentPrefix).append(e.getMessage()) 123 .append(_EOL); 124 } 125 return finalBuffer.toString(); 126 } 127 } 129 | Popular Tags |