2
/*___INFO__MARK_BEGIN__*/
3
/*************************************************************************
5
* The Contents of this file are made available subject to the terms of
6
* the Sun Industry Standards Source License Version 1.2
8
* Sun Microsystems Inc., March, 2001
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
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.
25
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
27
* Copyright: 2001 by Sun Microsystems, Inc.
29
* All Rights Reserved.
31
************************************************************************/
32
/*___INFO__MARK_END__*/
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;
43
keyAttrLine = lnr.readLine().trim();
44
if (keyAttrLine.startsWith(keyAttr)) {
45
keyAttrValue = keyAttrLine.substring(keyAttr.length()).trim();
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");
54
//TODO LP: Set correct exit code
56
} catch (IOException ex) {
57
err.println(ex.getMessage());
64
String readFile(final OptionInfo oi) throws JGDIException {
65
String msg = "Error messages file not found!";
67
String option = oi.getOd().getOption();
68
if (oi.getArgs().size() == 0) {
69
msg = getErrorMessage("NoArgument", option);
71
setExitCode(getCustomExitCode("NoArgument", option));
72
throw new JGDIException(msg, exitCode);
74
File f = new File(oi.getFirstArg());
75
long fileSize = f.length();
77
StringBuilder sb = new StringBuilder();
79
fr = new FileReader(f);
80
char[] buff = new char[2048];
85
sb.append(buff, 0, r);
88
} catch (IOException ex) {
89
msg = getErrorMessage("InvalidFile", option);
90
exitCode = getCustomExitCode("InvalidFile", option);
91
throw new JGDIException(msg, exitCode);
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());
100
private String runJavaEditor(final String text) {
101
TextEditor ted = new TextEditor(text);
102
while (!ted.isDone()) {
104
Thread.currentThread().sleep(1000);
105
} catch (InterruptedException ex) {
106
ex.printStackTrace();
109
return ted.getText();
112
String runEditor(final String text) {
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");
119
editor = System.getenv("EDITOR");
121
if (editor == null) {
122
return runJavaEditor(text);
124
StringBuilder sb = new StringBuilder();
126
File f = File.createTempFile("edit", null, new File("/tmp"));
127
FileWriter fw = new FileWriter(f);
132
int exitCode = EditorUtil.sgeEdit(f);
136
char[] buff = new char[1024];
137
FileReader fr = new FileReader(f);
139
while (fr.ready() && readChars != -1) {
140
readChars = fr.read(buff);
142
sb.append(buff, 0, readChars);
145
} catch (IOException ioe) {
146
ioe.printStackTrace();
148
} catch (InterruptedException ie) {
149
ie.printStackTrace();
152
return sb.toString();
b'\\ No newline at end of file'