~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/jgdi/templates/java_qconf_cmd.static

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<%
 
2
/*___INFO__MARK_BEGIN__*/
 
3
/*************************************************************************
 
4
 *
 
5
 *  The Contents of this file are made available subject to the terms of
 
6
 *  the Sun Industry Standards Source License Version 1.2
 
7
 *
 
8
 *  Sun Microsystems Inc., March, 2001
 
9
 *
 
10
 *
 
11
 *  Sun Industry Standards Source License Version 1.2
 
12
 *  =================================================
 
13
 *  The contents of this file are subject to the Sun Industry Standards
 
14
 *  Source License Version 1.2 (the "License"); You may not use this file
 
15
 *  except in compliance with the License. You may obtain a copy of the
 
16
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
17
 *
 
18
 *  Software provided under this License is provided on an "AS IS" basis,
 
19
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
20
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
21
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
22
 *  See the License for the specific provisions governing your rights and
 
23
 *  obligations concerning the Software.
 
24
 *
 
25
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
26
 *
 
27
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
28
 *
 
29
 *   All Rights Reserved.
 
30
 *
 
31
 ************************************************************************/
 
32
/*___INFO__MARK_END__*/
 
33
%>
 
34
   String getKeyAttributeValueFromString(final PrintWriter err, final String type, final String fileName, final String inputText) {
 
35
      String keyAttrValue = null;
 
36
      //Get the key attribute value from the file
 
37
      String keyAttr = EditorUtil.unifyAttrWithClientNames(type, "name");
 
38
      StringReader sr = new StringReader(inputText);
 
39
      LineNumberReader lnr = new LineNumberReader(sr);
 
40
      String keyAttrLine = null;
 
41
      try {
 
42
         while (lnr.ready()) {
 
43
            keyAttrLine = lnr.readLine().trim();
 
44
            if (keyAttrLine.startsWith(keyAttr)) {
 
45
               keyAttrValue = keyAttrLine.substring(keyAttr.length()).trim();
 
46
               break;
 
47
            }
 
48
         }
 
49
         //Exit if the key attribute is missing
 
50
         if (keyAttrValue == null) {
 
51
            err.println("error: required attribute \"" + keyAttr + "\" is missing");
 
52
            err.println(type + " file \"" + fileName + "\" is not correct");
 
53
            err.flush();
 
54
            //TODO LP: Set correct exit code
 
55
         }
 
56
      } catch (IOException ex) {
 
57
         err.println(ex.getMessage());
 
58
         err.flush();
 
59
         setExitCode(1);
 
60
      }
 
61
      return keyAttrValue;
 
62
   }
 
63
 
 
64
    String readFile(final OptionInfo oi) throws JGDIException {
 
65
        String msg = "Error messages file not found!";
 
66
        int exitCode = 0;
 
67
        String option = oi.getOd().getOption();
 
68
        if (oi.getArgs().size() == 0) {
 
69
            msg = getErrorMessage("NoArgument", option);
 
70
            //err.println(msg);
 
71
            setExitCode(getCustomExitCode("NoArgument", option));
 
72
            throw new JGDIException(msg, exitCode);
 
73
        }
 
74
        File f = new File(oi.getFirstArg());
 
75
        long fileSize = f.length();
 
76
        FileReader fr;
 
77
        StringBuilder sb = new StringBuilder();
 
78
        try {
 
79
            fr = new FileReader(f);
 
80
            char[] buff = new char[2048];
 
81
            int r;
 
82
            while (fr.ready()) {
 
83
                r = fr.read(buff);
 
84
                if (r > 0) {
 
85
                    sb.append(buff, 0, r);
 
86
                }
 
87
            }
 
88
        } catch (IOException ex) {
 
89
            msg = getErrorMessage("InvalidFile", option);
 
90
            exitCode = getCustomExitCode("InvalidFile", option);
 
91
            throw new JGDIException(msg, exitCode);
 
92
        }
 
93
        //Check we have whole content
 
94
        if (sb.length() != fileSize) {
 
95
            throw new JGDIException("Unable to read whole file content. Filesize is " + fileSize + " got only " + sb.length());
 
96
        }
 
97
        return sb.toString();
 
98
    }
 
99
 
 
100
   private String runJavaEditor(final String text) {
 
101
      TextEditor ted = new TextEditor(text);
 
102
      while (!ted.isDone()) {
 
103
         try {
 
104
            Thread.currentThread().sleep(1000);
 
105
         } catch (InterruptedException ex) {
 
106
            ex.printStackTrace();
 
107
         }
 
108
      }
 
109
      return ted.getText();
 
110
   }
 
111
 
 
112
   String runEditor(final String text) {
 
113
      String editor;
 
114
      String version = System.getProperty("java.specification.version");
 
115
      //TODO LP <1.5 doesn't list properties like EDITOR...
 
116
      if (Double.parseDouble(version) < 1.5) {
 
117
         editor = System.getProperty("EDITOR");
 
118
      } else {
 
119
         editor = System.getenv("EDITOR");
 
120
      }
 
121
      if (editor == null) {
 
122
         return runJavaEditor(text);
 
123
      }
 
124
      StringBuilder sb = new StringBuilder();
 
125
      try {
 
126
         File f = File.createTempFile("edit", null, new File("/tmp"));
 
127
         FileWriter fw = new FileWriter(f);
 
128
         fw.write(text);
 
129
         fw.flush();
 
130
         fw.close();
 
131
 
 
132
         int exitCode = EditorUtil.sgeEdit(f);
 
133
         if (exitCode != 0) {
 
134
            return null;
 
135
         }
 
136
         char[] buff = new char[1024];
 
137
         FileReader fr = new FileReader(f);
 
138
         int readChars = 0;
 
139
         while (fr.ready() && readChars != -1) {
 
140
            readChars = fr.read(buff);
 
141
            if (readChars > 0) {
 
142
               sb.append(buff, 0, readChars);
 
143
            }
 
144
         }
 
145
      } catch (IOException ioe) {
 
146
         ioe.printStackTrace();
 
147
/*
 
148
      } catch (InterruptedException ie) {
 
149
         ie.printStackTrace();
 
150
*/
 
151
      }
 
152
      return sb.toString();
 
153
   }
 
 
b'\\ No newline at end of file'