7

I am using the Lobo - Java Web Browser library, and it gives me an exception which after some research I determined could be due to the library having been complied against an older version of Java.

The code is as follows:

import java.io.IOException;
import org.lobobrowser.html.UserAgentContext;
import org.lobobrowser.html.parser.DocumentBuilderImpl;
import org.lobobrowser.html.parser.InputSourceImpl;
import org.lobobrowser.html.test.SimpleUserAgentContext;
import org.xml.sax.SAXException;

public class Cobratest
{
    public static void main(String[] args) throws SAXException, IOException
    {
        UserAgentContext uAgent = new SimpleUserAgentContext();
        DocumentBuilderImpl docBuild = new DocumentBuilderImpl(uAgent);
        docBuild.parse(new InputSourceImpl("http://dic.amdz.com/"));
    }
}

and the stack trace is:

 Exception in thread "main" java.lang.IncompatibleClassChangeError: Found interface sun.font.FontManager, but class was expected
    at org.lobobrowser.util.gui.FontFactory.createFont(FontFactory.java:210)
    at org.lobobrowser.util.gui.FontFactory.createFont_Impl(FontFactory.java:180)
    at org.lobobrowser.util.gui.FontFactory.createFont(FontFactory.java:127)
    at org.lobobrowser.util.gui.FontFactory.getFont(FontFactory.java:98)
    at org.lobobrowser.html.style.StyleSheetRenderState.<clinit>(StyleSheetRenderState.java:43)
    at org.lobobrowser.html.domimpl.NodeImpl.<clinit>(NodeImpl.java:39)
    at org.lobobrowser.html.parser.DocumentBuilderImpl.createDocument(DocumentBuilderImpl.java:143)
    at org.lobobrowser.html.parser.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:97)

when I examined org.lobobrowser.util.gui.FontFactory.createFont I found out there is an interface called FontManager which changed from the previous version of Java. In this FontFactory class, they used a class of this interface which is no longer available. How can I fix this problem?

the interface FontManager:

package sun.font;

import java.awt.Font;
import java.awt.FontFormatException;
import java.io.File;

public interface FontManager {

    public static final int NO_FALLBACK = 0;
    public static final int PHYSICAL_FALLBACK = 1;
    public static final int LOGICAL_FALLBACK = 2;

    public boolean registerFont(Font font);

    public void deRegisterBadFont(Font2D font2d);

    public Font2D findFont2D(String string, int i, int i1);

    public Font2D createFont2D(File file, int i, boolean bln, CreatedFontTracker cft) throws FontFormatException;

    public boolean usingPerAppContextComposites();

    public Font2DHandle getNewComposite(String string, int i, Font2DHandle fdh);

    public void preferLocaleFonts();

    public void preferProportionalFonts();
}

and the class used in the library which is not available:

   return FontManager.getCompositeFontUIResource(new Font(name, style, size));
Steve Armstrong
  • 5,252
  • 7
  • 32
  • 43
lonesome
  • 2,503
  • 6
  • 35
  • 61
  • 4
    Possible duplicate of http://stackoverflow.com/questions/2863043/do-not-use-com-sun-xml-internal . `sun.*` and `com.sun.*` are internal packages that are liable to change without notice. "com.sun.xml.internal package is an internal package as the name suggestes. Users should not write code that depends on internal JDK implementation classes. Such classes are internal implementation details of the JDK and subject to change without notice" – Mike Samuel Feb 12 '12 at 04:13
  • 1
    @MikeSamuel so you're telling me im doomed? – lonesome Feb 12 '12 at 04:16
  • 1
    I suspect that the library you are using depends on the internal details of a particular JVM version. There may be ways to hack around the problem, but I do not know them. I would check with the library developer to see if they are aware of the problem -- they may already have a fix or plans for one. – Mike Samuel Feb 12 '12 at 04:20
  • 2
    *"there is a situation"* With your shift key? If not, apply once to the start of each sentence, for the word I, and any proper name. If so, ***fix it.*** It is painful to try and read such 'mumbling'. – Andrew Thompson Feb 12 '12 at 04:22
  • @AndrewThompson what do you mean by situation and shift key? didn't get it :( – lonesome Feb 12 '12 at 04:27
  • @MikeSamuel how about if i use an old version of a java IDE? (such as eclipse or netbeans) – lonesome Feb 12 '12 at 04:29
  • @user1064929 - that library is only going to work with whatever version of the sun.* packages it was written against. I would suggest contacting whomever wrote it. – Brian Roach Feb 12 '12 at 05:14

3 Answers3

4

I think 'sun.font.FontManager'was removed with Java7, so if you must use it (I'd recommend against it and look for another package instead) you could try running it with java6.

Peter Svensson
  • 6,105
  • 1
  • 31
  • 31
  • it may looks cheap to ask, but never been in this situation, i had some searches about what you said and downloaded **jre6**, but now i have no idea how to recompile the old .jar file. or should i continue the whole thing with java 6 ? in any of these cases, how it could be? i mean how come using an IDE with java 6? thanks :) – lonesome Feb 13 '12 at 08:19
  • My suggestion was to run the compilation and application with JDK6 - not recompile the old jar file. I have no idea if it will work, but it might be worth a try. – Peter Svensson Feb 13 '12 at 08:38
4

The LoboBrowser project has been superseded by LoboEvolution, but there's a patch that's mentioned for the obsolete LoboBrowser implementation.

Update FontFactory.java to import a public method and revise the createFont method as follows:

import static javax.swing.text.StyleContext.*;

private Font createFont(String name, int style, int size) {
  return getDefaultStyleContext().getFont(name, style, size);
}
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
alfonx
  • 6,936
  • 2
  • 49
  • 58
  • Can't download the linked jar, but can get lobo to work after manually compiling and replacing the class mentioned in the ticket (and grabbing Rhino JS engine from Mozilla). CSV source seems to be up to date. – Sheepy Apr 09 '12 at 16:23
0

javax.swing.text.StyleContext.getDefaultStyleContext.getFont might work for you, across JDK releases.

See further http://elliotth.blogspot.com.au/2007/04/far-east-asian-fonts-with-java-7-on.html

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84