001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the license.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.kelp.common.dods;
024:
025: // Kelp imports
026: import org.enhydra.kelp.common.AbstractEchoBuilder;
027: import org.enhydra.kelp.common.PathUtil;
028: import org.enhydra.kelp.common.event.WriteListener;
029: import org.enhydra.kelp.common.node.OtterTemplateNode;
030: import org.enhydra.kelp.common.node.OtterFileNode;
031: import org.enhydra.kelp.common.node.OtterNode;
032: import org.enhydra.kelp.common.node.OtterNodeFactory;
033:
034: // ToolBox imports
035: import org.enhydra.tool.common.FileUtil;
036: import org.enhydra.tool.common.PathHandle;
037: import org.enhydra.tool.common.Template;
038: import org.enhydra.tool.common.ToolException;
039: import org.enhydra.tool.configure.ConfigTool;
040: import org.enhydra.tool.common.event.ProgressListener;
041:
042: // Standard imports
043: import java.awt.Component;
044: import java.io.File;
045: import java.util.ArrayList;
046: import java.util.Arrays;
047: import java.util.ResourceBundle;
048:
049: import java.io.*;
050: import javax.swing.*;
051: import org.enhydra.dods.xslt.*;
052: import org.enhydra.kelp.common.AbstractEchoBuilder;
053:
054: //
055: public class DodsBuilder extends AbstractEchoBuilder {
056:
057: static ResourceBundle res = ResourceBundle
058: .getBundle("org.enhydra.kelp.common.Res"); // nores
059: private File[] builtTemplates = new File[0];
060: private File[] builtPassthrough = new File[0];
061: private OtterNode[] nodes = null;
062: private Component owner = null;
063:
064: public DodsBuilder(WriteListener listener) {
065: super (listener);
066: }
067:
068: protected void buildImpl() throws ToolException {
069:
070: Exception ex = null;
071:
072: try {
073:
074: String as[] = new String[5];
075: if (System.getProperty("os.name").toLowerCase().startsWith(
076: "win"))
077: as[0] = this .getEnhydraPath() + File.separator + "bin"
078: + File.separator + "dods.bat";
079: else
080: as[0] = this .getEnhydraPath() + File.separator + "bin"
081: + File.separator + "dods";
082: as[1] = getProject().getDomlFilePath();
083: as[2] = getProject().getDodsRootPath();
084: as[3] = getProject().getDodsParameters();
085: as[4] = getProject().getExstensionParameter();
086:
087: Process process = Runtime.getRuntime().exec(as);
088:
089: java.io.InputStream inputstream = process.getInputStream();
090: BufferedReader bufferedreader = new BufferedReader(
091: new InputStreamReader(inputstream));
092: java.io.InputStream inputstream1 = process.getErrorStream();
093: BufferedReader bufferedreader1 = new BufferedReader(
094: new InputStreamReader(inputstream1));
095:
096: String str1 = "";
097: String str2 = "";
098: (new ErrorReader(bufferedreader1, this )).start();
099:
100: int i = 1;
101: while ((str1 = bufferedreader.readLine()) != null) {
102: if (isFresh()) {
103: echo(str1);
104: if (i < 90) {
105: refreshProgress(i, "Generating Dods files");
106: }
107: i = i + 2;
108: } else {
109: process.destroy();
110: refreshProgress(100, "");
111: echo("Process has been terminated");
112: return;
113: }
114: }
115:
116: process.waitFor();
117: int k = process.exitValue();
118:
119: String dodsRootPath = getProject().getDodsRootPath();
120: if (dodsRootPath.endsWith("/"))
121: dodsRootPath = dodsRootPath.substring(0, dodsRootPath
122: .length() - 1);
123:
124: String[] sourcePath = getProject().getSourcePathArray();
125: boolean isFind = false;
126: for (int j = 0; j < sourcePath.length; j++) {
127:
128: if (dodsRootPath.equalsIgnoreCase(sourcePath[j]))
129: isFind = true;
130: }
131: if (!isFind) {
132: String[] newSourcePath = new String[sourcePath.length + 1];
133: for (int j = 0; j < sourcePath.length; j++) {
134: newSourcePath[j] = sourcePath[j];
135: }
136: newSourcePath[sourcePath.length] = getProject()
137: .getDodsRootPath();
138: getProject().setSourcePathArray(newSourcePath);
139: }
140:
141: } catch (Exception e) {
142: ex = e;
143: }
144:
145: }
146:
147: public Component getOwner() {
148: return owner;
149: }
150:
151: private String getEnhydraPath() {
152: return getProject().getEnhydraPath();
153: }
154:
155: private String getProjectJavaPath() {
156: return getProject().getProjectJavaPath();
157: }
158:
159: }
|