summaryrefslogtreecommitdiffstats
path: root/part/kxedocument.h
blob: 2b78659f9b58e007da576d51ba72d2ef4a88f3b0 (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//
// C++ Interface: kxedocument
//
// Description:
//
//
// Author: Adam Charytoniuk <[email protected]>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef KXEDOCUMENT_H
#define KXEDOCUMENT_H

#include <kurl.h>

#include <qobject.h>
#include <qdom.h>
#include <kparts/part.h>
#include <kxmlguiclient.h>

#define SCHEMA_NAMESPACE 		"http://www.w3.org/2001/XMLSchema-instance"
#define SCHEMA_ATTRIBUTE		"schemaLocation"
#define SCHEMA_ATTRIBUTE_XSI	"xsi:schemaLocation"

class QString;
class KCommand;


/**
@file
*/

/**
@short Base class for documents in KXMLEditor.

Stores XML document data which can be manipulated by KXMLEditor application.


@author Adam Charytoniuk
*/
class KXEDocument : public QObject, public QDomDocument, public KXMLGUIClient
{
        Q_OBJECT
public:
	/** @short Constructor */
	KXEDocument(QObject *parent=0, const char *name=0);

	/** @short Destructor */
	~KXEDocument();

	/** @short Saves document into given file */
	bool save(const QString &);

	/** @short Loads document from given file */
	bool open(const QString &);

	/** @short Sets modification flag.

	Should be called after every operation done on the document content  */
	void setModified(bool value=true);

	/** @short Returns true if this document was modified and not saved yet */
	bool isModified() {return m_bIsModified;}

        /** @short Changes document url */
	void setURL(KURL url);

	/** @short Executes given command and adds it into internal document command history list

		@param pCmd pointer to KXECommand object which encapsulates required operations
					on a document content
	 */
	
	/** @short Notifies views about creating new element

		@param node newly created node
	*/
	void updateNodeCreated(const QDomNode & node);

	/** @short Notifies views about deleting node

	This should be called before given node from the document will be deleted.
	This will give a chanse to the views to remove that node visualization.
		@param node that is going to be deleted
	*/
	void updateNodeDeleted(const QDomNode & node);

	/** @short Notifies views about element properties changes

	Should be called after element name or element attributes are changed.
		@param domElement element that has changed
	*/
	void updateNodeChanged( const QDomElement & domElement );

	/** @short Notifies views after change char. data properties

	Should be called after any kind of character data is changed
	(including texts, comments, .CDATA sections).
		@param node character data node that has changed
	*/
	void updateNodeChanged( const QDomCharacterData & node ) ;

	/** @short Notifies views after change proc. instr. properties

	Should be called after any processing intruction is changed.
		@param domProcInstr processing instruction that has changed
	*/
	void updateNodeChanged( const QDomProcessingInstruction &domProcInstr );

	/** @short Notifies views after moving node

	Should be called if any node in the document was moved.
		@param node XML node that has been moved
	*/
	void updateNodeMoved( const QDomNode & node );

	/** @short Removes spec. processing instruction from XML file.

		@param target name of the proc. instruction target
		@warning Removes processing instruction from DomDocument children node list only (no subnodes are modiified).
		@sa setSpecProcInstr()
	*/
	void removeSpecProcInstr(const QString &target);

	/** @short Adds or changes (if already exists) processing instruction.

	Processing instruction will be added as a child in QDomDocument object.
		@param target processing intruction target
		@param data processing intruction data
		@sa removeSpecProcInstr()
	*/
	virtual void setSpecProcInstr(const QString& target, const QString& data);

	/** @short  Returns processing instruction located in QDomDocument.

	If given processing intruction is not found, null node is returned.
		@param target name of the processing instruction target.
		@sa setSpecProcInstr()
	*/
	QDomNode getSpecProcInstr(const QString& target);

	/** @short  Attaches stylesheet to current XML file.

	If file is already attached to stylesheet, this attachment will be overriten.
		@param stylesheet url to stylesheet location
		@sa detachStylesheet()
	*/
	virtual void attachStylesheet(const KURL& stylesheet);

	/** @short  Detaches stylesheet from current XML file.

		@sa attachStylesheet()*/
	virtual void detachStylesheet();

	/** Attaches schema to current XML file. If file is already attached to schema,
	this attachment will be overriten.
		@param schema url to schema location
		@sa detachSchema()*/
	virtual void attachSchema(const KURL& schema);

	/** @short Detaches schema from current XML file.

		@sa attachSchema()*/
	virtual void detachSchema();

	/** @short prepares content of newly created document.

	The preparation will be done accordingly to settings.
	In addition, signal sigOpened() is emited to notify all views
	about the change.*/
	virtual void newFile();


	/** @short Inserts special proc.instruction into document. */
	KCommand * actVersionEncoding();

	/** @short Called on user's action response.

	Creates <?xml-stylesheet ...?> processing instruction
	with reference to specified stylesheet URI.
	*/
  KCommand * actAttachStylesheet();

	/** @short Called on user's action response. */
	KCommand * actDetachStylesheet();

	/** @short Called on user's action response */
	KCommand * actDetachSchema();

	/** @short Called on user's action response */
	KCommand * actAttachSchema();

private:
	QString m_strCompressedTarEntryName;
	/** Equals true if document was opened from compressed file */
	bool m_bDocIsCompressed;
	/** @short Stores modification flag */
	bool m_bIsModified;
	KURL m_url;

signals:
	/** @short Emmited when document has a new content.

	This may happen in the following scenarios:
	- document was opened from the fille or URL,
	- document has modified big part of the content
	- document initialized it's content after creations

		@sa newFile()
	*/
	void sigOpened();

	/** @short Emitted when document content have been changed.

	This allows to notify all attached views about that event.*/
	void sigModified(bool value);

	void sigURLChanged(KURL url);
	/** @short Emitted when new node was added to document.*/
	void sigNodeCreated(const QDomNode & node);
	/** @short Emitted everytime node was deleted from document.*/
	void sigNodeDeleted(const QDomNode & node);
	/** @short Emitted everytime document element was changed .*/
	void sigNodeChanged( const QDomElement & domElement );
	/** @short Emitted everytime character data node was changed.

	This is the case for nodes like:
	- text,
	- comments,
	- CDATA sections,
	*/
	void sigNodeChanged( const QDomCharacterData & node ) ;
	/** @short Emitted everytime processing instruction in document was changed .*/
	void sigNodeChanged( const QDomProcessingInstruction &domProcInstr );
	/** @short Emitted everytime document node was moved was changed .*/
	void sigNodeMoved( const QDomNode & node );
};

#endif