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.List;
028: import java.util.Vector;
029:
030: import javax.xml.parsers.DocumentBuilder;
031: import javax.xml.parsers.DocumentBuilderFactory;
032:
033: import org.w3c.dom.Document;
034: import org.w3c.dom.Element;
035: import org.w3c.dom.Node;
036:
037: public class EclipseClasspathFile {
038:
039: private Vector<ClassPathEntry> entries;
040:
041: public EclipseClasspathFile() {
042: entries = new Vector<ClassPathEntry>();
043: }
044:
045: public void load(File classpathFile) throws Exception {
046: DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
047: .newInstance();
048: DocumentBuilder docBuilder = docBuilderFactory
049: .newDocumentBuilder();
050: Document doc = docBuilder.parse(classpathFile);
051: Element root = doc.getDocumentElement();
052: if ("classpath".equals(root.getNodeName())) {
053: Node child = root.getFirstChild();
054: while (child != null) {
055: if (child.getNodeType() == Node.ELEMENT_NODE
056: && "classpathentry".equals(child.getNodeName())) {
057: Element classpathentry = (Element) child;
058: String kind = classpathentry.getAttribute("kind");
059: String path = classpathentry.getAttribute("path");
060: if (kind != null && path != null) {
061: ClassPathEntry entry = new ClassPathEntry();
062: entry.setKind(kind);
063: entry.setPath(path);
064: entries.add(entry);
065: }
066: }
067: child = child.getNextSibling();
068: }
069: } else {
070: throw new Exception(
071: "Root element of file is not 'classpath'.");
072: }
073: }
074:
075: public List<ClassPathEntry> getEntries() {
076: return entries;
077: }
078:
079: public class ClassPathEntry {
080: private String kind;
081: private String path;
082:
083: public String getKind() {
084: return kind;
085: }
086:
087: public void setKind(String kind) {
088: this .kind = kind;
089: }
090:
091: public String getPath() {
092: return path;
093: }
094:
095: public void setPath(String path) {
096: this .path = path;
097: }
098:
099: public boolean isProjectReference() {
100: return (kind.equals("src") && (path.startsWith("/") || path
101: .startsWith("\\")));
102: }
103:
104: public boolean isJarFile() {
105: return (kind.equals("lib") && (path.endsWith(".jar")));
106: }
107: }
108: }
|