1 11 12 package org.eclipse.help.internal.webapp.servlet; 13 14 import java.io.OutputStream ; 15 import java.io.UnsupportedEncodingException ; 16 17 import javax.servlet.http.HttpServletRequest ; 18 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.core.runtime.Path; 21 import org.eclipse.core.runtime.Platform; 22 import org.eclipse.help.internal.base.BaseHelpSystem; 23 import org.eclipse.help.internal.base.HelpBasePlugin; 24 import org.eclipse.help.internal.webapp.data.UrlUtil; 25 26 30 public class InjectionFilter implements IFilter { 31 private static final String narrowBook1 = "\n<link rel=\"stylesheet\" HREF=\""; 33 private static final String narrowBook2 = "narrow_book.css\" charset=\"ISO-8859-1\" type=\"text/css\">"; 35 private static final String osNarrowBook2 = "_narrow_book.css\" charset=\"ISO-8859-1\" type=\"text/css\">"; private static final String disabledBook1 = "\n<link rel=\"stylesheet\" HREF=\""; 38 private static final String disabledBook2 = "disabled_book.css\" charset=\"ISO-8859-1\" type=\"text/css\">"; 40 private static final String disabledBook3 = "\n<script language=\"JavaScript\" SRC=\""; 42 private static final String disabledBook4 = "livehelp.js\"> </script>"; 44 47 public OutputStream filter(HttpServletRequest req, OutputStream out) { 48 if (BaseHelpSystem.getMode() != BaseHelpSystem.MODE_WORKBENCH) 50 return out; 51 52 boolean addNarrow = false; 53 boolean addDisabled = false; 54 boolean needsLiveHelp = false; 55 56 String uri = req.getRequestURI(); 57 if (uri == null || !uri.endsWith("html") && !uri.endsWith("htm")) { return out; 59 } 60 if (UrlUtil.isBot(req)) { 61 return out; 62 } 63 String pathInfo = req.getPathInfo(); 64 if (pathInfo == null) { 65 return out; 66 } 67 boolean enabled = HelpBasePlugin.getActivitySupport().isRoleEnabled( 68 pathInfo); 69 if ("/ntopic".equals(req.getServletPath())) addNarrow = true; 71 if (!enabled) { 72 addDisabled = true; 73 } 74 if (!addNarrow && !addDisabled) 75 return out; 76 77 needsLiveHelp = HelpBasePlugin.getActivitySupport().getDocumentMessageUsesLiveHelp(addNarrow); 78 79 IPath path = new Path(pathInfo); 80 int upLevels = path.segmentCount() - 1; 81 StringBuffer script = new StringBuffer (); 82 StringBuffer disabledContent = new StringBuffer (); 83 if (addNarrow) { 85 script.append(narrowBook1); 86 appendRelativePath(script, upLevels); 87 script.append(narrowBook2); 88 script.append(narrowBook1); 89 appendRelativePath(script, upLevels); 90 script.append(Platform.getOS()); 91 script.append(osNarrowBook2); 92 } 93 if (addDisabled) { 94 script.append(disabledBook1); 95 appendRelativePath(script, upLevels); 96 script.append(disabledBook2); 97 if (needsLiveHelp) { 98 script.append(disabledBook3); 99 appendRelativePath(script, upLevels, "org.eclipse.help"); script.append(disabledBook4); 101 } 102 appendDisabled(disabledContent, upLevels, addNarrow); 103 } 104 try { 105 return new FilterHTMLHeadAndBodyOutputStream( 106 out, 107 script.toString().getBytes("ASCII"), addDisabled ? disabledContent.toString() : null); } catch (UnsupportedEncodingException uee) { 109 return out; 110 } 111 } 112 113 private void appendRelativePath(StringBuffer buff, int nsteps, 114 String pluginId) { 115 for (int i = 0; i < nsteps; i++) { 116 buff.append("../"); } 118 buff.append(pluginId + "/"); } 120 121 private void appendRelativePath(StringBuffer buff, int nsteps) { 122 appendRelativePath(buff, nsteps, "PRODUCT_PLUGIN"); } 124 125 private void appendDisabled(StringBuffer buff, int nsteps, boolean narrow) { 126 String message = HelpBasePlugin.getActivitySupport().getDocumentMessage(narrow); 127 if (message==null) 128 return; 129 buff.append("<div id=\"help-disabledTopic\">"); buff.append("<img SRC=\""); appendRelativePath(buff, nsteps, "org.eclipse.help.webapp"); buff.append("advanced/images/e_show_all.gif\" border=\"0\" align=\"bottom\"> "); buff.append(message); 134 buff.append("<br><hr></div>"); } 136 } 137 | Popular Tags |