Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDejan Gloszic2006-02-09 15:22:20 -0500
committerDejan Gloszic2006-02-09 15:22:20 -0500
commit0d186317483e08735b4495749b530f02ddf38807 (patch)
tree5367ca27aa0e10ad23cbc22055b09fb354b697d6 /org.eclipse.help
parent3f82f37f65a604a5b84955037483a98b20ac849f (diff)
downloadeclipse.platform.ua-0d186317483e08735b4495749b530f02ddf38807.tar.gz
eclipse.platform.ua-0d186317483e08735b4495749b530f02ddf38807.tar.xz
eclipse.platform.ua-0d186317483e08735b4495749b530f02ddf38807.zip
*** empty log message ***
Diffstat (limited to 'org.eclipse.help')
-rw-r--r--org.eclipse.help/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.help/src/org/eclipse/help/UAContentFilter.java45
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/FilterableUAElement.java119
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentFilterProcessor.java36
4 files changed, 197 insertions, 5 deletions
diff --git a/org.eclipse.help/META-INF/MANIFEST.MF b/org.eclipse.help/META-INF/MANIFEST.MF
index 8a26b7a3c..48678ac17 100644
--- a/org.eclipse.help/META-INF/MANIFEST.MF
+++ b/org.eclipse.help/META-INF/MANIFEST.MF
@@ -7,7 +7,7 @@ Bundle-Activator: org.eclipse.help.internal.HelpPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.help,
- org.eclipse.help.internal;x-friends:="org.eclipse.help.base,org.eclipse.help.ui,org.eclipse.help.webapp",
+ org.eclipse.help.internal;x-friends:="org.eclipse.help.base,org.eclipse.help.ui,org.eclipse.help.webapp,org.eclipse.ui.intro",
org.eclipse.help.internal.context;x-friends:="org.eclipse.help.base,org.eclipse.help.ui",
org.eclipse.help.internal.index;x-friends:="org.eclipse.help.webapp",
org.eclipse.help.internal.model;x-friends:="org.eclipse.help.base,org.eclipse.help.ui,org.eclipse.help.webapp",
diff --git a/org.eclipse.help/src/org/eclipse/help/UAContentFilter.java b/org.eclipse.help/src/org/eclipse/help/UAContentFilter.java
new file mode 100644
index 000000000..65dc123a7
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/UAContentFilter.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.help;
+
+import org.eclipse.help.internal.FilterableUAElement;
+import org.eclipse.help.internal.xhtml.XHTMLSupport;
+
+/**
+ * <p>
+ * This class provides the ability to filter out user assistance model elements that
+ * support filtering (e.g. <code>IToc</code>, <code>ITopic</code>, ...).
+ * Implementations that display such filterable elements should consult this class
+ * before attempting to display them.
+ * </p>
+ *
+ * @since 3.2
+ */
+public class UAContentFilter {
+
+ /**
+ * <p>
+ * Returns whether or not the given object should be filtered out. This applies
+ * to any user assistance component's elements where filters apply (e.g. help tocs,
+ * topics, intro elements, context help topics). If the element is <code>null</code>
+ * or is not filterable, this method returns <code>false</code>.
+ * </p>
+ *
+ * @param element the element to check
+ * @return whether or not the element should be filtered out
+ */
+ public static boolean isFiltered(Object element) {
+ if (element instanceof FilterableUAElement) {
+ return !XHTMLSupport.getFilterProcessor().isFilteredIn((FilterableUAElement)element);
+ }
+ return false;
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/FilterableUAElement.java b/org.eclipse.help/src/org/eclipse/help/internal/FilterableUAElement.java
new file mode 100644
index 000000000..588c5fa15
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/FilterableUAElement.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.help.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.Attributes;
+
+/**
+ * Any model element or node in any user assistance component that is filterable.
+ * Filters are generally specified in the XML as a filter attribute or child element,
+ * where the filter has a name and value, for example:
+ *
+ * <myUAElement filter="os=win32" myattribute="..." />
+ *
+ * or
+ *
+ * <myUAElement myattribute="...">
+ * <filter name="os" value="linux" />
+ * <filter name="ws" value="gtk" />
+ * </myUAElement>
+ *
+ * Filters must be stored in the model because they should only be processed when
+ * the content is about to be shown, because some of the filtering properties can change
+ * during a session (e.g. activities).
+ */
+public abstract class FilterableUAElement {
+
+ private Map filters;
+
+ /**
+ * Adds the filters specified in the given attributes. This looks for
+ * the "filter" attribute and parses it.
+ *
+ * @param attrs the XML attributes for the element
+ */
+ public void addFilters(Attributes attrs) {
+ // add filter attribute if it exists
+ if (attrs != null) {
+ String filterAttribute = attrs.getValue("filter"); //$NON-NLS-1$
+ if (filterAttribute != null) {
+ addFilter(filterAttribute);
+ }
+ }
+ }
+
+ /**
+ * Adds all filters associated with the given element in the DOM. These can be defined
+ * as either a filter attribute on the element, or filter elements as children of this
+ * element.
+ *
+ * @param element the element whose filters to find
+ * @return a filter name to value mapping for all the filters on this element
+ */
+ public void addFilters(Element element) {
+ // check for filter attribute
+ String filterAttribute = element.getAttribute("filter"); //$NON-NLS-1$
+ if (filterAttribute.length() > 0) {
+ addFilter(filterAttribute);
+ }
+ // check for child filter elements
+ NodeList list = element.getChildNodes();
+ for (int i=0;i<list.getLength();++i) {
+ Node node = list.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE && "filter".equals(node.getNodeName())) {
+ Element elementNode = (Element)node;
+ addFilter(elementNode.getAttribute("name"), elementNode.getAttribute("value"));
+ }
+ }
+ }
+
+ /**
+ * Adds the filter specified by the given string containing both the
+ * filter name and value (e.g. "os=win32").
+ *
+ * @param nameAndValue the filter name and value
+ */
+ public void addFilter(String nameAndValue) {
+ int equalsIndex = nameAndValue.indexOf('=');
+ String name = nameAndValue.substring(0, equalsIndex);
+ String value = nameAndValue.substring(equalsIndex + 1);
+ addFilter(name, value);
+ }
+
+ /**
+ * Adds the specified filter to this element, e.g. name="os", value="win32".
+ *
+ * @param name the filter name, e.g. "os"
+ * @param name the filter value, e.g. "win32"
+ */
+ public void addFilter(String name, String value) {
+ if (filters == null) {
+ filters = new HashMap();
+ }
+ filters.put(name, value);
+ }
+
+ /**
+ * Returns all the filters on this element. This is a mapping of
+ * filter names (e.g. "os") to filter values (e.g. "win32").
+ *
+ * @return this element's filters
+ */
+ public Map getFilters() {
+ return filters;
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentFilterProcessor.java b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentFilterProcessor.java
index a3f647b42..1caa9d124 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentFilterProcessor.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentFilterProcessor.java
@@ -9,8 +9,12 @@
package org.eclipse.help.internal.xhtml;
+import java.util.Iterator;
+import java.util.Map;
+
import org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.help.internal.FilterableUAElement;
import org.osgi.framework.Bundle;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -109,11 +113,12 @@ public class UAContentFilterProcessor {
/**
- * FIltering capabilities. Can be overiden by subclasses to add more filtering capabilities.
+ * Returns whether or not the object with the given filter should be filtered out.
+ * Can be overriden to provide additional filtering.
*
- * @param filter
- * @param value
- * @return
+ * @param filter the filter name (e.g. "os")
+ * @param value the filter value (e.g. "win32")
+ * @return whether or not to filter the element
*/
public boolean isFilteredIn(String filter, String value) {
boolean filtered_in = false;
@@ -134,6 +139,29 @@ public class UAContentFilterProcessor {
}
/**
+ * Returns whether or not the given object should be filtered out.
+ * Can be overriden to provide additional filtering.
+ *
+ * @param element the element to check
+ * @return whether or not to filter the element
+ */
+ public boolean isFilteredIn(FilterableUAElement element) {
+ if (element != null) {
+ Map filters = ((FilterableUAElement)element).getFilters();
+ if (filters != null) {
+ Iterator iter = filters.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry entry = (Map.Entry)iter.next();
+ if (!isFilteredIn((String)entry.getKey(), (String)entry.getValue())) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
* evaluates WS filter.
*/
private static boolean filterByWS(String ws) {

Back to the top