1 package org.apache.maven;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import java.io.*;
21 import javax.xml.parsers.*;
22 import org.w3c.dom.*;
23 import org.xml.sax.*;
24
25 /**
26 * Some utility methods.
27 * @author <a href="mailto:ltheussl@apache.org">Lukas Theussl</a>
28 */
29 public class PomUtils
30 {
31 private File file;
32 private String parent;
33
34 /** The parent.
35 * @return The parent
36 */
37 public String getParent()
38 {
39 return parent;
40 }
41
42 /** The file.
43 * @return The file
44 */
45 public File getFile()
46 {
47 return file;
48 }
49
50 /**
51 * Sets the file.
52 * @param newFile The file to set
53 */
54 public void setFile(File newFile)
55 {
56 this.file = newFile;
57 }
58
59 /** The file.
60 * @return True if the file contains <extend>.
61 */
62 public boolean extend()
63 {
64 Document doc = parseXmlFile(file, false);
65 NodeList list = doc.getElementsByTagName("extend");
66 boolean extend = false;
67 if ( list.getLength() > 0 )
68 {
69 extend = true;
70 Element element = (Element) list.item(0);
71 try
72 {
73 Node firstChild = element.getFirstChild();
74 parent = firstChild.getNodeValue();
75 } catch (DOMException e) {
76 }
77 }
78 return extend;
79 }
80
81 private Document parseXmlFile(File filename, boolean validating)
82 {
83 try
84 {
85 DocumentBuilderFactory factory =
86 DocumentBuilderFactory.newInstance();
87 factory.setValidating(validating);
88 Document doc = factory.newDocumentBuilder().parse(filename);
89 return doc;
90 } catch (SAXException e) {
91 } catch (ParserConfigurationException e) {
92 } catch (IOException e) {
93 }
94 return null;
95 }
96 }