Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,33 @@ public static TocManager getTocManager() {
* Used to obtain Context Manager returns an instance of ContextManager
*/
public static ContextManager getContextManager() {
if (getDefault().contextManager == null)
if (getDefault().contextManager == null) {
getDefault().contextManager = new ContextManager();
}
return getDefault().contextManager;
}

/**
* Used to obtain the ContentExtensionManager
*/
public static ContentExtensionManager getContentExtensionManager() {
if (getDefault().contentExtensionManager == null)
if (getDefault().contentExtensionManager == null) {
getDefault().contentExtensionManager = new ContentExtensionManager();
}
return getDefault().contentExtensionManager;
}

public static IndexManager getIndexManager() {
if (getDefault().indexManager == null)
if (getDefault().indexManager == null) {
getDefault().indexManager = new IndexManager();
}
return getDefault().indexManager;
}

public static CriteriaManager getCriteriaManager() {
if (getDefault().criteriaManager == null)
if (getDefault().criteriaManager == null) {
getDefault().criteriaManager = new CriteriaManager();
}
return getDefault().criteriaManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,13 @@ private Map<String, Context> loadContextsFromInputStream(ContextFile descriptor,
IUAElement[] children = root.getChildren();
Map<String, Context> contexts = new HashMap<>();
for (int i=0;i<children.length;++i) {
if (children[i] instanceof Context) {
Context context = (Context)children[i];
if (children[i] instanceof Context context) {
String id = context.getId();
if (id != null) {
Object existingContext = contexts.get(id);
if (existingContext==null)
if (existingContext==null) {
contexts.put(id, context);
else
} else
{
((Context)existingContext).mergeContext(context);

Expand Down Expand Up @@ -290,8 +289,7 @@ private Map<String, String[]> getRequiredAttributes() {
private class NormalizeHandler extends ProcessorHandler {
@Override
public short handle(UAElement element, String id) {
if (element instanceof Context) {
Context context = (Context)element;
if (element instanceof Context context) {
IUAElement[] children = context.getChildren();
if (children.length > 0 && Context.ELEMENT_DESCRIPTION.equals(((UAElement)children[0]).getElementName())) {
StringBuilder buf = new StringBuilder();
Expand Down Expand Up @@ -321,8 +319,7 @@ else if (node.getNodeType() == Node.ELEMENT_NODE) {
description.appendChild(document.createTextNode(buf.toString()));
}
}
else if (element instanceof Topic) {
Topic topic = (Topic)element;
else if (element instanceof Topic topic) {
String href = topic.getHref();
if (href != null) {
int index = id.indexOf('/', 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public class ContextManager {

public ContextManager()
{
if (HelpPlugin.DEBUG_CONTEXT)
if (HelpPlugin.DEBUG_CONTEXT) {
checkContextProviders();
}
}

/*
Expand Down Expand Up @@ -88,8 +89,9 @@ public IContext getContext(String contextId, String locale) {

String id = contextId;
ArrayList<String> potentialMatches = new ArrayList<>();
if ((index = contextId.lastIndexOf('.'))>-1)
if ((index = contextId.lastIndexOf('.'))>-1) {
id = contextId.substring(index+1);
}

String warning = "Registered Context Provider IDs:\n"; //$NON-NLS-1$
Iterator<String> iter = contextIDsByPluginId.keySet().iterator();
Expand All @@ -109,8 +111,9 @@ public IContext getContext(String contextId, String locale) {
warning+="--------------------------------"; //$NON-NLS-1$
System.out.println(warning);

if (!potentialMatches.isEmpty())
if (!potentialMatches.isEmpty()) {
System.out.println("The ID searched is "+contextId+". Did you mean to call setHelp with:\n"+potentialMatches); //$NON-NLS-1$ //$NON-NLS-2$
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ public String getPluginId() {
}

public InputStream getInputStream() throws IOException {
if (pluginId != null)
if (pluginId != null) {
return ResourceLocator.openFromPlugin(pluginId, file, locale);
else
} else {
return new FileInputStream(file);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public ICriteriaDefinitionContribution[] getCriteriaDefinitionContributions(Stri

// Use the contained exception.
Exception x = spe;
if (spe.getException() != null)
if (spe.getException() != null) {
x = spe.getException();
}
ILog.of(getClass()).error(buffer.toString(), x);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ public void addCriteriaValues(ICriteria[] criteria, String locale){
List<String> criterionValues = criterion.getCriterionValues();

Set<String> existedValues = criteriaInLocale.get(criterionName);
if (null == existedValues)
if (null == existedValues) {
existedValues = new HashSet<>();
}
existedValues.addAll(criterionValues);
criteriaInLocale.put(criterionName, existedValues);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public IIndexEntry[] getEntries() {
* @return the entry with matching keyword or null
*/
public IndexEntry getSeeTarget(IndexSee see) {
if (children == null) getChildren();
if (children == null) {
getChildren();
}
String keyword = see.getKeyword();
for (Iterator<UAElement> iter = children.iterator(); iter.hasNext();) {
UAElement next = iter.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ boolean isValidSeeReference(IndexSee see) {
private static class NormalizeHandler extends ProcessorHandler {
@Override
public short handle(UAElement element, String id) {
if (element instanceof Topic) {
Topic topic = (Topic)element;
if (element instanceof Topic topic) {
String href = topic.getHref();
if (href != null) {
int index = id.indexOf('/', 1);
Expand Down Expand Up @@ -295,8 +294,7 @@ else if (Character.isLetter(c)) {
* used for sorting.
*/
private String getLabel(IUAElement element) {
if (element instanceof Topic) {
Topic topic = (Topic)element;
if (element instanceof Topic topic) {
if (topic.getLabel() == null) {
ITopic topic2 = HelpPlugin.getTocManager().getTopic(topic.getHref(), locale);
if (topic2 != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ public String getPluginId() {
}

public InputStream getInputStream() throws IOException {
if (pluginId != null)
if (pluginId != null) {
return ResourceLocator.openFromPlugin(pluginId, file, locale);
else
} else {
return new FileInputStream(file);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public IIndexContribution[] getIndexContributions(String locale) {

// Use the contained exception.
Exception x = spe;
if (spe.getException() != null)
if (spe.getException() != null) {
x = spe.getException();
}
ILog.of(getClass()).error(buffer.toString(), x);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public static String[] collectExtraDocuments(TocFile tocFile) {
}
Bundle pluginDesc = Platform.getBundle(pluginID);
if (pluginDesc == null || pluginDesc.getState() == Bundle.INSTALLED
|| pluginDesc.getState() == Bundle.UNINSTALLED)
|| pluginDesc.getState() == Bundle.UNINSTALLED) {
return new String[0];
}
String directory = HrefUtil.getResourcePathFromHref(dir);
if (directory == null) {
// the root - all files in a zip should be indexed
Expand Down
36 changes: 24 additions & 12 deletions ua/org.eclipse.help/src/org/eclipse/help/internal/toc/HrefUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public class HrefUtil {
*/
public static String normalizeDirectoryHref(String pluginID, String dir) {
// "" is treated as if extra directory was not provided
if (dir == null || dir.length() <= 0)
if (dir == null || dir.length() <= 0) {
return null;
}
// "." means all the files in the plugin
if (".".equals(dir)) //$NON-NLS-1$
if (".".equals(dir)) { //$NON-NLS-1$
dir = ""; //$NON-NLS-1$
}
// remove not needed trailing separator
if (dir.length() > 0 && dir.lastIndexOf('/') == dir.length() - 1) {
dir = dir.substring(0, dir.length() - 1);
Expand All @@ -47,18 +49,21 @@ public static String normalizeDirectoryHref(String pluginID, String dir) {
* /pluginID/path[#anchorID]
*/
public final static String normalizeHref(String pluginID, String href) {
if (href == null)
if (href == null) {
return null;
}
if (href.startsWith("http:") //$NON-NLS-1$
|| href.startsWith("https:") //$NON-NLS-1$
|| href.startsWith("file:") //$NON-NLS-1$
|| href.startsWith("jar:")) //$NON-NLS-1$
|| href.startsWith("jar:")) { //$NON-NLS-1$
// external doc
return href;
}
href = normalizeDirectoryPath(href);
if (href.startsWith("/")) //$NON-NLS-1$
if (href.startsWith("/")) { //$NON-NLS-1$
// already normalized
return href;
}
if (href.startsWith("../")) { //$NON-NLS-1$
return href.substring(2);
}
Expand All @@ -82,11 +87,13 @@ public final static String normalizeHref(String pluginID, String href) {
* @return plugin ID, or null
*/
public static String getPluginIDFromHref(String href) {
if (href == null || href.length() < 2 || href.charAt(0) != '/')
if (href == null || href.length() < 2 || href.charAt(0) != '/') {
return null;
}
int secondSlashIx = href.indexOf("/", 1); //$NON-NLS-1$
if (secondSlashIx < 0) // href is /pluginID
if (secondSlashIx < 0) { // href is /pluginID
return href.substring(1);
}
// href is /pluginID/path[#anchorID]
return href.substring(1, secondSlashIx);
}
Expand All @@ -99,19 +106,24 @@ public static String getPluginIDFromHref(String href) {
* @return relative resource path, or null
*/
public static String getResourcePathFromHref(String href) {
if (href == null)
if (href == null) {
return null;
}
// drop anchor id
int anchorIx = href.lastIndexOf("#"); //$NON-NLS-1$
if (anchorIx >= 0) //anchor exists, drop it
if (anchorIx >= 0) { //anchor exists, drop it
href = href.substring(0, anchorIx);
if (href.length() < 2 || href.charAt(0) != '/')
}
if (href.length() < 2 || href.charAt(0) != '/') {
return null;
}
int secondSlashIx = href.indexOf("/", 1); //$NON-NLS-1$
if (secondSlashIx < 0) // href is /pluginID
if (secondSlashIx < 0) { // href is /pluginID
return null;
if (secondSlashIx + 1 < href.length()) // href is /pluginID/path
}
if (secondSlashIx + 1 < href.length()) { // href is /pluginID/path
return href.substring(secondSlashIx + 1);
}
// href is /pluginID/
return ""; //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ private Map<String, String> getLinkedContributionIds(List<TocContribution> contr
new ProcessorHandler() {
@Override
public short handle(UAElement element, String id) {
if (element instanceof Link) {
Link link = (Link)element;
if (element instanceof Link link) {
String toc = link.getToc();
if (toc != null) {
TocContribution srcContribution = getContribution(id);
Expand Down Expand Up @@ -356,8 +355,7 @@ private void addExtraDocuments(TocContribution contribution, String[] extraDocum
private class LinkHandler extends ProcessorHandler {
@Override
public short handle(UAElement element, String id) {
if (element instanceof Link) {
Link link = (Link)element;
if (element instanceof Link link) {
UAElement parent = link.getParentElement();
if (parent != null) {
String toc = link.getToc();
Expand Down Expand Up @@ -388,11 +386,10 @@ public short handle(UAElement element, String id) {
private class AnchorHandler extends ProcessorHandler {
@Override
public short handle(UAElement element, String id) {
if (element instanceof Anchor) {
if (element instanceof Anchor anchor) {
if (tocsToFilter.contains(id)) {
return UNHANDLED;
}
Anchor anchor = (Anchor)element;
UAElement parent = anchor.getParentElement();
if (parent != null) {
String anchorId = anchor.getId();
Expand Down Expand Up @@ -437,8 +434,7 @@ public short handle(UAElement element, String id) {
private class NormalizeHandler extends ProcessorHandler {
@Override
public short handle(UAElement element, String id) {
if (element instanceof Topic) {
Topic topic = (Topic)element;
if (element instanceof Topic topic) {
String href = topic.getHref();
if (href != null) {
topic.setHref(normalize(href, id));
Expand All @@ -448,8 +444,7 @@ public short handle(UAElement element, String id) {

return HANDLED_CONTINUE;
}
else if (element instanceof Toc) {
Toc toc = (Toc)element;
else if (element instanceof Toc toc) {
toc.setHref(id);
String topic = toc.getTopic();
if (topic != null) {
Expand Down Expand Up @@ -484,12 +479,10 @@ private void processCriteria(UAElement element, String id) {
ITocContribution contribution = getContribution(id);
String locale = contribution.getLocale();
ICriteria[] criteria = new ICriteria[0];
if (element instanceof Topic) {
Topic topic = (Topic) element;
if (element instanceof Topic topic) {
criteria = CriteriaProviderRegistry.getInstance().getAllCriteria(topic);
}
else if (element instanceof Toc) {
Toc toc = (Toc) element;
else if (element instanceof Toc toc) {
criteria = CriteriaProviderRegistry.getInstance().getAllCriteria(toc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public ITocContribution[] getTocContributions(String locale) {
}
catch (Throwable t) {
String locationInfo = ""; //$NON-NLS-1$
if (t instanceof SAXParseException) {
SAXParseException spe = (SAXParseException) t;
if (t instanceof SAXParseException spe) {
locationInfo = " at line " + spe.getLineNumber() //$NON-NLS-1$
+ ", column " + spe.getColumnNumber(); //$NON-NLS-1$
}
Expand Down
Loading
Loading