Skip to main content
summaryrefslogtreecommitdiffstats
blob: faf9511a9b96ed178ffad2edc1de5601726ac9f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package org.eclipse.help.internal.server;

/*
 * Licensed Materials - Property of IBM,
 * WebSphere Studio Workbench
 * (c) Copyright IBM Corp 2000
 */

import java.io.*;
import org.eclipse.help.internal.HelpSystem;
import org.eclipse.help.internal.util.*;

/**
 * URL to files in the plugin's working directory, as well as
 * to temporary files that might be generated on the fly.
 * One instance of this is a "Table of Contents" URL.
 * Example: http://localhost:80/temp/TableOfContents
 *              /?topicId=org.eclipse.help.examples.ex1.someTopicId
 *              &viewId=org.eclipse.help.examples.ex1.someViewId 
 *              &infosetId=org.eclipse.help.examples.ex1.someInfosetId  
 */
public class TempURL extends HelpURL {
	// the prefix that identifies a Table Of Contents Temp URL.
	public static String TABLE_OF_CONTENTS_PREFIX = "TableOfContents";

	public TempURL(String url) {
		super(url);
	}
	public TempURL(String url, String query) {
		super(url, query);
	}
	/** 
	 * generates a Table Of Contents as an InputStream
	 */
	private InputStream generateTableOfContents() {
		// delegate to the TableOfContentsGenerator
		String infosetId = getValue("infosetId");
		String viewId = getValue("viewId");
		String topicId = getValue("topicId");
		TableOfContentsGenerator generator = new TableOfContentsGenerator();
		return generator.generateTableOfContents(infosetId, viewId, topicId);

	}
	public String getContentType() {
		//** this is a special case for a Table Of Contents url
		//** need to override parent behavior
		if (isTableOfContentsURL())
			return "text/html";
		else
			return super.getContentType();
	}
	/**
	 * Returns the path prefix that identifies the URL. 
	 */
	public static String getPrefix() {
		return "temp";
	}
	public boolean isTableOfContentsURL() {
		if (url.startsWith(TABLE_OF_CONTENTS_PREFIX))
			return true;
		else
			return false;
	}
	/**
	 * Opens a stream for reading.
	 * 
	 * @return java.io.InputStream
	 */
	public InputStream openStream() {

		// First check if this is a special "Table Of Contents" request.
		// If it is, do HTML generation on the client.
		if (isTableOfContentsURL())
			return generateTableOfContents();

		String path =
			HelpSystem.getPlugin().getStateLocation().toFile().getAbsolutePath().replace(
				File.separatorChar,
				'/');
		try {
			File f = new File(path + "/" + url);
			if (!f.exists())
				return null;
			contentSize = f.length();
			return new FileInputStream(f);
		} catch (IOException e) {
			return null;
		}
	}
}

Back to the top