Skip to main content
summaryrefslogtreecommitdiffstats
blob: 83d5afc5bd63beb11c4ea72fa66096c581f0f3f0 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*******************************************************************************
 * Copyright (c) 2013 Obeo.
 * 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:
 *     Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.compare.doc;

import java.io.StringWriter;
import java.io.Writer;
import java.nio.file.Path;

import org.eclipse.mylyn.wikitext.core.util.DefaultXmlStreamWriter;
import org.eclipse.mylyn.wikitext.core.util.FormattingXMLStreamWriter;
import org.eclipse.mylyn.wikitext.core.util.XmlStreamWriter;

/**
 * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
 *
 */
public class PrimaryTOCWriter {
	
	private StringWriter primaryTOCOut;
	private XmlStreamWriter primaryTOCWriter;
	
	private StringWriter pluginOut;
	private XmlStreamWriter pluginWriter;
	private Path baseDir;

	void startPrimaryTOC(Path indexHTMLFile, String title) {
		baseDir = indexHTMLFile.getParent();
		primaryTOCOut = new StringWriter(8096);
		primaryTOCWriter = createXmlStreamWriter(primaryTOCOut);
		
		pluginOut = new StringWriter(8096);
		pluginWriter = createXmlStreamWriter(pluginOut);

		primaryTOCWriter.writeStartDocument("UTF-8", "1.0");
		primaryTOCWriter.writeStartElement("toc"); 
		primaryTOCWriter.writeAttribute("topic", indexHTMLFile.toString()); 
		primaryTOCWriter.writeAttribute("label", title); 

		pluginWriter.writeStartDocument("UTF-8", "1.0");
		pluginWriter.writeLiteral("\n<?eclipse version=\"3.2\"?>\n");
		pluginWriter.writeStartElement("plugin");
		
		pluginWriter.writeStartElement("extension");
		pluginWriter.writeAttribute("point", "org.eclipse.help.toc");
		
		pluginWriter.writeEmptyElement("toc");
		pluginWriter.writeAttribute("file", "help/toc.xml");
		pluginWriter.writeAttribute("primary", "true");
		
		pluginWriter.writeEndElement();
		
		pluginWriter.writeStartElement("extension");
		pluginWriter.writeAttribute("point", "org.eclipse.help.toc");
		
	}
	
	void endPrimaryTOC() {
		primaryTOCWriter.writeEndElement();
		primaryTOCWriter.writeEndDocument();
		primaryTOCWriter.close();
		
		pluginWriter.writeEndElement();
		pluginWriter.writeEndElement();
		pluginWriter.writeEndDocument();
		pluginWriter.close();
	}
	
	void startTopic(String label, Path href) {
		primaryTOCWriter.writeStartElement("topic");
		primaryTOCWriter.writeAttribute("label", label);
		
		if (href != null) {
			primaryTOCWriter.writeAttribute("href", href.toString());
		}
	}
	
	void createLink(Path linkedTOC) {
		primaryTOCWriter.writeStartElement("link");
		primaryTOCWriter.writeAttribute("toc", baseDir.resolve(linkedTOC).toString());
		primaryTOCWriter.writeEndElement();
		
		pluginWriter.writeEmptyElement("toc");
		pluginWriter.writeAttribute("file", baseDir.resolve(linkedTOC).toString());
	}
	
	void endTopic() {
		primaryTOCWriter.writeEndElement();
	}
	
	String getPrimaryTOCContent() {
		return primaryTOCOut.toString();
	}
	
	String getPluginContent() {
		return pluginOut.toString();
	}
	
	protected XmlStreamWriter createXmlStreamWriter(Writer out) {
		XmlStreamWriter writer = new DefaultXmlStreamWriter(out);
		return new FormattingXMLStreamWriter(writer);
	}
}

Back to the top