1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
;
15 import java
.io
.ByteArrayInputStream
;
17 import java
.io
.FileWriter
;
18 import java
.io
.IOException
;
19 import java
.io
.StringWriter
;
20 import java
.util
.ArrayList
;
21 import java
.util
.List
;
23 import javax
.xml
.parsers
.DocumentBuilder
;
24 import javax
.xml
.parsers
.DocumentBuilderFactory
;
25 import javax
.xml
.parsers
.ParserConfigurationException
;
26 import javax
.xml
.transform
.OutputKeys
;
27 import javax
.xml
.transform
.Transformer
;
28 import javax
.xml
.transform
.TransformerConfigurationException
;
29 import javax
.xml
.transform
.TransformerException
;
30 import javax
.xml
.transform
.TransformerFactory
;
31 import javax
.xml
.transform
.TransformerFactoryConfigurationError
;
32 import javax
.xml
.transform
.dom
.DOMSource
;
33 import javax
.xml
.transform
.stream
.StreamResult
;
35 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
36 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
37 import org
.w3c
.dom
.Document
;
38 import org
.w3c
.dom
.Element
;
39 import org
.w3c
.dom
.Node
;
40 import org
.w3c
.dom
.NodeList
;
41 import org
.xml
.sax
.EntityResolver
;
42 import org
.xml
.sax
.ErrorHandler
;
43 import org
.xml
.sax
.InputSource
;
44 import org
.xml
.sax
.SAXException
;
45 import org
.xml
.sax
.SAXParseException
;
47 public class CustomXmlTraceDefinition
extends CustomTraceDefinition
{
49 protected static final String CUSTOM_XML_TRACE_DEFINITIONS_FILE_NAME
= "custom_xml_parsers.xml"; //$NON-NLS-1$
50 protected static final String CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME
=
51 Activator
.getDefault().getStateLocation().addTrailingSeparator().append(CUSTOM_XML_TRACE_DEFINITIONS_FILE_NAME
).toString();
53 public static final String TAG_IGNORE
= Messages
.CustomXmlTraceDefinition_ignoreTag
;
55 private static final String CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT
= Messages
.CustomXmlTraceDefinition_definitionRootElement
;
56 private static final String DEFINITION_ELEMENT
= Messages
.CustomXmlTraceDefinition_definition
;
57 private static final String NAME_ATTRIBUTE
= Messages
.CustomXmlTraceDefinition_name
;
58 private static final String LOG_ENTRY_ATTRIBUTE
= Messages
.CustomXmlTraceDefinition_logEntry
;
59 private static final String TIME_STAMP_OUTPUT_FORMAT_ELEMENT
= Messages
.CustomXmlTraceDefinition_timestampOutputFormat
;
60 private static final String INPUT_ELEMENT_ELEMENT
= Messages
.CustomXmlTraceDefinition_inputElement
;
61 private static final String ATTRIBUTE_ELEMENT
= Messages
.CustomXmlTraceDefinition_attribute
;
62 private static final String INPUT_DATA_ELEMENT
= Messages
.CustomXmlTraceDefinition_inputData
;
63 private static final String ACTION_ATTRIBUTE
= Messages
.CustomXmlTraceDefinition_action
;
64 private static final String FORMAT_ATTRIBUTE
= Messages
.CustomXmlTraceDefinition_format
;
65 private static final String OUTPUT_COLUMN_ELEMENT
= Messages
.CustomXmlTraceDefinition_outputColumn
;
67 public InputElement rootInputElement
;
69 public CustomXmlTraceDefinition() {
70 this("", null, new ArrayList
<OutputColumn
>(), ""); //$NON-NLS-1$ //$NON-NLS-2$
73 public CustomXmlTraceDefinition(String logtype
, InputElement rootElement
, List
<OutputColumn
> outputs
, String timeStampOutputFormat
) {
74 this.definitionName
= logtype
;
75 this.rootInputElement
= rootElement
;
76 this.outputs
= outputs
;
77 this.timeStampOutputFormat
= timeStampOutputFormat
;
80 public static class InputElement
{
81 public String elementName
;
82 public boolean logEntry
;
83 public String inputName
;
84 public int inputAction
;
85 public String inputFormat
;
86 public List
<InputAttribute
> attributes
;
87 public InputElement parentElement
;
88 public InputElement nextElement
;
89 public List
<InputElement
> childElements
;
91 public InputElement() {}
93 public InputElement(String elementName
, boolean logEntry
, String inputName
, int inputAction
, String inputFormat
, List
<InputAttribute
> attributes
) {
94 this.elementName
= elementName
;
95 this.logEntry
= logEntry
;
96 this.inputName
= inputName
;
97 this.inputAction
= inputAction
;
98 this.inputFormat
= inputFormat
;
99 this.attributes
= attributes
;
102 public void addAttribute(InputAttribute attribute
) {
103 if (attributes
== null) {
104 attributes
= new ArrayList
<InputAttribute
>(1);
106 attributes
.add(attribute
);
109 public void addChild(InputElement input
) {
110 if (childElements
== null) {
111 childElements
= new ArrayList
<InputElement
>(1);
112 } else if (childElements
.size() > 0) {
113 InputElement last
= childElements
.get(childElements
.size() - 1);
114 last
.nextElement
= input
;
116 childElements
.add(input
);
117 input
.parentElement
= this;
120 public void addNext(InputElement input
) {
121 if (parentElement
!= null) {
122 int index
= parentElement
.childElements
.indexOf(this);
123 parentElement
.childElements
.add(index
+ 1, input
);
124 InputElement next
= nextElement
;
126 input
.nextElement
= next
;
128 input
.parentElement
= this.parentElement
;
131 public void moveUp() {
132 if (parentElement
!= null) {
133 int index
= parentElement
.childElements
.indexOf(this);
135 parentElement
.childElements
.add(index
- 1 , parentElement
.childElements
.remove(index
));
136 parentElement
.childElements
.get(index
).nextElement
= nextElement
;
137 nextElement
= parentElement
.childElements
.get(index
);
142 public void moveDown() {
143 if (parentElement
!= null) {
144 int index
= parentElement
.childElements
.indexOf(this);
145 if (index
< parentElement
.childElements
.size() - 1) {
146 parentElement
.childElements
.add(index
+ 1 , parentElement
.childElements
.remove(index
));
147 nextElement
= parentElement
.childElements
.get(index
).nextElement
;
148 parentElement
.childElements
.get(index
).nextElement
= this;
155 public static class InputAttribute
{
156 public String attributeName
;
157 public String inputName
;
158 public int inputAction
;
159 public String inputFormat
;
161 public InputAttribute() {}
163 public InputAttribute(String attributeName
, String inputName
, int inputAction
, String inputFormat
) {
164 this.attributeName
= attributeName
;
165 this.inputName
= inputName
;
166 this.inputAction
= inputAction
;
167 this.inputFormat
= inputFormat
;
173 save(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME
);
177 public void save(String path
) {
179 DocumentBuilderFactory dbf
= DocumentBuilderFactory
.newInstance();
180 DocumentBuilder db
= dbf
.newDocumentBuilder();
182 // The following allows xml parsing without access to the dtd
183 EntityResolver resolver
= new EntityResolver () {
185 public InputSource
resolveEntity (String publicId
, String systemId
) {
186 String empty
= ""; //$NON-NLS-1$
187 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
188 return new InputSource(bais
);
191 db
.setEntityResolver(resolver
);
193 // The following catches xml parsing exceptions
194 db
.setErrorHandler(new ErrorHandler(){
196 public void error(SAXParseException saxparseexception
) throws SAXException
{}
198 public void warning(SAXParseException saxparseexception
) throws SAXException
{}
200 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
201 throw saxparseexception
;
205 File file
= new File(path
);
206 if (file
.canRead()) {
207 doc
= db
.parse(file
);
208 if (! doc
.getDocumentElement().getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT
)) {
212 doc
= db
.newDocument();
213 Node node
= doc
.createElement(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT
);
214 doc
.appendChild(node
);
217 Element root
= doc
.getDocumentElement();
219 NodeList nodeList
= root
.getChildNodes();
220 for (int i
= 0; i
< nodeList
.getLength(); i
++) {
221 Node node
= nodeList
.item(i
);
222 if (node
instanceof Element
&&
223 node
.getNodeName().equals(DEFINITION_ELEMENT
) &&
224 definitionName
.equals(((Element
) node
).getAttribute(NAME_ATTRIBUTE
))) {
225 root
.removeChild(node
);
228 Element definitionElement
= doc
.createElement(DEFINITION_ELEMENT
);
229 root
.appendChild(definitionElement
);
230 definitionElement
.setAttribute(NAME_ATTRIBUTE
, definitionName
);
232 Element formatElement
= doc
.createElement(TIME_STAMP_OUTPUT_FORMAT_ELEMENT
);
233 definitionElement
.appendChild(formatElement
);
234 formatElement
.appendChild(doc
.createTextNode(timeStampOutputFormat
));
236 if (rootInputElement
!= null) {
237 definitionElement
.appendChild(createInputElementElement(rootInputElement
, doc
));
240 if (outputs
!= null) {
241 for (OutputColumn output
: outputs
) {
242 Element outputColumnElement
= doc
.createElement(OUTPUT_COLUMN_ELEMENT
);
243 definitionElement
.appendChild(outputColumnElement
);
244 outputColumnElement
.setAttribute(NAME_ATTRIBUTE
, output
.name
);
248 Transformer transformer
= TransformerFactory
.newInstance().newTransformer();
249 transformer
.setOutputProperty(OutputKeys
.INDENT
, "yes"); //$NON-NLS-1$
251 //initialize StreamResult with File object to save to file
252 StreamResult result
= new StreamResult(new StringWriter());
253 DOMSource source
= new DOMSource(doc
);
254 transformer
.transform(source
, result
);
255 String xmlString
= result
.getWriter().toString();
257 FileWriter writer
= new FileWriter(file
);
258 writer
.write(xmlString
);
260 } catch (ParserConfigurationException e
) {
261 Activator
.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path
, e
); //$NON-NLS-1$
262 } catch (TransformerConfigurationException e
) {
263 Activator
.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path
, e
); //$NON-NLS-1$
264 } catch (TransformerFactoryConfigurationError e
) {
265 Activator
.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path
, e
); //$NON-NLS-1$
266 } catch (TransformerException e
) {
267 Activator
.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path
, e
); //$NON-NLS-1$
268 } catch (IOException e
) {
269 Activator
.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path
, e
); //$NON-NLS-1$
270 } catch (SAXException e
) {
271 Activator
.getDefault().logError("Error saving CustomXmlTraceDefinition: path=" + path
, e
); //$NON-NLS-1$
275 private Element
createInputElementElement(InputElement inputElement
, Document doc
) {
276 Element inputElementElement
= doc
.createElement(INPUT_ELEMENT_ELEMENT
);
277 inputElementElement
.setAttribute(NAME_ATTRIBUTE
, inputElement
.elementName
);
279 if (inputElement
.logEntry
) {
280 inputElementElement
.setAttribute(LOG_ENTRY_ATTRIBUTE
, Boolean
.toString(inputElement
.logEntry
));
283 if (inputElement
.parentElement
!= null) {
284 Element inputDataElement
= doc
.createElement(INPUT_DATA_ELEMENT
);
285 inputElementElement
.appendChild(inputDataElement
);
286 inputDataElement
.setAttribute(NAME_ATTRIBUTE
, inputElement
.inputName
);
287 inputDataElement
.setAttribute(ACTION_ATTRIBUTE
, Integer
.toString(inputElement
.inputAction
));
288 if (inputElement
.inputFormat
!= null) {
289 inputDataElement
.setAttribute(FORMAT_ATTRIBUTE
, inputElement
.inputFormat
);
293 if (inputElement
.attributes
!= null) {
294 for (InputAttribute attribute
: inputElement
.attributes
) {
295 Element inputAttributeElement
= doc
.createElement(ATTRIBUTE_ELEMENT
);
296 inputElementElement
.appendChild(inputAttributeElement
);
297 inputAttributeElement
.setAttribute(NAME_ATTRIBUTE
, attribute
.attributeName
);
298 Element inputDataElement
= doc
.createElement(INPUT_DATA_ELEMENT
);
299 inputAttributeElement
.appendChild(inputDataElement
);
300 inputDataElement
.setAttribute(NAME_ATTRIBUTE
, attribute
.inputName
);
301 inputDataElement
.setAttribute(ACTION_ATTRIBUTE
, Integer
.toString(attribute
.inputAction
));
302 if (attribute
.inputFormat
!= null) {
303 inputDataElement
.setAttribute(FORMAT_ATTRIBUTE
, attribute
.inputFormat
);
308 if (inputElement
.childElements
!= null) {
309 for (InputElement childInputElement
: inputElement
.childElements
) {
310 inputElementElement
.appendChild(createInputElementElement(childInputElement
, doc
));
314 return inputElementElement
;
317 public static CustomXmlTraceDefinition
[] loadAll() {
318 return loadAll(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME
);
321 public static CustomXmlTraceDefinition
[] loadAll(String path
) {
323 DocumentBuilderFactory dbf
= DocumentBuilderFactory
.newInstance();
324 DocumentBuilder db
= dbf
.newDocumentBuilder();
326 // The following allows xml parsing without access to the dtd
327 EntityResolver resolver
= new EntityResolver () {
329 public InputSource
resolveEntity (String publicId
, String systemId
) {
330 String empty
= ""; //$NON-NLS-1$
331 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
332 return new InputSource(bais
);
335 db
.setEntityResolver(resolver
);
337 // The following catches xml parsing exceptions
338 db
.setErrorHandler(new ErrorHandler(){
340 public void error(SAXParseException saxparseexception
) throws SAXException
{}
342 public void warning(SAXParseException saxparseexception
) throws SAXException
{}
344 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
345 throw saxparseexception
;
348 File file
= new File(path
);
349 if (!file
.canRead()) {
350 return new CustomXmlTraceDefinition
[0];
352 Document doc
= db
.parse(file
);
354 Element root
= doc
.getDocumentElement();
355 if (! root
.getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT
)) {
356 return new CustomXmlTraceDefinition
[0];
359 ArrayList
<CustomXmlTraceDefinition
> defList
= new ArrayList
<CustomXmlTraceDefinition
>();
360 NodeList nodeList
= root
.getChildNodes();
361 for (int i
= 0; i
< nodeList
.getLength(); i
++) {
362 Node node
= nodeList
.item(i
);
363 if (node
instanceof Element
&& node
.getNodeName().equals(DEFINITION_ELEMENT
)) {
364 CustomXmlTraceDefinition def
= extractDefinition((Element
) node
);
370 return defList
.toArray(new CustomXmlTraceDefinition
[0]);
371 } catch (ParserConfigurationException e
) {
372 Activator
.getDefault().logError("Error loading all in CustomXmlTraceDefinition: path=" + path
, e
); //$NON-NLS-1$
373 } catch (SAXException e
) {
374 Activator
.getDefault().logError("Error loading all in CustomXmlTraceDefinition: path=" + path
, e
); //$NON-NLS-1$
375 } catch (IOException e
) {
376 Activator
.getDefault().logError("Error loading all in CustomXmlTraceDefinition: path=" + path
, e
); //$NON-NLS-1$
378 return new CustomXmlTraceDefinition
[0];
381 public static CustomXmlTraceDefinition
load(String definitionName
) {
383 DocumentBuilderFactory dbf
= DocumentBuilderFactory
.newInstance();
384 DocumentBuilder db
= dbf
.newDocumentBuilder();
386 // The following allows xml parsing without access to the dtd
387 EntityResolver resolver
= new EntityResolver () {
389 public InputSource
resolveEntity (String publicId
, String systemId
) {
390 String empty
= ""; //$NON-NLS-1$
391 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
392 return new InputSource(bais
);
395 db
.setEntityResolver(resolver
);
397 // The following catches xml parsing exceptions
398 db
.setErrorHandler(new ErrorHandler(){
400 public void error(SAXParseException saxparseexception
) throws SAXException
{}
402 public void warning(SAXParseException saxparseexception
) throws SAXException
{}
404 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
405 throw saxparseexception
;
408 File file
= new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME
);
409 Document doc
= db
.parse(file
);
411 Element root
= doc
.getDocumentElement();
412 if (! root
.getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT
)) {
416 NodeList nodeList
= root
.getChildNodes();
417 for (int i
= 0; i
< nodeList
.getLength(); i
++) {
418 Node node
= nodeList
.item(i
);
419 if (node
instanceof Element
&&
420 node
.getNodeName().equals(DEFINITION_ELEMENT
) &&
421 definitionName
.equals(((Element
) node
).getAttribute(NAME_ATTRIBUTE
))) {
422 return extractDefinition((Element
) node
);
425 } catch (ParserConfigurationException e
) {
426 Activator
.getDefault().logError("Error loading CustomXmlTraceDefinition: definitionName=" + definitionName
, e
); //$NON-NLS-1$
427 } catch (SAXException e
) {
428 Activator
.getDefault().logError("Error loading CustomXmlTraceDefinition: definitionName=" + definitionName
, e
); //$NON-NLS-1$
429 } catch (IOException e
) {
430 Activator
.getDefault().logError("Error loading CustomXmlTraceDefinition: definitionName=" + definitionName
, e
); //$NON-NLS-1$
435 public static CustomXmlTraceDefinition
extractDefinition(Element definitionElement
) {
436 CustomXmlTraceDefinition def
= new CustomXmlTraceDefinition();
438 def
.definitionName
= definitionElement
.getAttribute(NAME_ATTRIBUTE
);
439 if (def
.definitionName
== null) {
443 NodeList nodeList
= definitionElement
.getChildNodes();
444 for (int i
= 0; i
< nodeList
.getLength(); i
++) {
445 Node node
= nodeList
.item(i
);
446 String nodeName
= node
.getNodeName();
447 if (nodeName
.equals(TIME_STAMP_OUTPUT_FORMAT_ELEMENT
)) {
448 Element formatElement
= (Element
) node
;
449 def
.timeStampOutputFormat
= formatElement
.getTextContent();
450 } else if (nodeName
.equals(INPUT_ELEMENT_ELEMENT
)) {
451 InputElement inputElement
= extractInputElement((Element
) node
);
452 if (inputElement
!= null) {
453 if (def
.rootInputElement
== null) {
454 def
.rootInputElement
= inputElement
;
459 } else if (nodeName
.equals(OUTPUT_COLUMN_ELEMENT
)) {
460 Element outputColumnElement
= (Element
) node
;
461 OutputColumn outputColumn
= new OutputColumn();
462 outputColumn
.name
= outputColumnElement
.getAttribute(NAME_ATTRIBUTE
);
463 def
.outputs
.add(outputColumn
);
469 private static InputElement
extractInputElement(Element inputElementElement
) {
470 InputElement inputElement
= new InputElement();
471 inputElement
.elementName
= inputElementElement
.getAttribute(NAME_ATTRIBUTE
);
472 inputElement
.logEntry
= (Boolean
.toString(true).equals(inputElementElement
.getAttribute(LOG_ENTRY_ATTRIBUTE
))) ?
true : false;
473 NodeList nodeList
= inputElementElement
.getChildNodes();
474 for (int i
= 0; i
< nodeList
.getLength(); i
++) {
475 Node node
= nodeList
.item(i
);
476 String nodeName
= node
.getNodeName();
477 if (nodeName
.equals(INPUT_DATA_ELEMENT
)) {
478 Element inputDataElement
= (Element
) node
;
479 inputElement
.inputName
= inputDataElement
.getAttribute(NAME_ATTRIBUTE
);
480 inputElement
.inputAction
= Integer
.parseInt(inputDataElement
.getAttribute(ACTION_ATTRIBUTE
));
481 inputElement
.inputFormat
= inputDataElement
.getAttribute(FORMAT_ATTRIBUTE
);
482 } else if (nodeName
.equals(ATTRIBUTE_ELEMENT
)) {
483 Element attributeElement
= (Element
) node
;
484 InputAttribute attribute
= new InputAttribute();
485 attribute
.attributeName
= attributeElement
.getAttribute(NAME_ATTRIBUTE
);
486 NodeList attributeNodeList
= attributeElement
.getChildNodes();
487 for (int j
= 0; j
< attributeNodeList
.getLength(); j
++) {
488 Node attributeNode
= attributeNodeList
.item(j
);
489 String attributeNodeName
= attributeNode
.getNodeName();
490 if (attributeNodeName
.equals(INPUT_DATA_ELEMENT
)) {
491 Element inputDataElement
= (Element
) attributeNode
;
492 attribute
.inputName
= inputDataElement
.getAttribute(NAME_ATTRIBUTE
);
493 attribute
.inputAction
= Integer
.parseInt(inputDataElement
.getAttribute(ACTION_ATTRIBUTE
));
494 attribute
.inputFormat
= inputDataElement
.getAttribute(FORMAT_ATTRIBUTE
);
497 inputElement
.addAttribute(attribute
);
498 } else if (nodeName
.equals(INPUT_ELEMENT_ELEMENT
)) {
499 Element childInputElementElement
= (Element
) node
;
500 InputElement childInputElement
= extractInputElement(childInputElementElement
);
501 if (childInputElement
!= null) {
502 inputElement
.addChild(childInputElement
);
509 public static void delete(String definitionName
) {
511 DocumentBuilderFactory dbf
= DocumentBuilderFactory
.newInstance();
512 DocumentBuilder db
= dbf
.newDocumentBuilder();
514 // The following allows xml parsing without access to the dtd
515 EntityResolver resolver
= new EntityResolver () {
517 public InputSource
resolveEntity (String publicId
, String systemId
) {
518 String empty
= ""; //$NON-NLS-1$
519 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
520 return new InputSource(bais
);
523 db
.setEntityResolver(resolver
);
525 // The following catches xml parsing exceptions
526 db
.setErrorHandler(new ErrorHandler(){
528 public void error(SAXParseException saxparseexception
) throws SAXException
{}
530 public void warning(SAXParseException saxparseexception
) throws SAXException
{}
532 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
533 throw saxparseexception
;
536 File file
= new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME
);
537 Document doc
= db
.parse(file
);
539 Element root
= doc
.getDocumentElement();
540 if (! root
.getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT
)) {
544 NodeList nodeList
= root
.getChildNodes();
545 for (int i
= 0; i
< nodeList
.getLength(); i
++) {
546 Node node
= nodeList
.item(i
);
547 if (node
instanceof Element
&&
548 node
.getNodeName().equals(DEFINITION_ELEMENT
) &&
549 definitionName
.equals(((Element
) node
).getAttribute(NAME_ATTRIBUTE
))) {
550 root
.removeChild(node
);
554 Transformer transformer
= TransformerFactory
.newInstance().newTransformer();
555 transformer
.setOutputProperty(OutputKeys
.INDENT
, "yes"); //$NON-NLS-1$
557 //initialize StreamResult with File object to save to file
558 StreamResult result
= new StreamResult(new StringWriter());
559 DOMSource source
= new DOMSource(doc
);
560 transformer
.transform(source
, result
);
561 String xmlString
= result
.getWriter().toString();
563 FileWriter writer
= new FileWriter(file
);
564 writer
.write(xmlString
);
566 } catch (ParserConfigurationException e
) {
567 Activator
.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName
, e
); //$NON-NLS-1$
568 } catch (SAXException e
) {
569 Activator
.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName
, e
); //$NON-NLS-1$
570 } catch (IOException e
) {
571 Activator
.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName
, e
); //$NON-NLS-1$
572 } catch (TransformerConfigurationException e
) {
573 Activator
.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName
, e
); //$NON-NLS-1$
574 } catch (TransformerFactoryConfigurationError e
) {
575 Activator
.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName
, e
); //$NON-NLS-1$
576 } catch (TransformerException e
) {
577 Activator
.getDefault().logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName
, e
); //$NON-NLS-1$