I'm having a problem with TC4.0.3 (Win2K, JDK1.3.1)
I have some code that reads a property file and tries to load fonts 
listed within. ClassLoader.getResource() is used to locate the prop file 
and font files
I'm attaching the servlet test code. This code works fine under TC3.2.2 
and TC3.3a
BTW, the files being loaded are in a jar in my WEB-INF/lib directory.

I've seen two problems:
1. when the font path contains a space, the resource URL is OK, but 
calling url.openStream() returns null. (works fine in TC3.x)
2. even if the input stream is good (as shown in the log below), there 
seems to be a problem creating a temp file.

Could problem 2 be caused by some security features that have been put 
in place sincee TC3?

Here is my catalina.out (the relavent section)

file = fonts/Pgl_____.ttf
resource = 
jar:file:D:/work/pix.light/light/WEB-INF/lib/fonts.jar!/fonts/Pgl_____.ttf
input stream = java.util.zip.ZipFile$1@5dd910
java.io.IOException: The system cannot find the path specified
    at java.io.Win32FileSystem.createFileExclusively(Native Method)
    at java.io.File.checkAndCreate(File.java:1162)
    at java.io.File.createTempFile(File.java:1247)
    at java.awt.Font.createFont(Font.java:398)
    at com.xerox.pix.servlet.FontServlet.doGet(FontServlet.java:41)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
...

Thanks,

    David
package com.xerox.pix.servlet;

import java.awt.Font;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * This class ...
 *
 * @version $Revision$ $Date$
 * @author D. Kavanagh
 * @author [EMAIL PROTECTED]
 */
public class FontServlet extends LightServlet {

        public void doGet( HttpServletRequest request, HttpServletResponse response ){
                PrintWriter writer = null;

                try {
                        response.setHeader("Pragma", "no-cache");
                        response.setHeader("Expires", "0");
                        response.setHeader("Cache-control", "no-cache, 
must-revalidate");
                        response.setContentType( "text/html" );
                
                        Properties props = new Properties();
                        
props.load(getClass().getClassLoader().getResource("fonts/fonts.properties").openStream());
                        Enumeration enum = props.keys();
                        while (enum.hasMoreElements()) {
                                String file = (String)props.get(enum.nextElement());
                                System.err.println("file = "+file);
                                URL url = 
getClass().getClassLoader().getResource(file);
                                System.err.println("resource = "+url);
                                InputStream in = url.openStream();
                                System.err.println("input stream = "+in);
                                Font f = Font.createFont(Font.TRUETYPE_FONT, in);
                        }

                        writer = response.getWriter();
                        writer.println("<html><body><h1>loaded 
fonts!</ht></body></html>");

                } catch (Exception e) {
                        try {
                                writer = response.getWriter();
                                writer.println("<html><body><h1>ERROR: 
"+e.getMessage()+"</ht></body></html>");
                        } catch (Exception ex) {}
                        e.printStackTrace();
                } finally {
                        if (writer != null)
                                writer.close();
                }

        }
}

--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to