Subversion Repositories general

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
240 swalkenh 1
PK
545 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
545 swalkenh 26
 
521 swalkenh 27
pluginNameLjava/lang/String;
ConstantValue
28
TextEditorguiInterfaceLsrc/gui/GuiInterface;ourEventListenerLsrc/control/OurEventListener;textAreaLjavax/swing/JTextArea;
545 swalkenh 29
scrollPaneLjavax/swing/JScrollPane;
521 swalkenh 30
syncButtonLjavax/swing/JButton;logInterfaceLsrc/gui/LogInterface;statusInterfaceLsrc/gui/StatusInterface;transformer!Ljavax/xml/transform/Transformer;changedNodeLorg/w3c/dom/Node;oldNode
31
oldContentmodifiedZ<init>()VCode()
545 swalkenh 32
+
	-javax/swing/JTextArea/
33
 
34
 
35
 
36
 
37
 
38
 
39
p+java/awt/Containerr	setLayout(Ljava/awt/LayoutManager;)Vtu
40
 
41
 
42
 
43
 
44
 
45
 
46
 
47
 
48
 
49
 
50
 
51
 
52
²¾toStringÀ¹
53
 
54
 
55
 
56
 
57
 
58
 
59
 
60
 
61
 
62
$(javax/xml/parsers/DocumentBuilderFactory&,()Ljavax/xml/parsers/DocumentBuilderFactory;§(
63
')newDocumentBuilder%()Ljavax/xml/parsers/DocumentBuilder;+,
64
'-!javax/xml/parsers/DocumentBuilder/setErrorHandler(Lorg/xml/sax/ErrorHandler;)V12
65
03java/io/StringReader5
66
6@org/xml/sax/InputSource8(Ljava/io/Reader;)V(:
67
9;parse1(Lorg/xml/sax/InputSource;)Lorg/w3c/dom/Document;=>
68
0?
getFirstChild()Lorg/w3c/dom/Node;AB“C"#	EchangedNode = G,(Ljava/lang/Object;)Ljava/lang/StringBuffer;¼I
69
²J"org/apache/xerces/dom/DocumentImplL
70
M+NOTVALIDO&org/apache/xerces/dom/CoreDocumentImplQcreateProcessingInstructionI(Ljava/lang/String;Ljava/lang/String;)Lorg/w3c/dom/ProcessingInstruction;ST
71
RUNode Type = W(I)Ljava/lang/StringBuffer;¼Y
72
 
73
IO error: eIllegal argument error: gSAX parser error: iorg/xml/sax/SAXExceptionk
74
lºReturn this node:nfirePluginChangedElement'(Lorg/w3c/dom/Node;Lorg/w3c/dom/Node;)Vpq
75
 
76
‘•src/control/OurEventListener—
firedOurEvent(Lsrc/control/OurEvent;)V™š˜›eLsrc/control/OurEvent;actionPerformed(Ljava/awt/event/ActionEvent;)Vjava/util/EventObject¡	getSource()Ljava/lang/Object;£¤
77
¢¥)
78
 
79
®±getLineOfOffset(I)I³´
80
0µgetLineStartOffset·´
81
0¸java/awt/Pointº(II)V(¼
82
 
83
isModified()Z
84
 
85
 
86
BC$D1K6N>OT?UVWX*²V*+µZ*+¹`µb*+¹fµh*¶n*»pY·q¶w**´:y¶}**´C¶}*´C*¶…*´3*¶‹²K¶R±S.YZ[\])^3_=`EaMbUcTVUVVŽ*ü*+µ‘+¹— Æ»™Y+·œN»žY·Ÿ:»¡Y·¤:¸ª:*¶®µ°§#:*´b»²Y´·µ¶»¶¿¶Â¹È*´°Ê̶Ò*´°Ô̶Ò*´°ÖضÒ*´°ÚܶÒ*´°-¶à§#:*´b»²Yâ·µ¶»¶¿¶Â¹È¶æ¶Â:*µè*´3¶ë§*´3+¹î¶ë*´Z*¹ò*´3¶ö*¹ü*¶n±,==þ‰––Szoqrs!t,w1x=|?}D}M~U}]€hs‚~ƒ‰…–‡˜ˆˆ¦‰®ˆ¶‹ÀŒÆ¶Òºß¿éÀöÁûÂTf
87
üUVü#üº!±,¦	1
88
?
˜À)*4*¶n±S
89
ËÌTUV*>*+µ±S
90
 
91
 
92
 
93
 
94
 
95
 
96
 * This file contains the TextEditorPlugin class.
97
 
98
 
99
 
100
 
101
 * @version $Revision: 1.29 $
102
 
103
 * Last modification: $Date: 2003/07/16 13:23:24 $
104
 
105
 
521 swalkenh 106
107
package src.plugins.textEditorPlugin;
108
109
import java.awt.BorderLayout;
110
import java.awt.event.*;
545 swalkenh 111
521 swalkenh 112
import java.io.StringReader;
545 swalkenh 113
114
import javax.swing.JButton;
521 swalkenh 115
import javax.swing.JPanel;
116
 
117
import javax.swing.JTextArea;
118
 
119
import javax.swing.text.BadLocationException;
120
121
 
122
import javax.swing.text.StyleContext;
123
 
124
import javax.swing.text.BadLocationException;*/
125
126
import org.w3c.dom.Document;
127
import org.w3c.dom.Node;
545 swalkenh 128
129
import org.xml.sax.InputSource;
521 swalkenh 130
 
131
import javax.xml.transform.Transformer;
132
import javax.xml.transform.TransformerFactory;
133
import javax.xml.transform.TransformerConfigurationException;
134
import javax.xml.transform.TransformerException;
135
 
136
import javax.xml.transform.stream.StreamResult;
137
import javax.xml.parsers.DocumentBuilder;
138
 
139
import javax.xml.parsers.ParserConfigurationException;
140
 
141
import src.control.OurEvent;
142
import src.control.OurEventListener;
143
import src.gui.*;
144
import src.plugins.PluginInterface;
145
146
/** 
147
 * The Text Editor Plugin is used for textual XML node editing
148
 * 
149
 * @author Christian Stollenwerk
150
 
151
public class TextEditorPlugin extends JPanel
152
							  implements PluginInterface, ActionListener, CaretListener, DocumentListener {
153
							  	
154
	//added 16.07.03 Sascha W. cause method "firedOurEvent" has changed
155
 
156
	final private String pluginName = "TextEditor";
157
	
158
	private GuiInterface guiInterface;
159
	private OurEventListener ourEventListener;
160
	private JTextArea textArea = new JTextArea();
161
	private JScrollPane scrollPane = new JScrollPane(textArea);
545 swalkenh 162
	private JButton syncButton = new JButton("synchronize");
521 swalkenh 163
 
164
	private StatusInterface statusInterface;
165
	private Transformer transformer;
166
	private Node changedNode;
167
 
168
	private String oldContent;
169
	private boolean modified = false;
170
171
	public TextEditorPlugin() {
172
		System.out.println("I'm a new instance of the TextEditorPlugin!");
173
	}
174
	
175
176
	/** 
177
	 * Initializes the Text Editor Plugin, but does not show it
178
	 * 
545 swalkenh 179
	 * @see src.gui.PluginInterface#init(src.gui.GuiInterface)
521 swalkenh 180
 
181
	public void init(GuiInterface guiInterface) {
182
		// connects the Plugin to the GUI
183
		this.guiInterface = guiInterface;
184
 
185
 
186
		setVisible(false);
187
		setLayout(new BorderLayout());
188
		add(scrollPane, BorderLayout.CENTER);
189
		add(syncButton, BorderLayout.NORTH);
190
		syncButton.addActionListener(this);
191
		textArea.addCaretListener(this);
192
		System.out.println("TextEditorPlugin initialized");
193
	}
194
195
196
	/** 
197
	 * Starts the Text Editor Plugin if a registered node is choosen
198
	 * 
199
	 * @param element: The selected node from the XML document, read-only.
200
	 * @param environment: The whole XML document, read-only.
545 swalkenh 201
	 * 
521 swalkenh 202
	 * @see src.gui.PluginInterface#start(org.w3c.dom.Element, org.w3c.dom.Document)
203
	 */
204
 
205
 
206
		// casts the node into a DOMSource for transforming
207
		if(node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
208
			DOMSource source = new DOMSource(node);
209
			java.io.StringWriter stringWriter = new java.io.StringWriter();
210
			StreamResult stream = new StreamResult(stringWriter);
211
			try {
212
				/* Create a TransformerFactory and a new Transformer. */
213
				TransformerFactory transformerFactory = TransformerFactory.newInstance();
214
				transformer = transformerFactory.newTransformer();
215
			}
216
		
217
			/* Catch and log exceptions thrown by the TransformerFactory.*/
218
			catch (TransformerConfigurationException tce) {
219
				logInterface.log(LogInterface.TYPE_ERROR, "TransformerFactory error: "
220
				+ tce.getMessage());
221
			}
222
			transformer.setOutputProperty(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
223
			transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes");
224
			transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
225
			transformer.setOutputProperty(javax.xml.transform.OutputKeys.METHOD, "xml");
226
 
227
				transformer.transform(source, stream);
228
			}
229
			catch (TransformerException te){
230
				logInterface.log(LogInterface.TYPE_ERROR, "Transformer error: "
231
				+ te.getMessage());
232
			}
233
			String string = stringWriter.getBuffer().toString();
234
			oldContent = string;
235
			
236
			// try syntax highlighting
237
			/*javax.swing.text.Document textDocument = textArea.getDocument();
238
			StyleContext styleContext = StyleContext.getDefaultStyleContext();
239
			Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
240
		
241
			Style tagStyle = styleContext.addStyle(null, defaultStyle);
242
			StyleConstants.setForeground(tagStyle, java.awt.Color.BLUE);
243
			//StyleConstants.setFontFamily(tagStyle, "Arial");
244
			System.out.println("tagStyle = " +tagStyle);
245
 
246
			char c;
247
			boolean newLine = false;
248
			for(int i = 0; i < string.length(); i++) {
249
				c = string.charAt(i);
250
 
251
					if(newLine && c == ' ') {
252
						textDocument.insertString(textDocument.getLength(), 
253
													"   ", style);
254
					}
255
					if(c != ' ')
256
						newLine = false;
257
					if(c == '\n') {
258
						newLine = true;
259
					}
260
					if(c == '<') {
261
						style = tagStyle;
262
						//textArea.setDisabledTextColor(java.awt.Color.BLUE);
263
					}
264
					if(c == '>') {
265
						style = defaultStyle;
266
						//textArea.setDisabledTextColor(java.awt.Color.BLACK);
267
					}
268
					textDocument.insertString(textDocument.getLength(), 
269
												String.valueOf(c), style);
270
				}
271
				catch(BadLocationException ble) {
272
					logInterface.log(LogInterface.TYPE_ERROR, ble.getMessage());
273
				}
274
				//textArea.setText(String.valueOf(c));
275
			}*/
276
			textArea.setText(string);
277
		}
278
		// if the node ist a text node or similar, only get the value
279
		else {
280
			textArea.setText(node.getNodeValue());
281
		}
282
		
283
		//added 14.07.03 Sascha W. -> fixed problem of not visible plugins
284
		// (deleted this line in method "init"!)
285
		guiInterface.setPluginPanel(this);
286
		textArea.getDocument().addDocumentListener(this);
287
		setVisible(true);
288
	}
289
290
291
	/** 
292
 
293
	 * 
294
	 * @see src.gui.PluginInterface#stop()
295
	 */
545 swalkenh 296
	public void stop() {
521 swalkenh 297
		setVisible(false);
298
	}
299
 
300
 
301
	//added 11/07/03 Sascha W.; own events are available now
302
	/* (non-Javadoc)
303
	 * @see src.gui.PluginInterface#setOurEventListener(src.control.OurEventListener)
304
	 */
305
	public void setOurEventListener(OurEventListener newListener) {
306
		ourEventListener = newListener;
307
	}
308
309
 
310
 
311
	 *  Forces the Text Editor Plugin to return the actual status as a node
312
	 *  not well-formed parts have to be capsuled into a prosessing instruction.
313
	 * 
314
	 *  @see src.gui.PluginInterface#forceStatusReport()
315
	 */
316
	public void forceStatusReport() {
317
		// parse the content of the JTextArea
318
 
319
 
320
		src.parser.ValidationErrorHandler errorHandler = new src.parser.ValidationErrorHandler();
321
		errorHandler.setLogInterface(logInterface);
322
		errorHandler.setStatusInterface(statusInterface);
323
		do {
324
			try {
325
				DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
326
				DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
327
				documentBuilder.setErrorHandler(errorHandler);
328
				// if the content of the edior is well-formed, parse only
329
				if(valid == true) {
330
					StringReader stringReader = new StringReader(content);
331
					InputSource inputSource = new InputSource(stringReader);
332
					//doc.appendChild(documentBuilder.parse(inputSource));
333
					changedNode = documentBuilder.parse(inputSource).getFirstChild();
334
					System.out.println("changedNode = " + changedNode);
335
				}
336
				// if the content is not well-formed, capsule it into a processing instruction
337
				else {
338
					if(oldNode.getNodeType() == Node.ELEMENT_NODE || oldNode.getNodeType() == Node.ENTITY_NODE) {
339
						content = textArea.getText();
340
						org.apache.xerces.dom.DocumentImpl doc = new org.apache.xerces.dom.DocumentImpl(); 
341
						changedNode = doc.createProcessingInstruction("NOTVALID", content);
342
						valid = true;
343
					}
344
					else {
345
						System.out.println("Node Type = " + oldNode.getNodeType());
346
						changedNode = oldNode.cloneNode(true);
347
						changedNode.setNodeValue(textArea.getText());
348
						valid = true;
349
					}
350
				}
351
			}
352
			
353
			/* Catch and log configuration errors. */
354
			catch(ParserConfigurationException pce) {
355
				logInterface.log(LogInterface.TYPE_ERROR, "Parser configuration error: "
356
				+ pce.getMessage());
357
			}
358
			
359
			/* Catch and log I/O-errors during parsing. */
360
			catch(java.io.IOException ioe) {
361
				logInterface.log(LogInterface.TYPE_ERROR, "IO error: "
362
 
363
			}
364
			
365
			catch(IllegalArgumentException iae) {
366
				logInterface.log(LogInterface.TYPE_ERROR, "Illegal argument error: "
367
				+ iae.getMessage());
368
 
369
			
370
			/* Catch and log parsing errors. */
371
			catch(org.xml.sax.SAXException saxe) {
372
				logInterface.log(LogInterface.TYPE_ERROR, "SAX parser error: "
373
				+ saxe.getMessage());
374
 
375
			}
376
		}
377
		while(valid == false);
378
379
 
380
		System.out.println("Return this node:" + changedNode);
381
		firePluginChangedElement(oldNode, changedNode);
382
	}
383
	
384
	//added 11/07/03 Sascha W.; own events are available now
385
	private void firePluginChangedElement(Node oldNode, Node changedNode) {
386
		OurEvent e = new OurEvent(new Object[] {oldNode, changedNode, pluginName});
387
		ourEventListener.firedOurEvent(e);
388
 
389
	
390
	// TODO JavaDoc-comments
391
	public void actionPerformed(ActionEvent ae) {
392
		if(ae.getSource() == syncButton) {
393
 
394
		}
395
	}
396
	
397
	public void caretUpdate(CaretEvent ce) {
398
		int dot = ce.getDot();
399
 
400
			int line = textArea.getLineOfOffset(dot);
401
			int column = dot - textArea.getLineStartOffset(line);
402
			statusInterface.setPoint(new java.awt.Point(line + 1, column + 1));
403
		}
404
		catch(BadLocationException badLEx) {
405
			logInterface.log(LogInterface.TYPE_ERROR, "Bad cursor location: "
545 swalkenh 406
 
407
		}
408
	}
409
	
410
	/* (non-Javadoc)
411
	 * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
412
	 */
413
	public void changedUpdate(DocumentEvent de) {
414
	}
415
416
	/* (non-Javadoc)
417
	 * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
418
	 */
419
 
420
		modified = true;
421
		statusInterface.setModified(true);
422
	}
423
424
	/* (non-Javadoc)
425
 
426
	 */
427
	public void removeUpdate(DocumentEvent de) {
428
		modified = true;
429
		statusInterface.setModified(true);
430
	}
431
	
432
	public boolean isModified() {
433
 
434
	}
435
}PK
436
ið.skµXX:src/plugins/textEditorPlugin/TextEditorPluginTransform.xsl<!-- for TextEditor plugin: simply copy the whole document -->
437
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
438
<xsl:output method="xml" indent="yes" />
439
440
<xsl:template match="/">
441
 
442
</xsl:template>
443
444
<xsl:template match="node()">
240 swalkenh 445
	<xsl:copy-of select="." />
545 swalkenh 446
 
447
448
</xsl:stylesheet>PK
449
 
450
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
451
<xsl:output method="xml" indent="yes" />
452
453
 
454
	<xsl:apply-templates />
455
</xsl:template>
456
457
 
240 swalkenh 458
	<xsl:copy-of select="." />
545 swalkenh 459
 
460
461
</xsl:stylesheet>PK
462
 
463
šð.	META-INF/þÊPK
464
465
šð.~ƒkk66+META-INF/MANIFEST.MFPK
466
 
467
&ƒð.9˜>?Ï%Ï%3“src/plugins/textEditorPlugin/TextEditorPlugin.classPK
468
469
ìzð.×vÓoe+e+2³)src/plugins/textEditorPlugin/TextEditorPlugin.javaPK
470
 
240 swalkenh 471
ið.skµXX:hUsrc/plugins/textEditorPlugin/TextEditorPluginTransform.xslPK
472
 
545 swalkenh 473