public static TextEffigy newTextEffigy(CompositeEntity container, URL base,
URL in) throws Exception {
// Create a new effigy.
TextEffigy effigy = new TextEffigy(container, container
.uniqueName("effigy"));
Document doc = new DefaultStyledDocument();
effigy.setDocument(doc);
if (in != null) {
// A URL has been given. Read it.
BufferedReader reader = null;
try {
try {
InputStream inputStream = null;
try {
inputStream = in.openStream();
} catch (NullPointerException npe) {
throw new IOException("Failed to open '" + in
+ "', base: '" + base
+ "' : openStream() threw a "
+ "NullPointerException");
}
reader = new BufferedReader(new InputStreamReader(
inputStream));
// openStream throws an IOException, not a
// FileNotFoundException
} catch (IOException ex) {
try {
// If we are running under WebStart, and try
// view source on a .html file that is not in
// ptsupport.jar, then we may end up here,
// so we look for the file as a resource.
URL jarURL = ptolemy.util.ClassUtilities
.jarURLEntryResource(in.toString());
reader = new BufferedReader(new InputStreamReader(
jarURL.openStream()));
// We were able to open the URL, so update the
// original URL so that the title bar accurately
// reflects the location of the file.
in = jarURL;
} catch (Throwable throwable) {
// Looking for the file as a resource did not work,
// so we rethrow the original exception.
throw ex;
}
}
String line = reader.readLine();
while (line != null) {
// Translate newlines to Java form.
doc.insertString(doc.getLength(), line + "\n", null);
line = reader.readLine();
}
} finally {
if (reader != null) {
reader.close();