This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 182359
Collapse All | Expand All

(-)a/css.visual/src/org/netbeans/modules/css/visual/ui/preview/CssPreviewPanel.java (-2 / +50 lines)
Lines 41-47 Link Here
41
package org.netbeans.modules.css.visual.ui.preview;
41
package org.netbeans.modules.css.visual.ui.preview;
42
42
43
import java.awt.Graphics;
43
import java.awt.Graphics;
44
import java.io.File;
44
import java.io.InputStream;
45
import java.io.InputStream;
46
import java.net.URL;
45
import java.util.concurrent.FutureTask;
47
import java.util.concurrent.FutureTask;
46
import java.util.logging.Handler;
48
import java.util.logging.Handler;
47
import java.util.logging.Level;
49
import java.util.logging.Level;
Lines 49-58 Link Here
49
import java.util.logging.Logger;
51
import java.util.logging.Logger;
50
import javax.swing.JComponent;
52
import javax.swing.JComponent;
51
import javax.swing.SwingUtilities;
53
import javax.swing.SwingUtilities;
54
import org.netbeans.api.project.FileOwnerQuery;
55
import org.netbeans.api.project.Project;
56
import org.netbeans.modules.web.common.spi.ProjectWebRootQuery;
52
import org.openide.awt.StatusDisplayer;
57
import org.openide.awt.StatusDisplayer;
58
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileStateInvalidException;
60
import org.openide.filesystems.FileUtil;
53
import org.openide.util.Exceptions;
61
import org.openide.util.Exceptions;
54
import org.openide.util.RequestProcessor;
62
import org.openide.util.RequestProcessor;
63
import org.xhtmlrenderer.extend.UserAgentCallback;
55
import org.xhtmlrenderer.simple.XHTMLPanel;
64
import org.xhtmlrenderer.simple.XHTMLPanel;
65
import org.xhtmlrenderer.swing.NaiveUserAgent;
56
66
57
/**
67
/**
58
 * JPanel wrapping XHTMLPanel, the Flying Saucer's rendering area.
68
 * JPanel wrapping XHTMLPanel, the Flying Saucer's rendering area.
Lines 80-86 Link Here
80
            @Override
90
            @Override
81
            public void run() {
91
            public void run() {
82
                //create outside of AWT
92
                //create outside of AWT
83
                final XHTMLPanel panel = new PatchedXHTMLPanel();
93
                final XHTMLPanel panel = new PatchedXHTMLPanel(new PreviewUserAgent());
84
                //and set the panel to this component in AWT
94
                //and set the panel to this component in AWT
85
                SwingUtilities.invokeLater(new Runnable() {
95
                SwingUtilities.invokeLater(new Runnable() {
86
                    @Override
96
                    @Override
Lines 196-201 Link Here
196
206
197
    //workaround for FlyingSaucer bug (reported as netbeans issue #117499 (NullPointerException for unreachable url))
207
    //workaround for FlyingSaucer bug (reported as netbeans issue #117499 (NullPointerException for unreachable url))
198
    private static class PatchedXHTMLPanel extends XHTMLPanel {
208
    private static class PatchedXHTMLPanel extends XHTMLPanel {
209
        /**
210
         * Instantiates a panel with a custom {@link org.xhtmlrenderer.extend.UserAgentCallback}
211
         * implementation.
212
         *
213
         * @param uac The custom UserAgentCallback implementation.
214
         */
215
        public PatchedXHTMLPanel(UserAgentCallback uac) {
216
            super(uac);
217
        }
218
199
        @Override
219
        @Override
200
        public void paintComponent(Graphics g) {
220
        public void paintComponent(Graphics g) {
201
            try {
221
            try {
Lines 208-212 Link Here
208
            }
228
            }
209
        }
229
        }
210
    }
230
    }
211
    
231
232
    //workaround for specifying Base URL
233
    private static class PreviewUserAgent extends NaiveUserAgent {
234
        @Override
235
        public String resolveURI(String uri) {
236
            if (uri == null) {
237
                return null;
238
            }
239
            if (uri.startsWith("/")) {
240
                // Absolute path now we will look to the webRoot of the project
241
                FileObject edited = FileUtil.toFileObject(FileUtil.normalizeFile(new File(getBaseURL())));
242
                if (edited != null) {
243
                    FileObject webRoot = ProjectWebRootQuery.getWebRoot(edited);
244
                    if(webRoot == null) {
245
                        //no web root, use project's root
246
                        Project project = FileOwnerQuery.getOwner(edited);
247
                        webRoot = project.getProjectDirectory();
248
                    }
249
                    try {
250
                        return webRoot.getFileObject(uri).getURL().toExternalForm();
251
                    } catch (FileStateInvalidException ex) {
252
                        // ignore it and falling back to flysaucer implementation
253
                    }
254
                }
255
            }
256
            // falling back to FlyingSaucer implementation
257
            return super.resolveURI(uri);
258
        }
259
    }
212
}
260
}

Return to bug 182359