Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/scope/CriteriaHelpScope.java (renamed from org.eclipse.help.base/src/org/eclipse/help/internal/workingset/CriteriaHelpScope.java)15
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/scope/WorkingSetScope.java87
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/util/CriteriaUtilities.java33
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchResults.java32
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/workingset/IHelpWorkingSetManager.java18
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSet.java82
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSetManager.java167
-rw-r--r--org.eclipse.help.webapp/advanced/workingSet.jsp311
-rw-r--r--org.eclipse.help.webapp/advanced/workingSetManager.jsp5
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/WebappResources.properties6
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/WorkingSetData.java100
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/WorkingSetManagerData.java142
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/CookieUtil.java2
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InfocenterWorkingSetManager.java231
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/WebappWorkingSetManager.java44
-rw-r--r--org.eclipse.help/plugin.xml9
-rw-r--r--org.eclipse.help/preferences.ini7
-rw-r--r--org.eclipse.help/schema/criteriaDefinition.exsd185
-rw-r--r--org.eclipse.help/src/org/eclipse/help/AbstractCriteriaDefinitionProvider.java30
-rw-r--r--org.eclipse.help/src/org/eclipse/help/ICriteriaDefinition.java30
-rw-r--r--org.eclipse.help/src/org/eclipse/help/ICriteriaDefinitionContribution.java42
-rw-r--r--org.eclipse.help/src/org/eclipse/help/ICriterionDefinition.java42
-rw-r--r--org.eclipse.help/src/org/eclipse/help/ICriterionValueDefinition.java35
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java12
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/UAElementFactory.java12
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinition.java40
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionAssembler.java108
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionContribution.java47
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionDocumentReader.java61
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFile.java49
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFileParser.java43
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFileProvider.java94
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionManager.java195
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaManager.java (renamed from org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaPreferences.java)44
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionDefinition.java55
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionResource.java14
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionValueDefinition.java49
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocAssembler.java13
-rw-r--r--org.eclipse.ua.tests/data/help/criteria/criteria_definition/a.xml22
-rw-r--r--org.eclipse.ua.tests/data/help/criteria/criteria_definition/b.xml37
-rw-r--r--org.eclipse.ua.tests/data/help/criteria/criteria_definition/result_a_b.xml33
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/AllCriteriaTests.java1
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/CriteriaUtilitiesTest.java2
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseCriteriaDefinition.java87
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java4
45 files changed, 2439 insertions, 238 deletions
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/CriteriaHelpScope.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/scope/CriteriaHelpScope.java
index 09ac9a4a5..432f73f0c 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/CriteriaHelpScope.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/scope/CriteriaHelpScope.java
@@ -9,10 +9,9 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.help.internal.workingset;
+package org.eclipse.help.internal.base.scope;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -96,17 +95,7 @@ public class CriteriaHelpScope extends AbstractHelpScope {
private Map getCriteriaInfo(CriterionResource[] criteria) {
Map criteriaMap = new HashMap();
- for(int i = 0; i < criteria.length; ++ i){
- CriterionResource criterion = criteria[i];
- String criterionName = criterion.getCriterionName();
- List criterionValues = criterion.getCriterionValues();
-
- Set existedValueSet = (Set)criteriaMap.get(criterionName);
- if (null == existedValueSet)
- existedValueSet = new HashSet();
- existedValueSet.addAll(criterionValues);
- criteriaMap.put(criterionName, existedValueSet);
- }
+ CriteriaUtilities.addCriteriaToMap(criteriaMap, criteria);
return criteriaMap;
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/scope/WorkingSetScope.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/scope/WorkingSetScope.java
index ce1ed1041..23892f868 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/scope/WorkingSetScope.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/scope/WorkingSetScope.java
@@ -11,35 +11,56 @@
package org.eclipse.help.internal.base.scope;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Locale;
+import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.help.ICriteria;
import org.eclipse.help.IIndexEntry;
import org.eclipse.help.IIndexSee;
import org.eclipse.help.IToc;
+import org.eclipse.help.IToc2;
import org.eclipse.help.ITopic;
+import org.eclipse.help.ITopic2;
import org.eclipse.help.base.AbstractHelpScope;
+import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.UAElement;
+import org.eclipse.help.internal.base.util.CriteriaUtilities;
+import org.eclipse.help.internal.criteria.CriterionResource;
import org.eclipse.help.internal.workingset.AdaptableHelpResource;
import org.eclipse.help.internal.workingset.IHelpWorkingSetManager;
import org.eclipse.help.internal.workingset.WorkingSet;
public class WorkingSetScope extends AbstractHelpScope {
+ private static final String UNCATEGORIZED = "Uncategorized"; //$NON-NLS-1$
+
IHelpWorkingSetManager wSetManager;
private WorkingSet workingSet;
AdaptableHelpResource[] elements;
+ CriterionResource[] criteria;
public WorkingSetScope(String scope, IHelpWorkingSetManager manager) {
wSetManager = manager;
workingSet = wSetManager.getWorkingSet(scope);
elements = workingSet.getElements();
+ criteria = workingSet.getCriteria();
wSetManager = manager;
}
public boolean inScope(IToc toc) {
+ if(HelpPlugin.getCriteriaManager().isCriteriaEnabled()) {
+ return inContentScope(toc) && inCriteriaScope(toc);
+ } else {
+ return inContentScope(toc);
+ }
+ }
+
+ private boolean inContentScope(IToc toc) {
for (int i = 0; i < elements.length; i++) {
for (AdaptableHelpResource adaptable = elements[i]; adaptable != null; ) {
Object itoc = adaptable.getAdapter(IToc.class);
@@ -56,8 +77,63 @@ public class WorkingSetScope extends AbstractHelpScope {
}
return false;
}
+
+ private boolean inCriteriaScope(IToc toc) {
+ if(null == toc){
+ if(null == criteria || 0 == criteria.length){
+ return true;
+ }
+ return false;
+ }
+ ICriteria[] criteriaOfToc = ((IToc2) toc).getCriteria();
+ return isCriteriaInScope(criteriaOfToc);
+ }
+
+ private boolean isCriteriaInScope(ICriteria[] criteriaOfTopic) {
+ if(null ==criteria){
+ return true;
+ }
+ Map ownCriteria = getCriteriaInfo(criteriaOfTopic);
+ Map scope = getCriteriaInfo(criteria);
+ outer: for (Iterator keyIterator = scope.keySet().iterator(); keyIterator.hasNext();) {
+ String key = String.valueOf(keyIterator.next());
+ for (Iterator valueIterator = ((Set)scope.get(key)).iterator(); valueIterator.hasNext();) {
+ String value = String.valueOf(valueIterator.next());
+ if (value.equals(UNCATEGORIZED)) {
+ if (!ownCriteria.containsKey(key)) {
+ continue outer;
+ }
+ } else {
+ if (null != ownCriteria.get(key) && ((Set)ownCriteria.get(key)).contains(value))
+ continue outer;
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
+ private Map getCriteriaInfo(CriterionResource[] criteria) {
+ Map criteriaMap = new HashMap();
+ CriteriaUtilities.addCriteriaToMap(criteriaMap, criteria);
+ return criteriaMap;
+ }
+
+ private Map getCriteriaInfo(ICriteria[] criteria) {
+ Map criteriaMap = new HashMap();
+ CriteriaUtilities.addCriteriaToMap(criteriaMap, criteria);
+ return criteriaMap;
+ }
public boolean inScope(ITopic topic) {
+ if(HelpPlugin.getCriteriaManager().isCriteriaEnabled()) {
+ return inContentScope(topic) && inCriteriaScope(topic);
+ } else {
+ return inContentScope(topic);
+ }
+ }
+
+ private boolean inContentScope(ITopic topic) {
Set topics = new HashSet();
IToc toc = null;
topics.add(topic);
@@ -103,6 +179,17 @@ public class WorkingSetScope extends AbstractHelpScope {
}
return false;
}
+
+ private boolean inCriteriaScope(ITopic topic) {
+ if(null == topic){
+ if(null == criteria || 0 == criteria.length){
+ return true;
+ }
+ return false;
+ }
+ ICriteria[] criteriaOfTopic = ((ITopic2) topic).getCriteria();
+ return isCriteriaInScope(criteriaOfTopic);
+ }
public boolean inScope(IIndexEntry entry) {
return hasInScopeChildren(entry);
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/util/CriteriaUtilities.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/util/CriteriaUtilities.java
index 0b74b54ab..82a996872 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/util/CriteriaUtilities.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/util/CriteriaUtilities.java
@@ -18,14 +18,14 @@ import java.util.Map;
import java.util.Set;
import org.eclipse.help.ICriteria;
+import org.eclipse.help.internal.criteria.CriterionResource;
public class CriteriaUtilities {
public static List getCriteriaValues(String rawValues) {
List result = new ArrayList();
if (rawValues != null) {
- String lowerCaseValues = rawValues.toLowerCase();
- String[] values = lowerCaseValues.split(","); //$NON-NLS-1$
+ String[] values = rawValues.split(","); //$NON-NLS-1$
for(int j = 0; j < values.length; ++j){
String value = values[j].trim();
if (value.length() > 0) {
@@ -42,15 +42,28 @@ public class CriteriaUtilities {
String name = criterion.getName();
List values = CriteriaUtilities.getCriteriaValues(criterion.getValue());
if (name != null && name.length() > 0 && values.size() > 0) {
-
- }
-
- Set existingValueSet = (Set) map.get(name);
- if (null == existingValueSet) {
- existingValueSet = new HashSet();
+ name = name.toLowerCase();
+ Set existingValueSet = (Set) map.get(name);
+ if (null == existingValueSet) {
+ existingValueSet = new HashSet();
+ }
+ existingValueSet.addAll(values);
map.put(name, existingValueSet);
- }
- existingValueSet.addAll(values);
+ }
+ }
+ }
+
+ public static void addCriteriaToMap(Map map, CriterionResource[] criteria) {
+ for(int i = 0; i < criteria.length; ++ i){
+ CriterionResource criterion = criteria[i];
+ String criterionName = criterion.getCriterionName();
+ List criterionValues = criterion.getCriterionValues();
+
+ Set existedValueSet = (Set)map.get(criterionName);
+ if (null == existedValueSet)
+ existedValueSet = new HashSet();
+ existedValueSet.addAll(criterionValues);
+ map.put(criterionName, existedValueSet);
}
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchResults.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchResults.java
index 485a70b30..64247fc54 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchResults.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchResults.java
@@ -18,6 +18,8 @@ import org.eclipse.help.IToc;
import org.eclipse.help.ITopic;
import org.eclipse.help.base.AbstractHelpScope;
import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.base.scope.CriteriaHelpScope;
+import org.eclipse.help.internal.criteria.CriterionResource;
import org.eclipse.help.internal.util.URLCoder;
import org.eclipse.help.internal.workingset.AdaptableHelpResource;
import org.eclipse.help.internal.workingset.AdaptableSelectedToc;
@@ -36,6 +38,7 @@ public class SearchResults implements ISearchHitCollector {
private int maxHits;
private String locale;
private AbstractHelpScope filter;
+ private CriteriaHelpScope criteriaScope;
protected SearchHit[] searchHits = new SearchHit[0];
private QueryTooComplexException searchException = null;
/**
@@ -48,6 +51,7 @@ public class SearchResults implements ISearchHitCollector {
this.maxHits = maxHits;
this.locale = locale;
this.scopes = getScopes(workingSets);
+ this.criteriaScope = new CriteriaHelpScope(getCriteriaScopes(workingSets));
}
public void setFilter(AbstractHelpScope filter) {
@@ -131,13 +135,17 @@ public class SearchResults implements ISearchHitCollector {
* Finds a topic within a scope
*/
private AdaptableHelpResource getScopeForTopic(String href) {
+ boolean enabled = HelpPlugin.getCriteriaManager().isCriteriaEnabled();
for (int i = 0; i < scopes.size(); i++) {
AdaptableHelpResource scope = (AdaptableHelpResource) scopes.get(i);
ITopic inScopeTopic = scope.getTopic(href);
- if (inScopeTopic != null)
+ if (inScopeTopic != null){
if (filter == null || filter.inScope(inScopeTopic)) {
- return scope;
+ if(!enabled || (enabled && criteriaScope.inScope(inScopeTopic))){
+ return scope;
+ }
}
+ }
// add root toc's extradir topics to search scope
IToc tocRoot = getTocForScope(scope, locale);
@@ -147,9 +155,10 @@ public class SearchResults implements ISearchHitCollector {
String owningTocHref = toc.getHref();
if (owningTocHref == tocRoot.getHref()) {
if (filter == null || filter.inScope(inScopeTopic)) {
- return scope;
+ if(!enabled || (enabled && criteriaScope.inScope(inScopeTopic))){
+ return scope;
+ }
}
- return scope;
}
}
}
@@ -198,7 +207,7 @@ public class SearchResults implements ISearchHitCollector {
if (topic != null) {
foundInToc = true;
if (filter == null || filter.inScope(topic)) {
- return tocs[i];
+ return tocs[i];
}
}
}
@@ -246,6 +255,19 @@ public class SearchResults implements ISearchHitCollector {
}
return scopes;
}
+
+ private ArrayList getCriteriaScopes(WorkingSet[] wSets){
+ if (wSets == null)
+ return null;
+
+ ArrayList criteriaScopes = new ArrayList(wSets.length);
+ for (int w = 0; w < wSets.length; w++) {
+ CriterionResource[] elements = wSets[w].getCriteria();
+ for (int i = 0; i < elements.length; i++)
+ criteriaScopes.add(elements[i]);
+ }
+ return criteriaScopes;
+ }
public void addQTCException(QueryTooComplexException exception) throws QueryTooComplexException {
this.searchException = exception;
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/IHelpWorkingSetManager.java b/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/IHelpWorkingSetManager.java
index 9cc4a93fb..2016c25bd 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/IHelpWorkingSetManager.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/IHelpWorkingSetManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -10,7 +10,9 @@
*******************************************************************************/
package org.eclipse.help.internal.workingset;
-import java.io.*;
+import java.io.IOException;
+
+import org.eclipse.help.internal.criteria.CriterionResource;
/**
* The working set manager stores help working sets. Working sets are persisted
@@ -32,6 +34,8 @@ public interface IHelpWorkingSetManager {
public WorkingSet createWorkingSet(String name,
AdaptableHelpResource[] elements);
+ public WorkingSet createWorkingSet(String name, AdaptableHelpResource[] elements, CriterionResource[] criteria);
+
/**
* Returns a working set by name
*
@@ -67,4 +71,14 @@ public interface IHelpWorkingSetManager {
public String getCurrentWorkingSet();
public void setCurrentWorkingSet(String workingSet);
+
+ public boolean isCriteriaScopeEnabled();
+
+ public String[] getCriterionIds();
+
+ public String[] getCriterionValueIds(String criterionId);
+
+ public String getCriterionDisplayName(String criterionId);
+
+ public String getCriterionValueDisplayName(String criterionId, String criterionValueId);
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSet.java b/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSet.java
index ca1ff7fa4..203ddbf38 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSet.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSet.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -14,26 +14,45 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.w3c.dom.*;
+import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.criteria.CriterionResource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
public class WorkingSet {
private String name;
private List elements;
+ private List criteria;
public WorkingSet(String name) {
- this(name, (List) null);
+ this(name, (List) null, (List) null);
}
public WorkingSet(String name, List elements) {
+ this(name, elements, null);
+ }
+
+ public WorkingSet(String name, List elements, List criteria) {
this.name = name;
+
if (elements == null)
elements = new ArrayList();
-
this.elements = elements;
+
+ if (criteria != null) {
+ this.criteria = criteria;
+ } else {
+ this.criteria = new ArrayList();
+ }
}
public WorkingSet(String name, AdaptableHelpResource[] elements) {
+ this(name, elements, null);
+ }
+
+ public WorkingSet(String name, AdaptableHelpResource[] elements, CriterionResource[] criteria) {
this.name = name;
+
if (elements == null)
elements = new AdaptableHelpResource[0];
@@ -41,6 +60,14 @@ public class WorkingSet {
for (int i = 0; i < elements.length; i++) {
this.elements.add(elements[i]);
}
+
+ if (criteria == null)
+ criteria = new CriterionResource[0];
+
+ this.criteria = new ArrayList(criteria.length);
+ for (int j = 0; j < criteria.length; j++) {
+ this.criteria.add(criteria[j]);
+ }
}
public void removeElement(AdaptableHelpResource element) {
@@ -71,19 +98,58 @@ public class WorkingSet {
for (int i = 0; i < elements.length; i++)
this.elements.add(elements[i]);
}
+
+
+ public void setCriteria(CriterionResource[] criteria) {
+ this.criteria = new ArrayList(criteria.length);
+ for(int i = 0; i < criteria.length; i++) {
+ this.criteria.add(criteria[i]);
+ }
+ }
+
+ public CriterionResource[] getCriteria(){
+ CriterionResource[] array = new CriterionResource[criteria.size()];
+ criteria.toArray(array);
+ return array;
+ }
public void saveState(Element parent) {
Document doc = parent.getOwnerDocument();
Element ws = doc.createElement("workingSet"); //$NON-NLS-1$
ws.setAttribute("name", name); //$NON-NLS-1$
parent.appendChild(ws);
-
+
+ Element contents = doc.createElement("contents"); //$NON-NLS-1$
+ ws.appendChild(contents);
for (Iterator it = elements.iterator(); it.hasNext();) {
Element child = doc.createElement("item"); //$NON-NLS-1$
- AdaptableHelpResource helpResource = (AdaptableHelpResource) it
- .next();
+ AdaptableHelpResource helpResource = (AdaptableHelpResource) it.next();
helpResource.saveState(child);
- ws.appendChild(child);
+ contents.appendChild(child);
+ }
+
+ if(HelpPlugin.getCriteriaManager().isCriteriaEnabled() && !criteria.isEmpty()){
+ Element criteriaElement = doc.createElement("criteria"); //$NON-NLS-1$
+ ws.appendChild(criteriaElement);
+
+ for(Iterator iterator = criteria.iterator(); iterator.hasNext();){
+ Element criterionItem = doc.createElement("criterion"); //$NON-NLS-1$
+ criteriaElement.appendChild(criterionItem);
+ CriterionResource criterion = (CriterionResource)iterator.next();
+ String criterionName = criterion.getCriterionName();
+ criterionItem.setAttribute("name", criterionName);//$NON-NLS-1$
+ List criterionValues = criterion.getCriterionValues();
+ if(!criterionValues.isEmpty()){
+ for(Iterator iter = criterionValues.iterator(); iter.hasNext();){
+ String value = (String)iter.next();
+ if(value != null){
+ Element item = doc.createElement("item"); //$NON-NLS-1$
+ criterionItem.appendChild(item);
+ item.setAttribute("value", value.trim());//$NON-NLS-1$
+ }
+ }
+ }
+ }
}
}
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSetManager.java b/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSetManager.java
index 9dce7b95c..e8146026d 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSetManager.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSetManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -16,8 +16,11 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -39,6 +42,7 @@ import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.base.HelpBasePlugin;
+import org.eclipse.help.internal.criteria.CriterionResource;
import org.osgi.service.prefs.BackingStoreException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -58,9 +62,13 @@ public class WorkingSetManager implements IHelpWorkingSetManager {
// Working set persistence
private static final String WORKING_SET_STATE_FILENAME = "workingsets.xml"; //$NON-NLS-1$
+ private static final String UNCATEGORIZED = "Uncategorized"; //$NON-NLS-1$
+
private SortedSet workingSets = new TreeSet(new WorkingSetComparator());
private AdaptableTocsArray root;
+
+ private Map allCriteriaValues;
private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
.newInstance();
@@ -99,6 +107,12 @@ public class WorkingSetManager implements IHelpWorkingSetManager {
AdaptableHelpResource[] elements) {
return new WorkingSet(name, elements);
}
+
+ public WorkingSet createWorkingSet(String name, AdaptableHelpResource[] elements, CriterionResource[] criteria) {
+ return new WorkingSet(name, elements, criteria);
+ }
+
+
/**
* Tests the receiver and the object for equality
@@ -231,8 +245,7 @@ public class WorkingSetManager implements IHelpWorkingSetManager {
if (workingSets.item(i).getNodeType() != Node.ELEMENT_NODE)
continue;
- WorkingSet workingSet = restoreWorkingSet((Element) workingSets
- .item(i));
+ WorkingSet workingSet = restoreWorkingSet((Element) workingSets.item(i));
if (workingSet != null) {
this.workingSets.add(workingSet);
}
@@ -246,46 +259,75 @@ public class WorkingSetManager implements IHelpWorkingSetManager {
* failed.
*/
private WorkingSet restoreWorkingSet(Element workingSetNode) {
-
String name = workingSetNode.getAttribute("name"); //$NON-NLS-1$
- NodeList items = workingSetNode.getElementsByTagName("item"); //$NON-NLS-1$
- List helpResources = new ArrayList(items.getLength());
- for (int i = 0; i < items.getLength(); i++) {
- Element item = (Element) items.item(i);
- String href = item.getAttribute("toc"); //$NON-NLS-1$
- if (href == null || href.length() == 0)
- continue;
- String child_pos = item.getAttribute("topic"); //$NON-NLS-1$
- int pos = -1;
- if (child_pos != null) {
- try {
- pos = Integer.parseInt(child_pos);
- } catch (Exception e) {
+ // scope
+ List helpResources = new ArrayList();
+ NodeList contents = workingSetNode.getElementsByTagName("contents"); //$NON-NLS-1$
+ for (int i = 0; i < contents.getLength(); i++) {
+ Element content = (Element) contents.item(i);
+ NodeList items = content.getElementsByTagName("item"); //$NON-NLS-1$
+ for(int j = 0; j < items.getLength(); j++){
+ Element itemI = (Element) items.item(j);
+ String href = itemI.getAttribute("toc"); //$NON-NLS-1$
+ if (href == null || href.length() == 0)
+ continue;
+
+ String child_pos = itemI.getAttribute("topic"); //$NON-NLS-1$
+ int pos = -1;
+ if (child_pos != null) {
+ try {
+ pos = Integer.parseInt(child_pos);
+ } catch (Exception e) {
+ }
}
- }
- AdaptableHelpResource toc = getAdaptableToc(href);
+ AdaptableHelpResource toc = getAdaptableToc(href);
- if (toc == null)
- return null;
+ if (toc == null)
+ return null;
- if (pos == -1) {
- // Create the adaptable toc.
- helpResources.add(toc);
- } else {
- // Create the adaptable topic
- AdaptableTopic[] topics = (AdaptableTopic[]) toc.getChildren();
- if (pos >= 0 && topics.length > pos)
- helpResources.add(topics[pos]);
+ if (pos == -1) {
+ // Create the adaptable toc.
+ helpResources.add(toc);
+ } else {
+ // Create the adaptable topic
+ AdaptableTopic[] topics = (AdaptableTopic[]) toc.getChildren();
+ if (pos >= 0 && topics.length > pos)
+ helpResources.add(topics[pos]);
+ }
}
}
-
- AdaptableHelpResource[] elements = new AdaptableHelpResource[helpResources
- .size()];
+ AdaptableHelpResource[] elements = new AdaptableHelpResource[helpResources.size()];
helpResources.toArray(elements);
+
+ //criteria
+
+ List criteriaResource = new ArrayList();
+ NodeList criteriaContents = workingSetNode.getElementsByTagName("criterion"); //$NON-NLS-1$
+ for (int i = 0; i < criteriaContents.getLength(); ++i) {
+ Element criterion = (Element) criteriaContents.item(i);
+ String criterionName = criterion.getAttribute("name"); //$NON-NLS-1$
+ if(null != name && 0 != name.length() && HelpPlugin.getCriteriaManager().isSupportedCriterion(criterionName)){
+ NodeList items = criterion.getElementsByTagName("item"); //$NON-NLS-1$
+ List criterionValues = new ArrayList();
+ for(int j = 0; j < items.getLength(); ++j){
+ String value = ((Element) items.item(j)).getAttribute("value"); //$NON-NLS-1$
+ if(null != value && 0 != value.length()){
+ criterionValues.add(value);
+ }
+ }
+ if(criterionValues.size() > 0){
+ CriterionResource criterionResource = new CriterionResource(criterionName, criterionValues);
+ criteriaResource.add(criterionResource);
+ }
+ }
+ }
+
+ CriterionResource[] criteria = new CriterionResource[criteriaResource.size()];
+ criteriaResource.toArray(criteria);
- WorkingSet ws = createWorkingSet(name, elements);
+ WorkingSet ws = createWorkingSet(name, elements, criteria);
return ws;
}
@@ -296,8 +338,7 @@ public class WorkingSetManager implements IHelpWorkingSetManager {
public synchronized boolean saveState() {
File stateFile = null;
try {
- DocumentBuilder docBuilder = documentBuilderFactory
- .newDocumentBuilder();
+ DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("workingSets"); //$NON-NLS-1$
doc.appendChild(rootElement);
@@ -415,5 +456,61 @@ public class WorkingSetManager implements IHelpWorkingSetManager {
workingSets = new TreeSet(new WorkingSetComparator());
restoreState();
}
+
+ public boolean isCriteriaScopeEnabled(){
+ if(null == allCriteriaValues){
+ allCriteriaValues = HelpPlugin.getCriteriaManager().getAllCriteriaValues(Platform.getNL());
+ }
+ if(HelpPlugin.getCriteriaManager().isCriteriaEnabled() && !allCriteriaValues.isEmpty()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public String[] getCriterionIds() {
+ if(null == allCriteriaValues){
+ allCriteriaValues = HelpPlugin.getCriteriaManager().getAllCriteriaValues(Platform.getNL());
+ }
+ List criterionIds = new ArrayList();
+ if(null != allCriteriaValues){
+ for(Iterator iter = allCriteriaValues.keySet().iterator(); iter.hasNext();){
+ String criterion = (String) iter.next();
+ if(null == criterion || 0 == criterion.length() || 0 == getCriterionValueIds(criterion).length)
+ continue;
+ criterionIds.add(criterion);
+ }
+ Collections.sort(criterionIds);
+ }
+ String[] ids = new String[criterionIds.size()];
+ criterionIds.toArray(ids);
+ return ids;
+ }
+
+ public String[] getCriterionValueIds(String criterionName) {
+ if(null == allCriteriaValues){
+ allCriteriaValues = HelpPlugin.getCriteriaManager().getAllCriteriaValues(Platform.getNL());
+ }
+ List valueIds = new ArrayList();
+ if(null != criterionName && null != allCriteriaValues) {
+ Set criterionValues = (Set)allCriteriaValues.get(criterionName);
+ if(null != criterionValues && !criterionValues.isEmpty()) {
+ valueIds.addAll(criterionValues);
+ Collections.sort(valueIds);
+ valueIds.add(UNCATEGORIZED);
+ }
+ }
+ String[] valueIdsArray = new String[valueIds.size()];
+ valueIds.toArray(valueIdsArray);
+ return valueIdsArray;
+ }
+
+ public String getCriterionDisplayName(String criterionId) {
+ return HelpPlugin.getCriteriaManager().getCriterionDisplayName(criterionId, Platform.getNL());
+ }
+
+ public String getCriterionValueDisplayName(String criterionId, String criterionValueId) {
+ return HelpPlugin.getCriteriaManager().getCriterionValueDisplayName(criterionId, criterionValueId, Platform.getNL());
+ }
}
diff --git a/org.eclipse.help.webapp/advanced/workingSet.jsp b/org.eclipse.help.webapp/advanced/workingSet.jsp
index 3b59c3c6e..2e1901054 100644
--- a/org.eclipse.help.webapp/advanced/workingSet.jsp
+++ b/org.eclipse.help.webapp/advanced/workingSet.jsp
@@ -1,5 +1,5 @@
<%--
- Copyright (c) 2000, 2009 IBM Corporation and others.
+ Copyright (c) 2000, 2010 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
@@ -14,6 +14,7 @@
WorkingSetData data = new WorkingSetData(application, request, response);
TocData tocData = new TocData(application,request, response);
WebappPreferences prefs = data.getPrefs();
+ boolean isCriteriaEnable = data.isCriteriaScopeEnabled();
%>
@@ -67,6 +68,26 @@ INPUT {
border: 2px inset ThreeDHighlight;
margin:10px;
margin-top:2px;
+ margin-bottom: 0px;
+ padding-<%=isRTL?"right":"left"%>:5px;
+ overflow:auto;
+ height:350px;
+<%
+if (data.isIE()) {
+%>
+ width:100%;
+<%
+}
+%>
+}
+
+#criteriaContainer {
+ background:Window;
+ color:WindowText;
+ border: 2px inset ThreeDHighlight;
+ margin-<%=isRTL?"left":"right"%>:10px;
+ margin-top:2px;
+ margin-bottom: 0px;
padding-<%=isRTL?"right":"left"%>:5px;
overflow:auto;
height:350px;
@@ -90,14 +111,14 @@ if (data.isMozilla()) {
%>
}
-.book {
+.book, .criterion {
margin:0px;
border:0px;
padding:0px;
white-space: nowrap;
}
-.topic {
+.topic, .criterionValue {
margin-<%=isRTL?"right":"left"%>:30px;
border:0px;
padding:0px;
@@ -154,6 +175,8 @@ plus.src = "<%=prefs.getImagesDirectory()%>"+"/plus.gif";
var oldName = '<%=data.isEditMode()?UrlUtil.JavaScriptEncode(data.getWorkingSetName()):""%>';
var altBookClosed = "<%=UrlUtil.JavaScriptEncode(ServletResources.getString("bookClosed", request))%>";
var altBookOpen = "<%=UrlUtil.JavaScriptEncode(ServletResources.getString("bookOpen", request))%>";
+var altCriterionClosed = "<%=UrlUtil.JavaScriptEncode(ServletResources.getString("criterionClosed", request))%>";
+var altCriterionOpen = "<%=UrlUtil.JavaScriptEncode(ServletResources.getString("criterionOpen", request))%>";
function onloadHandler() {
<%if(!data.isMozilla() || "1.3".compareTo(data.getMozillaVersion()) <=0){
@@ -161,7 +184,7 @@ function onloadHandler() {
%>
sizeButtons();
<%}%>
- sizeBookContainer();
+ sizeContainer();
document.getElementById("workingSet").focus();
enableOK();
<%-- event handlers that call enableOK() are not invoked properly on Japanese --%>
@@ -180,8 +203,11 @@ function sizeButtons() {
}
}
-function sizeBookContainer() {
- resizeVertical("booksContainer", "wsTable", "buttonBar", 100, 20);
+function sizeContainer() {
+ resizeVertical("booksContainer", "wsTable", "buttonBar", 100, 30);
+ <%if(isCriteriaEnable){%>
+ resizeVertical("criteriaContainer", "wsTable", "buttonBar", 100, 30);
+ <%}%>
}
function doSubmit()
@@ -192,23 +218,25 @@ function doSubmit()
if (!workingSet || workingSet == "")
return false;
- var hrefs = getSelectedResources();
+ var hrefs = getSelectedContentResources();
if (!hrefs || hrefs == "")
return false;
- var query = "operation="+'<%=UrlUtil.JavaScriptEncode(data.getOperation())%>'+"&workingSet="+encodeURIComponent(workingSet)+ hrefs+"&oldName="+encodeURIComponent(oldName);
+ var criteria = getSelectedCriteriaResources();
+ var query = "operation="+'<%=UrlUtil.JavaScriptEncode(data.getOperation())%>'+"&workingSet="+encodeURIComponent(workingSet)+ hrefs+criteria+"&oldName="+encodeURIComponent(oldName);
window.opener.location.replace("workingSetManager.jsp?"+query);
window.opener.focus();
window.close();
} catch(ex) {alert("Error..." + ex.message)}
}
-function getSelectedResources() {
+function getSelectedContentResources() {
var hrefs = "";
var inputs = document.getElementsByTagName("INPUT");
for (var i=0; i<inputs.length; i++)
{
if (inputs[i].type != "checkbox") continue;
+ if (inputs[i].parentNode.id.indexOf("_criterion") > -1) continue;
if (inputs[i].checked == false) continue;
if (getGrayed(inputs[i])) continue;
if (isToc(inputs[i].name)) {
@@ -220,12 +248,42 @@ function getSelectedResources() {
return hrefs;
}
-// Assumption: last character of a toc reference cannot be underscore _
+//Assumption: last character of a toc reference cannot be underscore _
function isToc(name) {
return name.charAt(name.length-1) != "_";
}
function isParentTocSelected(name) {
+ return isParentCheckboxSelected(name);
+}
+
+function getSelectedCriteriaResources() {
+ var criteria = "";
+ var inputs = document.getElementsByTagName("INPUT");
+ for (var i=0; i<inputs.length; i++)
+ {
+ if (inputs[i].type != "checkbox") continue;
+ if (inputs[i].parentNode.id.indexOf("_criterion") < 0) continue;
+ if (inputs[i].checked == false) continue;
+ if (getGrayed(inputs[i])) continue;
+ if (isCriterionCategory(inputs[i].name)) {
+ criteria += "&criteria=" + encodeURIComponent(inputs[i].name);
+ } else if(!isParentTocSelected(inputs[i].name)){
+ criteria += "&criteria=" + encodeURIComponent(inputs[i].name);
+ }
+ }
+ return criteria;
+}
+
+function isCriterionCategory(name) {
+ return name.charAt(name.length-1) != "_";
+}
+
+function isParentCategorySelected(name){
+ return isParentCheckboxSelected(name);
+}
+
+function isParentCheckboxSelected(name) {
var parentCheckbox = getParentCheckbox(name);
return (parentCheckbox.checked && !getGrayed(parentCheckbox));
}
@@ -235,6 +293,13 @@ function getParentCheckbox(name) {
return document.getElementById(parentId);
}
+function isCriterionNode(nodeId){
+ if(nodeId && nodeId.indexOf("_criterion") > -1){
+ return true;
+ }
+ return false;
+}
+
function collapseOrExpand(nodeId) {
var node = document.getElementById("div"+nodeId);
var img = document.getElementById("img"+nodeId);
@@ -242,13 +307,23 @@ function collapseOrExpand(nodeId) {
if (node.className == "expanded") {
node.className = "collapsed";
img.src = plus.src;
- img.alt = altBookClosed;
- img.title = altBookClosed;
+ if(isCriterionNode(nodeId)){
+ img.alt = altCritrionClosed;
+ img.title = altCriterionClosed;
+ }else{
+ img.alt = altBookClosed;
+ img.title = altBookClosed;
+ }
} else {
node.className = "expanded";
img.src = minus.src;
- img.alt = altBookOpen;
- img.title = altBookOpen;
+ if(isCriterionNode(nodeId)){
+ img.alt = altCriterionOpen;
+ img.title = altCriterionOpen;
+ }else{
+ img.alt = altBookOpen;
+ img.title = altBookOpen;
+ }
}
}
@@ -258,8 +333,13 @@ function collapse(nodeId) {
if (!node || !img) return;
node.className = "collapsed";
img.src = plus.src;
- img.alt = altBookClosed;
- img.title = altBookClosed;
+ if(isCriterionNode(nodeId)){
+ img.alt = altCritrionClosed;
+ img.title = altCriterionClosed;
+ }else{
+ img.alt = altBookClosed;
+ img.title = altBookClosed;
+ }
}
function expand(nodeId) {
@@ -268,8 +348,13 @@ function expand(nodeId) {
if (!node || !img) return;
node.className = "expanded";
img.src = minus.src;
- img.alt = altBookOpen;
- img.title = altBookOpen;
+ if(isCriterionNode(nodeId)){
+ img.alt = altCriterionOpen;
+ img.title = altCriterionOpen;
+ }else{
+ img.alt = altBookOpen;
+ img.title = altBookOpen;
+ }
}
function getParent(child) {
@@ -364,8 +449,8 @@ function keyDownHandler(folderId, key, target)
return false;
}
-function hasSelections() {
- var hrefs = getSelectedResources();
+function hasContentSelections() {
+ var hrefs = getSelectedContentResources();
if (!hrefs || hrefs == "")
return false;
else
@@ -374,7 +459,7 @@ function hasSelections() {
function enableOK() {
var value = document.getElementById("workingSet").value;
- if (!value || value.length == 0 || value.charAt(0) == " " || !hasSelections())
+ if (!value || value.length == 0 || value.charAt(0) == " " || !hasContentSelections())
document.getElementById("ok").disabled = true;
else
document.getElementById("ok").disabled = false;
@@ -384,7 +469,7 @@ function enableOK() {
</head>
-<body dir="<%=direction%>" onload="onloadHandler()" onresize = "sizeBookContainer()">
+<body dir="<%=direction%>" onload="onloadHandler()" onresize = "sizeContainer()">
<form onsubmit="doSubmit();return false;">
<table id="wsTable" width="100%" cellspacing=0 cellpading=0 border=0 align=center >
<tr><td style="padding:5px 10px 0px 10px;"><label for="workingSet" accesskey="<%=ServletResources.getAccessKey("WorkingSetName", request)%>"><%=ServletResources.getLabel("WorkingSetName", request)%></label>
@@ -392,63 +477,139 @@ function enableOK() {
<tr><td style="padding:0px 10px;"><input type="text" id="workingSet" name="workingSet"
value='<%=data.isEditMode()?UrlUtil.htmlEncode(data.getWorkingSetName()):data.getDefaultName()%>' maxlength=256 alt='<%=ServletResources.getString("WorkingSetName", request)%>' title='<%=ServletResources.getString("WorkingSetName", request)%>' onkeyup="enableOK();return true;">
</td></tr>
- <tr><td><div id="selectBook" style="padding-top:5px; margin-<%=isRTL?"right":"left"%>:10px;"><%=ServletResources.getString("WorkingSetContent", request)%>:</div>
- </td></tr>
</table>
-<div id="booksContainer">
+ <table width="100%" cellspacing=0 cellpading=0 border=0 align=center style="table-layout:fixed;">
+ <tr>
+ <td>
+ <div id="selectBook" style="padding-top:5px; margin-<%=isRTL?"right":"left"%>:10px;"><%=ServletResources.getString("WorkingSetContent", request)%>:</div>
+ </td>
+ <%if(isCriteriaEnable){ %>
+ <td width="50%">
+ <div id="selectCriteria" style="padding-top:5px;"><%=ServletResources.getString("Criteria", request)%>:</div>
+ </td>
+ <% }%>
+ </tr>
+ <tr>
+ <td>
+ <div id="booksContainer">
+ <% for (int i=0; i<data.getTocCount(); i++){
+ if(!tocData.isEnabled(i)){
+ // do not show
+ continue;
+ }
+ String label = data.getTocLabel(i);
+ short state = data.getTocState(i);
+ String checked = state == WorkingSetData.STATE_CHECKED || state == WorkingSetData.STATE_GRAYED ? "checked" : "";
+ String className = state == WorkingSetData.STATE_GRAYED ? "grayed" : "checkbox";
+ %>
+ <div class="book" id='<%="id"+i%>' >
+ <img id='<%="img"+i%>' alt="<%=ServletResources.getString("bookClosed", request)%>" title="<%=ServletResources.getString("bookClosed", request)%>" src="<%=prefs.getImagesDirectory()%>/plus.gif" onclick="collapseOrExpand('<%=i%>')">
+ <input class='<%=className%>'
+ type="checkbox"
+ id='<%=UrlUtil.htmlEncode(data.getTocHref(i))%>'
+ name='<%=UrlUtil.htmlEncode(data.getTocHref(i))%>'
+ alt="<%=UrlUtil.htmlEncode(label)%>" <%=checked%>
+ onkeydown="keyDownHandler(<%=i%>, event.keyCode, this)"
+ onclick="setSubtreeChecked(this, '<%="div"+i%>')">
+ <label for="<%=UrlUtil.htmlEncode(data.getTocHref(i))%>"><%=UrlUtil.htmlEncode(label)%></label>
+ <div id='<%="div"+i%>' class="collapsed">
+ <%
+ for (int topic=0; topic<data.getTopicCount(i); topic++)
+ {
+ String topicLabel = data.getTopicLabel(i, topic);
+ String topicChecked = (state == WorkingSetData.STATE_CHECKED) ||
+ (state == WorkingSetData.STATE_GRAYED && data.getTopicState(i,topic) == WorkingSetData.STATE_CHECKED)
+ ? "checked" : "";
+ %>
+ <div class="topic" id='<%="id"+i+"_"+topic%>'>
+ <input class="checkbox"
+ type="checkbox"
+ id='<%=UrlUtil.htmlEncode(data.getTocHref(i))+"_"+topic+"_"%>'
+ name='<%=UrlUtil.htmlEncode(data.getTocHref(i))+"_"+topic+"_"%>'
+ alt="<%=UrlUtil.htmlEncode(topicLabel)%>" <%=topicChecked%>
+ onkeydown="keyDownHandler(<%=i%>, event.keyCode, this)"
+ onclick="updateParentState(this, '<%="div"+i%>')">
+ <label for="<%=UrlUtil.htmlEncode(data.getTocHref(i))+"_"+topic+"_"%>"><%=UrlUtil.htmlEncode(topicLabel)%></label>
+ </div>
+ <%
+ }
+ %>
+ </div>
+ </div>
+ <%
+ }
+ %>
+ </div>
+ </td>
+ <%if(isCriteriaEnable){ %>
+ <td width="50%">
+ <div id="criteriaContainer">
+ <%
+ String[] category = data.getCriterionIds();
+ for (int i=0; i < category.length; i++){
+ String criterionId = category[i];
+ if(null == criterionId || 0 == criterionId.trim().length()){
+ // do not show
+ continue;
+ }
+
+ short categoryState = data.getCriterionCategoryState(i);
+ String categoryChecked = categoryState == WorkingSetData.STATE_CHECKED || categoryState == WorkingSetData.STATE_GRAYED ? "checked" : "";
+ String inputClassName = categoryState == WorkingSetData.STATE_GRAYED ? "grayed" : "checkbox";
+ String criterionDisplayName = data.getCriterionDisplayName(criterionId);
+ %>
+ <div class="criterion" id='<%="id_criterion"+i%>' >
+ <img id='<%="img_criterion"+i%>' alt="<%=ServletResources.getString("criterionClosed", request)%>" title="<%=ServletResources.getString("criterionClosed", request)%>" src="<%=prefs.getImagesDirectory()%>/plus.gif" onclick="collapseOrExpand('_criterion'+'<%=i%>')">
+ <input class='<%=inputClassName%>'
+ type="checkbox"
+ id='<%=UrlUtil.htmlEncode(criterionId)%>'
+ name='<%=UrlUtil.htmlEncode(criterionId)%>'
+ alt="<%=UrlUtil.htmlEncode(criterionDisplayName)%>" <%=categoryChecked%>
+ onkeydown="keyDownHandler('_criterion'+<%=i%>, event.keyCode, this)"
+ onclick="setSubtreeChecked(this, '<%="div_criterion"+i%>')">
+ <label for="<%=UrlUtil.htmlEncode(criterionId)%>"><%=UrlUtil.htmlEncode(criterionDisplayName)%></label>
+ <div id='<%="div_criterion"+i%>' class="collapsed">
+ <%
+ String[] criterionValueIds = data.getCriterionValueIds(criterionId);
+ for (int j=0; j<criterionValueIds.length; j++)
+ {
+ String criterionValue = criterionValueIds[j];
+ String valueChecked = (categoryState == WorkingSetData.STATE_CHECKED) ||
+ (categoryState == WorkingSetData.STATE_GRAYED && data.getCriterionValueState(i,j) == WorkingSetData.STATE_CHECKED)
+ ? "checked" : "";
+ String criterionValueDisplayName ="";
+ if(criterionValue.equalsIgnoreCase("Uncategorized")){
+ criterionValueDisplayName = ServletResources.getString("Uncategorized", request);
+ } else {
+ criterionValueDisplayName = data.getCriterionValueDisplayName(criterionId, criterionValue);
+ }
+ %>
+ <div class="criterionValue" id='<%="id_criterion"+i+"_"+j%>'>
+ <input class="checkbox"
+ type="checkbox"
+ id='<%=UrlUtil.htmlEncode(criterionId)+"_"+j+"_"%>'
+ name='<%=UrlUtil.htmlEncode(criterionId)+"_"+j+"_"%>'
+ alt="<%=UrlUtil.htmlEncode(criterionValueDisplayName)%>" <%=valueChecked%>
+ onkeydown="keyDownHandler('_criterion'+<%=i%>, event.keyCode, this)"
+ onclick="updateParentState(this, '<%="div_criterion"+i%>')">
+ <label for="<%=UrlUtil.htmlEncode(criterionId)+"_"+j+"_"%>"><%=UrlUtil.htmlEncode(criterionValueDisplayName)%></label>
+ </div>
+ <%
+ }
+ %>
+ </div>
+ </div>
+ <%
+ }
+ %>
+ </div>
+ </td>
+ <% }%>
+ </tr>
-<%
-for (int i=0; i<data.getTocCount(); i++)
-{
- if(!tocData.isEnabled(i)){
- // do not show
- continue;
- }
- String label = data.getTocLabel(i);
- short state = data.getTocState(i);
- String checked = state == WorkingSetData.STATE_CHECKED || state == WorkingSetData.STATE_GRAYED ? "checked" : "";
- String className = state == WorkingSetData.STATE_GRAYED ? "grayed" : "checkbox";
-%>
- <div class="book" id='<%="id"+i%>' >
- <img id='<%="img"+i%>' alt="<%=ServletResources.getString("bookClosed", request)%>" title="<%=ServletResources.getString("bookClosed", request)%>" src="<%=prefs.getImagesDirectory()%>/plus.gif" onclick="collapseOrExpand('<%=i%>')">
- <input class='<%=className%>'
- type="checkbox"
- id='<%=UrlUtil.htmlEncode(data.getTocHref(i))%>'
- name='<%=UrlUtil.htmlEncode(data.getTocHref(i))%>'
- alt="<%=UrlUtil.htmlEncode(label)%>" <%=checked%>
- onkeydown="keyDownHandler(<%=i%>, event.keyCode, this)"
- onclick="setSubtreeChecked(this, '<%="div"+i%>')">
- <label for="<%=UrlUtil.htmlEncode(data.getTocHref(i))%>"><%=UrlUtil.htmlEncode(label)%></label>
- <div id='<%="div"+i%>' class="collapsed">
-<%
- for (int topic=0; topic<data.getTopicCount(i); topic++)
- {
- String topicLabel = data.getTopicLabel(i, topic);
- String topicChecked = (state == WorkingSetData.STATE_CHECKED) ||
- (state == WorkingSetData.STATE_GRAYED && data.getTopicState(i,topic) == WorkingSetData.STATE_CHECKED)
- ? "checked" : "";
-%>
- <div class="topic" id='<%="id"+i+"_"+topic%>'>
- <input class="checkbox"
- type="checkbox"
- id='<%=UrlUtil.htmlEncode(data.getTocHref(i))+"_"+topic+"_"%>'
- name='<%=UrlUtil.htmlEncode(data.getTocHref(i))+"_"+topic+"_"%>'
- alt="<%=UrlUtil.htmlEncode(topicLabel)%>" <%=topicChecked%>
- onkeydown="keyDownHandler(<%=i%>, event.keyCode, this)"
- onclick="updateParentState(this, '<%="div"+i%>')">
- <label for="<%=UrlUtil.htmlEncode(data.getTocHref(i))+"_"+topic+"_"%>"><%=UrlUtil.htmlEncode(topicLabel)%></label>
- </div>
-<%
- }
-%>
- </div>
- </div>
-<%
-}
-%>
+ </table>
-</div>
<div id="buttonBar" >
<table valign="bottom" align="<%=isRTL?"left":"right"%>">
<tr id="buttonsTable" valign="bottom"><td valign="bottom" align="<%=isRTL?"left":"right"%>">
diff --git a/org.eclipse.help.webapp/advanced/workingSetManager.jsp b/org.eclipse.help.webapp/advanced/workingSetManager.jsp
index 85d5c05c7..db20e7b74 100644
--- a/org.eclipse.help.webapp/advanced/workingSetManager.jsp
+++ b/org.eclipse.help.webapp/advanced/workingSetManager.jsp
@@ -1,5 +1,5 @@
<%--
- Copyright (c) 2000, 2009 IBM Corporation and others.
+ Copyright (c) 2000, 2010 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
@@ -14,6 +14,7 @@
WorkingSetManagerData data = new WorkingSetManagerData(application, request, response);
WebappPreferences prefs = data.getPrefs();
String dataSaveError = data.getSaveError();
+ boolean showCriteriaScope = data.isCriteriaScopeEnabled();
%>
@@ -207,7 +208,7 @@ function removeWorkingSet() {
}
var workingSetDialog;
-var w = 300;
+var w = <%=showCriteriaScope%>? 640:320;
var h = 500;
function newWorkingSet() {
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/WebappResources.properties b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/WebappResources.properties
index 16fe949ab..3fae297dd 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/WebappResources.properties
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/WebappResources.properties
@@ -191,3 +191,9 @@ noConnection=The maximum capacity for active connections to the server has been
ioException=An error occured during content retrieval.\n
alert=Alert
error=Error
+
+#criteria
+Uncategorized=Uncategorized
+criterionClosed=Criterion closed
+criterionOpen=Criterion open
+Criteria=Criteria
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/WorkingSetData.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/WorkingSetData.java
index 3de794b61..8d30274dd 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/WorkingSetData.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/WorkingSetData.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -10,11 +10,24 @@
*******************************************************************************/
package org.eclipse.help.internal.webapp.data;
-import javax.servlet.*;
-import javax.servlet.http.*;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
-import org.eclipse.help.internal.webapp.servlet.*;
-import org.eclipse.help.internal.workingset.*;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.help.internal.base.util.CriteriaUtilities;
+import org.eclipse.help.internal.criteria.CriterionResource;
+import org.eclipse.help.internal.webapp.servlet.WebappWorkingSetManager;
+import org.eclipse.help.internal.workingset.AdaptableHelpResource;
+import org.eclipse.help.internal.workingset.AdaptableToc;
+import org.eclipse.help.internal.workingset.AdaptableTocsArray;
+import org.eclipse.help.internal.workingset.AdaptableTopic;
+import org.eclipse.help.internal.workingset.WorkingSet;
/**
* This class manages help working sets
@@ -164,4 +177,81 @@ public class WorkingSetData extends RequestData {
return ""; //$NON-NLS-1$
}
+ public boolean isCriteriaScopeEnabled(){
+ return wsmgr.isCriteriaScopeEnabled();
+ }
+
+ public String[] getCriterionIds() {
+ return wsmgr.getCriterionIds();
+ }
+
+
+ public String[] getCriterionValueIds(String criterionId) {
+ return wsmgr.getCriterionValueIds(criterionId);
+ }
+
+
+ public String getCriterionDisplayName(String criterionId) {
+ return wsmgr.getCriterionDisplayName(criterionId);
+ }
+
+ public String getCriterionValueDisplayName(String criterionId, String criterionValueId) {
+ return wsmgr.getCriterionValueDisplayName(criterionId, criterionValueId);
+ }
+
+ public short getCriterionCategoryState(int index) {
+ String[] categories = getCriterionIds();
+
+ if (!isEditMode())
+ return STATE_UNCHECKED;
+ WorkingSet ws = getWorkingSet();
+ if (ws == null)
+ return STATE_UNCHECKED;
+ if (index < 0 || index >= categories.length)
+ return STATE_UNCHECKED;
+
+ String category = categories[index];
+ Map criteriaMap = new HashMap();
+ CriterionResource[] criteria = ws.getCriteria();
+ CriteriaUtilities.addCriteriaToMap(criteriaMap, criteria);
+ if(!criteriaMap.keySet().contains(category))
+ return STATE_UNCHECKED;
+
+ Set criterionValuesFromWS = (Set) criteriaMap.get(category);
+ Set criterionValuesSet = new HashSet(Arrays.asList(getCriterionValueIds(category)));
+ if(criterionValuesFromWS.containsAll(criterionValuesSet)){
+ return STATE_CHECKED;
+ }else{
+ return STATE_GRAYED;
+ }
+ }
+
+ public short getCriterionValueState(int categoryIndex, int valueIndex) {
+ String[] categories = getCriterionIds();
+ if (!isEditMode)
+ return STATE_UNCHECKED;
+ WorkingSet ws = getWorkingSet();
+ if (ws == null)
+ return STATE_UNCHECKED;
+ if (categoryIndex < 0 || categoryIndex >= categories.length)
+ return STATE_UNCHECKED;
+
+ String category = categories[categoryIndex];
+ Map criteriaMap = new HashMap();
+ CriterionResource[] criteria = ws.getCriteria();
+ CriteriaUtilities.addCriteriaToMap(criteriaMap, criteria);
+
+ Set criterionValuesFromWS = (Set) criteriaMap.get(category);
+ String[] crietriaValues = getCriterionValueIds(category);
+ if (valueIndex < 0 || valueIndex >= crietriaValues.length){
+ return STATE_UNCHECKED;
+ }
+ String relatedCriterionValue = crietriaValues[valueIndex];
+ if(criterionValuesFromWS.contains(relatedCriterionValue)){
+ return STATE_CHECKED;
+ }else{
+ return STATE_UNCHECKED;
+ }
+ }
+
}
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/WorkingSetManagerData.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/WorkingSetManagerData.java
index 48c49c48f..8ca95b09d 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/WorkingSetManagerData.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/WorkingSetManagerData.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -10,14 +10,24 @@
*******************************************************************************/
package org.eclipse.help.internal.webapp.data;
-import java.io.*;
-import java.util.*;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
-import javax.servlet.*;
-import javax.servlet.http.*;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
-import org.eclipse.help.internal.webapp.servlet.*;
-import org.eclipse.help.internal.workingset.*;
+import org.eclipse.help.internal.criteria.CriterionResource;
+import org.eclipse.help.internal.webapp.servlet.WebappWorkingSetManager;
+import org.eclipse.help.internal.workingset.AdaptableHelpResource;
+import org.eclipse.help.internal.workingset.WorkingSet;
/**
* This class manages help working sets
@@ -40,17 +50,17 @@ public class WorkingSetManagerData extends RequestData {
name = request.getParameter("workingSet"); //$NON-NLS-1$
try {
switch (getOperation()) {
- case ADD :
- addWorkingSet();
- break;
- case REMOVE :
- removeWorkingSet();
- break;
- case EDIT :
- editWorkingSet();
- break;
- default :
- break;
+ case ADD:
+ addWorkingSet();
+ break;
+ case REMOVE:
+ removeWorkingSet();
+ break;
+ case EDIT:
+ editWorkingSet();
+ break;
+ default:
+ break;
}
} catch (IOException ioe) {
saved = false;
@@ -74,7 +84,15 @@ public class WorkingSetManagerData extends RequestData {
AdaptableHelpResource[] elements = new AdaptableHelpResource[selectedElements
.size()];
selectedElements.toArray(elements);
- WorkingSet ws = wsmgr.createWorkingSet(name, elements);
+
+ WorkingSet ws = null;
+ if(!isCriteriaScopeEnabled()) {
+ ws = wsmgr.createWorkingSet(name, elements);
+ } else {
+ CriterionResource[] criteria = getCriteriaResource();
+ ws = wsmgr.createWorkingSet(name, elements, criteria);
+ }
+
wsmgr.addWorkingSet(ws);
}
}
@@ -113,6 +131,10 @@ public class WorkingSetManagerData extends RequestData {
ws.setElements(elements);
ws.setName(name);
+
+ if(isCriteriaScopeEnabled()){
+ ws.setCriteria(getCriteriaResource());
+ }
// should also change the name....
// We send this notification, so that the manager fires to its
@@ -171,6 +193,7 @@ public class WorkingSetManagerData extends RequestData {
res = wsmgr.getAdaptableTopic(internalId);
return res;
}
+
/**
* @return null or error message if saving saved
*/
@@ -181,4 +204,85 @@ public class WorkingSetManagerData extends RequestData {
return UrlUtil.JavaScriptEncode(ServletResources.getString(
"cookieSaveFailed", request)); //$NON-NLS-1$
}
+
+ private CriterionResource[] getCriteriaResource(){
+ // all values in one criterion selected: version
+ // one criterion value selected(based on criterion category name and index of the value)
+ // eg:version_1_
+ List category = Arrays.asList(getCriterionIds());
+
+ String[] criteria = request.getParameterValues("criteria"); //$NON-NLS-1$
+ if (criteria == null)
+ criteria = new String[0];
+
+ Map selectedElements = new HashMap();
+ for (int i = 0; i < criteria.length; ++i) {
+ String criterion = criteria[i];
+ if(category.contains(criterion)){
+ List allValuesInCategory = Arrays.asList(getCriterionValueIds(criterion));
+ if(0 == allValuesInCategory.size()){
+ continue;
+ }
+ Set elements = (Set)selectedElements.get(criterion);
+ if(null == elements){
+ elements = new HashSet();
+ }
+ elements.addAll(allValuesInCategory);
+ selectedElements.put(criterion, elements);
+ }else{
+ int len = criterion.length();
+ if (criterion.charAt(len - 1) == '_') {
+ String indexStr = criterion.substring(criterion.lastIndexOf('_', len - 2) + 1, len - 1);
+ int index = 0;
+ try {
+ index = Integer.parseInt(indexStr);
+ } catch (Exception e) {
+ continue;
+ }
+
+ String criterionName = criterion.substring(0, criterion.lastIndexOf('_', len - 2));
+ if(category.contains(criterionName)){
+ String values[] = getCriterionValueIds(criterionName);
+ if (index < 0 || index >= values.length)
+ continue;
+ String selectedValue = values[index];
+ if(null == selectedValue || 0 == selectedValue.length())
+ continue;
+ Set existedElements = (Set)selectedElements.get(criterionName);
+ if(null == existedElements){
+ existedElements = new HashSet();
+ }
+ existedElements.add(selectedValue);
+ selectedElements.put(criterionName, existedElements);
+ }
+ }
+ }
+ }
+
+
+ List resources = new ArrayList();
+ for(Iterator iter = selectedElements.keySet().iterator(); iter.hasNext();){
+ String key = (String)iter.next();
+ Set values = (Set) selectedElements.get(key);
+ CriterionResource resource = new CriterionResource(key, new ArrayList(values));
+ resources.add(resource);
+ }
+
+ CriterionResource[] processedResources = new CriterionResource[resources.size()];
+ resources.toArray(processedResources);
+ return processedResources;
+
+ }
+
+ public boolean isCriteriaScopeEnabled() {
+ return wsmgr.isCriteriaScopeEnabled();
+ }
+
+ private String[] getCriterionIds() {
+ return wsmgr.getCriterionIds();
+ }
+
+ private String[] getCriterionValueIds(String criterionId) {
+ return wsmgr.getCriterionValueIds(criterionId);
+ }
}
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/CookieUtil.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/CookieUtil.java
index 8f3b2ac6a..4ff68dcf9 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/CookieUtil.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/CookieUtil.java
@@ -25,7 +25,7 @@ import org.eclipse.help.internal.webapp.data.*;
public class CookieUtil {
private static final int COOKIE_LIFE = 5 * 365 * 24 * 60 * 60;
private static final int MAX_COOKIE_PAYLOAD = 4096
- - "wset01=".length() - "81920<".length() - 1; //$NON-NLS-1$ //$NON-NLS-2$
+ - "wset_contents01=".length() - "81920<".length() - 1; //$NON-NLS-1$ //$NON-NLS-2$
/**
* @return null or String
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InfocenterWorkingSetManager.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InfocenterWorkingSetManager.java
index 501ad1292..e0897724d 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InfocenterWorkingSetManager.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/InfocenterWorkingSetManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -10,16 +10,32 @@
*******************************************************************************/
package org.eclipse.help.internal.webapp.servlet;
-import java.io.*;
-import java.util.*;
-
-import javax.servlet.http.*;
-
-import org.eclipse.core.runtime.*;
-import org.eclipse.help.internal.*;
-import org.eclipse.help.internal.util.*;
-import org.eclipse.help.internal.webapp.*;
-import org.eclipse.help.internal.workingset.*;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.criteria.CriterionResource;
+import org.eclipse.help.internal.util.URLCoder;
+import org.eclipse.help.internal.webapp.HelpWebappPlugin;
+import org.eclipse.help.internal.workingset.AdaptableHelpResource;
+import org.eclipse.help.internal.workingset.AdaptableToc;
+import org.eclipse.help.internal.workingset.AdaptableTocsArray;
+import org.eclipse.help.internal.workingset.AdaptableTopic;
+import org.eclipse.help.internal.workingset.IHelpWorkingSetManager;
+import org.eclipse.help.internal.workingset.WorkingSet;
+import org.eclipse.help.internal.workingset.WorkingSetComparator;
/**
* The Infocenter working set manager stores help working sets. Working sets are
@@ -28,7 +44,8 @@ import org.eclipse.help.internal.workingset.*;
* @since 3.0
*/
public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
- private static final String COOKIE_NAME = "wset"; //$NON-NLS-1$
+ private static final String COOKIE_WSET_CONTENTS = "wset_contents"; //$NON-NLS-1$
+ private static final String COOKIE_WSET_CRITERIA = "wset_criteria"; //$NON-NLS-1$
private static final int MAX_COOKIES = 15;
private HttpServletRequest request;
private HttpServletResponse response;
@@ -38,6 +55,9 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
private SortedSet workingSets = new TreeSet(new WorkingSetComparator());
private String locale;
private AdaptableTocsArray root;
+
+ private static final String UNCATEGORIZED = "Uncategorized"; //$NON-NLS-1$
+ private Map allCriteriaValues;
/**
* Constructor
@@ -77,6 +97,10 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
return new WorkingSet(name, elements);
}
+ public WorkingSet createWorkingSet(String name, AdaptableHelpResource[] elements, CriterionResource[] criteria) {
+ return new WorkingSet(name, elements, criteria);
+ }
+
/**
* Returns a working set by name
*
@@ -115,8 +139,13 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
}
}
- private void restoreState() {
- String data = CookieUtil.restoreString(COOKIE_NAME, request);
+ private void restoreState() {
+ restoreContents();
+ restoreCriteria();
+ }
+
+ private void restoreContents(){
+ String data = CookieUtil.restoreString(COOKIE_WSET_CONTENTS, request);
if (data == null) {
return;
}
@@ -125,36 +154,75 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
if (values.length < 1) {
return;
}
- currentWorkingSet = URLCoder.decode(values[0] /* , "UTF8" */
- );
+
+ currentWorkingSet = URLCoder.decode(values[0]);
i : for (int i = 1; i < values.length; i++) {
String[] nameAndHrefs = values[i].split("&", -1); //$NON-NLS-1$
- String name = URLCoder.decode(nameAndHrefs[0] /* , "UTF8" */
- );
+ String name = URLCoder.decode(nameAndHrefs[0]);
AdaptableHelpResource[] elements = new AdaptableHelpResource[nameAndHrefs.length - 1];
// for each href (working set resource)
for (int e = 0; e < nameAndHrefs.length - 1; e++) {
int h = e + 1;
- elements[e] = getAdaptableToc(URLCoder.decode(nameAndHrefs[h]
- /* , "UTF8" */
- ));
+ elements[e] = getAdaptableToc(URLCoder.decode(nameAndHrefs[h]));
if (elements[e] == null) {
- elements[e] = getAdaptableTopic(URLCoder
- .decode(nameAndHrefs[h]
- /* , "UTF8" */
- ));
+ elements[e] = getAdaptableTopic(URLCoder.decode(nameAndHrefs[h]));
}
if (elements[e] == null) {
// working set cannot be restored
continue i;
}
}
- WorkingSet ws = createWorkingSet(name, elements);
+ WorkingSet ws = createWorkingSet(name, elements, null);
workingSets.add(ws);
}
}
+
+ private void restoreCriteria(){
+
+ String data = CookieUtil.restoreString(COOKIE_WSET_CRITERIA, request);
+ if (data == null) {
+ return;
+ }
+ String[] values = data.split("\\|", -1); //$NON-NLS-1$
+ if (values.length < 1) {
+ return;
+ }
+ //scope1$platform#AIX,WINDOWS,$version#1.0,2.0,
+ for (int i = 1; i < values.length; ++i) {
+ String[] nameAndCriteria = values[i].split("\\$", -1); //$NON-NLS-1$
+ if(nameAndCriteria.length < 2){
+ continue;
+ }
+ String name = URLCoder.decode(nameAndCriteria[0]);
+ List criteriaResource = new ArrayList();
+ for (int j = 1; j < nameAndCriteria.length; ++j) {
+ String criterion = nameAndCriteria[j];
+ String[] keyAndValue = criterion.split("#", -1); //$NON-NLS-1$
+ if(keyAndValue.length != 2)
+ continue;
+ String key = URLCoder.decode(keyAndValue[0]);
+ String value = URLCoder.decode(keyAndValue[1]);
+ if(HelpPlugin.getCriteriaManager().isSupportedCriterion(key)){
+ String[] criterionValues = value.split(",", -1); //$NON-NLS-1$
+ if(criterionValues.length < 1)
+ continue;
+
+ List criterionValuesList = Arrays.asList(criterionValues);
+ CriterionResource criterionResource = new CriterionResource(key, criterionValuesList);
+ criteriaResource.add(criterionResource);
+ }
+ }
+
+ WorkingSet workingset = getWorkingSet(name);
+ if(workingset != null){
+ CriterionResource[] criteria = new CriterionResource[criteriaResource.size()];
+ criteriaResource.toArray(criteria);
+ workingset.setCriteria(criteria);
+ }
+ }
+ }
/***************************************************************************
* Persists all working sets. Should only be called by the webapp working
@@ -162,6 +230,12 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
* format: curentWorkingSetName|name1&href11&href12|name2&href22
*/
private void saveState() throws IOException {
+ saveContents();
+ saveCriteria();
+ }
+
+ private void saveContents() throws IOException {
+
StringBuffer data = new StringBuffer();
data.append(URLCoder.encode(currentWorkingSet /* , "UTF8" */
));
@@ -200,19 +274,54 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
}
}
}
-
+
+ saveToCookie(COOKIE_WSET_CONTENTS, data.toString());
+ }
+
+ private void saveCriteria() throws IOException {
+
+ StringBuffer data = new StringBuffer();
+ data.append(URLCoder.encode(currentWorkingSet));
+ //|scope1$platform#AIX,WINDOWS,$version#1.0,2.0,
+ for (Iterator i = workingSets.iterator(); i.hasNext();) {
+ data.append('|');
+ WorkingSet ws = (WorkingSet) i.next();
+ data.append(URLCoder.encode(ws.getName()));
+
+ CriterionResource[] criteria = ws.getCriteria();
+ for (int j = 0; j < criteria.length; ++ j){
+ CriterionResource criterion = criteria[j];
+ String criterionName = criterion.getCriterionName();
+ List criterionValues = criterion.getCriterionValues();
+ if(null != criterionValues && !criterionValues.isEmpty()){
+ data.append('$');
+ data.append(URLCoder.encode(criterionName));
+ data.append('#');
+ for (Iterator iter = criterionValues.iterator(); iter.hasNext();) {
+ String value = (String) iter.next();
+ data.append(URLCoder.encode(value));
+ data.append(',');
+ }
+ }
+ }
+ }
+
+ saveToCookie(COOKIE_WSET_CRITERIA, data.toString());
+ }
+
+ private void saveToCookie(String name, String data) throws IOException{
+
try {
- CookieUtil.saveString(COOKIE_NAME, data.toString(), MAX_COOKIES,
- request, response);
+ CookieUtil.saveString(name, data, MAX_COOKIES, request, response);
} catch (IOException ioe) {
if (HelpWebappPlugin.DEBUG_WORKINGSETS) {
- System.out
- .println("InfocenterWorkingSetManager.saveState(): Too much data to save: " //$NON-NLS-1$
- + data.toString());
+ String msg = "InfocenterWorkingSetManager.saveState(): Too much data to save: " + data; //$NON-NLS-1$
+ System.out.println(msg);
}
throw ioe;
}
}
+
/**
* *
@@ -273,4 +382,62 @@ public class InfocenterWorkingSetManager implements IHelpWorkingSetManager {
}
}
+ public boolean isCriteriaScopeEnabled(){
+ if(null == allCriteriaValues){
+ allCriteriaValues = HelpPlugin.getCriteriaManager().getAllCriteriaValues(locale);
+ }
+ if(HelpPlugin.getCriteriaManager().isCriteriaEnabled() && !allCriteriaValues.isEmpty()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public String[] getCriterionIds() {
+ if(null == allCriteriaValues){
+ allCriteriaValues = HelpPlugin.getCriteriaManager().getAllCriteriaValues(locale);
+ }
+ List criterionIds = new ArrayList();
+ if(null != allCriteriaValues){
+ for(Iterator iter = allCriteriaValues.keySet().iterator(); iter.hasNext();){
+ String criterion = (String) iter.next();
+ if(null == criterion || 0 == criterion.length() || 0 == getCriterionValueIds(criterion).length)
+ continue;
+ criterionIds.add(criterion);
+ }
+ Collections.sort(criterionIds);
+ }
+ String[] ids = new String[criterionIds.size()];
+ criterionIds.toArray(ids);
+ return ids;
+ }
+
+
+ public String[] getCriterionValueIds(String criterionName) {
+ if(null == allCriteriaValues){
+ allCriteriaValues = HelpPlugin.getCriteriaManager().getAllCriteriaValues(locale);
+ }
+ List valueIds = new ArrayList();
+ if(null != criterionName && null != allCriteriaValues) {
+ Set criterionValues = (Set)allCriteriaValues.get(criterionName);
+ if(null != criterionValues && !criterionValues.isEmpty()) {
+ valueIds.addAll(criterionValues);
+ Collections.sort(valueIds);
+ valueIds.add(UNCATEGORIZED);
+ }
+ }
+ String[] valueIdsArray = new String[valueIds.size()];
+ valueIds.toArray(valueIdsArray);
+ return valueIdsArray;
+ }
+
+
+ public String getCriterionDisplayName(String criterionId) {
+ return HelpPlugin.getCriteriaManager().getCriterionDisplayName(criterionId, locale);
+ }
+
+ public String getCriterionValueDisplayName(String criterionId, String criterionValueId) {
+ return HelpPlugin.getCriteriaManager().getCriterionValueDisplayName(criterionId, criterionValueId, locale);
+ }
+
}
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/WebappWorkingSetManager.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/WebappWorkingSetManager.java
index 0da476a7c..22baa4c50 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/WebappWorkingSetManager.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/WebappWorkingSetManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -10,12 +10,19 @@
*******************************************************************************/
package org.eclipse.help.internal.webapp.servlet;
-import java.io.*;
+import java.io.IOException;
-import javax.servlet.http.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
-import org.eclipse.help.internal.base.*;
-import org.eclipse.help.internal.workingset.*;
+import org.eclipse.help.internal.base.BaseHelpSystem;
+import org.eclipse.help.internal.criteria.CriterionResource;
+import org.eclipse.help.internal.workingset.AdaptableHelpResource;
+import org.eclipse.help.internal.workingset.AdaptableToc;
+import org.eclipse.help.internal.workingset.AdaptableTocsArray;
+import org.eclipse.help.internal.workingset.AdaptableTopic;
+import org.eclipse.help.internal.workingset.IHelpWorkingSetManager;
+import org.eclipse.help.internal.workingset.WorkingSet;
/**
* Proxy for WorkingSetManager or InfocenterWorkingSetManager.
@@ -61,6 +68,10 @@ public class WebappWorkingSetManager implements IHelpWorkingSetManager {
return wSetManager.createWorkingSet(name, elements);
}
+ public WorkingSet createWorkingSet(String name, AdaptableHelpResource[] elements, CriterionResource[] criteria) {
+ return wSetManager.createWorkingSet(name, elements, criteria);
+ }
+
/**
* Returns a working set by name
*
@@ -110,5 +121,28 @@ public class WebappWorkingSetManager implements IHelpWorkingSetManager {
public void setCurrentWorkingSet(String scope) {
wSetManager.setCurrentWorkingSet(scope);
}
+
+ public boolean isCriteriaScopeEnabled(){
+ return wSetManager.isCriteriaScopeEnabled();
+ }
+
+ public String[] getCriterionIds() {
+ return wSetManager.getCriterionIds();
+ }
+
+
+ public String[] getCriterionValueIds(String criterionId) {
+ return wSetManager.getCriterionValueIds(criterionId);
+ }
+
+
+ public String getCriterionDisplayName(String criterionId) {
+ return wSetManager.getCriterionDisplayName(criterionId);
+ }
+
+ public String getCriterionValueDisplayName(String criterionId, String criterionValueId) {
+ return wSetManager.getCriterionValueDisplayName(criterionId, criterionValueId);
+ }
+
}
diff --git a/org.eclipse.help/plugin.xml b/org.eclipse.help/plugin.xml
index 4d2823b1d..0bb76a8d9 100644
--- a/org.eclipse.help/plugin.xml
+++ b/org.eclipse.help/plugin.xml
@@ -17,7 +17,7 @@
<extension-point id="contexts" name="%contexts_extension_point_name" schema="schema/contexts.exsd"/>
<extension-point id="index" name="%index_extension_point_name" schema="schema/index.exsd"/>
<extension-point id="toc" name="%toc_extension_point_name" schema="schema/toc.exsd"/>
-
+ <extension-point id="criteriaDefinition" name="%criteriaDefinition_extension_point_name" schema="schema/criteriaDefinition.exsd"/>
<extension
point="org.eclipse.help.contentExtension">
<contentExtensionProvider class="org.eclipse.help.internal.extension.ContentExtensionFileProvider"/>
@@ -38,4 +38,11 @@
<tocProvider class="org.eclipse.help.internal.toc.TocFileProvider"/>
</extension>
+ <extension
+ point="org.eclipse.help.criteriaDefinition">
+ <criteriaDefinitionProvider
+ class="org.eclipse.help.internal.criteria.CriteriaDefinitionFileProvider">
+ </criteriaDefinitionProvider>
+ </extension>
+
</plugin>
diff --git a/org.eclipse.help/preferences.ini b/org.eclipse.help/preferences.ini
index 8f4b0d12e..4affb91bd 100644
--- a/org.eclipse.help/preferences.ini
+++ b/org.eclipse.help/preferences.ini
@@ -4,3 +4,10 @@
# as /pluginId/path/to/toc.xml. This option is deprecated,
# use org.eclipse.help.base.HELP_DATA instead
baseTOCS=
+
+# Filtering by criteria
+# Set true to enable criteria filtering, otherwise set false
+enableCriteria=false
+
+# List all the supported criteria names, separated by comma
+supportedCriteria= \ No newline at end of file
diff --git a/org.eclipse.help/schema/criteriaDefinition.exsd b/org.eclipse.help/schema/criteriaDefinition.exsd
new file mode 100644
index 000000000..1617d875f
--- /dev/null
+++ b/org.eclipse.help/schema/criteriaDefinition.exsd
@@ -0,0 +1,185 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.help" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.help" id="criteriaDefinition" name="Criteria Definition"/>
+ </appInfo>
+ <documentation>
+ For registering a criteria definition for contributed help content.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <choice minOccurs="1" maxOccurs="unbounded">
+ <element ref="criteriaDefinition"/>
+ <element ref="criteriaDefinitionProvider"/>
+ </choice>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="criteriaDefinition">
+ <annotation>
+ <documentation>
+ an criteria contribution made by supplying an XML file
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="file" type="string" use="required">
+ <annotation>
+ <documentation>
+ the name of the criteria definition file which contains the list of criteria id and name of the help content.
+&lt;p&gt;
+&lt;i&gt;&lt;b&gt;Configuration Markup for criteria definition file:&lt;/b&gt;&lt;/i&gt;
+&lt;/p&gt;
+&lt;p&gt;
+&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ELEMENT criteriaDefinition (criterion)* &gt;&lt;/tt&gt;&lt;br&gt;
+&lt;/p&gt;
+&lt;p&gt;
+&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ELEMENT criterion (criterion-value)* &gt;&lt;/tt&gt;&lt;br&gt;
+&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST criterion id CDATA #REQUIRED &gt;&lt;/tt&gt;&lt;br&gt;
+&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST criterion name CDATA #REQUIRED &gt;&lt;/tt&gt;&lt;br&gt;
+&lt;/p&gt;
+&lt;p&gt;
+&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ELEMENT criterion-value EMPTY &gt;&lt;/tt&gt;&lt;br&gt;
+&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST criterion-value id CDATA #REQUIRED &gt;&lt;/tt&gt;&lt;br&gt;
+&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST criterion-value name CDATA #REQUIRED &gt;&lt;/tt&gt;&lt;br&gt;
+&lt;/p&gt;
+&lt;p&gt;&lt;b&gt;The criteriaDefinition element&lt;/b&gt;
+&lt;p&gt;The criteriaDefinition element represents an instance of criteria definition. CriteriaDefinition consists of criterion, each of them corresponds to a particular id and its name.
+&lt;p&gt;&lt;b&gt;The criterion element&lt;/b&gt;
+&lt;p&gt;The criterion element represents a criterion. Each criterion may contain several criterion-value which associated with the critrion.
+&lt;p&gt;&lt;b&gt;The criterion-value element&lt;/b&gt;
+&lt;p&gt;The criterion-value element provides value to the criterion category. It also has id and name accociated with it.
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="resource"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="criteriaDefinitionProvider">
+ <annotation>
+ <documentation>
+ (&lt;b&gt;since 3.5&lt;/b&gt;) an criteria definition contribution made by plugging in code
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ the implementation class for the criteria definition provider. This class must implement the &lt;samp&gt;org.eclipse.help.AbstractCriteriaDefinitionProvider&lt;/samp&gt; interface.
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.help.AbstractCriteriaDefinitionProvider:"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 3.5
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ The following is an example of using the criteria definition extension point.
+
+&lt;p&gt;(in file &lt;tt&gt;plugin.xml&lt;/tt&gt;)
+&lt;pre&gt;
+ &lt;extension point=&quot;org.eclipse.help.criteriaDefinition&quot;&gt;
+ &lt;criteriaDefinition file=&quot;criteria.xml&quot;/&gt;
+ &lt;/extension&gt;
+&lt;/pre&gt;
+
+&lt;p&gt;(in file &lt;tt&gt;criteria.xml&lt;/tt&gt;)
+&lt;blockquote&gt;&lt;tt&gt;&amp;lt;criteriaDefinition&gt;&lt;/tt&gt;&lt;br&gt;
+ &lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;criterion id=&quot;version&quot; name =&quot;Version&quot;&gt;&lt;/tt&gt;&lt;br&gt;
+ &lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;criterion-value id=&quot;1.0&quot; name =&quot;1.0&quot;/&gt;&lt;/tt&gt;&lt;br&gt;
+ &lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;criterion-value id=&quot;2.0&quot; name =&quot;2.0&quot;/&gt;&lt;/tt&gt;&lt;br&gt;
+ &lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/criterion&gt;&lt;/tt&gt;&lt;br&gt;
+ &lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;criterion id=&quot;product&quot; name =&quot;Product&quot;&gt;&lt;/tt&gt;&lt;br&gt;
+ &lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;criterion-value id=&quot;DB2&quot; name =&quot;DB2&quot;/&gt;&lt;/tt&gt;&lt;br&gt;
+ &lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;criterion-value id=&quot;WAS&quot; name =&quot;WAS&quot;/&gt;&lt;/tt&gt;&lt;br&gt;
+ &lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/criterion&gt;&lt;/tt&gt;&lt;br&gt;
+&lt;tt&gt;&amp;lt;/criteriaDefinition&gt;&lt;/tt&gt;&lt;br&gt;&lt;/blockquote&gt;
+
+&lt;p&gt;&lt;b&gt;&lt;em&gt;Internationalization&lt;/em&gt;&lt;/b&gt; The criteria definition XML files can be translated and the resulting copy should be placed in nl/&amp;lt;language&gt;/&amp;lt;country&gt; or nl/&amp;lt;language&gt; directory. The &amp;lt;language&gt; and &amp;lt;country&gt; stand for two letter language and country codes as used in locale codes. For example, Traditional Chinese translations should be placed in the nl/zh/TW directory. The nl/&amp;lt;language&gt;/&amp;lt;country&gt; directory has a higher priority than nl/&amp;lt;language&gt;. Only if no file is found in the nl/&amp;lt;language&gt;/&amp;lt;country&gt;, the file residing in nl/&amp;lt;language&gt; will be used. The root directory of a plugin will be searched last.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ An implementation of &lt;samp&gt;org.eclipse.help.AbstractCriteriaDefinitionProvider&lt;/samp&gt; must be supplied if a &lt;samp&gt;criteriaDefinitionProvider&lt;/samp&gt; is used.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ The default implementation of the help system UI supplied with the Eclipse platform fully supports the &lt;samp&gt;criteriaDefinition&lt;/samp&gt; extension point.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2010 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
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.help/src/org/eclipse/help/AbstractCriteriaDefinitionProvider.java b/org.eclipse.help/src/org/eclipse/help/AbstractCriteriaDefinitionProvider.java
new file mode 100644
index 000000000..930211052
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/AbstractCriteriaDefinitionProvider.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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;
+
+/**
+ * An <code>AbstractCriteriaDefinitionProvider</code> is a mechanism to provide display name
+ * for criteria attached to toc or topic. <code>AbstractCriteriaDefinitionProvider</code>s must be
+ * registered via the <code>org.eclipse.help.criteriaDefinition</code> extension point.
+ *
+ * @since 3.5
+ */
+public abstract class AbstractCriteriaDefinitionProvider {
+
+ /**
+ * Returns all criteria definition contributions for this provider. Providers
+ * are free to provide any number of contributions (zero or more).
+ *
+ * @param locale the locale for which to get contributions
+ * @return all the criteria definition contributions for this provider
+ */
+ public abstract ICriteriaDefinitionContribution[] getCriteriaDefinitionContributions(String locale);
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/ICriteriaDefinition.java b/org.eclipse.help/src/org/eclipse/help/ICriteriaDefinition.java
new file mode 100644
index 000000000..a0c68e0a3
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/ICriteriaDefinition.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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;
+
+/**
+ * ICriteriaDefinition represents the criteria definition of one plug-in.
+ * It contains criterion definitions, each of them is criterion id and its
+ * display name, and criterion values id and their display names.
+ *
+ * @since 3.5
+ */
+
+public interface ICriteriaDefinition extends IUAElement{
+
+ /**
+ * Obtains the criterion definitions contained in the definition file.
+ *
+ * @return Array of ICriterionDefinition
+ */
+ ICriterionDefinition[] getCriterionDefinitions();
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/ICriteriaDefinitionContribution.java b/org.eclipse.help/src/org/eclipse/help/ICriteriaDefinitionContribution.java
new file mode 100644
index 000000000..6758855e9
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/ICriteriaDefinitionContribution.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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;
+
+/**
+ * Represents criteria definition contribution
+ *
+ * @since 3.5
+ */
+
+public interface ICriteriaDefinitionContribution {
+
+ /**
+ * Returns a unique identifier for this criteria definition.
+ *
+ * @return the contribution's unique identifier
+ */
+ public String getId();
+
+ /**
+ * Returns this contributions criteria definition.
+ *
+ * @return the criteria definition data for this contribution
+ */
+ public ICriteriaDefinition getCriteriaDefinition();
+
+ /**
+ * Returns the locale for this contribution.
+ *
+ * @return the contribution's locale
+ */
+ public String getLocale();
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/ICriterionDefinition.java b/org.eclipse.help/src/org/eclipse/help/ICriterionDefinition.java
new file mode 100644
index 000000000..69543a1f6
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/ICriterionDefinition.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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;
+
+/**
+ * ICriterionDefinition represents a single criterion definition of the help content.
+ * It includes criterion id and its related values id, and also their display names.
+ *
+ * @since 3.5
+ */
+public interface ICriterionDefinition extends IUAElement{
+
+ /**
+ * Returns the id that this criterion definition is associated with
+ *
+ * @return the id
+ */
+ public String getId();
+
+ /**
+ * Obtains the display name associated with this criterion definition.
+ *
+ * @return the name
+ */
+ public String getName();
+
+ /**
+ * Obtains the criterion value definitions contained in the criterion.
+ *
+ * @return array of ICriterionValueDefinition
+ */
+ public ICriterionValueDefinition[] getCriterionValueDefinitions();
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/ICriterionValueDefinition.java b/org.eclipse.help/src/org/eclipse/help/ICriterionValueDefinition.java
new file mode 100644
index 000000000..5cb9cde12
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/ICriterionValueDefinition.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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;
+
+/**
+ * ICriterionValueDefinition represents one criterion value definition of one criterion.
+ * It includes value id and its display name.
+ *
+ * @since 3.5
+ */
+public interface ICriterionValueDefinition extends IUAElement {
+
+ /**
+ * Returns the id that this criterion value
+ *
+ * @return the id
+ */
+ public String getId();
+
+ /**
+ * Obtains the display name associated with this criterion value.
+ *
+ * @return the name
+ */
+ public String getName();
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java b/org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java
index dce0b5f88..c7c3d1ede 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.help.internal.context.ContextManager;
+import org.eclipse.help.internal.criteria.CriteriaManager;
import org.eclipse.help.internal.extension.ContentExtensionManager;
import org.eclipse.help.internal.index.IndexManager;
import org.eclipse.help.internal.toc.TocManager;
@@ -37,6 +38,7 @@ public class HelpPlugin extends Plugin {
public static boolean DEBUG_SEARCH = false;
public static boolean DEBUG_TOC = false;
public static boolean DEBUG_INDEX = false;
+ public static boolean DEBUG_CRITERIA = false;
public final static String HELP_DATA_KEY = "HELP_DATA"; //$NON-NLS-1$
public final static String BASE_TOCS_KEY = "baseTOCS"; //$NON-NLS-1$
@@ -50,6 +52,7 @@ public class HelpPlugin extends Plugin {
private ContextManager contextManager;
private ContentExtensionManager contentExtensionManager;
private IndexManager indexManager;
+ private CriteriaManager criteriaManager;
private IHelpProvider helpProvider;
private File configurationDirectory;
@@ -122,6 +125,12 @@ public class HelpPlugin extends Plugin {
return getDefault().indexManager;
}
+ public static CriteriaManager getCriteriaManager() {
+ if (getDefault().criteriaManager == null)
+ getDefault().criteriaManager = new CriteriaManager();
+ return getDefault().criteriaManager;
+ }
+
/*
* Returns the provider responsible for serving help documents.
*/
@@ -161,7 +170,8 @@ public class HelpPlugin extends Plugin {
DEBUG_CONTEXT = "true".equalsIgnoreCase(Platform.getDebugOption(PLUGIN_ID + "/debug/context")); //$NON-NLS-1$ //$NON-NLS-2$
DEBUG_SEARCH = "true".equalsIgnoreCase(Platform.getDebugOption(PLUGIN_ID + "/debug/search")); //$NON-NLS-1$ //$NON-NLS-2$
DEBUG_TOC = "true".equalsIgnoreCase(Platform.getDebugOption(PLUGIN_ID + "/debug/toc")); //$NON-NLS-1$ //$NON-NLS-2$
- DEBUG_INDEX = "true".equalsIgnoreCase(Platform.getDebugOption(PLUGIN_ID + "/debug/index")); //$NON-NLS-1$ //$NON-NLS-2$
+ DEBUG_INDEX = "true".equalsIgnoreCase(Platform.getDebugOption(PLUGIN_ID + "/debug/index")); //$NON-NLS-1$ //$NON-NLS-2$
+ DEBUG_CRITERIA = "true".equalsIgnoreCase(Platform.getDebugOption(PLUGIN_ID + "/debug/criteria")); //$NON-NLS-1$ //$NON-NLS-2$
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/UAElementFactory.java b/org.eclipse.help/src/org/eclipse/help/internal/UAElementFactory.java
index 112bd648a..0de68ff8f 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/UAElementFactory.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/UAElementFactory.java
@@ -20,6 +20,9 @@ import org.eclipse.help.ICommandLink;
import org.eclipse.help.IContentExtension;
import org.eclipse.help.IContext;
import org.eclipse.help.ICriteria;
+import org.eclipse.help.ICriteriaDefinition;
+import org.eclipse.help.ICriterionDefinition;
+import org.eclipse.help.ICriterionValueDefinition;
import org.eclipse.help.IInclude;
import org.eclipse.help.IIndex;
import org.eclipse.help.IIndexEntry;
@@ -31,6 +34,9 @@ import org.eclipse.help.ITopic;
import org.eclipse.help.IUAElement;
import org.eclipse.help.internal.context.Context;
import org.eclipse.help.internal.criteria.Criteria;
+import org.eclipse.help.internal.criteria.CriteriaDefinition;
+import org.eclipse.help.internal.criteria.CriterionDefinition;
+import org.eclipse.help.internal.criteria.CriterionValueDefinition;
import org.eclipse.help.internal.extension.ContentExtension;
import org.eclipse.help.internal.index.Index;
import org.eclipse.help.internal.index.IndexEntry;
@@ -60,6 +66,9 @@ public class UAElementFactory {
{ IIndex.class, Index.class },
{ IContentExtension.class, ContentExtension.class },
{ ICriteria.class, Criteria.class },
+ { ICriteriaDefinition.class, CriteriaDefinition.class },
+ { ICriterionDefinition.class, CriterionDefinition.class },
+ { ICriterionValueDefinition.class, CriterionValueDefinition.class },
};
private static final Map classByElementName;
@@ -78,6 +87,9 @@ public class UAElementFactory {
classByElementName.put(IndexSee.NAME, IndexSee.class);
classByElementName.put(IndexSubpath.NAME, IndexSubpath.class);
classByElementName.put(Criteria.NAME, Criteria.class);
+ classByElementName.put(CriteriaDefinition.NAME, CriteriaDefinition.class);
+ classByElementName.put(CriterionDefinition.NAME, CriterionDefinition.class);
+ classByElementName.put(CriterionValueDefinition.NAME, CriterionValueDefinition.class);
classByElementName.put(ContentExtension.NAME_CONTRIBUTION, ContentExtension.class);
classByElementName.put(ContentExtension.NAME_CONTRIBUTION_LEGACY, ContentExtension.class);
classByElementName.put(ContentExtension.NAME_REPLACEMENT, ContentExtension.class);
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinition.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinition.java
new file mode 100644
index 000000000..a2e3b2b87
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinition.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.criteria;
+
+import org.eclipse.help.ICriteriaDefinition;
+import org.eclipse.help.ICriterionDefinition;
+import org.eclipse.help.internal.UAElement;
+import org.w3c.dom.Element;
+
+public class CriteriaDefinition extends UAElement implements ICriteriaDefinition {
+
+ public static final String NAME = "criteriaDefinition"; //$NON-NLS-1$
+
+ public CriteriaDefinition() {
+ super(NAME);
+ }
+
+ public CriteriaDefinition(ICriteriaDefinition src) {
+ super(NAME, src);
+ appendChildren(src.getChildren());
+ }
+
+ public CriteriaDefinition(Element src) {
+ super(src);
+ }
+
+ public ICriterionDefinition[] getCriterionDefinitions() {
+ return (ICriterionDefinition[])getChildren(ICriterionDefinition.class);
+ }
+
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionAssembler.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionAssembler.java
new file mode 100644
index 000000000..c761256ac
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionAssembler.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.criteria;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.help.IUAElement;
+import org.eclipse.help.internal.UAElement;
+
+/*
+ * Assembles individual criteria definition contributions into a complete, fully
+ * criteria definition.
+ */
+public class CriteriaDefinitionAssembler {
+
+ /*
+ * Assembles the given criteria definition contributions into a complete criteria definition.
+ * The originals are not modified.
+ */
+ public CriteriaDefinition assemble(List contributions) {
+ return merge(contributions);
+ }
+
+ /*
+ * Merge all criteria definition contributions into one.
+ */
+ private CriteriaDefinition merge(List contributions) {
+ CriteriaDefinition criteriaDefinition = new CriteriaDefinition();
+ Iterator iter = contributions.iterator();
+ while (iter.hasNext()) {
+ CriteriaDefinitionContribution contribution = (CriteriaDefinitionContribution)iter.next();
+ mergeChildren(criteriaDefinition, (CriteriaDefinition)contribution.getCriteriaDefinition());
+ contribution.setCriteriaDefinition(null);
+ }
+ return criteriaDefinition;
+ }
+
+ /*
+ * Merges the children of nodes a and b, and stores them into a. If the two
+ * contain the same criterion id, only one is kept but its children are merged,
+ * recursively. In one criterion, if multiple criterion values exist with the
+ * same id, only the first one found is kept.
+ *
+ * Insure criterion has its id at least, and criterion value has both its id and name.
+ */
+ private void mergeChildren(UAElement a, UAElement b) {
+ Map criterionById = new HashMap();
+ Set criterionValueIds = new HashSet();
+
+ IUAElement[] childrenA = a.getChildren();
+ for(int i = 0; i < childrenA.length; ++i){
+ UAElement childA = (UAElement)childrenA[i];
+ if(childA instanceof CriterionDefinition) {
+ String id = childA.getAttribute(CriterionDefinition.ATTRIBUTE_ID);
+ if(null != id && id.trim().length() > 0) {
+ criterionById.put(childA.getAttribute(CriterionDefinition.ATTRIBUTE_ID), childA);
+ }
+ } else if(childA instanceof CriterionValueDefinition) {
+ String valueId = childA.getAttribute(CriterionValueDefinition.ATTRIBUTE_ID);
+ String valueName = childA.getAttribute(CriterionValueDefinition.ATTRIBUTE_NAME);
+ if(null != valueId && valueId.trim().length() > 0 && null != valueName && valueName.trim().length() > 0){
+ criterionValueIds.add(childA.getAttribute(CriterionValueDefinition.ATTRIBUTE_ID));
+ }
+ }
+ }
+
+ IUAElement[] childrenB = b.getChildren();
+ for(int i = 0; i < childrenB.length; ++i){
+ UAElement childB = (UAElement) childrenB[i];
+ if(childB instanceof CriterionDefinition) {
+ String idB = childB.getAttribute(CriterionDefinition.ATTRIBUTE_ID);
+ if(null != idB && idB.trim().length() > 0){
+ if (criterionById.containsKey(idB)) {
+ // duplicate id; merge children
+ mergeChildren((CriterionDefinition)criterionById.get(idB), childB);
+ } else {
+ // wasn't a duplicate
+ a.appendChild(childB);
+ criterionById.put(idB, childB);
+ }
+ }
+ } else if(childB instanceof CriterionValueDefinition) {
+ String valueIdB = childB.getAttribute(CriterionValueDefinition.ATTRIBUTE_ID);
+ String valueNameB = childB.getAttribute(CriterionValueDefinition.ATTRIBUTE_NAME);
+ if(null != valueIdB && valueIdB.trim().length() > 0 && null != valueNameB && valueNameB.trim().length() > 0){
+ if (!criterionValueIds.contains(valueIdB)) {
+ // For one criterion, add criterion value only if id doesn't exist yet
+ a.appendChild(childB);
+ criterionValueIds.add(valueIdB);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionContribution.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionContribution.java
new file mode 100644
index 000000000..4abc5666c
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionContribution.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.criteria;
+
+import org.eclipse.help.ICriteriaDefinition;
+import org.eclipse.help.ICriteriaDefinitionContribution;
+
+
+public class CriteriaDefinitionContribution implements ICriteriaDefinitionContribution{
+
+ private String id;
+ private ICriteriaDefinition criteriaDefinition;
+ private String locale;
+
+ public String getId() {
+ return id;
+ }
+
+ public ICriteriaDefinition getCriteriaDefinition() {
+ return criteriaDefinition;
+ }
+
+ public String getLocale() {
+ return locale;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setCriteriaDefinition(ICriteriaDefinition criteriaDefinition) {
+ this.criteriaDefinition = criteriaDefinition;
+ }
+
+ public void setLocale(String locale) {
+ this.locale = locale;
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionDocumentReader.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionDocumentReader.java
new file mode 100644
index 000000000..80fb38b5a
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionDocumentReader.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.criteria;
+
+import org.eclipse.help.internal.dynamic.DocumentReader;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class CriteriaDefinitionDocumentReader extends DocumentReader {
+
+ private static final String CRITERION_ELEMENT = "criterion"; //$NON-NLS-1$
+ private static final String CRITERION_ID_ATTRIBUTE = "id"; //$NON-NLS-1$
+
+
+ protected void prepareDocument(Document document) {
+ prune(document.getDocumentElement());
+ }
+
+ private void prune(Node element) {
+ NodeList nodes = element.getChildNodes();
+ Node node = nodes.item(0);
+ while (node != null) {
+ short nodeType = node.getNodeType();
+ if (nodeType == Node.TEXT_NODE || nodeType == Node.COMMENT_NODE) {
+ Node nodeToDelete = node;
+ node = node.getNextSibling();
+ element.removeChild(nodeToDelete);
+ } else if (nodeType == Node.ELEMENT_NODE) {
+ String kind = node.getNodeName();
+ if (CRITERION_ELEMENT.equalsIgnoreCase(kind)) {
+ fixCriterionId((Element)node);
+ }
+ prune(node);
+ node = node.getNextSibling();
+ } else {
+ node = node.getNextSibling();
+ }
+ }
+ }
+
+ /*
+ * Cause criterion ID is case insensitive, so just change it to lower case.
+ */
+ private void fixCriterionId(Element criterion) {
+ String id = criterion.getAttribute(CRITERION_ID_ATTRIBUTE);
+ if (id != null && id.length() > 0) {
+ criterion.setAttribute(CRITERION_ID_ATTRIBUTE, id.toLowerCase());
+ }
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFile.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFile.java
new file mode 100644
index 000000000..e30abd29a
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFile.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.criteria;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.help.internal.util.ResourceLocator;
+
+public class CriteriaDefinitionFile {
+
+ private String pluginId;
+ private String file;
+ private String locale;
+
+ public CriteriaDefinitionFile(String pluginId, String file, String locale) {
+ this.pluginId = pluginId;
+ this.file = file;
+ this.locale = locale;
+ }
+
+ public String getFile() {
+ return file;
+ }
+
+ public String getLocale() {
+ return locale;
+ }
+
+ public String getPluginId() {
+ return pluginId;
+ }
+
+ public InputStream getInputStream() throws IOException {
+ if (pluginId != null)
+ return ResourceLocator.openFromPlugin(pluginId, file, locale);
+ else
+ return new FileInputStream(file);
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFileParser.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFileParser.java
new file mode 100644
index 000000000..de1af6b97
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFileParser.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.criteria;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.help.internal.dynamic.DocumentReader;
+import org.xml.sax.SAXException;
+
+public class CriteriaDefinitionFileParser {
+
+ private DocumentReader reader;
+
+ public CriteriaDefinitionContribution parse(CriteriaDefinitionFile criteriaDefinitionFile) throws IOException, SAXException, ParserConfigurationException {
+ if (reader == null) {
+ reader = new CriteriaDefinitionDocumentReader();
+ }
+ InputStream in = criteriaDefinitionFile.getInputStream();
+ if (in != null) {
+ CriteriaDefinition criteria = (CriteriaDefinition)reader.read(in);
+ CriteriaDefinitionContribution contrib = new CriteriaDefinitionContribution();
+ contrib.setId('/' + criteriaDefinitionFile.getPluginId() + '/' + criteriaDefinitionFile.getFile());
+ contrib.setCriteriaDefinition(criteria);
+ contrib.setLocale(criteriaDefinitionFile.getLocale());
+ return contrib;
+ }
+ else {
+ throw new FileNotFoundException();
+ }
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFileProvider.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFileProvider.java
new file mode 100644
index 000000000..4550889b6
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionFileProvider.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.criteria;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.help.AbstractCriteriaDefinitionProvider;
+import org.eclipse.help.ICriteriaDefinitionContribution;
+import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.util.ResourceLocator;
+import org.xml.sax.SAXParseException;
+
+/*
+ * Provides criteria definition data from XML files to the help system.
+ */
+public class CriteriaDefinitionFileProvider extends AbstractCriteriaDefinitionProvider {
+
+ private static final String ERROR_READING_HELP_CRITERIA_DEFINITION_FILE = "Error reading criteria definition file /\""; //$NON-NLS-1$
+ public static final String EXTENSION_POINT_ID_CRITERIA_DEFINITION = HelpPlugin.PLUGIN_ID + ".criteriaDefinition"; //$NON-NLS-1$
+ public static final String ELEMENT_NAME_CRITERIA = "criteriaDefinition"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_NAME_FILE = "file"; //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.AbstractCriteriaDefinitionProvider#getCriteriaDefinitionContributions(java.lang.String)
+ */
+ public ICriteriaDefinitionContribution[] getCriteriaDefinitionContributions(String locale) {
+ List contributions = new ArrayList();
+ CriteriaDefinitionFile[] criteriaDefinitionFiles = getCriteriaDefinitionFiles(locale);
+ CriteriaDefinitionFileParser parser = new CriteriaDefinitionFileParser();
+ for (int i = 0; i < criteriaDefinitionFiles.length; ++i) {
+ CriteriaDefinitionFile criteriaDefinitionFile = criteriaDefinitionFiles[i];
+ try {
+ ICriteriaDefinitionContribution criteria = parser.parse(criteriaDefinitionFile);
+ contributions.add(criteria);
+ } catch (SAXParseException spe) {
+ StringBuffer buffer = new StringBuffer(ERROR_READING_HELP_CRITERIA_DEFINITION_FILE);
+ buffer.append(getCriteriaDefinitionFilePath(criteriaDefinitionFile));
+ buffer.append("\" at line "); //$NON-NLS-1$
+ buffer.append(spe.getLineNumber());
+ buffer.append(". "); //$NON-NLS-1$
+ buffer.append(spe.getMessage());
+
+ // Use the contained exception.
+ Exception x = spe;
+ if (spe.getException() != null)
+ x = spe.getException();
+ HelpPlugin.logError(buffer.toString(), x);
+
+ }
+ catch (Throwable t) {
+ String msg = ERROR_READING_HELP_CRITERIA_DEFINITION_FILE + getCriteriaDefinitionFilePath(criteriaDefinitionFile) + "\" (skipping file)"; //$NON-NLS-1$
+ HelpPlugin.logError(msg, t);
+ }
+ }
+ return (ICriteriaDefinitionContribution[])contributions.toArray(new ICriteriaDefinitionContribution[contributions.size()]);
+ }
+
+ private String getCriteriaDefinitionFilePath(CriteriaDefinitionFile criteriaDefinitionFile) {
+ String pluginId = criteriaDefinitionFile.getPluginId();
+ String file = criteriaDefinitionFile.getFile();
+ return ResourceLocator.getErrorPath(pluginId, file, criteriaDefinitionFile.getLocale());
+ }
+
+ /*
+ * Returns all available CriteriaDefinitionFiles for the given locale.
+ */
+ private CriteriaDefinitionFile[] getCriteriaDefinitionFiles(String locale) {
+ List criteriaDefinitionFiles = new ArrayList();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] elements = registry.getConfigurationElementsFor(EXTENSION_POINT_ID_CRITERIA_DEFINITION);
+ for (int i=0;i<elements.length;++i) {
+ IConfigurationElement elem = elements[i];
+ String pluginId = elem.getContributor().getName();
+ if (elem.getName().equals(ELEMENT_NAME_CRITERIA)) {
+ String file = elem.getAttribute(ATTRIBUTE_NAME_FILE);
+ CriteriaDefinitionFile criteriaDefinitionFile = new CriteriaDefinitionFile(pluginId, file, locale);
+ criteriaDefinitionFiles.add(criteriaDefinitionFile);
+ }
+ }
+ return (CriteriaDefinitionFile[])criteriaDefinitionFiles.toArray(new CriteriaDefinitionFile[criteriaDefinitionFiles.size()]);
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionManager.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionManager.java
new file mode 100644
index 000000000..d8f0f8455
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaDefinitionManager.java
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.criteria;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.AbstractCriteriaDefinitionProvider;
+import org.eclipse.help.ICriteriaDefinition;
+import org.eclipse.help.ICriteriaDefinitionContribution;
+import org.eclipse.help.ICriterionDefinition;
+import org.eclipse.help.ICriterionValueDefinition;
+import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.UAElementFactory;
+
+public class CriteriaDefinitionManager {
+
+ private static final String EXTENSION_POINT_ID_CRITERIA_DEFINITION = HelpPlugin.PLUGIN_ID + ".criteriaDefinition"; //$NON-NLS-1$
+ private static final String ELEMENT_NAME_CRITERIA_DEFINITION_PROVIDER = "criteriaDefinitionProvider"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_NAME_CLASS = "class"; //$NON-NLS-1$
+
+ private Map criteriaDefinitionContributionsByLocale = new HashMap();
+ private Map criteriaDefinitionsByLocale = new HashMap();
+ private AbstractCriteriaDefinitionProvider[] criteriaDefinitionProviders;
+
+ public synchronized ICriteriaDefinition getCriteriaDefinition(String locale) {
+ CriteriaDefinition criteriaDefinition = (CriteriaDefinition)criteriaDefinitionsByLocale.get(locale);
+ if (null == criteriaDefinition) {
+ HelpPlugin.getTocManager().getTocs(locale);
+ long start = System.currentTimeMillis();
+ if (HelpPlugin.DEBUG_CRITERIA) {
+ System.out.println("Start to update criteria definition for locale " + locale); //$NON-NLS-1$
+ }
+ List contributions = new ArrayList(Arrays.asList(readCriteriaDefinitionContributions(locale)));
+ CriteriaDefinitionAssembler assembler = new CriteriaDefinitionAssembler();
+ criteriaDefinition = assembler.assemble(contributions);
+ criteriaDefinitionsByLocale.put(locale, criteriaDefinition);
+ long stop = System.currentTimeMillis();
+ if (HelpPlugin.DEBUG_CRITERIA) {
+ System.out.println("Milliseconds to update criteria definition for locale " + locale + " = " + (stop - start)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ return criteriaDefinition;
+ }
+
+ /*
+ * Returns all criteria definition contributions for the given locale, from all providers.
+ */
+ public synchronized CriteriaDefinitionContribution[] getCriteriaDefinitionContributions(String locale) {
+ CriteriaDefinitionContribution[] contributions = (CriteriaDefinitionContribution[])criteriaDefinitionContributionsByLocale.get(locale);
+ if (contributions == null) {
+ contributions = readCriteriaDefinitionContributions(locale);
+ criteriaDefinitionContributionsByLocale.put(locale, contributions);
+ }
+ return contributions;
+ }
+
+ private CriteriaDefinitionContribution[] readCriteriaDefinitionContributions(String locale) {
+ CriteriaDefinitionContribution[] cached;
+ List contributions = new ArrayList();
+ AbstractCriteriaDefinitionProvider[] providers = getCriteriaDefinitionProviders();
+ for (int i=0;i<providers.length;++i) {
+ ICriteriaDefinitionContribution[] contrib;
+ try {
+ contrib = providers[i].getCriteriaDefinitionContributions(locale);
+ }
+ catch (Throwable t) {
+ // log, and skip the offending provider
+ String msg = "Error getting help criteria definition data from provider: " + providers[i].getClass().getName() + " (skipping provider)"; //$NON-NLS-1$ //$NON-NLS-2$
+ HelpPlugin.logError(msg, t);
+ continue;
+ }
+
+ // check for nulls and root element
+ for (int j=0;j<contrib.length;++j) {
+ if (contrib[j] == null) {
+ String msg = "Help criteria definition provider \"" + providers[i].getClass().getName() + "\" returned a null contribution (skipping)"; //$NON-NLS-1$ //$NON-NLS-2$
+ HelpPlugin.logError(msg);
+ }
+ else if (contrib[j].getCriteriaDefinition() == null) {
+ String msg = "Help criteria definition provider \"" + providers[i].getClass().getName() + "\" returned a contribution with a null root element (expected a \"" + CriteriaDefinition.NAME + "\" element; skipping)"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ HelpPlugin.logError(msg);
+ }
+ else {
+ CriteriaDefinitionContribution contribution = new CriteriaDefinitionContribution();
+ contribution.setId(contrib[j].getId());
+ contribution.setLocale(contrib[j].getLocale());
+ ICriteriaDefinition criteria = contrib[j].getCriteriaDefinition();
+ contribution.setCriteriaDefinition(criteria instanceof CriteriaDefinition ? (CriteriaDefinition)criteria : (CriteriaDefinition)UAElementFactory.newElement(criteria));
+ contributions.add(contribution);
+ }
+ }
+ }
+ cached = (CriteriaDefinitionContribution[])contributions.toArray(new CriteriaDefinitionContribution[contributions.size()]);
+ return cached;
+ }
+
+ /*
+ * Clears all cached contributions, forcing the manager to query the
+ * providers again next time a request is made.
+ */
+ public void clearCache() {
+ criteriaDefinitionContributionsByLocale.clear();
+ criteriaDefinitionsByLocale.clear();
+ }
+
+ /*
+ * Internal hook for unit testing.
+ */
+ public AbstractCriteriaDefinitionProvider[] getCriteriaDefinitionProviders() {
+ if (null == criteriaDefinitionProviders) {
+ List providers = new ArrayList();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] elements = registry.getConfigurationElementsFor(EXTENSION_POINT_ID_CRITERIA_DEFINITION);
+ for (int i=0;i<elements.length;++i) {
+ IConfigurationElement elem = elements[i];
+ if (elem.getName().equals(ELEMENT_NAME_CRITERIA_DEFINITION_PROVIDER)) {
+ try {
+ AbstractCriteriaDefinitionProvider provider = (AbstractCriteriaDefinitionProvider)elem.createExecutableExtension(ATTRIBUTE_NAME_CLASS);
+ providers.add(provider);
+ }
+ catch (CoreException e) {
+ // log and skip
+ String msg = "Error instantiating help keyword index provider class \"" + elem.getAttribute(ATTRIBUTE_NAME_CLASS) + '"'; //$NON-NLS-1$
+ HelpPlugin.logError(msg, e);
+ }
+ }
+ }
+ criteriaDefinitionProviders = (AbstractCriteriaDefinitionProvider[])providers.toArray(new AbstractCriteriaDefinitionProvider[providers.size()]);
+ }
+ return criteriaDefinitionProviders;
+ }
+
+ public boolean isCriteriaDefinitionLoaded(String locale) {
+ return criteriaDefinitionsByLocale.get(locale) != null;
+ }
+
+ /*
+ * Internal hook for unit testing.
+ */
+ public void setCriteriaDefinitionProviders(AbstractCriteriaDefinitionProvider[] criteriaDefinitionProviders) {
+ this.criteriaDefinitionProviders = criteriaDefinitionProviders;
+ }
+
+ public String getCriterionName(String id, String locale) {
+ ICriteriaDefinition definition = getCriteriaDefinition(locale);
+ ICriterionDefinition[] criterionDefinitions = definition.getCriterionDefinitions();
+ for(int i = 0; i < criterionDefinitions.length; i++) {
+ CriterionDefinition criterionDefinition = (CriterionDefinition) criterionDefinitions[i];
+ if(null != criterionDefinition.getId() && criterionDefinition.getId().equalsIgnoreCase(id)){
+ String name = criterionDefinition.getName();
+ if(null != name && 0 != name.length()) {
+ return name;
+ }
+ }
+ }
+ return id;
+ }
+
+ public String getCriterionValueName(String criterionId, String criterionValueId, String locale) {
+ ICriteriaDefinition definition = getCriteriaDefinition(locale);
+ ICriterionDefinition[] criterionDefinitions = definition.getCriterionDefinitions();
+ for(int i = 0; i < criterionDefinitions.length; ++ i) {
+ CriterionDefinition criterionDefinition = (CriterionDefinition) criterionDefinitions[i];
+ if(null != criterionDefinition.getId() && criterionDefinition.getId().equalsIgnoreCase(criterionId)){
+ ICriterionValueDefinition[] valueDefinitions = criterionDefinition.getCriterionValueDefinitions();
+ for(int j = 0; j < valueDefinitions.length; ++ j){
+ CriterionValueDefinition valueDefinition = (CriterionValueDefinition) valueDefinitions[j];
+ if(null != valueDefinition.getId() && valueDefinition.getId().equals(criterionValueId)){
+ String name = valueDefinition.getName();
+ if(null != name && 0 != name.length()) {
+ return name;
+ }
+ }
+ }
+ }
+ }
+ return criterionValueId;
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaPreferences.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaManager.java
index bf5a7b16c..aece2105e 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaPreferences.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaManager.java
@@ -28,7 +28,7 @@ import org.eclipse.help.internal.HelpPlugin;
*
* @since 3.5
*/
-public class CriteriaPreferences {
+public class CriteriaManager {
private final static String SUPPORTED_CRITERIA = "supportedCriteria"; //$NON-NLS-1$
private final static String ENABLE_CRITERIA = "enableCriteria"; //$NON-NLS-1$
@@ -37,11 +37,9 @@ public class CriteriaPreferences {
private boolean criteriaEnabled;
private Map allCriteriaValues;
- static class InstanceHolder{
- static CriteriaPreferences instance = new CriteriaPreferences();
- }
+ private CriteriaDefinitionManager criteriaDefinitionManager;
- private CriteriaPreferences() {
+ public CriteriaManager() {
criteriaEnabled = Platform.getPreferencesService().getBoolean(HelpPlugin.PLUGIN_ID, ENABLE_CRITERIA, false, null);
supportedCriteria = new ArrayList();
@@ -51,10 +49,10 @@ public class CriteriaPreferences {
}
allCriteriaValues = new HashMap();
- }
-
- public static CriteriaPreferences getInstance() {
- return InstanceHolder.instance;
+
+ if (criteriaDefinitionManager == null){
+ criteriaDefinitionManager = new CriteriaDefinitionManager();
+ }
}
public boolean isSupportedCriterion(String criterion){
@@ -68,23 +66,41 @@ public class CriteriaPreferences {
return criteriaEnabled;
}
- public void addCriteriaValues(ICriteria[] criteria){
+ public void addCriteriaValues(ICriteria[] criteria, String locale){
+ Map criteriaInLocale = (HashMap)allCriteriaValues.get(locale);
+ if(null == criteriaInLocale) {
+ criteriaInLocale = new HashMap();
+ }
CriterionResource[] resources = CriterionResource.toCriterionResource(criteria);
for(int i = 0; i < resources.length; ++ i){
CriterionResource criterion = resources[i];
String criterionName = criterion.getCriterionName();
List criterionValues = criterion.getCriterionValues();
- Set existedValues = (Set)allCriteriaValues.get(criterionName);
+ Set existedValues = (Set)criteriaInLocale.get(criterionName);
if (null == existedValues)
existedValues = new HashSet();
existedValues.addAll(criterionValues);
- allCriteriaValues.put(criterionName, existedValues);
+ criteriaInLocale.put(criterionName, existedValues);
}
+ allCriteriaValues.put(locale, criteriaInLocale);
+ }
+
+ public Map getAllCriteriaValues(String locale){
+ Map criteria = (Map) allCriteriaValues.get(locale);
+ if(null == criteria) {
+ criteria = new HashMap();
+ }
+ return criteria;
+ }
+
+
+ public String getCriterionDisplayName (String criterionId, String locale){
+ return criteriaDefinitionManager.getCriterionName(criterionId, locale);
}
- public Map getAllCriteriaValues(){
- return allCriteriaValues;
+ public String getCriterionValueDisplayName(String criterionId, String criterionValueId, String locale) {
+ return criteriaDefinitionManager.getCriterionValueName(criterionId, criterionValueId, locale);
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionDefinition.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionDefinition.java
new file mode 100644
index 000000000..20ff15645
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionDefinition.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.criteria;
+
+import org.eclipse.help.ICriterionDefinition;
+import org.eclipse.help.ICriterionValueDefinition;
+import org.eclipse.help.internal.UAElement;
+import org.w3c.dom.Element;
+
+public class CriterionDefinition extends UAElement implements ICriterionDefinition {
+
+ public static final String NAME = "criterion"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
+
+ public CriterionDefinition(ICriterionDefinition src) {
+ super(NAME, src);
+ setId(src.getId());
+ setName(src.getName());
+ appendChildren(src.getChildren());
+ }
+
+ public CriterionDefinition(Element src) {
+ super(src);
+ }
+
+ public String getId() {
+ return getAttribute(ATTRIBUTE_ID);
+ }
+
+ public String getName() {
+ return getAttribute(ATTRIBUTE_NAME);
+ }
+
+ public void setId(String id) {
+ setAttribute(ATTRIBUTE_ID, id);
+ }
+
+ public void setName(String name){
+ setAttribute(ATTRIBUTE_NAME, name);
+ }
+
+ public ICriterionValueDefinition[] getCriterionValueDefinitions() {
+ return (ICriterionValueDefinition[])getChildren(ICriterionValueDefinition.class);
+ }
+
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionResource.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionResource.java
index d70f39bfd..88c7ec78f 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionResource.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionResource.java
@@ -6,6 +6,18 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.help.ICriteria;
+/*******************************************************************************
+ * Copyright (c) 2010 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
+ *******************************************************************************/
+
+import org.eclipse.help.internal.HelpPlugin;
/**
* A class represents one criterion, which has the name and values
@@ -57,7 +69,7 @@ public class CriterionResource {
String elementValue = criteriaElements[i].getValue();
if (null != elementName && 0 != elementName.length() && null != elementValue
&& 0 != elementValue.length()) {
- if (CriteriaPreferences.getInstance().isSupportedCriterion(elementName)) {
+ if (HelpPlugin.getCriteriaManager().isSupportedCriterion(elementName)) {
elementName = elementName.toLowerCase();
List values = Arrays.asList(elementValue.split(",")); //$NON-NLS-1$
for(int j = 0; j < criteriaList.size(); ++j){
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionValueDefinition.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionValueDefinition.java
new file mode 100644
index 000000000..0745a4470
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriterionValueDefinition.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.criteria;
+
+import org.eclipse.help.ICriterionDefinition;
+import org.eclipse.help.ICriterionValueDefinition;
+import org.eclipse.help.internal.UAElement;
+import org.w3c.dom.Element;
+
+public class CriterionValueDefinition extends UAElement implements ICriterionValueDefinition {
+
+ public static final String NAME = "criterion-value"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
+
+ public CriterionValueDefinition(ICriterionDefinition src) {
+ super(NAME, src);
+ setId(src.getId());
+ setName(src.getName());
+ }
+
+ public CriterionValueDefinition(Element src) {
+ super(src);
+ }
+
+ public String getId() {
+ return getAttribute(ATTRIBUTE_ID);
+ }
+
+ public String getName() {
+ return getAttribute(ATTRIBUTE_NAME);
+ }
+
+ public void setId(String id) {
+ setAttribute(ATTRIBUTE_ID, id);
+ }
+
+ public void setName(String name){
+ setAttribute(ATTRIBUTE_NAME, name);
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocAssembler.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocAssembler.java
index 54a5d8f95..ab1966cb2 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocAssembler.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocAssembler.java
@@ -27,7 +27,6 @@ import org.eclipse.help.internal.Anchor;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.Topic;
import org.eclipse.help.internal.UAElement;
-import org.eclipse.help.internal.criteria.CriteriaPreferences;
import org.eclipse.help.internal.dynamic.DocumentProcessor;
import org.eclipse.help.internal.dynamic.DocumentReader;
import org.eclipse.help.internal.dynamic.ExtensionHandler;
@@ -434,7 +433,7 @@ public class TocAssembler {
topic.setHref(normalize(href, id));
}
- processCriteria(element);
+ processCriteria(element, id);
return HANDLED_CONTINUE;
}
@@ -446,7 +445,7 @@ public class TocAssembler {
toc.setTopic(normalize(topic, id));
}
- processCriteria(element);
+ processCriteria(element, id);
return HANDLED_CONTINUE;
}
@@ -469,8 +468,10 @@ public class TocAssembler {
return href;
}
- private void processCriteria(UAElement element) {
- if(CriteriaPreferences.getInstance().isCriteriaEnabled()){
+ private void processCriteria(UAElement element, String id) {
+ if(HelpPlugin.getCriteriaManager().isCriteriaEnabled()){
+ ITocContribution contribution = getContribution(id);
+ String locale = contribution.getLocale();
ICriteria[] criteria = new ICriteria[0];
if (element instanceof Topic) {
Topic topic = (Topic) element;
@@ -481,7 +482,7 @@ public class TocAssembler {
criteria = toc.getCriteria();
}
- CriteriaPreferences.getInstance().addCriteriaValues(criteria);
+ HelpPlugin.getCriteriaManager().addCriteriaValues(criteria, locale);
}
}
}
diff --git a/org.eclipse.ua.tests/data/help/criteria/criteria_definition/a.xml b/org.eclipse.ua.tests/data/help/criteria/criteria_definition/a.xml
new file mode 100644
index 000000000..047edb32c
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/criteria/criteria_definition/a.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2010 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
+ -->
+
+<criteriaDefinition>
+ <criterion id="version" name="Version">
+ <criterion-value id="1.0" name ="1.0.0"/>
+ <criterion-value id="2.0" name ="2.0.0"/>
+ </criterion>
+ <criterion id="platform" name="Platform">
+ <criterion-value id="AIX" name ="AIX"/>
+ <criterion-value id="WINDOWS" name ="Windows"/>
+ </criterion>
+</criteriaDefinition>
diff --git a/org.eclipse.ua.tests/data/help/criteria/criteria_definition/b.xml b/org.eclipse.ua.tests/data/help/criteria/criteria_definition/b.xml
new file mode 100644
index 000000000..c732b07e2
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/criteria/criteria_definition/b.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2010 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
+ -->
+
+<criteriaDefinition>
+ <criterion id="version" name="Version">
+ <criterion-value id="1.0" name ="1.0.0"/>
+ <criterion-value id="3.0" name ="3.0.0"/>
+ <criterion-value id="4.0" name = "4.0.0"/>
+ <criterion-value id="5.0"/>
+ <criterion-value id=""/>
+ <criterion-value id="" name ="aaa"/>
+ <criterion-value name =""/>
+ <criterion-value name ="aaa"/>
+ </criterion>
+ <criterion id="platform" name="Platform">
+ <criterion-value id="AIX" name ="AIX"/>
+ <criterion-value id="Linux" name ="LINUX"/>
+ </criterion>
+ <criterion id="product" name="Product">
+ <criterion-value id="DB2" name ="DB2"/>
+ <criterion-value id="WAS" name ="WAS"/>
+ </criterion>
+ <criterion id="no criterion value" name ="no criterion value"/>
+ <criterion id="no name">
+ <criterion-value id="bb" name ="bb"/>
+ </criterion>
+ <criterion name="no id"/>
+</criteriaDefinition>
diff --git a/org.eclipse.ua.tests/data/help/criteria/criteria_definition/result_a_b.xml b/org.eclipse.ua.tests/data/help/criteria/criteria_definition/result_a_b.xml
new file mode 100644
index 000000000..7ff9f6260
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/criteria/criteria_definition/result_a_b.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2010 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
+ -->
+
+<criteriaDefinition>
+ <criterion id="version" name="Version">
+ <criterion-value id="1.0" name ="1.0.0"/>
+ <criterion-value id="2.0" name ="2.0.0"/>
+ <criterion-value id="3.0" name ="3.0.0"/>
+ <criterion-value id="4.0" name = "4.0.0"/>
+ </criterion>
+ <criterion id="platform" name="Platform">
+ <criterion-value id="AIX" name ="AIX"/>
+ <criterion-value id="WINDOWS" name ="Windows"/>
+ <criterion-value id="Linux" name ="LINUX"/>
+ </criterion>
+ <criterion id="product" name="Product">
+ <criterion-value id="DB2" name ="DB2"/>
+ <criterion-value id="WAS" name ="WAS"/>
+ </criterion>
+ <criterion id="no criterion value" name ="no criterion value"/>
+ <criterion id="no name">
+ <criterion-value id="bb" name ="bb"/>
+ </criterion>
+</criteriaDefinition>
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/AllCriteriaTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/AllCriteriaTests.java
index 9fb4c415c..82046d6b0 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/AllCriteriaTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/AllCriteriaTests.java
@@ -31,5 +31,6 @@ public class AllCriteriaTests extends TestSuite {
public AllCriteriaTests() {
addTestSuite(ParseTocWithCriteria.class);
addTestSuite(CriteriaUtilitiesTest.class);
+ addTestSuite(ParseCriteriaDefinition.class);
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/CriteriaUtilitiesTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/CriteriaUtilitiesTest.java
index 8a1464ddf..8b3b0e7b0 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/CriteriaUtilitiesTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/CriteriaUtilitiesTest.java
@@ -45,7 +45,7 @@ public class CriteriaUtilitiesTest extends TestCase {
public void testUppercaseValue() {
List values = CriteriaUtilities.getCriteriaValues("LINUX");
assertEquals(1, values.size());
- assertEquals("linux", values.get(0));
+ assertNotSame("linux", values.get(0));
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseCriteriaDefinition.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseCriteriaDefinition.java
new file mode 100644
index 000000000..392f795fc
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseCriteriaDefinition.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.ua.tests.help.criteria;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.help.internal.UAElement;
+import org.eclipse.help.internal.criteria.CriteriaDefinition;
+import org.eclipse.help.internal.criteria.CriteriaDefinitionAssembler;
+import org.eclipse.help.internal.criteria.CriteriaDefinitionContribution;
+import org.eclipse.help.internal.criteria.CriteriaDefinitionFile;
+import org.eclipse.help.internal.criteria.CriteriaDefinitionFileParser;
+import org.eclipse.help.internal.dynamic.DocumentWriter;
+import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
+
+public class ParseCriteriaDefinition extends TestCase {
+
+ /*
+ * Returns an instance of this Test.
+ */
+ public static Test suite() {
+ return new TestSuite(ParseCriteriaDefinition.class);
+ }
+
+ public void testAssemble() throws Exception {
+ CriteriaDefinitionFileParser parser = new CriteriaDefinitionFileParser();
+ CriteriaDefinitionContribution a = parser.parse(new CriteriaDefinitionFile(UserAssistanceTestPlugin.getPluginId(), "data/help/criteria/criteria_definition/a.xml", "en"));
+ CriteriaDefinitionContribution b = parser.parse(new CriteriaDefinitionFile(UserAssistanceTestPlugin.getPluginId(), "data/help/criteria/criteria_definition/b.xml", "en"));
+ CriteriaDefinitionContribution result_a_b = parser.parse(new CriteriaDefinitionFile(UserAssistanceTestPlugin.getPluginId(), "data/help/criteria/criteria_definition/result_a_b.xml", "en"));
+
+ CriteriaDefinitionAssembler assembler = new CriteriaDefinitionAssembler();
+ List contributions = new ArrayList(Arrays.asList(new Object[] { a, b }));
+ CriteriaDefinition assembled = assembler.assemble(contributions);
+
+ String expected = serialize((UAElement)result_a_b.getCriteriaDefinition());
+ String actual = serialize(assembled);
+ assertEquals(trimWhiteSpace(expected), trimWhiteSpace(actual));
+ }
+
+
+ // Replaces white space between ">" and "<" by a single newline
+
+ private String trimWhiteSpace(String input) {
+ StringBuffer result = new StringBuffer();
+ boolean betweenElements = false;
+ for (int i = 0; i < input.length(); i++) {
+ char next = input.charAt(i);
+ if (betweenElements) {
+ if (!Character.isWhitespace(next)) {
+ result.append(next);
+ if (next == '<') {
+ betweenElements = false;
+ }
+ }
+ } else {
+ result.append(next);
+ if (next == '>') {
+ betweenElements = true;
+ result.append('\r');
+ result.append('\n');
+ }
+ }
+ }
+ String resString = result.toString();
+ return resString;
+ }
+
+ private String serialize(UAElement element) throws Exception {
+ DocumentWriter writer = new DocumentWriter();
+ return writer.writeString(element, true);
+ }
+
+}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java
index 8dca4d739..e00de0df0 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java
@@ -27,13 +27,13 @@ import org.eclipse.help.IToc2;
import org.eclipse.help.ITopic;
import org.eclipse.help.ITopic2;
import org.eclipse.help.internal.Topic;
+import org.eclipse.help.internal.base.scope.CriteriaHelpScope;
import org.eclipse.help.internal.base.util.CriteriaUtilities;
import org.eclipse.help.internal.criteria.CriterionResource;
import org.eclipse.help.internal.toc.Toc;
import org.eclipse.help.internal.toc.TocContribution;
import org.eclipse.help.internal.toc.TocFile;
import org.eclipse.help.internal.toc.TocFileParser;
-import org.eclipse.help.internal.workingset.CriteriaHelpScope;
import org.eclipse.ua.tests.help.other.UserCriteria;
import org.eclipse.ua.tests.help.other.UserToc2;
import org.eclipse.ua.tests.help.other.UserTopic2;
@@ -273,7 +273,7 @@ public class ParseTocWithCriteria extends TestCase {
linuxResource[0] = new CriterionResource("platform");
linuxResource[0].addCriterionValue("linux");
CriteriaHelpScope linuxScope = new CriteriaHelpScope(linuxResource);
- assertTrue(linuxScope.inScope(topics[0]));
+ assertFalse(linuxScope.inScope(topics[0]));
}
public void testValuesWithWhitespace() throws Exception {

Back to the top