001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2008 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.build.ant.util;
025:
026: import java.io.File;
027: import java.util.Vector;
028:
029: import javax.xml.parsers.DocumentBuilder;
030: import javax.xml.parsers.DocumentBuilderFactory;
031:
032: import org.w3c.dom.Document;
033: import org.w3c.dom.Element;
034: import org.w3c.dom.Node;
035:
036: public class EclipseProjectFile {
037:
038: public static final String JAVA_NATURE = "org.eclipse.jdt.core.javanature";
039: public static final String PLUGIN_NATURE = "org.eclipse.pde.PluginNature";
040:
041: private String projectName;
042: private String comment;
043: private Vector<String> natures;
044:
045: public EclipseProjectFile() {
046: natures = new Vector<String>();
047: }
048:
049: public String getComment() {
050: return comment;
051: }
052:
053: public void setComment(String comment) {
054: this .comment = comment;
055: }
056:
057: public String getProjectName() {
058: return projectName;
059: }
060:
061: public void setProjectName(String projectName) {
062: this .projectName = projectName;
063: }
064:
065: public boolean isPluginProject() {
066: return natures.contains(PLUGIN_NATURE);
067: }
068:
069: public void load(File projectFile) throws Exception {
070: DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
071: .newInstance();
072: DocumentBuilder docBuilder = docBuilderFactory
073: .newDocumentBuilder();
074: Document doc = docBuilder.parse(projectFile);
075: Element root = doc.getDocumentElement();
076: if ("projectDescription".equals(root.getNodeName())) {
077: Node child = root.getFirstChild();
078: while (child != null) {
079: if (child.getNodeType() == Node.ELEMENT_NODE) {
080: if (child.getNodeName().equals("name")) {
081: loadNameElement((Element) child);
082: } else if (child.getNodeName().equals("comment")) {
083: loadCommentElement((Element) child);
084: } else if (child.getNodeName().equals("projects")) {
085: loadProjectsElement((Element) child);
086: } else if (child.getNodeName().equals("buildSpec")) {
087: loadBuildSpec((Element) child);
088: } else if (child.getNodeName().equals("natures")) {
089: loadNatures((Element) child);
090: }
091: }
092: child = child.getNextSibling();
093: }
094: } else {
095: throw new Exception(
096: "Root element of file is not 'projectDescription'.");
097: }
098: }
099:
100: private void loadNameElement(Element nameElement) {
101: projectName = nameElement.getTextContent();
102: }
103:
104: private void loadCommentElement(Element commentElement) {
105: comment = commentElement.getTextContent();
106: }
107:
108: private void loadProjectsElement(Element projectsElement) {
109: //Don't need right now
110: }
111:
112: private void loadBuildSpec(Element buildSpecElement) {
113: //Don't need right now
114: }
115:
116: private void loadNatures(Element naturesElement) {
117: Node child = naturesElement.getFirstChild();
118: while (child != null) {
119: if (child.getNodeType() == Node.ELEMENT_NODE
120: && "nature".equals(child.getNodeName())) {
121: String nature = ((Element) child).getTextContent();
122: natures.add(nature);
123: }
124: child = child.getNextSibling();
125: }
126: }
127:
128: }
|