org.eclipse.help.webapp_3.6.1.r37_20110929

16:44:56.554 INFO  jd.cli.Main - Decompiling org.eclipse.help.webapp_3.6.1.r37_20110929.jar
package org.eclipse.help.internal.webapp;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;

public class HelpWebappPlugin
  extends Plugin
{
  public static final String PLUGIN_ID = "org.eclipse.help.webapp";
  public static boolean DEBUG = false;
  public static boolean DEBUG_WORKINGSETS = false;
  protected static HelpWebappPlugin plugin;
  private static BundleContext bundleContext;
  
  public static synchronized void logError(String message, Throwable ex)
  {
    if (message == null) {
      message = "";
    }
    Status errorStatus = new Status(4, "org.eclipse.help.webapp", 0, 
      message, ex);
    getDefault().getLog().log(errorStatus);
  }
  
  public static synchronized void logWarning(String message)
  {
    if (DEBUG)
    {
      if (message == null) {
        message = "";
      }
      Status warningStatus = new Status(2, "org.eclipse.help.webapp", 
        0, message, null);
      getDefault().getLog().log(warningStatus);
    }
  }
  
  public static HelpWebappPlugin getDefault()
  {
    return plugin;
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    plugin = this;
    bundleContext = context;
    
    DEBUG = isDebugging();
    if (DEBUG) {
      DEBUG_WORKINGSETS = "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.help.webapp/debug/workingsets"));
    }
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    plugin = null;
    
    super.stop(context);
  }
  
  public static BundleContext getContext()
  {
    return bundleContext;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.webapp.HelpWebappPlugin
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.webapp;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Locale;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.help.IHelpContentProducer;
import org.eclipse.help.internal.base.remote.RemoteStatusData;
import org.eclipse.help.internal.protocols.HelpURLStreamHandler;
import org.eclipse.help.internal.util.ProductPreferences;
import org.eclipse.help.internal.webapp.data.WebappPreferences;

public class StatusProducer
  implements IHelpContentProducer
{
  public static final String REMOTE_STATUS_HREF = "NetworkHelpStatus.html";
  public static final String MISSING_TOPIC_HREF = "MissingTopicStatus.html";
  public static final String SEARCH_REMOTE_STATUS_HREF = "SearchNetworkHelpStatus.html";
  private static final String TAB = "  ";
  private static final String INDEX = "/index.jsp";
  private static final String BEGIN_HEAD_HTML = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n<html>\n" + 
  
    tab(1) + "<head>\n" + 
    tab(2) + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n";
  private static final String END_HEAD_HTML = tab(1) + "</head>\n";
  private static final String END_BODY_HTML = tab(2) + "</div>\n" + tab(1) + "</body>\n</html>";
  
  public InputStream getInputStream(String pluginID, String href, Locale locale)
  {
    if ((!href.equalsIgnoreCase("NetworkHelpStatus.html")) && 
      (!href.equalsIgnoreCase("MissingTopicStatus.html")) && 
      (!href.equalsIgnoreCase("SearchNetworkHelpStatus.html"))) {
      return null;
    }
    StringBuffer pageBuffer = new StringBuffer();
    
    ArrayList remoteSites = RemoteStatusData.getRemoteSites();
    ArrayList badSites = RemoteStatusData.checkSitesConnectivity(remoteSites);
    RemoteStatusData.clearCache();
    if (remoteSites.isEmpty()) {
      return null;
    }
    if (href.equalsIgnoreCase("MissingTopicStatus.html"))
    {
      String errorPage = Platform.getPreferencesService().getString(
        "org.eclipse.help.base", 
        "page_not_found", 
        null, 
        null);
      if ((errorPage != null) && (errorPage.length() > 0)) {
        try
        {
          URL helpURL = new URL("help", 
            null, -1, errorPage, 
            HelpURLStreamHandler.getDefault());
          return helpURL.openStream();
        }
        catch (MalformedURLException e)
        {
          HelpWebappPlugin.logError("Unable to locate error page: " + errorPage, e);
        }
        catch (IOException e)
        {
          HelpWebappPlugin.logError("Unable to open error page: " + errorPage, e);
        }
      }
    }
    pageBuffer.append(getHtmlHead(locale));
    pageBuffer.append(getBeginHtmlBody());
    boolean allFailed;
    if (remoteSites.size() == badSites.size())
    {
      boolean allFailed = true;
      pageBuffer.append(tab(3) + "<h1>" + WebappResources.getString("allRemoteHelpUnavailable", locale) + "</h1>\n");
    }
    else
    {
      allFailed = false;
      pageBuffer.append(tab(3) + "<h1>" + WebappResources.getString("someRemoteHelpUnavailable", locale) + "</h1>\n");
    }
    if (href.equalsIgnoreCase("NetworkHelpStatus.html"))
    {
      WebappPreferences prefs = new WebappPreferences();
      String homepage = "/help/topic" + prefs.getHelpHome();
      
      pageBuffer.append(tab(3) + "<div style=\"position:absolute;right:4px;top:4px;\">\n");
      pageBuffer.append(tab(4) + "<table>\n" + tab(5) + "<tr>\n");
      pageBuffer.append(tab(6) + "<td style=\"background-color:white;border-width:1px;border-style:solid;border-color:grey;\">" + makeAnchor(homepage, WebappResources.getString("Close", locale), "style=\"font-size:.8em;\"", false) + "</td>\n");
      pageBuffer.append(tab(5) + "</tr>\n" + tab(4) + "</table>\n" + tab(3) + "</div>\n");
    }
    if (href.equalsIgnoreCase("MissingTopicStatus.html")) {
      pageBuffer.append(tab(3) + "<p>" + WebappResources.getString("topicUnavailable", locale) + "</p>\n");
    }
    pageBuffer.append(tab(3) + "<p>" + WebappResources.getString("potentialCauses", locale) + "</p>\n");
    
    pageBuffer.append(tab(3) + "<ul>\n");
    pageBuffer.append(tab(4) + "<li>" + WebappResources.getString("serversCouldBeDown", locale) + "</li>\n");
    pageBuffer.append(tab(4) + "<li>" + WebappResources.getString("mayNeedProxy", locale) + "</li>\n");
    if (allFailed) {
      pageBuffer.append(tab(4) + "<li>" + WebappResources.getString("networkCouldBeDown", locale) + "</li>\n");
    }
    pageBuffer.append(tab(3) + "</ul>\n");
    if (remoteSites.size() > badSites.size())
    {
      pageBuffer.append(tab(3) + "<h2>" + WebappResources.getString("sitesWithConnectivity", locale) + "</h2>\n");
      pageBuffer.append(tab(3) + "<ul>\n");
      for (int r = 0; r < remoteSites.size(); r++) {
        if (!badSites.contains(remoteSites.get(r))) {
          pageBuffer.append(tab(4) + "<li>" + makeAnchor(new StringBuffer().append(remoteSites.get(r)).append("/index.jsp").toString(), new StringBuffer().append(remoteSites.get(r)).append("/index.jsp").toString(), "", true) + "</li>\n");
        }
      }
      pageBuffer.append(tab(3) + "</ul>\n");
    }
    else
    {
      pageBuffer.append(tab(3) + WebappResources.getString("noRemoteSitesAvailable", locale) + "</br>\n");
    }
    if (!badSites.isEmpty())
    {
      pageBuffer.append(tab(3) + "<h2>" + WebappResources.getString("sitesWithoutConnectivity", locale) + "</h2>\n");
      pageBuffer.append(tab(3) + "<ul>\n");
      for (int b = 0; b < badSites.size(); b++) {
        pageBuffer.append(tab(4) + "<li>" + badSites.get(b) + "/index.jsp" + "</li>\n");
      }
      pageBuffer.append(tab(3) + "</ul>\n");
    }
    String activeLink = 
      MessageFormat.format(
      WebappResources.getString("remotePreferences", locale), 
      new String[] { getActiveLink(locale) });
    
    pageBuffer.append(tab(3) + activeLink);
    
    pageBuffer.append(END_BODY_HTML);
    
    ByteArrayInputStream bais = new ByteArrayInputStream(pageBuffer.toString().getBytes());
    
    return bais;
  }
  
  private String getHtmlHead(Locale locale)
  {
    return 
    
      BEGIN_HEAD_HTML + '\n' + tab(2) + "<meta name=\"copyright\" content=\"Copyright (c) IBM Corporation and others 2000, 2009. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page.\" >\n" + tab(2) + "<title>" + WebappResources.getString("remoteStatusTitle", locale) + "</title>\n" + tab(2) + "<link rel=\"stylesheet\" href=\"PLUGINS_ROOT/org.eclipse.help.base/doc/book.css\" charset=\"utf-8\" type=\"text/css\">\n" + tab(2) + "<script language=\"JavaScript\" src=\"PLUGINS_ROOT/org.eclipse.help/livehelp.js\"> </script>\n" + tab(2) + "<script type=\"text/javascript\" src=\"../../../content/org.eclipse.help/livehelp.js\"></script>\n" + END_HEAD_HTML;
  }
  
  private String getBeginHtmlBody()
  {
    String body = tab(1);
    if (ProductPreferences.isRTL()) {
      body = body + "<body dir=\"rtl\">";
    } else {
      body = body + "<body>";
    }
    return 
    
      body + '\n' + tab(2) + "<div id=\"banner\"><img src=\"PLUGINS_ROOT/org.eclipse.help.base/doc/help_banner.jpg\" alt=\"Help banner\" width=\"1600\" height=\"36\"></div>\n" + tab(2) + "<div id=\"content\">\n";
  }
  
  private String getActiveLink(Locale locale)
  {
    return 
    
      "<img src=\"PLUGINS_ROOT/org.eclipse.help/command_link.png\"/><a class=\"command-link\" href='javascript:executeCommand(\"org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.help.ui.contentPreferencePage)\")'>" + WebappResources.getString("remotePreferencesMenuSelect", locale) + "</a>";
  }
  
  private String makeAnchor(String url, String title, String style, boolean newWindow)
  {
    String target = "";
    if (newWindow) {
      target = "target=\"_blank\" ";
    }
    return "<a " + style + " " + target + "href=\"" + url + "\">" + title + "</a>";
  }
  
  private static String tab(int count)
  {
    String tabs = "";
    for (int i = 0; i < count; i++) {
      tabs = tabs + "  ";
    }
    return tabs;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.webapp.StatusProducer
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.webapp;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.Platform;

public class WebappResources
{
  private static HashMap resourceBundleTable = new HashMap();
  
  public static String getString(String name, Locale locale)
  {
    ResourceBundle bundle = getBundle(locale);
    if (bundle == null) {
      return name;
    }
    try
    {
      return bundle.getString(name);
    }
    catch (MissingResourceException localMissingResourceException) {}
    return name;
  }
  
  public static String getString(String name, Locale locale, String replace0)
  {
    ResourceBundle bundle = getBundle(locale);
    if (bundle == null) {
      return name;
    }
    try
    {
      String stringFromPropertiesFile = bundle.getString(name);
      return MessageFormat.format(
        stringFromPropertiesFile, new Object[] { replace0 });
    }
    catch (Exception localException) {}
    return name;
  }
  
  public static String getString(String name, Locale locale, String[] args)
  {
    ResourceBundle bundle = getBundle(locale);
    if (bundle == null) {
      return name;
    }
    try
    {
      String stringFromPropertiesFile = bundle.getString(name);
      return MessageFormat.format(
        stringFromPropertiesFile, args);
    }
    catch (Exception localException) {}
    return name;
  }
  
  private static ResourceBundle getBundle(Locale locale)
  {
    if (locale == null) {
      locale = getDefaultLocale();
    }
    ResourceBundle bundle = (ResourceBundle)resourceBundleTable
      .get(locale);
    if (bundle == null)
    {
      bundle = ResourceBundle.getBundle(WebappResources.class.getName(), 
        locale);
      if (bundle != null) {
        resourceBundleTable.put(locale, bundle);
      }
    }
    return bundle;
  }
  
  private static Locale getDefaultLocale()
  {
    String nl = Platform.getNL();
    if (nl == null) {
      return Locale.getDefault();
    }
    StringTokenizer locales = new StringTokenizer(nl, "_");
    if (locales.countTokens() == 1) {
      return new Locale(locales.nextToken(), "");
    }
    if (locales.countTokens() == 2) {
      return new Locale(locales.nextToken(), locales.nextToken());
    }
    if (locales.countTokens() == 3) {
      return new Locale(locales.nextToken(), locales.nextToken(), locales
        .nextToken());
    }
    return Locale.getDefault();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.webapp.WebappResources
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.webapp.data;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.help.internal.base.IHelpActivitySupport;

public class ActivitiesData
  extends RequestData
{
  public ActivitiesData(ServletContext context, HttpServletRequest request, HttpServletResponse response)
  {
    super(context, request, response);
    String changeShowAll = request.getParameter("showAll");
    if (changeShowAll != null) {
      if ("off".equalsIgnoreCase(changeShowAll)) {
        HelpBasePlugin.getActivitySupport().setFilteringEnabled(true);
      } else if ("on".equalsIgnoreCase(changeShowAll)) {
        HelpBasePlugin.getActivitySupport().setFilteringEnabled(false);
      }
    }
    String confirmShowAll = request.getParameter("showconfirm");
    if ("false".equalsIgnoreCase(confirmShowAll)) {
      preferences.setDontConfirmShowAll(true);
    }
  }
  
  public boolean isActivityFiltering()
  {
    return HelpBasePlugin.getActivitySupport().isFilteringEnabled();
  }
  
  public String getButtonState()
  {
    if (!HelpBasePlugin.getActivitySupport().isUserCanToggleFiltering()) {
      return "hidden";
    }
    if (HelpBasePlugin.getActivitySupport().isFilteringEnabled()) {
      return "off";
    }
    return "on";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.webapp.data.ActivitiesData
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.webapp.data;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.help.IHelpResource;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.base.BookmarkManager;

public class BookmarksData
  extends RequestData
{
  public static final int NONE = 0;
  public static final int ADD = 1;
  public static final int REMOVE = 2;
  public static final int REMOVE_ALL = 3;
  
  public BookmarksData(ServletContext context, HttpServletRequest request, HttpServletResponse response)
  {
    super(context, request, response);
    switch (getOperation())
    {
    case 1: 
      addBookmark();
      break;
    case 2: 
      removeBookmark();
      break;
    case 3: 
      removeAllBookmarks();
      break;
    }
  }
  
  public void addBookmark()
  {
    String bookmarkURL = request.getParameter("bookmark");
    if ((bookmarkURL != null) && (bookmarkURL.length() > 0) && 
      (!bookmarkURL.equals("about:blank")))
    {
      String title = request.getParameter("title");
      if (title == null) {
        return;
      }
      BookmarkManager manager = BaseHelpSystem.getBookmarkManager();
      manager.addBookmark(bookmarkURL, title);
    }
  }
  
  public void removeBookmark()
  {
    String bookmarkURL = request.getParameter("bookmark");
    if ((bookmarkURL != null) && (bookmarkURL.length() > 0) && 
      (!bookmarkURL.equals("about:blank")))
    {
      String title = request.getParameter("title");
      if (title == null) {
        return;
      }
      BookmarkManager manager = BaseHelpSystem.getBookmarkManager();
      manager.removeBookmark(bookmarkURL, title);
    }
  }
  
  public void removeAllBookmarks()
  {
    BookmarkManager manager = BaseHelpSystem.getBookmarkManager();
    manager.removeAllBookmarks();
  }
  
  public Topic[] getBookmarks()
  {
    if (BaseHelpSystem.getMode() != 1)
    {
      BookmarkManager manager = BaseHelpSystem.getBookmarkManager();
      IHelpResource[] bookmarks = manager.getBookmarks();
      Topic[] topics = new Topic[bookmarks.length];
      for (int i = 0; i < bookmarks.length; i++)
      {
        IHelpResource bookmark = bookmarks[i];
        topics[i] = new Topic(bookmark.getLabel(), bookmark.getHref());
      }
      return topics;
    }
    return new Topic[0];
  }
  
  private int getOperation()
  {
    String op = request.getParameter("operation");
    if ("add".equals(op)) {
      return 1;
    }
    if ("remove".equals(op)) {
      return 2;
    }
    if ("removeAll".equals(op)) {
      return 3;
    }
    return 0;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.webapp.data.BookmarksData
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.webapp.data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.internal.webapp.HelpWebappPlugin;
import org.eclipse.help.webapp.AbstractButton;

public class ButtonData
  extends RequestData
{
  private static final String BUTTON_EXTENSION_POINT = "org.eclipse.help.webapp.toolbarButton";
  private List allButtons;
  
  public ButtonData(ServletContext context, HttpServletRequest request, HttpServletResponse response)
  {
    super(context, request, response);
  }
  
  public AbstractButton[] getButtons()
  {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] elements = registry
      .getConfigurationElementsFor("org.eclipse.help.webapp.toolbarButton");
    if (allButtons == null)
    {
      allButtons = new ArrayList();
      for (int i = 0; i < elements.length; i++)
      {
        Object obj = null;
        try
        {
          obj = elements[i].createExecutableExtension("class");
        }
        catch (CoreException e)
        {
          HelpWebappPlugin.logError("Create extension failed:[org.eclipse.help.webapp.toolbarButton].", 
            e);
        }
        if ((obj instanceof AbstractButton)) {
          allButtons.add(obj);
        }
      }
      Collections.sort(allButtons);
    }
    List buttonList = new ArrayList();
    for (Iterator iter = allButtons.iterator(); iter.hasNext();)
    {
      AbstractButton button = (AbstractButton)iter.next();
      
      buttonList.add(button);
    }
    AbstractButton[] buttons = (AbstractButton[])buttonList.toArray(new AbstractButton[buttonList.size()]);
    return buttons;
  }
  
  public String getImageUrl(AbstractButton button)
  {
    return request.getContextPath() + button.getImageURL();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.webapp.data.ButtonData
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.webapp.data;

import javax.servlet.ServletContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.help.internal.webapp.servlet.CookieUtil;

public class CookiesData
  extends RequestData
{
  public CookiesData(ServletContext context, HttpServletRequest request, HttpServletResponse response)
  {
    super(context, request, response);
  }
  
  public boolean isSynchToc()
  {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
      for (int i = 0; i < cookies.length; i++) {
        if ("synchToc".equals(cookies[i].getName())) {
          return String.valueOf(true).equals(cookies[i].getValue());
        }
      }
    }
    boolean isSynchToc = Platform.getPreferencesService().getBoolean(
      "org.eclipse.help.base", "advanced.syncDefault", false, null);
    CookieUtil.setCookieValue("synchToc", Boolean.toString(isSynchToc), request, response);
    return isSynchToc;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.webapp.data.CookiesData
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.webapp.data;

import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.help.internal.util.ProductPreferences;

public class CssUtil
{
  private static final String cssLink1 = "<link rel=\"stylesheet\" href=\"";
  private static final String cssLink2 = "\" type=\"text/css\"></link>\n";
  
  private static String replaceParameters(String input)
  {
    int index = input.indexOf("${os}");
    if (index < 0) {
      return input;
    }
    String result = input.substring(0, index) + Platform.getOS() + input.substring(index + "${os}".length());
    return replaceParameters(result);
  }
  
  public static String[] getCssFilenames(String filenames)
  {
    if (filenames == null) {
      return new String[0];
    }
    StringTokenizer tok = new StringTokenizer(filenames, ",");
    String[] result = new String[tok.countTokens()];
    for (int i = 0; tok.hasMoreTokens(); i++) {
      result[i] = replaceParameters(tok.nextToken().trim());
    }
    return result;
  }
  
  public static void addCssFiles(String preference, List list)
  {
    String topicCssPath = Platform.getPreferencesService().getString("org.eclipse.help.base", preference, "", null);
    String[] cssFiles = getCssFilenames(topicCssPath);
    for (int i = 0; i < cssFiles.length; i++) {
      list.add(cssFiles[i]);
    }
  }
  
  public static String createCssIncludes(List cssFiles, String backPath)
  {
    StringBuffer script = new StringBuffer();
    for (Iterator iter = cssFiles.iterator(); iter.hasNext();)
    {
      String cssPath = (String)iter.next();
      script.append("<link rel=\"stylesheet\" href=\"");
      script.append(fixCssPath(cssPath, backPath));
      script.append("\" type=\"text/css\"></link>\n");
    }
    return script.toString();
  }
  
  private static String fixCssPath(String path, String prefix)
  {
    String newPath = ProductPreferences.resolveSpecialIdentifiers(path);
    return prefix + "content" + newPath;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.webapp.data.CssUtil
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.webapp.data;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.help.IIndexEntry;
import org.eclipse.help.IIndexEntry2;
import org.eclipse.help.IIndexSee;
import org.eclipse.help.IToc;
import org.eclipse.help.ITopic;
import org.eclipse.help.UAContentFilter;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.help.internal.base.HelpEvaluationContext;
import org.eclipse.help.internal.base.IHelpActivitySupport;

public class EnabledTopicUtils
{
  public static boolean isEnabled(ITopic topic)
  {
    if (!topic.isEnabled(HelpEvaluationContext.getContext())) {
      return false;
    }
    if (topic.getHref() != null) {
      return true;
    }
    return hasEnabledSubtopic(topic);
  }
  
  public static boolean hasEnabledSubtopic(ITopic topic)
  {
    ITopic[] subtopics = topic.getSubtopics();
    for (int i = 0; i < subtopics.length; i++) {
      if (isEnabled(subtopics[i])) {
        return true;
      }
    }
    return false;
  }
  
  public static boolean isEnabled(IToc toc)
  {
    if ((!HelpBasePlugin.getActivitySupport().isEnabled(toc.getHref())) || 
      (UAContentFilter.isFiltered(toc, HelpEvaluationContext.getContext()))) {
      return false;
    }
    ITopic[] subtopics = toc.getTopics();
    for (int i = 0; i < subtopics.length; i++) {
      if (isEnabled(subtopics[i])) {
        return true;
      }
    }
    return false;
  }
  
  public static boolean isEnabled(IIndexEntry entry)
  {
    if (UAContentFilter.isFiltered(entry, HelpEvaluationContext.getContext())) {
      return false;
    }
    ITopic[] topics = entry.getTopics();
    for (int i = 0; i < topics.length; i++) {
      if (isEnabled(topics[i])) {
        return true;
      }
    }
    IIndexEntry[] subentries = entry.getSubentries();
    for (int i = 0; i < subentries.length; i++) {
      if (isEnabled(subentries[i])) {
        return true;
      }
    }
    if ((entry instanceof IIndexEntry2))
    {
      IIndexSee[] sees = ((IIndexEntry2)entry).getSees();
      for (int i = 0; i < sees.length; i++) {
        if (isEnabled(sees[i])) {
          return true;
        }
      }
    }
    return false;
  }
  
  public static boolean isEnabled(IIndexSee see)
  {
    return see.isEnabled(HelpEvaluationContext.getContext());
  }
  
  public static IIndexEntry[] getEnabled(IIndexEntry[] entries)
  {
    for (int i = 0; i < entries.length; i++) {
      if (!isEnabled(entries[i]))
      {
        List list = new ArrayList(entries.length);
        for (int j = 0; j < entries.length; j++) {
          if ((j < i) || (isEnabled(entries[j]))) {
            list.add(entries[j]);
          }
        }
        return (IIndexEntry[])list.toArray(new IIndexEntry[list.size()]);
      }
    }
    return entries;
  }
  
  public static ITopic[] getEnabled(ITopic[] topics)
  {
    for (int i = 0; i < topics.length; i++) {
      if (!isEnabled(topics[i]))
      {
        List list = new ArrayList(topics.length);
        for (int j = 0; j < topics.length; j++) {
          if ((j < i) || (isEnabled(topics[j]))) {
            list.add(topics[j]);
          }
        }
        return (ITopic[])list.toArray(new ITopic[list.size()]);
      }
    }
    return topics;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.webapp.data.EnabledTopicUtils
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.webapp.data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.internal.webapp.HelpWebappPlugin;
import org.eclipse.help.webapp.AbstractFrame;

public class FrameData
  extends RequestData
{
  private static final String FRAME_EXTENSION_POINT = "org.eclipse.help.webapp.frame";
  private List allFrames;
  
  public FrameData(ServletContext context, HttpServletRequest request, HttpServletResponse response)
  {
    super(context, request, response);
  }
  
  public AbstractFrame[] getFrames(int location)
  {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] elements = registry
      .getConfigurationElementsFor("org.eclipse.help.webapp.frame");
    if (allFrames == null)
    {
      allFrames = new ArrayList();
      for (int i = 0; i < elements.length; i++)
      {
        Object obj = null;
        try
        {
          obj = elements[i].createExecutableExtension("class");
        }
        catch (CoreException e)
        {
          HelpWebappPlugin.logError("Create extension failed:[org.eclipse.help.webapp.frame].", 
            e);
        }
        if ((obj instanceof AbstractFrame)) {
          allFrames.add(obj);
        }
      }
      Collections.sort(allFrames);
    }
    List frameList = new ArrayList();
    for (Iterator iter = allFrames.iterator(); iter.hasNext();)
    {
      AbstractFrame frame = (AbstractFrame)iter.next();
      if ((frame.isVisible()) && (frame.getLocation() == location)) {
        frameList.add(frame);
      }
    }
    AbstractFrame[] frames = (AbstractFrame[])frameList.toArray(new AbstractFrame[frameList.size()]);
    return frames;
  }
  
  public String getUrl(AbstractFrame frame)
  {
    return request.getContextPath() + frame.getURL();
  }
  
  public String getContentAreaFrameSizes()
  {
    String size = "24,*";
    AbstractFrame[] frames = getFrames(1);
    for (int f = 0; f < frames.length; f++)
    {
      size = size + ',';
      size = size + frames[f].getSize();
    }
    return size;
  }
  
  public AbstractFrame getHelpToolbarFrame()
  {
    AbstractFrame[] frames = getFrames(2);
    if (frames.length > 0)
    {
      if (frames.length > 1) {
        HelpWebappPlugin.logWarning("Only one extra frame is supported to be added to Help Toolbar. The first reterived element will be used.");
      }
      return frames[0];
    }
    return null;
  }
  
  public String getHelpToolbarFrameSizes()
  {
    String size = "*";
    AbstractFrame frame = getHelpToolbarFrame();
    if (frame != null)
    {
      boolean isRTL = UrlUtil.isRTL(request, response);
      if (isRTL) {
        size = frame.getSize() + ", " + size;
      } else {
        size = size + ", " + frame.getSize();
      }
    }
    return size;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.webapp.data.FrameData
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.webapp.data;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;

public class IconFinder
{
  private static final String LEAF = "_leaf";
  private static final String CLOSED = "_closed";
  private static final String OPEN = "_open";
  private static final String ALT = "_alt";
  private static final String EXT_PT = "org.eclipse.help.toc";
  private static final String TOC_ICON_ELEMENT = "tocIcon";
  private static final String TOC_ICON_ID = "id";
  private static final String OPEN_ICON_PATH = "openIcon";
  private static final String CLOSED_ICON_PATH = "closedIcon";
  private static final String LEAF_ICON_PATH = "leafIcon";
  private static final String ICON_ALT_TEXT = "altText";
  private static final String PATH_SEPARATOR = "/";
  private static boolean iconsInitialized = false;
  public static int TYPEICON_OPEN = 0;
  public static int TYPEICON_CLOSED = 1;
  public static int TYPEICON_LEAF = 2;
  private static Map IconPathMap = null;
  
  private static void addIconPath(String IconKey, String IconPath)
  {
    if (IconPathMap == null)
    {
      IconPathMap = new HashMap();
      IconPathMap = new TreeMap();
    }
    IconPathMap.put(IconKey, IconPath);
  }
  
  private static String getIconPath(String IconKey)
  {
    return getEntry(IconKey);
  }
  
  private static String getIconAltText(String IconKey)
  {
    return getEntry(IconKey);
  }
  
  private static String getEntry(String IconKey)
  {
    if (IconPathMap == null) {
      return null;
    }
    Object key = IconPathMap.get(IconKey);
    return (String)key;
  }
  
  private static void setIconImagePath(String bundleId, String path, String key)
  {
    String iconPath = getIconPath(key);
    if (iconPath == null)
    {
      iconPath = bundleId + "/" + path;
      addIconPath(key, iconPath);
    }
  }
  
  private static void setIconAltText(String value, String key)
  {
    addIconPath(key, value);
  }
  
  public static String getImagePathFromId(String iconId, int type)
  {
    if (iconId == null) {
      return null;
    }
    initializeTocIcons();
    String suffix;
    String suffix;
    String suffix;
    String suffix;
    switch (type)
    {
    case 0: 
      suffix = "_open"; break;
    case 1: 
      suffix = "_closed"; break;
    case 2: 
      suffix = "_leaf"; break;
    default: 
      suffix = "_open";
    }
    String result = lookupImagePath(iconId + suffix);
    if (result != null) {
      return result;
    }
    return lookupImagePath(iconId + "_open");
  }
  
  public static String getIconAltFromId(String iconId)
  {
    if (iconId == null) {
      return null;
    }
    initializeTocIcons();
    return getIconAltText(iconId + "_alt");
  }
  
  public static boolean isIconDefined(String icon)
  {
    if ((icon == null) || (icon.length() == 0)) {
      return false;
    }
    String result = getImagePathFromId(icon, TYPEICON_OPEN);
    return result != null;
  }
  
  private static String lookupImagePath(String name)
  {
    return getIconPath(name);
  }
  
  private static void initializeTocIcons()
  {
    if (iconsInitialized) {
      return;
    }
    iconsInitialized = true;
    
    IExtension[] extensionsFound = Platform.getExtensionRegistry()
      .getExtensionPoint("org.eclipse.help.toc").getExtensions();
    for (int i = 0; i < extensionsFound.length; i++)
    {
      IConfigurationElement[] configElements = extensionsFound[i]
        .getConfigurationElements();
      for (int j = 0; j < configElements.length; j++) {
        if (configElements[j].getName().equals("tocIcon"))
        {
          IConfigurationElement iconElem = configElements[j];
          String[] attrs = iconElem.getAttributeNames();
          String contributorID = iconElem.getContributor().getName();
          for (int k = 0; k < attrs.length; k++)
          {
            if (attrs[k].equals("openIcon")) {
              setIconImagePath(contributorID, iconElem.getAttribute("openIcon"), iconElem.getAttribute("id") + "_open");
            }
            if (attrs[k].equals("closedIcon")) {
              setIconImagePath(contributorID, iconElem.getAttribute("closedIcon"), iconElem.getAttribute("id") + "_closed");
            }
            if (attrs[k].equals("leafIcon")) {
              setIconImagePath(contributorID, iconElem.getAttribute("leafIcon"), iconElem.getAttribute("id") + "_leaf");
            }
            if (attrs[k].equals("altText")) {
              setIconAltText(iconElem.getAttribute("altText"), iconElem.getAttribute("id") + "_alt");
            }
          }
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.webapp.data.IconFinder
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.webapp.data;

import java.io.IOException;
import java.io.Writer;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.help.IIndex;
import org.eclipse.help.IIndexEntry;
import org.eclipse.help.ITopic;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.index.IndexManager;

public class IndexData
  extends ActivitiesData
{
  private IIndex index;
  private String imagesDirectory;
  private String plusMinusImage;
  private String expandedCollapsed;
  private boolean usePlusMinus;
  private boolean expandAll;
  private boolean isRTL;
  private Writer out;
  
  public IndexData(ServletContext context, HttpServletRequest request, HttpServletResponse response)
  {
    super(context, request, response);
    
    imagesDirectory = preferences.getImagesDirectory();
    usePlusMinus = preferences.isIndexPlusMinus();
    expandAll = preferences.isIndexExpandAll();
    plusMinusImage = (expandAll ? "/minus.gif" : "/plus.gif");
    expandedCollapsed = (expandAll ? "expanded" : "collapsed");
    isRTL = UrlUtil.isRTL(request, response);
    index = HelpPlugin.getIndexManager().getIndex(getLocale());
  }
  
  public void generateIds(Writer out)
    throws IOException
  {
    boolean first = true;
    IIndexEntry[] entries = index.getEntries();
    for (int i = 0; i < entries.length; i++)
    {
      IIndexEntry entry = entries[i];
      if ((entry != null) && (entry.getKeyword() != null) && (entry.getKeyword().length() > 0))
      {
        if (first) {
          first = false;
        } else {
          out.write(",\n");
        }
        out.write("\"");
        out.write(UrlUtil.JavaScriptEncode(entry.getKeyword()));
        out.write("\"");
      }
    }
  }
  
  public void generateIndex(Writer out)
    throws IOException
  {
    this.out = out;
    IIndexEntry[] entries = index.getEntries();
    for (int i = 0; i < entries.length; i++) {
      if (EnabledTopicUtils.isEnabled(entries[i])) {
        generateEntry(entries[i], 0);
      }
    }
  }
  
  private void generateEntry(IIndexEntry entry, int level)
    throws IOException
  {
    if ((entry.getKeyword() != null) && (entry.getKeyword().length() > 0))
    {
      ITopic[] topics = EnabledTopicUtils.getEnabled(entry.getTopics());
      IIndexEntry[] subentries = EnabledTopicUtils.getEnabled(entry.getSubentries());
      boolean multipleTopics = topics.length > 1;
      boolean singleTopic = topics.length == 1;
      
      out.write("<li>");
      if ((usePlusMinus) && (advancedUI)) {
        generatePlusImage(multipleTopics);
      }
      generateAnchor(singleTopic, entry, level);
      if ((multipleTopics) || (subentries.length > 0))
      {
        if (!advancedUI) {
          out.write("<ul>\n");
        }
        if (multipleTopics) {
          generateTopicList(entry);
        }
        generateSubentries(entry, level + 1);
        if (!advancedUI) {
          out.write("</ul>\n");
        }
      }
      out.write("</li>\n");
    }
  }
  
  public void generateBasicIndex(Writer out)
    throws IOException
  {
    this.out = out;
    IIndexEntry[] entries = index.getEntries();
    for (int i = 0; i < entries.length; i++) {
      generateBasicEntry(entries[i], 0);
    }
  }
  
  private void generateBasicEntry(IIndexEntry entry, int level)
    throws IOException
  {
    ITopic[] topics = entry.getTopics();
    IIndexEntry[] subentries = entry.getSubentries();
    boolean multipleTopics = topics.length > 1;
    boolean singleTopic = topics.length == 1;
    
    out.write("<tr><td align=\"");
    out.write(isRTL ? "right" : "left");
    out.write("\" nowrap>\n");
    generateAnchor(singleTopic, entry, level);
    out.write("</td></tr>\n");
    if ((multipleTopics) || (subentries.length > 0))
    {
      out.write("<tr><td align=\"");
      out.write(isRTL ? "right" : "left");
      out.write("\" nowrap><ul>\n");
      if (multipleTopics) {
        generateTopicList(entry);
      }
      generateSubentries(entry, level + 1);
      out.write("</ul></td></tr>\n");
    }
  }
  
  private void generatePlusImage(boolean multipleTopics)
    throws IOException
  {
    out.write("<img src=\"");
    out.write(imagesDirectory);
    out.write(plusMinusImage);
    out.write("\" class=\"");
    if (multipleTopics) {
      out.write(expandedCollapsed);
    } else {
      out.write("h");
    }
    out.write("\" alt=\"");
    if (multipleTopics) {
      if (expandAll) {
        out.write(ServletResources.getString("collapseTopicTitles", request));
      } else {
        out.write(ServletResources.getString("expandTopicTitles", request));
      }
    }
    out.write("\">");
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd