Subversion Repositories general

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
240 swalkenh 1
PK
521 swalkenh 2
 
3
 
240 swalkenh 4
Comment: view everything as text, best as default plugin
5
Transform-To-File: src/plugins/textEditorPlugin/TextEditorPluginTransf
6
 orm.xsl
7
Created-By: 1.4.0 (Sun Microsystems Inc.)
8
Description: ...(todo)
9
XMLEditor-Plugin-Name: TextEditor
10
Class-Path: 
11
Transform-Fro-File: src/plugins/textEditorPlugin/TextEditorPluginTrans
12
 formBack.xsl
13
Main-Class: src.plugins.textEditorPlugin.TextEditorPlugin
14
 
15
Name: src/plugins/textEditorPlugin
16
Specification-Version: 0.4 (05/07/03)
17
Specification-Title: plugin for XMLEditor
18
Implementation-Version: 0.1 (05/07/03)
19
Implementation-Title: src.plugins.textEditorPlugin
20
Implementation-Vendor: group5, software practice SS_2003, University B
21
 ielefeld, Germany
22
Specification-Vendor: group5, software practice SS_2003, University Bi
23
 elefeld, Germany
24
 
25
PK
521 swalkenh 26
 
27
pluginNameLjava/lang/String;
ConstantValue
28
TextEditorguiInterfaceLsrc/gui/GuiInterface;ourEventListenerLsrc/control/OurEventListener;textAreaLjavax/swing/JTextArea;
29
scrollPaneLjavax/swing/JScrollPane;
30
syncButtonLjavax/swing/JButton;logInterfaceLsrc/gui/LogInterface;statusInterfaceLsrc/gui/StatusInterface;transformer!Ljavax/xml/transform/Transformer;changedNodeLorg/w3c/dom/Node;oldNode
31
oldContent<init>()VCode"#
32
%	
33
 
34
 
35
 
36
 
37
 
38
 
39
bejava/awt/BorderLayoutg
40
 
41
 
42
 
43
 
44
 
45
 
46
 
47
 
48
 
49
 
50
 
51
©¬append,(Ljava/lang/String;)Ljava/lang/StringBuffer;®¯
52
 
53
 
54
 
55
 
56
 
57
 
58
 
59
 
60
 
61

62
setStatusInterface(Lsrc/gui/StatusInterface;)V
63
(javax/xml/parsers/DocumentBuilderFactory,()Ljavax/xml/parsers/DocumentBuilderFactory;™
64
newDocumentBuilder%()Ljavax/xml/parsers/DocumentBuilder;
65
!javax/xml/parsers/DocumentBuildersetErrorHandler(Lorg/xml/sax/ErrorHandler;)V
66
java/io/StringReader
67
 :org/xml/sax/InputSource"(Ljava/io/Reader;)V"$
68
#%parse1(Lorg/xml/sax/InputSource;)Lorg/w3c/dom/Document;'(
69
)
getFirstChild()Lorg/w3c/dom/Node;+,…-	/changedNode = 1,(Ljava/lang/Object;)Ljava/lang/StringBuffer;®3
70
¤4"org/apache/xerces/dom/DocumentImpl6
71
7%NOTVALID9&org/apache/xerces/dom/CoreDocumentImpl;createProcessingInstructionI(Ljava/lang/String;Ljava/lang/String;)Lorg/w3c/dom/ProcessingInstruction;=>
72
 
73
¤D	cloneNode(Z)Lorg/w3c/dom/Node;FG…HsetNodeValueJ9…KParser configuration error: M
74
IO error: OIllegal argument error: QSAX parser error: Sorg/xml/sax/SAXExceptionU
75
 
76
\.javax/xml/parsers/ParserConfigurationException^java/io/IOException`"java/lang/IllegalArgumentExceptionbvalidZcontenterrorHandler#Lsrc/parser/ValidationErrorHandler;documentBuilderFactory*Ljavax/xml/parsers/DocumentBuilderFactory;documentBuilder#Ljavax/xml/parsers/DocumentBuilder;stringReaderLjava/io/StringReader;inputSourceLorg/xml/sax/InputSource;doc$Lorg/apache/xerces/dom/DocumentImpl;pce0Ljavax/xml/parsers/ParserConfigurationException;ioeLjava/io/IOException;iae$Ljava/lang/IllegalArgumentException;saxeLorg/xml/sax/SAXException;src/control/OurEvent{java/lang/Object}([Ljava/lang/Object;)V"
77
|€src/control/OurEventListener‚
firedOurEvent(Lsrc/control/OurEvent;)V„…ƒ†eLsrc/control/OurEvent;actionPerformed(Ljava/awt/event/ActionEvent;)Vjava/util/EventObjectŒ	getSource()Ljava/lang/Object;Ž
78
 
79
’aeLjava/awt/event/ActionEvent;
80
SourceFileTextEditorPlugin.java!	
81

 !
82
 
83
@A$B1K9LL:MNOP$¦N*+µR*+¹XµZ*+¹^µ`*¶f*»hY·i¶o**´4q¶u**´=w¶u*´=*¶}²C¶J±K*
84
 
85
 
86
 
87
ÆÇLMNüý$>*+µÿ±K
88
 
89
 
90
 
91
 
92
 
93
 
94
 
95
 * 
96
 
97
 * University of Bielefeld, Germany
98
 
99
 * @version $Revision: 1.25 $
100
 
101
 * Last modification: $Date: 2003/07/15 16:44:11 $
102
 * $Id:  $
103
 */
104
105
package src.plugins.textEditorPlugin;
106
107
import java.awt.BorderLayout;
108
import java.awt.event.*;
109
110
import java.io.StringReader;
111
 
112
import javax.swing.JButton;
113
 
114
import javax.swing.JScrollPane;
115
import javax.swing.JTextArea;
116
 
117
/*import javax.swing.text.Style;
118
 
119
import javax.swing.text.StyleConstants;
120
import javax.swing.text.BadLocationException;*/
121
122
import org.w3c.dom.Document;
123
 
124
125
import org.xml.sax.InputSource;
126
127
import javax.xml.transform.Transformer;
128
 
129
import javax.xml.transform.TransformerConfigurationException;
130
import javax.xml.transform.TransformerException;
131
 
132
import javax.xml.transform.stream.StreamResult;
133
 
134
import javax.xml.parsers.DocumentBuilderFactory;
135
import javax.xml.parsers.ParserConfigurationException;
136
137
import src.control.OurEvent;
138
import src.control.OurEventListener;
139
import src.gui.*;
140
import src.plugins.PluginInterface;
141
142
/** 
143
 
144
 * 
145
 * @author Christian Stollenwerk
146
 */
147
public class TextEditorPlugin extends JPanel
148
 
149
							  	
150
	//added 16.07.03 Sascha W. cause method "firedOurEvent" has changed
151
	/** Name of the plugin, used in method <code>firePluginChangedElement</code> */
152
	final private String pluginName = "TextEditor";
153
	
154
	private GuiInterface guiInterface;
155
	private OurEventListener ourEventListener;
156
 
157
	private JScrollPane scrollPane = new JScrollPane(textArea);
158
	private JButton syncButton = new JButton("synchronize");
159
	private LogInterface logInterface;
160
 
161
	private Transformer transformer;
162
	private Node changedNode;
163
	private Node oldNode;
164
	private String oldContent;
165
166
	public TextEditorPlugin() {
167
		System.out.println("I'm a new instance of the TextEditorPlugin!");
168
	}
169
	
170
171
	/** 
172
 
173
	 * 
174
	 * @see src.gui.PluginInterface#init(src.gui.GuiInterface)
175
	 */
176
 
177
 
178
		this.guiInterface = guiInterface;
179
		logInterface = guiInterface.getLogInterface();
180
		statusInterface = guiInterface.getStatusInterface();
181
		setVisible(false);
182
		setLayout(new BorderLayout());
183
		add(scrollPane, BorderLayout.CENTER);
184
		add(syncButton, BorderLayout.NORTH);
185
		syncButton.addActionListener(this);
186
		System.out.println("TextEditorPlugin initialized");
187
	}
188
189
190
	/** 
191
	 * Starts the Text Editor Plugin if a registered node is choosen
192
	 * 
193
	 * @param element: The selected node from the XML document, read-only.
194
	 * @param environment: The whole XML document, read-only.
195
 
196
 
197
	 */
198
	public void start(final Node node, final Document environment) {
199
		oldNode = node;
200
		// casts the node into a DOMSource for transforming
201
		if(node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
202
			DOMSource source = new DOMSource(node);
203
			java.io.StringWriter stringWriter = new java.io.StringWriter();
204
			StreamResult stream = new StreamResult(stringWriter);
205
			try {
206
				/* Create a TransformerFactory and a new Transformer. */
207
				TransformerFactory transformerFactory = TransformerFactory.newInstance();
208
				transformer = transformerFactory.newTransformer();
209
			}
210
		
211
			/* Catch and log exceptions thrown by the TransformerFactory.*/
212
			catch (TransformerConfigurationException tce) {
213
				logInterface.log(LogInterface.TYPE_ERROR, "TransformerFactory error: "
214
				+ tce.getMessage());
215
			}
216
			transformer.setOutputProperty(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
217
 
218
			transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
219
			transformer.setOutputProperty(javax.xml.transform.OutputKeys.METHOD, "xml");
220
			try {
221
				transformer.transform(source, stream);
222
			}
223
			catch (TransformerException te){
224
				logInterface.log(LogInterface.TYPE_ERROR, "Transformer error: "
225
				+ te.getMessage());
226
			}
227
			String string = stringWriter.getBuffer().toString();
228
			oldContent = string;
229
			
230
			// try syntax highlighting
231
			/*javax.swing.text.Document textDocument = textArea.getDocument();
232
			StyleContext styleContext = StyleContext.getDefaultStyleContext();
233
			Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
234
		
235
			Style tagStyle = styleContext.addStyle(null, defaultStyle);
236
 
237
			//StyleConstants.setFontFamily(tagStyle, "Arial");
238
			System.out.println("tagStyle = " +tagStyle);
239
			Style style = defaultStyle;
240
			char c;
241
 
242
			for(int i = 0; i < string.length(); i++) {
243
				c = string.charAt(i);
244
				try {
245
					if(newLine && c == ' ') {
246
						textDocument.insertString(textDocument.getLength(), 
247
													"   ", style);
248
					}
249
					if(c != ' ')
250
						newLine = false;
251
					if(c == '\n') {
252
						newLine = true;
253
					}
254
					if(c == '<') {
255
						style = tagStyle;
256
						//textArea.setDisabledTextColor(java.awt.Color.BLUE);
257
					}
258
					if(c == '>') {
259
						style = defaultStyle;
260
						//textArea.setDisabledTextColor(java.awt.Color.BLACK);
261
					}
262
					textDocument.insertString(textDocument.getLength(), 
263
												String.valueOf(c), style);
264
				}
265
				catch(BadLocationException ble) {
266
					logInterface.log(LogInterface.TYPE_ERROR, ble.getMessage());
267
				}
268
				//textArea.setText(String.valueOf(c));
269
			}*/
270
			textArea.setText(string);
271
		}
272
		// if the node ist a text node or similar, only get the value
273
		else {
274
			textArea.setText(node.getNodeValue());
275
		}
276
		
277
		//added 14.07.03 Sascha W. -> fixed problem of not visible plugins
278
		// (deleted this line in method "init"!)
279
		guiInterface.setPluginPanel(this);
280
		setVisible(true);
281
	}
282
283
 
284
	/** 
285
	 * Stop showing the Text Editor Plugin
286
	 * 
287
	 * @see src.gui.PluginInterface#stop()
288
	 */
289
 
290
 
291
	}
292
293
294
	//added 11/07/03 Sascha W.; own events are available now
295
	/* (non-Javadoc)
296
	 * @see src.gui.PluginInterface#setOurEventListener(src.control.OurEventListener)
297
	 */
298
	public void setOurEventListener(OurEventListener newListener) {
299
 
300
 
301
302
303
	/**
304
	 *  Forces the Text Editor Plugin to return the actual status as a node
305
	 *  not well-formed parts have to be capsuled into a prosessing instruction.
306
	 * 
307
	 *  @see src.gui.PluginInterface#forceStatusReport()
308
 
309
 
310
		// parse the content of the JTextArea
311
		boolean valid = true;
312
		String content = textArea.getText();
313
		src.parser.ValidationErrorHandler errorHandler = new src.parser.ValidationErrorHandler();
314
		errorHandler.setLogInterface(logInterface);
315
		errorHandler.setStatusInterface(statusInterface);
316
		do {
317
			try {
318
				DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
319
				DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
320
				documentBuilder.setErrorHandler(errorHandler);
321
				// if the content of the edior is well-formed, parse only
322
				if(valid == true) {
323
					StringReader stringReader = new StringReader(content);
324
					InputSource inputSource = new InputSource(stringReader);
325
					//doc.appendChild(documentBuilder.parse(inputSource));
326
					changedNode = documentBuilder.parse(inputSource).getFirstChild();
327
					System.out.println("changedNode = " + changedNode);
328
				}
329
				// if the content is not well-formed, capsule it into a processing instruction
330
				else {
331
					if(oldNode.getNodeType() == Node.ELEMENT_NODE || oldNode.getNodeType() == Node.ENTITY_NODE) {
332
						content = textArea.getText();
333
						org.apache.xerces.dom.DocumentImpl doc = new org.apache.xerces.dom.DocumentImpl(); 
334
						changedNode = doc.createProcessingInstruction("NOTVALID", content);
335
						valid = true;
336
					}
337
					else {
338
						System.out.println("Node Type = " + oldNode.getNodeType());
339
						changedNode = oldNode.cloneNode(true);
340
						changedNode.setNodeValue(textArea.getText());
341
						valid = true;
342
					}
343
				}
344
			}
345
			
346
			/* Catch and log configuration errors. */
347
			catch(ParserConfigurationException pce) {
348
				logInterface.log(LogInterface.TYPE_ERROR, "Parser configuration error: "
349
				+ pce.getMessage());
350
			}
351
			
352
 
353
			catch(java.io.IOException ioe) {
354
				logInterface.log(LogInterface.TYPE_ERROR, "IO error: "
355
				+ ioe.getMessage());
356
			}
357
			
358
 
359
				logInterface.log(LogInterface.TYPE_ERROR, "Illegal argument error: "
360
				+ iae.getMessage());
361
			}
362
			
363
			/* Catch and log parsing errors. */
364
 
365
				logInterface.log(LogInterface.TYPE_ERROR, "SAX parser error: "
366
				+ saxe.getMessage());
367
				valid = false;
368
			}
369
 
370
		while(valid == false);
371
372
		// return the old and the changed node
373
		System.out.println("Return this node:" + changedNode);
374
		firePluginChangedElement(oldNode, changedNode);
375
	}
376
	
377
	//added 11/07/03 Sascha W.; own events are available now
378
 
379
		OurEvent e = new OurEvent(new Object[] {oldNode, changedNode, pluginName});
380
		ourEventListener.firedOurEvent(e);
381
	}
382
	
383
 
384
	public void actionPerformed(ActionEvent ae) {
385
		if(ae.getSource() == syncButton) {
386
			forceStatusReport();
387
		}
388
	}
389
 
390
Ùhð.Qæ³²dd:src/plugins/textEditorPlugin/TextEditorPluginTransform.xsl<!-- for TextEditor plugin: simply copy the whole document -->
391
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
392
<xsl:output method="xml" indent="yes" />
393
394
<xsl:template match="/">
395
	<xsl:apply-templates />
240 swalkenh 396
</xsl:template>
521 swalkenh 397
 
348 swalkenh 398
<xsl:template match="node()">
399
	<xsl:copy-of select="." />
400
 
521 swalkenh 401
402
</xsl:stylesheet>PK
348 swalkenh 403
Ùhð.‚ÐGnn>src/plugins/textEditorPlugin/TextEditorPluginTransformBack.xsl<!-- backwards for TextEditor plugin: simply copy the whole document -->
404
 
521 swalkenh 405
<xsl:output method="xml" indent="yes" />
406
407
<xsl:template match="/">
408
 
240 swalkenh 409
</xsl:template>
521 swalkenh 410
 
348 swalkenh 411
<xsl:template match="node()">
412
	<xsl:copy-of select="." />
413
 
521 swalkenh 414
415
</xsl:stylesheet>PK
348 swalkenh 416
417
 
521 swalkenh 418
419
¥ið.~ƒkk66+META-INF/MANIFEST.MFPK
420
421
 
240 swalkenh 422
423
 
521 swalkenh 424
 
240 swalkenh 425
 
521 swalkenh 426
 
240 swalkenh 427