ObjectTool
How can I unpack the zip file after downloading Ot.zip from sun website to install ObjectTool, it is mentioned that it can be unpacked by using Zip utility, which I do not know. my oprerating system is windows. Can anyone help?
Thanks!
You need a zip utility program, try a google search on zip.
Winzip or aladdin expander will do what is required.
Similar Messages
-
Problem with initializing a class object
I am trying to write a more modified version of the infamous SimpleBrowser by allowing for the WebBrowser object property to receive a given java.net.URL object.
private final WebBrowser webBrowser = new WebBrowser();
* Perform setup
private void setupSimpleBrowser() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
initObjects();
initComponents();
* Initialize objects
private void initObjects() {
WebBrowser.setDebug(true); // SET TO TRUE TO SEE trace() DEBUG STATEMENTS
* Initialize components
private void initComponents() {
setTitle(myName);
generateWebBrowser();
webAddressTextField = new JTextField(51);
generateJButton();
p1 = new JPanel();
p2 = new JPanel();
addToPanel();
forceTFFocus();
addToFrame();
showFrame();
* Generate {@link #webBrowser}
private void generateWebBrowser() {
//Use below code to check the status of the navigation process,
//or register a listener for the notification events.
webBrowser.addWebBrowserListener(
new WebBrowserListener() {
boolean isFirstPage = true;
public void downloadStarted(WebBrowserEvent event) {;}
public void downloadCompleted(WebBrowserEvent event) {;}
public void downloadProgress(WebBrowserEvent event) {;}
public void downloadError(WebBrowserEvent event) {;}
public void documentCompleted(WebBrowserEvent event) {
// Uncomment below code to test getContent()/setContent()/
// executeScript() APIs.
// As the setContent() call will invoke this event, which falls
// into a loop, so check if this event is fired by the first
// loaded page.
if (isFirstPage) {
testDOMAPI(webBrowser);
isFirstPage = false;
public void titleChange(WebBrowserEvent event) {;}
public void statusTextChange(WebBrowserEvent event) {;}
public void windowClose(WebBrowserEvent event) {;}
public void initializationCompleted(WebBrowserEvent event) {;}
setWebBrowserURL();
System.out.println(webBrowser.getURL().toString());
* Set {@link #webBrowser} with either instantiable {@link java.net.URL} or with {@link #DEFAULT_URL_PATH}
private void setWebBrowserURL() {
try {
URL url = getURL();
System.out.println("url = " + url);
String urlPath = getURLPath();
System.out.println("urlPath = " + urlPath);
if (url != null) {
webBrowser.setURL(url);
} else if (urlPath != null && !urlPath.equals("")) {
webBrowser.setURL(new URL(urlPath));
} else {
System.out.println("setting webBrowser with " + DEFAULT_URL_PATH);
webBrowser.setURL(new URL(DEFAULT_URL_PATH));
System.out.println("set up initial homepage of " + DEFAULT_URL_PATH);
} catch (Exception e) {
try {
System.out.println("oops! setting webBrowser with " + DEFAULT_URL_PATH);
webBrowser.setURL(new URL(DEFAULT_URL_PATH));
} catch (Exception e2) {
e2.printStackTrace();
}However, the moment you leave setWebBrowserURL(), or somehow, within the Thread that is running between setWebBrowserURL() and the System.out.println() line, this happens:
url = null
urlPath = null
setting webBrowser with http://java.net
set up initial homepage of http://java.net
*** Jtrace: You can't call this method before WebBrowser is initialized!
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.ppowell.tools.ObjectTools.SimpleBrowser.generateWebBrowser(SimpleBrowser.java:349)
at com.ppowell.tools.ObjectTools.SimpleBrowser.initComponents(SimpleBrowser.java:384)
at com.ppowell.tools.ObjectTools.SimpleBrowser.access$600(SimpleBrowser.java:42)
at com.ppowell.tools.ObjectTools.SimpleBrowser$4.run(SimpleBrowser.java:447)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
*** Jtrace: Process event to native browser: -1, 0,
*** Jtrace: Send data to socket: -1,0,</html><body></html>I can't figure out why webBrowser will not allow for me to determine the given java.net.URL object parameter which will allow for the display of the given URL.
This is based upon http://www.koders.com/java/fidC1435DC25F674DBFCB9C50BE409180D2CAD108E1.aspx
Thanx
PhilI believe your NullPointerException is happening at
this line (without seeing the line numbers in your
source file, which YOU can do):
>
System.out.println(webBrowser.getURL().toString());
Isn't that line 349, related to this part of the
stack trace?
atcom.ppowell.tools.ObjectTools.SimpleBrowser.generateWe
bBrowser(SimpleBrowser.java:349)
If so, then I'd conclude that webBrowser.getURL() is
returning null, so you can't invoke toString() on
that.It is line 349, it is the line that has System.out.println(webBrowser.getURL().toString()), Removing that line removes the NullPointerException being thrown, however, now I am suddenly unable to use setURL() as it constantly receives a null value when I am clearly sending it a non-null value.
* Set {@link #webBrowser} with either instantiable {@link java.net.URL} or with {@link #DEFAULT_URL_PATH}
private void setWebBrowserURL() {
try {
URL url = getURL();
System.out.println("url = " + url);
String urlPath = getURLPath();
System.out.println("urlPath = " + urlPath);
if (url != null) {
webBrowser.setURL(url);
} else if (urlPath != null && !urlPath.equals("")) {
webBrowser.setURL(new URL(urlPath));
} else {
System.out.println("setting webBrowser with " + DEFAULT_URL_PATH);
webBrowser.setURL(new URL(DEFAULT_URL_PATH));
System.out.println("set up initial homepage of " + DEFAULT_URL_PATH);
} catch (Exception e) {
try {
System.out.println("oops! setting webBrowser with " + DEFAULT_URL_PATH);
webBrowser.setURL(new URL(DEFAULT_URL_PATH));
} catch (Exception e2) {
e2.printStackTrace();
}Phil -
PopupMenuListener event on JComboBox fires multiple times per selection
// webAddressBox IS OF TYPE javax.swing.JComboBox
webAddressBox.addPopupMenuListener(new PopupMenuAdapter() {
/** @uses {@link com.ppowell.tools.ObjectTools.SimpleBrowser.Surf} */
final Surf surf = new Surf(webAddressBox.getSelectedItem().toString());
* Perform {@link #surf} processing
* @param evt {@link javax.swing.event.PopupMenuEvent}
public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) {
System.out.println("you selected:");
surf.doURLProcessing();
* PopupMenuAdapter.java
* Created on February 16, 2007, 11:53 AM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package com.ppowell.tools.ObjectTools.SwingTools;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
* Will allow for greater flexibility by implementing {@link javax.swing.event.PopupMenuListener}
* @author Phil Powell
* @version JDK 1.6.0
public abstract class PopupMenuAdapter implements PopupMenuListener {
/** Creates a new instance of PopupMenuAdapter */
public PopupMenuAdapter() {}
* Overrides {@link javax.swing.event.PopupMenuListener} method popupMenuCanceled
* @param evt {@link javax.swing.event.PopupMenuEvent}
public void popupMenuCanceled(PopupMenuEvent evt) {}
* Overrides {@link javax.swing.event.PopupMenuListener} method popupMenuWillBecomeInvisible
* @param evt {@link javax.swing.event.PopupMenuEvent}
public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) {}
* Overrides {@link javax.swing.event.PopupMenuListener} method popupMenuWillBecomeVisible
* @param evt {@link javax.swing.event.PopupMenuEvent}
public void popupMenuWillBecomeVisible(PopupMenuEvent evt) {}
}This code is supposed to handle a single selection from a JComboBox webAddressBox. The front-end functionality of this code blocks works just fine to the user, however, upon viewing the "behind the scenes action", I noticed that the overriden popupMenuWillBecomeInvisible() method within the anonymous inner class instance of PopupAdapter is being called 2 times upon the first time you select something from webAddressBox, 4 times the next time you select something, 8 times the next time, and so on..
Obviously this is a tremendous waste of resources to have it call that many times exponentially - it should only call once each time you select something from webAddressBox, but I can't figure out how to get that to happen.
What suggestions might you have to accomplish this? I already have an ActionListener that runs separately from PopupMenuAdapter that handles the user either clicking a JButton or hitting ENTER - this works just fine.
Thanx
Philis being called 2 times upon the first time youselect something from
webAddressBox, 4 times the next time you selectsomething, 8 times the next time, and so on..
Then you are adding the listener to the component
multiple times.WTO sigh.. thanx! :) -
Evaluator.java won't compile due to issues with javax.tools.*
* Evaluator.java
* Created on January 23, 2007, 4:17 PM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package ObjectTools;
import java.io.*;
import java.net.*;
import javax.tools.*;
import java.lang.reflect.*;
* Utilizes {@link java.lang.reflect} package
* @author ppowell-c
public abstract class Evaluator {
public static boolean writeSource(final String sourcePath, final String sourceCode)
throws FileNotFoundException {
PrintWriter writer = new PrintWriter(sourcePath);
writer.println(sourceCode);
writer.close();
return true;
public static boolean compile(final String sourcePath) throws IOException {
final JavaCompilerTool compiler = ToolProvider.defaultJavaCompiler();
final JavaFileManager manager = compiler.getStandardFileManager();
final JavaFileObject source =
manager.getFileForInput(sourcePath); /* java.io.IOException */
final JavaCompilerTool.CompilationTask task = compiler.run(null, source);
return task.getResult();
public static final java.lang.Class loadExpression(final String path, final String className)
throws MalformedURLException,
ClassNotFoundException { /* java.net.MalformedURLException */
final URLClassLoader myLoader = new URLClassLoader(new java.net.URL[] {
new File(path).toURI().toURL()
/* java.lang.ClassNotFoundException */
return Class.forName(className, true, myLoader);
public static java.lang.Object evalExpression(final Class test)
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
final Class[] parameterType = null;
/* java.lang.NoSuchMethodException */
final Method method = test.getMethod("expression", parameterType);
final Object[] argument = null;
Object instance = null;
/* java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException */
return method.invoke(instance, argument);
public static Object eval(final String expression)
throws FileNotFoundException, IOException, MalformedURLException,
ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
InvocationTargetException {
final Object result;
final String path = "c:/";
final String className = "ExpressionWrapper";
final String sourcePath = path + className + ".java";
writeSource(/* to */ sourcePath,
"public class " + className + "\n" +
"{ public static java.lang.Object expression()\n" +
" { return " + expression + "; }}\n" );
if(compile(sourcePath)) {
final Class class_ =
loadExpression(/* from */ path, className);
result = evalExpression(class_);
} else {
result = null;
return result;
}Produces compiler errors on javax.tools.ToolProvider along with nearly everything else in javax.tools to boot.
I'm using J2SE 1.5.0 with NetBeans 5.5 so they all should be there. I'm following the example at http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht9Ht/evaluating-expressions-with-java since all I want to do is come up with a Java equivalent of "eval()", which I use in PHP whenever I need it.
Help appreciated, I'm lost here.
Thanx
PhilHow do you do the Java equivalent of eval()?The language provides no support for that.
Reflection lets you call any method, where you
specify that method's name as a string and go through
a few other steps to build the proper Method object
with the proper args.
(http://java.sun.com/docs/books/tutorial/reflect/) It
won't let you just evaluate Java source code as a
script interpreter though. To do that, see
www.beanshell.org. Jython and I think Ruby on Rails
also give you scriptingin Java. Jython uses Python's
syntax, but gives you access to your Java classes. I
don't know ayhthing about RoR.I am going to look up PHP/Java myself as I know no Python right offhand (but probably could learn it in about 10,000 years). Tried to figure out reflection but couldn't figure out how to do what in PHP we do like this:
$msg = eval('JButton ' . $nameArray[$i][0] . ' = new JButton("' . $nameArray[$i][1] . '");'); -
Renaming packages has caused them to "no longer exist"
I am renaming my packages according to Java conventions..
Tried to rename "com.ppowell.tools.ObjectTools" to "com.ppowell.tools.objecttools"
However, upon doing so I am unable to find any of the classes in "com.ppowell.tools.objecttools"
I am getting "package com.ppowell.tools.objecttools does not exist" compiler errors by the boatload.
I am using NetBeans IDE 5.5
Please help!!
Thanx
PhilUPDATE
I have no idea but everything's restored again..
however, NetBeans continues to show the package name
as "com.ppowell.tools.ObjectTools" when it is, in
fact, "com.ppowell.tools.objecttools". Can't find
anything in build.xml that tells me anything I can
understand, and everything compiles and runs now.
Just the weird NetBeans bug with the package names
being wrongly displayed that I can't seem to fix.you could try deleting the projects from the workspace (not the filesystem!) and re-importing them. don't know how you'd do that in netbeans, I've never used it -
Inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker thread
On occasions I will get the following exception thrown whenever I happen to be using SimpleBrowser.this.processor.processTask() method to run a SwingWorker<Void, Void>-based class Task worker thread (within doInBackground()) :
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at javax.swing.text.BoxView.getOffset(BoxView.java:1076)
at javax.swing.text.BoxView.childAllocation(BoxView.java:670)
at javax.swing.text.CompositeView.getChildAllocation(CompositeView.java:215)
at javax.swing.text.BoxView.getChildAllocation(BoxView.java:428)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.calculateViewPosition(BasicTextUI.java:1978)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.layoutContainer(BasicTextUI.java:1954)
at java.awt.Container.layout(Container.java:1432)
at java.awt.Container.doLayout(Container.java:1421)
at java.awt.Container.validateTree(Container.java:1519)
at java.awt.Container.validateTree(Container.java:1526)
at java.awt.Container.validateTree(Container.java:1526)
at java.awt.Container.validate(Container.java:1491)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:639)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:127)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)I haven't found much reliable online information to illustrate this issue any further so I'm a bit in the dark. Following is my code that runs within the aforementioned worker thread which I believe throws the exception:
* Use {@link #setWebBrowserURL} using a local {@link com.ppowell.tools.ObjectTools.SwingTools.Task}
protected void processTask() {
Task task = new Task() {
public Void doInBackground() {
int progress = 0;
while (!SimpleBrowser.this.builder.hasLoadedWebpage && progress < 100) {
SimpleBrowser.this.statusBar.setMessage("Attempting to load " + SimpleBrowser.this.getURL().toString());
this.setProgress(progress);
progress++;
SimpleBrowser.this.setWebBrowserURL();
try {
Thread.sleep(2500);
} catch (InterruptedException ignore) {} // DO NOTHING
if (SimpleBrowser.this.builder.hasLoadedWebpage) {
SimpleBrowser.this.statusBar.setMessage("Done");
return null;
task.addPropertyChangeListener(SimpleBrowser.this);
task.execute();
}Is there a way I might at least be able to suppress this error (the GUI application browser functions just fine in spite of it), or, even better, solve this inconsistent problem?
Thanks
PhilI suspect that you need to "clean" your html priorto
calling super.setText(). My guess is that you're
yanking nodes from beaneath Swing while it'strying
to render.
In addition to that, you may want to use JTidy to
clean up your html, and convert it to xhtml --again
prior to calling super.setText().Problem is that however I clean up the HTML, the
moment I try to reinsert back into the JEditorPane
using setText(), I get EmptyStackException or I'll
get NullPointerException or it just might work - same
problem, different exception(s).Ok this time I am simply using setText() instead of setPage(), but the results are, while consistent, they are consistently completely wrong. The browser appears blank every time, no HTML can be retrieved (you get a NullPointerException if you try), all the while I can verify that that original HTML from the remote site is correct, it never, ever, inserts into JEditorPane.
Here is my code:
* SimpleHTMLRenderableEditorPane.java
* Created on March 13, 2007, 3:39 PM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package com.ppowell.tools.ObjectTools.SwingTools;
import java.io.*;
import java.net.*;
import javax.swing.JEditorPane;
import javax.swing.text.html.HTMLEditorKit;
* A safer version of {@link javax.swing.JEditorPane}
* @author Phil Powell
* @version JDK 1.6.0
public class SimpleHTMLRenderableEditorPane extends JEditorPane {
//--------------------------- --* CONSTRUCTORS *--
// <editor-fold defaultstate="collapsed" desc=" Constructors ">
/** Creates a new instance of SimpleHTMLRenderableEditorPane */
public SimpleHTMLRenderableEditorPane() {
super();
* Creates a new instance of SimpleHTMLRenderableEditorPane
* @param url {@link java.lang.String}
* @throws java.io.IOException Thrown if an I/O exception occurs
public SimpleHTMLRenderableEditorPane(String url) throws
IOException {
super(url);
* Creates a new instance of SimpleHTMLRenderableEditorPane
* @param type {@link java.lang.String}
* @param text {@link java.lang.String}
public SimpleHTMLRenderableEditorPane(String type, String text) {
super(type, text);
* Creates a new instance of SimpleHTMLRenderableEditorPane
* @param url {@link java.net.URL}
* @throws java.io.IOException Thrown if an I/O exception occurs
public SimpleHTMLRenderableEditorPane(URL url) throws IOException
super(url);
// </editor-fold>
//----------------------- --* GETTER/SETTER METHODS *--
// <editor-fold defaultstate="collapsed" desc=" Getter/Setter
Methods ">
* Retrieve HTML content
* @return html {@link java.lang.String}
public String getText() {
try {
* I decided to use {@link java.net.HttpURLConnection} to
retrieve the
* HTML code from the remote site instead of using
super.getText() because
* of the HTML code return constantly being stripped to
primitive HTML
* template formatting irregardless of the original HTML
source code
HttpURLConnection conn =
(HttpURLConnection)getPage().openConnection();
conn.setUseCaches(false);
conn.setDefaultUseCaches(false);
conn.setDoOutput(false); // READ-ONLY
BufferedReader in = new BufferedReader(
new InputStreamReader(
conn.getInputStream()));
int data;
StringBuffer sb = new StringBuffer();
char[] ch = new char[512];
while ((data = in.read(ch)) != -1) {
sb.append(ch, 0, data);
in.close();
conn.disconnect();
return sb.toString();
} catch (IOException e) {
return super.getText(); // DEFAULT TO USING
super.getText() IF NO I/O CONNECTION
* Overloaded to fix HTML rendering bug Bug ID: 4695909.
* @param text {@link java.lang.String}
public void setText(String text) {
// Workaround for bug Bug ID: 4695909 in java 1.4
// JEditorPane does not handle the META tag in the html HEAD
if (isJava14() && "text/
html".equalsIgnoreCase(getContentType())) {
text = stripMetaTag(text);
super.setText(text);
// </editor-fold>
//--------------------------- --* OTHER METHODS *--
// <editor-fold defaultstate="collapsed" desc=" Methods ">
* Clean HTML to remove things like <link>, <script>,
* <style>, <object>, <embed>, and <!-- -->
* Based upon <a href="http://bugs.sun.com/bugdatabase/view_bug.do?
bug_id=4695909">bug report</a>
public void cleanHTML() {
try {
setText(cleanHTML(getText()));
} catch (Exception e) {} // DO NOTHING
* Clean HTML
* @param html {@link java.lang.String}
* @return html {@link java.lang.String}
public String cleanHTML(String html) {
String[] tagArray = {"<LINK", "<SCRIPT", "<STYLE", "<OBJECT",
"<EMBED", "<!--"};
String upperHTML = html.toUpperCase();
String endTag;
int index = -1, endIndex = -1;
for (int i = 0; i < tagArray.length; i++) {
index = upperHTML.indexOf(tagArray);
endTag = "</" + tagArray[i].substring(1,
tagArray[i].length());
endIndex = upperHTML.indexOf(endTag, index);
while (index >= 0) {
if (endIndex >= 0) {
html = html.substring(0, index) +
html.substring(html.indexOf(">", endIndex)
+ 1,
html.length());
upperHTML = upperHTML.substring(0, index) +
upperHTML.substring(upperHTML.indexOf(">",
endIndex) + 1,
upperHTML.length());
} else {
html = html.substring(0, index) +
html.substring(html.indexOf(">", index) +
1,
html.length());
upperHTML = upperHTML.substring(0, index) +
upperHTML.substring(upperHTML.indexOf(">",
index) + 1,
upperHTML.length());
index = upperHTML.indexOf(tagArray[i]);
endIndex = upperHTML.indexOf(endTag, index);
// REF: http://forum.java.sun.com/thread.jspa?threadID=213582&messageID=735120
html = html.substring(0, upperHTML.indexOf(">",
upperHTML.indexOf("</HTML")) + 1);
// REF: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5042872
return html.trim();
* This actually only obtains the URL; this serves as a retriever
for cleanHTML(String html)
* @param url {@link java.net.URL}
* @return html {@link java.lang.String}
public String cleanHTML(URL url) {
try {
HttpURLConnection conn =
(HttpURLConnection)url.openConnection();
conn.setUseCaches(false);
conn.setDefaultUseCaches(false);
conn.setDoOutput(false); // READ-ONLY
BufferedReader in = new BufferedReader(
new InputStreamReader(
conn.getInputStream()));
int data;
StringBuffer sb = new StringBuffer();
char[] ch = new char[512];
while ((data = in.read(ch)) != -1) {
sb.append(ch, 0, data);
in.close();
conn.disconnect();
return cleanHTML(sb.toString());
} catch (IOException e) {
e.printStackTrace();
return null;
* Determine if java version is 1.4.
* @return true if java version is 1.4.x....
private boolean isJava14() {
if (System.getProperty("java.version") == null) return false;
return System.getProperty("java.version").startsWith("1.4");
* Workaround for Bug ID: 4695909 in java 1.4, fixed in 1.5
* JEditorPane fails to display HTML BODY when META tag included
in HEAD section.
* Code modified by Phil Powell
* <html>
* <head>
* <META http-equiv="Content-Type" content="text/html;
charset=UTF-8">
* </head>
* <body>
* @param text html to strip.
* @return same HTML text w/o the META tag.
private String stripMetaTag(String text) {
// String used for searching, comparison and indexing
String textUpperCase = text.toUpperCase();
int indexHead = textUpperCase.indexOf("<HEAD ");
int indexMeta = textUpperCase.indexOf("<META ");
int indexBody = textUpperCase.indexOf("<BODY ");
// Not found or meta not inside the head nothing to strip...
if (indexMeta == -1 || indexMeta < indexHead || indexMeta >
indexBody) {
return text;
// Find end of meta tag text.
int indexHeadEnd = textUpperCase.indexOf(">", indexMeta);
// Strip meta tag text
return text.substring(0, indexMeta - 1) +
text.substring(indexHeadEnd + 1);
// </editor-fold>
Instead if you try
browser.getText()
You will get a NullPointerException
If you try
public void setText(String text) {
// Workaround for bug Bug ID: 4695909 in java 1.4
// JEditorPane does not handle the META tag in the html HEAD
if (isJava14() && "text/
html".equalsIgnoreCase(getContentType())) {
text = stripMetaTag(text);
System.out.println(text); // YOU WILL SEE CNN'S HTML
super.setText(text);
System.out.println(super.getText()); // SEE BELOW
}You see only this:
<html>
<head>
</head>
<body>
<p style="margin-top: 0">
</p>
</body>
</html> -
JEditorPane.setPage(URL url), then I want to clean up HTML, how?
According to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4695909
the problem with the inconsistent ArrayIndexOutOfBoundsException that
I have been getting whenever I would go to a particular URL to put
into JEditorPane using setPage() - this may also be due to JEditorPane
containing HTML which contains a <META> tag and/or <!-- comment tag --
. I created a class SimpleHTMLRenderableEditorPane which extendsJEditorPane, based upon code I found in the aformentioned bug link
which should auto-strip out "bad tags":
* SimpleHTMLRenderableEditorPane.java
* Created on March 13, 2007, 3:39 PM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package com.ppowell.tools.ObjectTools.SwingTools;
import javax.swing.JEditorPane;
* A safer version of {@link javax.swing.JEditorPane}
* @author Phil Powell
* @version JDK 1.6.0
public class SimpleHTMLRenderableEditorPane extends JEditorPane {
//--------------------------- --* CONSTRUCTORS *--
// <editor-fold defaultstate="collapsed" desc=" Constructors
">
/** Creates a new instance of SimpleHTMLRenderableEditorPane */
public SimpleHTMLRenderableEditorPane() {
super();
// </editor-fold>
//----------------------- --* GETTER/SETTER METHODS *--
// <editor-fold defaultstate="collapsed" desc=" Getter/Setter
Methods ">
* Overloaded to fix HTML rendering bug Bug ID: 4695909.
* @param text
public void setText(String text) {
// Workaround for bug Bug ID: 4695909 in java 1.4
// JEditorPane does not handle the META tag in the html HEAD
if (isJava14() && "text/
html".equalsIgnoreCase(getContentType())) {
text = stripMetaTag(text);
super.setText(text);
// </editor-fold>
//--------------------------- --* OTHER METHODS *--
// <editor-fold defaultstate="collapsed" desc=" Methods ">
* Clean HTML to remove things like <script>, <style>, <object>,
<embed>, and <!-- -->
* Based upon <a href="http://bugs.sun.com/bugdatabase/view_bug.do?
bug_id=4695909">bug report</a>
public void cleanHTML() {
try {
String html = getText();
if (html != null && !html.equals("")) {
String[] patternArray = {
"<script[^>]*>[^<]*(</script>)?",
"<style[^>]*>[^<]*(</style>)?>",
"<object[^>]*>[^<]*(</object>)?>",
"<embed[^>]*>[^<]*(</embed>)?>",
"<!\\-\\-.*\\-\\->"
for (int i = 0; i < patternArray.length; i++) {
html = html.replaceAll(patternArray, "");
setText(html);
} catch (Exception e) {} // DO NOTHING
* Determine if java version is 1.4.
* @return true if java version is 1.4.x....
private boolean isJava14() {
String version = System.getProperty("java.version");
return version.startsWith("1.4");
* Workaround for Bug ID: 4695909 in java 1.4, fixed in 1.5
* JEditorPane fails to display HTML BODY when META
* tag included in HEAD section.
* <html>
* <head>
* <META http-equiv="Content-Type" content="text/html;
charset=UTF-8">
* </head>
* <body>
* @param text html to strip.
* @return same HTML text w/o the META tag.
private String stripMetaTag(String text) {
// String used for searching, comparison and indexing
String textUpperCase = text.toUpperCase();
int indexHead = textUpperCase.indexOf("<META ");
int indexMeta = textUpperCase.indexOf("<META ");
int indexBody = textUpperCase.indexOf("<BODY ");
// Not found or meta not inside the head nothing to strip...
if (indexMeta == -1 || indexMeta > indexHead && indexMeta <
indexBody) {
return text;
// Find end of meta tag text.
int indexHeadEnd = textUpperCase.indexOf(">", indexMeta);
// Strip meta tag text
return text.substring(0, indexMeta-1) +
text.substring(indexHeadEnd+1);
// </editor-fold>
However, upon running the following line:
SimpleBrowser.this.browser.cleanHTML();I spawn the following exception:
Exception in thread "Thread-2" java.lang.RuntimeException: Must insert
new content into body element-
at javax.swing.text.html.HTMLDocument
$HTMLReader.generateEndsSpecsForMidInsert(HTMLDocument.java:1961)
at javax.swing.text.html.HTMLDocument
$HTMLReader.<init>(HTMLDocument.java:1908)
at javax.swing.text.html.HTMLDocument
$HTMLReader.<init>(HTMLDocument.java:1782)
at javax.swing.text.html.HTMLDocument
$HTMLReader.<init>(HTMLDocument.java:1777)
at
javax.swing.text.html.HTMLDocument.getReader(HTMLDocument.java:137)
at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:
228)
at javax.swing.JEditorPane.read(JEditorPane.java:556)
at javax.swing.JEditorPane$PageLoader.run(JEditorPane.java:
647)What should I do at this point?
Thanks
PhilTransfer all purchases from the iPad to iTunes on your computer, backup the iPad and then sync one last time.
Then go to Settings>General>Reset>Erase all content and Settings to completely erase the iPad.
Connect the new iPad to your computer and launch iTunes, restore from the backup of the old iPad and then sync with iTunes. You should be prompted to restore from the backup when you connect the new iPad to your computer's iTunes, but you can select it on your own as well.
Transfer purchases.
http://support.apple.com/kb/HT1848
How to backup
http://support.apple.com/kb/HT1766 -
JButton is created "selected" even when I declare it not to be so
* Generate value and conditions for {@link #backButton}
private void generateBackButton() {
SimpleBrowser.this.backButton = new JButton("<--");
SimpleBrowser.this.backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SimpleBrowser.hasClickedBack = true;
SimpleBrowser.this.currentHistoryIndex--;
SimpleBrowser.this.setURL(
(URL)SimpleBrowser.this.actualHistoryURLVector.get(
SimpleBrowser.this.currentHistoryIndex)
SimpleBrowser.this.setURLPath(SimpleBrowser.this.getURL().toString());
SimpleBrowser.this.processor.processURL(SimpleBrowser.this.getURL());
SimpleBrowser.this.backButton.setSelected(false);
SimpleBrowser.this.backButton.setFont(SimpleBrowserGlobals.FONT);
}The moment this particular JButton is created it is created as "selected", even though I have done "setSelected(false)". It does not fire unless I click onto it, of course, but it appears as if I did and that's not good. Is there a way I can fix this?
Thanx
PhilIf you need further help then you need to create a
[url
http://homepage1.nifty.com/algafield/sscce.html]Short,
Self Contained, Compilable and Executable, Example
Program (SSCCE) that demonstrates the incorrectbehaviour, because I can't guess exactly what you are
doing based on the information provided.
Don't forget to use the [url
http://forum.java.sun.com/help.jspa?sec=formatting]Cod
e Formatting Tags so the posted code retains
its original formatting.
This is the absolute simplest class I could create that does the same thing: creates a JButton in a JPanel in a JFrame but the JButton appears already selected:
* SimpleFrame.java
* Created on March 16, 2007, 12:27 PM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package com.ppowell.tools.ObjectTools;
import java.awt.*;
import javax.swing.*;
* @author Phil Powell
public class SimpleFrame extends JFrame {
JButton backButton;
JPanel topPanel;
/** Creates a new instance of SimpleFrame */
public SimpleFrame() {
initComponents();
// ADD EVERYTHING TO THE FRAME
public void addToFrame() {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.NORTHWEST;
add(topPanel, c);
* Generate value and conditions for {@link #backButton}
private void generateBackButton() {
backButton = new JButton("<--");
backButton.setSelected(false);
backButton.setFocusPainted(false);
backButton.setFocusTraversalKeysEnabled(false);
backButton.setFont(new Font("Arial", Font.PLAIN, 12));
// SET EVERYTHING UP
public void initComponents() {
topPanel = new JPanel(true);
generateBackButton(); // GENERATE THE JBUTTON
layoutTopPanel(); // LAYOUT THE TOP PANEL BY PLACING JBUTTON INTO IT
addToFrame(); // ADD PANEL TO FRAME
showFrame(); // SHOW FRAME
// LAYOUT THE TOP PANEL
public void layoutTopPanel() {
topPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.NORTHWEST;
topPanel.add(backButton, c);
// SHOW THE FRAME
public void showFrame() {
// CODE BORROWED FROM http://today.java.net/pub/a/today/2003/12/08/swing.html WITH MODIFICATIONS
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (UnsupportedLookAndFeelException e) {
System.out.println("Unable to load native look and feel");
} catch (ClassNotFoundException e2) {
e2.printStackTrace();
} catch (InstantiationException e3) {
e3.printStackTrace();
} catch (IllegalAccessException e4) {
e4.printStackTrace();
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
public static void main(String[] args) {
SimpleFrame simp = new SimpleFrame();
}
Maybe you are looking for
-
My first gen ipod nano is not recognized by win or itunes. Plz help me!!!
After i plug my ipod it appears on my computer after 10 min as removable disk not labeled as (ipod drive H) and i am not able to access it, when i try the comp get frozen for some time and then i get alert that i should insert disk into drive H. When
-
Oracle 8.1.7 and HPUX IA64
I have been requested to install an oracle 8.1.7 on a HP IA system running HP-UX11.23 , I thinks it is not support but not sure? did any one have this experience to install an ORA 8.1.7 into HPUX 11.23 IA system. BTW both are in 64 bit version Regard
-
Fonts are no longer smooth after upgrading to 10.6.8
After the 10.6.8 combo updater, all my fonts appear unsmoothed. Font smoothing is turned on i System preferences (but makes no difference whether it as actually ticked or unticked) It is turned off only for fonts under 8px, however everything likes r
-
Trouble with hp pavilion dv 2000
I have a HP Pavilion dv 2000 (S/N 2CE71620R9, P/N RV325UA#ABA) that when I turn it on the hard drive does not function and the monitor remains dark (does not function),even when I press F4 many times. Also, when I put a CD or DVD in the DVD player t
-
Help Required For DropDownByIndex and Table
Hi All, Could anybody help me to solve my problem? Actualy I am working with one DropDownByIndex and two Tables.Where within one viewset DropDown box and one Table(say Table1) are in one view and another one table(say Table2) is in ot