Created
October 2, 2012 12:16
-
-
Save nielskrijger/3818569 to your computer and use it in GitHub Desktop.
This is a utility class for Remote Intradoc (RIDC).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ridcoo.ridc.util; | |
import java.util.Iterator; | |
import java.util.Map; | |
import oracle.stellent.ridc.model.DataBinder; | |
import oracle.stellent.ridc.model.DataObject; | |
/** | |
* This is a utility class for Remote Intradoc (RIDC). | |
* | |
* @author Niels Krijger <niels@kryger.nl> | |
*/ | |
public class RIDCUtils { | |
/** | |
* Creates a human readable string presentation of a <code>DataBinder</code> | |
* object. | |
* | |
* @param binder | |
* The binder. | |
* @return String. | |
*/ | |
public static String dataBinderToString(DataBinder binder) { | |
StringBuilder sb = new StringBuilder(); | |
sb.append("DataBinder {\n"); | |
// Files | |
sb.append("\tFiles {\n"); | |
if (binder.containsFiles()) { | |
for (String fileName : binder.getFileNames()) { | |
sb.append("\t\tFile name = " + fileName + "\n"); | |
sb.append("\t\tContent length = " + binder.getFile(fileName)); | |
} | |
} else { | |
sb.append("\t\tnone\n"); | |
} | |
sb.append("\t}\n"); | |
// Local Data | |
sb.append("\tLocalData {\n"); | |
if (!binder.getLocalData().isEmpty()) { | |
Map<String, String> sortedMap = new TreeMap<String, String>(binder.getLocalData()); | |
for (Map.Entry<String, String> entry : sortedMap.entrySet()) { | |
sb.append("\t\t").append(entry.getKey()).append(" = ") | |
.append(entry.getValue()).append("\n"); | |
} | |
} else { | |
sb.append("\t\tnone\n"); | |
} | |
sb.append("\t}\n"); | |
// Options | |
sb.append("\tOptions {\n"); | |
if (!binder.getOptionListNames().isEmpty()) { | |
List<String> options = new ArrayList<String>(binder.getOptionListNames()); | |
Collections.sort(options); | |
for (String option : options) { | |
Iterator<String> iterator = binder.getOptionList(option) | |
.iterator(); | |
while (iterator.hasNext()) { | |
sb.append("\t\t").append(iterator.next()).append("\n"); | |
} | |
} | |
} else { | |
sb.append("\t\tnone\n"); | |
} | |
sb.append("\t}\n"); | |
// Result sets | |
sb.append("\tResultSets {\n"); | |
if (!binder.getResultSetNames().isEmpty()) { | |
Iterator<String> names = binder.getResultSetNames().iterator(); | |
while (names.hasNext()) { | |
String name = names.next(); | |
sb.append("\t\t").append(name).append(" {\n"); | |
for (DataObject obj : binder.getResultSet(name).getRows()) { | |
Map<String, String> sortedMap = new TreeMap<String, String>(obj); | |
for (Map.Entry<String, String> entry : sortedMap.entrySet()) { | |
sb.append("\t\t\t").append(entry.getKey()) | |
.append(" = ").append(entry.getValue()) | |
.append("\n"); | |
} | |
} | |
sb.append("\t\t}\n"); | |
} | |
} else { | |
sb.append("\t\tnone\n"); | |
} | |
sb.append("\t}\n"); | |
sb.append("}"); | |
return sb.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment