PageRenderTime 57ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/core/src/org/pentaho/di/core/Const.java

https://github.com/dbogdanovich/pentaho-kettle
Java | 2980 lines | 1329 code | 377 blank | 1274 comment | 321 complexity | 93298c4ee5d9bd83b175a2ea3d6b9423 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. //CHECKSTYLE:FileLength:OFF
  2. /*! ******************************************************************************
  3. *
  4. * Pentaho Data Integration
  5. *
  6. * Copyright (C) 2002-2013 by Pentaho : http://www.pentaho.com
  7. *
  8. *******************************************************************************
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with
  12. * the License. You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. *
  22. ******************************************************************************/
  23. package org.pentaho.di.core;
  24. import java.awt.Font;
  25. import java.awt.GraphicsEnvironment;
  26. import java.io.BufferedReader;
  27. import java.io.IOException;
  28. import java.io.InputStreamReader;
  29. import java.io.PrintWriter;
  30. import java.io.StringWriter;
  31. import java.net.InetAddress;
  32. import java.net.NetworkInterface;
  33. import java.net.SocketException;
  34. import java.net.URL;
  35. import java.net.URLClassLoader;
  36. import java.text.DecimalFormat;
  37. import java.text.DecimalFormatSymbols;
  38. import java.text.NumberFormat;
  39. import java.text.ParseException;
  40. import java.text.ParsePosition;
  41. import java.text.SimpleDateFormat;
  42. import java.util.ArrayList;
  43. import java.util.Arrays;
  44. import java.util.Calendar;
  45. import java.util.Date;
  46. import java.util.Enumeration;
  47. import java.util.List;
  48. import java.util.Locale;
  49. import java.util.TimeZone;
  50. import java.util.regex.Matcher;
  51. import java.util.regex.Pattern;
  52. import org.apache.commons.lang.StringEscapeUtils;
  53. import org.apache.commons.lang.StringUtils;
  54. import org.pentaho.di.core.exception.KettleException;
  55. import org.pentaho.di.core.row.ValueMetaInterface;
  56. import org.pentaho.di.i18n.BaseMessages;
  57. import org.pentaho.di.laf.BasePropertyHandler;
  58. import org.pentaho.di.version.BuildVersion;
  59. /**
  60. * This class is used to define a number of default values for various settings throughout Kettle. It also contains a
  61. * number of static final methods to make your life easier.
  62. *
  63. * @author Matt
  64. * @since 07-05-2003
  65. *
  66. */
  67. public class Const {
  68. private static Class<?> PKG = Const.class; // for i18n purposes, needed by Translator2!!
  69. /**
  70. * Version number
  71. *
  72. * @deprecated Use {@link BuildVersion#getVersion()} instead
  73. */
  74. @Deprecated
  75. public static final String VERSION = BuildVersion.getInstance().getVersion();
  76. /**
  77. * Copyright year
  78. */
  79. public static final String COPYRIGHT_YEAR = "2013";
  80. /**
  81. * Release Type
  82. */
  83. public enum ReleaseType {
  84. RELEASE_CANDIDATE, MILESTONE, PREVIEW, GA
  85. }
  86. /**
  87. * Sleep time waiting when buffer is empty (the default)
  88. */
  89. public static final int TIMEOUT_GET_MILLIS = 50;
  90. /**
  91. * Sleep time waiting when buffer is full (the default)
  92. */
  93. public static final int TIMEOUT_PUT_MILLIS = 50;
  94. /**
  95. * print update every ... lines
  96. */
  97. public static final int ROWS_UPDATE = 50000;
  98. /**
  99. * Size of rowset: bigger = faster for large amounts of data
  100. */
  101. public static final int ROWS_IN_ROWSET = 10000;
  102. /**
  103. * Fetch size in rows when querying a database
  104. */
  105. public static final int FETCH_SIZE = 10000;
  106. /**
  107. * Sort size: how many rows do we sort in memory at once?
  108. */
  109. public static final int SORT_SIZE = 5000;
  110. /**
  111. * What's the file systems file separator on this operating system?
  112. */
  113. public static final String FILE_SEPARATOR = System.getProperty( "file.separator" );
  114. /**
  115. * What's the path separator on this operating system?
  116. */
  117. public static final String PATH_SEPARATOR = System.getProperty( "path.separator" );
  118. /**
  119. * CR: operating systems specific Carriage Return
  120. */
  121. public static final String CR = System.getProperty( "line.separator" );
  122. /**
  123. * DOSCR: MS-DOS specific Carriage Return
  124. */
  125. public static final String DOSCR = "\n\r";
  126. /**
  127. * An empty ("") String.
  128. */
  129. public static final String EMPTY_STRING = "";
  130. /**
  131. * The Java runtime version
  132. */
  133. public static final String JAVA_VERSION = System.getProperty( "java.vm.version" );
  134. /**
  135. * Path to the users home directory (keep this entry above references to getKettleDirectory())
  136. *
  137. * @deprecated Use {@link Const.getUserHomeDirectory()} instead.
  138. */
  139. @Deprecated
  140. public static final String USER_HOME_DIRECTORY = NVL( System.getProperty( "KETTLE_HOME" ), System
  141. .getProperty( "user.home" ) );
  142. /**
  143. * Path to the simple-jndi directory
  144. */
  145. public static String JNDI_DIRECTORY = NVL( System.getProperty( "KETTLE_JNDI_ROOT" ), System
  146. .getProperty( "org.osjava.sj.root" ) );
  147. /*
  148. * The images directory
  149. *
  150. * public static final String IMAGE_DIRECTORY = "/ui/images/";
  151. */
  152. public static final String PLUGIN_BASE_FOLDERS_PROP = "KETTLE_PLUGIN_BASE_FOLDERS";
  153. /**
  154. * the default comma separated list of base plugin folders.
  155. */
  156. public static final String DEFAULT_PLUGIN_BASE_FOLDERS = "plugins,"
  157. + ( Const.isEmpty( getDIHomeDirectory() ) ? "" : getDIHomeDirectory() + FILE_SEPARATOR + "plugins," )
  158. + getKettleDirectory() + FILE_SEPARATOR + "plugins";
  159. /**
  160. * Default minimum date range...
  161. */
  162. public static final Date MIN_DATE = new Date( -2208992400000L ); // 1900/01/01 00:00:00.000
  163. /**
  164. * Default maximum date range...
  165. */
  166. public static final Date MAX_DATE = new Date( 7258114799468L ); // 2199/12/31 23:59:59.999
  167. /**
  168. * The default minimum year in a dimension date range
  169. */
  170. public static final int MIN_YEAR = 1900;
  171. /**
  172. * The default maximum year in a dimension date range
  173. */
  174. public static final int MAX_YEAR = 2199;
  175. /**
  176. * Specifies the number of pixels to the right we have to go in dialog boxes.
  177. */
  178. public static final int RIGHT = 400;
  179. /**
  180. * Specifies the length (width) of fields in a number of pixels in dialog boxes.
  181. */
  182. public static final int LENGTH = 350;
  183. /**
  184. * The margin between the different dialog components & widgets
  185. */
  186. public static final int MARGIN = 4;
  187. /**
  188. * The default percentage of the width of screen where we consider the middle of a dialog.
  189. */
  190. public static final int MIDDLE_PCT = 35;
  191. /**
  192. * The default width of an arrow in the Graphical Views
  193. */
  194. public static final int ARROW_WIDTH = 1;
  195. /**
  196. * The horizontal and vertical margin of a dialog box.
  197. */
  198. public static final int FORM_MARGIN = 5;
  199. /**
  200. * The default shadow size on the graphical view.
  201. */
  202. public static final int SHADOW_SIZE = 4;
  203. /**
  204. * The size of relationship symbols
  205. */
  206. public static final int SYMBOLSIZE = 10;
  207. /**
  208. * Max nr. of files to remember
  209. */
  210. public static final int MAX_FILE_HIST = 9; // Having more than 9 files in the file history is not compatible with pre
  211. // 5.0 versions
  212. /**
  213. * The default locale for the kettle environment (system defined)
  214. */
  215. public static final Locale DEFAULT_LOCALE = Locale.getDefault(); // new Locale("nl", "BE");
  216. /**
  217. * The default decimal separator . or ,
  218. */
  219. public static final char DEFAULT_DECIMAL_SEPARATOR = ( new DecimalFormatSymbols( DEFAULT_LOCALE ) )
  220. .getDecimalSeparator();
  221. /**
  222. * The default grouping separator , or .
  223. */
  224. public static final char DEFAULT_GROUPING_SEPARATOR = ( new DecimalFormatSymbols( DEFAULT_LOCALE ) )
  225. .getGroupingSeparator();
  226. /**
  227. * The default currency symbol
  228. */
  229. public static final String DEFAULT_CURRENCY_SYMBOL = ( new DecimalFormatSymbols( DEFAULT_LOCALE ) )
  230. .getCurrencySymbol();
  231. /**
  232. * The default number format
  233. */
  234. public static final String DEFAULT_NUMBER_FORMAT = ( (DecimalFormat) ( NumberFormat.getInstance() ) )
  235. .toPattern();
  236. /**
  237. * Default string representing Null String values (empty)
  238. */
  239. public static final String NULL_STRING = "";
  240. /**
  241. * Default string representing Null Number values (empty)
  242. */
  243. public static final String NULL_NUMBER = "";
  244. /**
  245. * Default string representing Null Date values (empty)
  246. */
  247. public static final String NULL_DATE = "";
  248. /**
  249. * Default string representing Null BigNumber values (empty)
  250. */
  251. public static final String NULL_BIGNUMBER = "";
  252. /**
  253. * Default string representing Null Boolean values (empty)
  254. */
  255. public static final String NULL_BOOLEAN = "";
  256. /**
  257. * Default string representing Null Integer values (empty)
  258. */
  259. public static final String NULL_INTEGER = "";
  260. /**
  261. * Default string representing Null Binary values (empty)
  262. */
  263. public static final String NULL_BINARY = "";
  264. /**
  265. * Default string representing Null Undefined values (empty)
  266. */
  267. public static final String NULL_NONE = "";
  268. /**
  269. * The base name of the Chef logfile
  270. */
  271. public static final String CHEF_LOG_FILE = "chef";
  272. /**
  273. * The base name of the Spoon logfile
  274. */
  275. public static final String SPOON_LOG_FILE = "spoon";
  276. /**
  277. * The base name of the Menu logfile
  278. */
  279. public static final String MENU_LOG_FILE = "menu";
  280. /**
  281. * A number of tips that are shown when the application first starts.
  282. */
  283. private static String[] tips;
  284. /**
  285. * An array of date conversion formats
  286. */
  287. private static String[] dateFormats;
  288. /**
  289. * An array of number conversion formats
  290. */
  291. private static String[] numberFormats;
  292. /**
  293. * Generalized date/time format: Wherever dates are used, date and time values are organized from the most to the
  294. * least significant. see also method StringUtil.getFormattedDateTime()
  295. */
  296. public static final String GENERALIZED_DATE_TIME_FORMAT = "yyyyddMM_hhmmss";
  297. public static final String GENERALIZED_DATE_TIME_FORMAT_MILLIS = "yyyyddMM_hhmmssSSS";
  298. /**
  299. * Default we store our information in Unicode UTF-8 character set.
  300. */
  301. public static final String XML_ENCODING = "UTF-8";
  302. /** The possible extensions a transformation XML file can have. */
  303. public static final String[] STRING_TRANS_AND_JOB_FILTER_EXT = new String[] {
  304. "*.ktr;*.kjb;*.xml", "*.ktr;*.xml", "*.kjb;*.xml", "*.xml", "*.*" };
  305. /** The discriptions of the possible extensions a transformation XML file can have. */
  306. private static String[] STRING_TRANS_AND_JOB_FILTER_NAMES;
  307. /** The extension of a Kettle transformation XML file */
  308. public static final String STRING_TRANS_DEFAULT_EXT = "ktr";
  309. /** The possible extensions a transformation XML file can have. */
  310. public static final String[] STRING_TRANS_FILTER_EXT = new String[] { "*.ktr;*.xml", "*.xml", "*.*" };
  311. /** The discriptions of the possible extensions a transformation XML file can have. */
  312. private static String[] STRING_TRANS_FILTER_NAMES;
  313. /** The extension of a Kettle job XML file */
  314. public static final String STRING_JOB_DEFAULT_EXT = "kjb";
  315. /** The possible extensions a job XML file can have. */
  316. public static final String[] STRING_JOB_FILTER_EXT = new String[] { "*.kjb;*.xml", "*.xml", "*.*" };
  317. /** The discriptions of the possible extensions a job XML file can have. */
  318. private static String[] STRING_JOB_FILTER_NAMES;
  319. /** Name of the kettle parameters file */
  320. public static final String KETTLE_PROPERTIES = "kettle.properties";
  321. /** The prefix that all internal kettle variables should have */
  322. public static final String INTERNAL_VARIABLE_PREFIX = "Internal";
  323. /** The version number as an internal variable */
  324. public static final String INTERNAL_VARIABLE_KETTLE_VERSION = INTERNAL_VARIABLE_PREFIX + ".Kettle.Version";
  325. /** The build version as an internal variable */
  326. public static final String INTERNAL_VARIABLE_KETTLE_BUILD_VERSION = INTERNAL_VARIABLE_PREFIX
  327. + ".Kettle.Build.Version";
  328. /** The build date as an internal variable */
  329. public static final String INTERNAL_VARIABLE_KETTLE_BUILD_DATE = INTERNAL_VARIABLE_PREFIX + ".Kettle.Build.Date";
  330. /** The job filename directory */
  331. public static final String INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY = INTERNAL_VARIABLE_PREFIX
  332. + ".Job.Filename.Directory";
  333. /** The job filename name */
  334. public static final String INTERNAL_VARIABLE_JOB_FILENAME_NAME = INTERNAL_VARIABLE_PREFIX + ".Job.Filename.Name";
  335. /** The job name */
  336. public static final String INTERNAL_VARIABLE_JOB_NAME = INTERNAL_VARIABLE_PREFIX + ".Job.Name";
  337. /** The job directory */
  338. public static final String INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY = INTERNAL_VARIABLE_PREFIX
  339. + ".Job.Repository.Directory";
  340. /** The job run ID */
  341. public static final String INTERNAL_VARIABLE_JOB_RUN_ID = INTERNAL_VARIABLE_PREFIX + ".Job.Run.ID";
  342. /** The job run attempt nr */
  343. public static final String INTERNAL_VARIABLE_JOB_RUN_ATTEMPTNR = INTERNAL_VARIABLE_PREFIX + ".Job.Run.AttemptNr";
  344. /**
  345. * All the internal transformation variables
  346. */
  347. public static final String[] INTERNAL_TRANS_VARIABLES = new String[] {
  348. Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY,
  349. Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_NAME, Const.INTERNAL_VARIABLE_TRANSFORMATION_NAME,
  350. Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY,
  351. };
  352. /**
  353. * All the internal job variables
  354. */
  355. public static final String[] INTERNAL_JOB_VARIABLES = new String[] {
  356. Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME,
  357. Const.INTERNAL_VARIABLE_JOB_NAME, Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY,
  358. Const.INTERNAL_VARIABLE_JOB_RUN_ID, Const.INTERNAL_VARIABLE_JOB_RUN_ATTEMPTNR, };
  359. /** The transformation filename directory */
  360. public static final String INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY = INTERNAL_VARIABLE_PREFIX
  361. + ".Transformation.Filename.Directory";
  362. /** The transformation filename name */
  363. public static final String INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_NAME = INTERNAL_VARIABLE_PREFIX
  364. + ".Transformation.Filename.Name";
  365. /** The transformation name */
  366. public static final String INTERNAL_VARIABLE_TRANSFORMATION_NAME = INTERNAL_VARIABLE_PREFIX
  367. + ".Transformation.Name";
  368. /** The transformation directory */
  369. public static final String INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY = INTERNAL_VARIABLE_PREFIX
  370. + ".Transformation.Repository.Directory";
  371. /** The step partition ID */
  372. public static final String INTERNAL_VARIABLE_STEP_PARTITION_ID = INTERNAL_VARIABLE_PREFIX + ".Step.Partition.ID";
  373. /** The step partition number */
  374. public static final String INTERNAL_VARIABLE_STEP_PARTITION_NR = INTERNAL_VARIABLE_PREFIX
  375. + ".Step.Partition.Number";
  376. /** The slave transformation number */
  377. public static final String INTERNAL_VARIABLE_SLAVE_SERVER_NUMBER = INTERNAL_VARIABLE_PREFIX
  378. + ".Slave.Transformation.Number";
  379. /** The slave transformation name */
  380. public static final String INTERNAL_VARIABLE_SLAVE_SERVER_NAME = INTERNAL_VARIABLE_PREFIX + ".Slave.Server.Name";
  381. /** The size of the cluster : number of slaves */
  382. public static final String INTERNAL_VARIABLE_CLUSTER_SIZE = INTERNAL_VARIABLE_PREFIX + ".Cluster.Size";
  383. /** The slave transformation number */
  384. public static final String INTERNAL_VARIABLE_STEP_UNIQUE_NUMBER = INTERNAL_VARIABLE_PREFIX
  385. + ".Step.Unique.Number";
  386. /** Is this transformation running clustered, on the master? */
  387. public static final String INTERNAL_VARIABLE_CLUSTER_MASTER = INTERNAL_VARIABLE_PREFIX + ".Cluster.Master";
  388. /**
  389. * The internal clustered run ID, unique across a clustered execution, important while doing parallel clustered runs
  390. */
  391. public static final String INTERNAL_VARIABLE_CLUSTER_RUN_ID = INTERNAL_VARIABLE_PREFIX + ".Cluster.Run.ID";
  392. /** The size of the cluster : number of slaves */
  393. public static final String INTERNAL_VARIABLE_STEP_UNIQUE_COUNT = INTERNAL_VARIABLE_PREFIX + ".Step.Unique.Count";
  394. /** The step name */
  395. public static final String INTERNAL_VARIABLE_STEP_NAME = INTERNAL_VARIABLE_PREFIX + ".Step.Name";
  396. /** The step copy nr */
  397. public static final String INTERNAL_VARIABLE_STEP_COPYNR = INTERNAL_VARIABLE_PREFIX + ".Step.CopyNr";
  398. /** The default maximum for the nr of lines in the GUI logs */
  399. public static final int MAX_NR_LOG_LINES = 5000;
  400. /** The default maximum for the nr of lines in the history views */
  401. public static final int MAX_NR_HISTORY_LINES = 50;
  402. /** The default fetch size for lines of history. */
  403. public static final int HISTORY_LINES_FETCH_SIZE = 10;
  404. /** The default log line timeout in minutes : 12 hours */
  405. public static final int MAX_LOG_LINE_TIMEOUT_MINUTES = 12 * 60;
  406. /** UI-agnostic flag for warnings */
  407. public static final int WARNING = 1;
  408. /** UI-agnostic flag for warnings */
  409. public static final int ERROR = 2;
  410. /** UI-agnostic flag for warnings */
  411. public static final int INFO = 3;
  412. /**
  413. * The margin between the text of a note and its border.
  414. */
  415. public static final int NOTE_MARGIN = 5;
  416. /**
  417. * The default undo level for Kettle
  418. */
  419. public static final int MAX_UNDO = 100;
  420. /**
  421. * The file that documents these variables.
  422. */
  423. public static final String KETTLE_VARIABLES_FILE = "kettle-variables.xml";
  424. /**
  425. * If you set this environment variable you can limit the log size of all transformations and jobs that don't have the
  426. * "log size limit" property set in their respective properties.
  427. */
  428. public static final String KETTLE_LOG_SIZE_LIMIT = "KETTLE_LOG_SIZE_LIMIT";
  429. /**
  430. * The name of the variable that defines the log database connection by default for all transformations
  431. */
  432. public static final String KETTLE_TRANS_LOG_DB = "KETTLE_TRANS_LOG_DB";
  433. /**
  434. * The name of the variable that defines the logging schema for all transformations
  435. */
  436. public static final String KETTLE_TRANS_LOG_SCHEMA = "KETTLE_TRANS_LOG_SCHEMA";
  437. /**
  438. * The name of the variable that defines the logging table for all transformations
  439. */
  440. public static final String KETTLE_TRANS_LOG_TABLE = "KETTLE_TRANS_LOG_TABLE";
  441. /**
  442. * The name of the variable that defines the log database connection by default for all jobs
  443. */
  444. public static final String KETTLE_JOB_LOG_DB = "KETTLE_JOB_LOG_DB";
  445. /**
  446. * The name of the variable that defines the logging schema for all jobs
  447. */
  448. public static final String KETTLE_JOB_LOG_SCHEMA = "KETTLE_JOB_LOG_SCHEMA";
  449. /**
  450. * The name of the variable that defines the logging table for all jobs
  451. */
  452. public static final String KETTLE_JOB_LOG_TABLE = "KETTLE_JOB_LOG_TABLE";
  453. /**
  454. * The name of the variable that defines the transformation performance log schema by default for all transformations
  455. */
  456. public static final String KETTLE_TRANS_PERFORMANCE_LOG_DB = "KETTLE_TRANS_PERFORMANCE_LOG_DB";
  457. /**
  458. * The name of the variable that defines the transformation performance log database connection by default for all
  459. * transformations
  460. */
  461. public static final String KETTLE_TRANS_PERFORMANCE_LOG_SCHEMA = "KETTLE_TRANS_PERFORMANCE_LOG_SCHEMA";
  462. /**
  463. * The name of the variable that defines the transformation performance log table by default for all transformations
  464. */
  465. public static final String KETTLE_TRANS_PERFORMANCE_LOG_TABLE = "KETTLE_TRANS_PERFORMANCE_LOG_TABLE";
  466. /**
  467. * The name of the variable that defines the job entry log database by default for all jobs
  468. */
  469. public static final String KETTLE_JOBENTRY_LOG_DB = "KETTLE_JOBENTRY_LOG_DB";
  470. /**
  471. * The name of the variable that defines the job entry log schema by default for all jobs
  472. */
  473. public static final String KETTLE_JOBENTRY_LOG_SCHEMA = "KETTLE_JOBENTRY_LOG_SCHEMA";
  474. /**
  475. * The name of the variable that defines the job entry log table by default for all jobs
  476. */
  477. public static final String KETTLE_JOBENTRY_LOG_TABLE = "KETTLE_JOBENTRY_LOG_TABLE";
  478. /**
  479. * The name of the variable that defines the steps log database by default for all transformations
  480. */
  481. public static final String KETTLE_STEP_LOG_DB = "KETTLE_STEP_LOG_DB";
  482. /**
  483. * The name of the variable that defines the steps log schema by default for all transformations
  484. */
  485. public static final String KETTLE_STEP_LOG_SCHEMA = "KETTLE_STEP_LOG_SCHEMA";
  486. /**
  487. * The name of the variable that defines the steps log table by default for all transformations
  488. */
  489. public static final String KETTLE_STEP_LOG_TABLE = "KETTLE_STEP_LOG_TABLE";
  490. /**
  491. * The name of the variable that defines the log channel log database by default for all transformations and jobs
  492. */
  493. public static final String KETTLE_CHANNEL_LOG_DB = "KETTLE_CHANNEL_LOG_DB";
  494. /**
  495. * The name of the variable that defines the log channel log schema by default for all transformations and jobs
  496. */
  497. public static final String KETTLE_CHANNEL_LOG_SCHEMA = "KETTLE_CHANNEL_LOG_SCHEMA";
  498. /**
  499. * The name of the variable that defines the log channel log table by default for all transformations and jobs
  500. */
  501. public static final String KETTLE_CHANNEL_LOG_TABLE = "KETTLE_CHANNEL_LOG_TABLE";
  502. /**
  503. * The name of the variable that defines the metrics log database by default for all transformations and jobs
  504. */
  505. public static final String KETTLE_METRICS_LOG_DB = "KETTLE_METRICS_LOG_DB";
  506. /**
  507. * The name of the variable that defines the metrics log schema by default for all transformations and jobs
  508. */
  509. public static final String KETTLE_METRICS_LOG_SCHEMA = "KETTLE_METRICS_LOG_SCHEMA";
  510. /**
  511. * The name of the variable that defines the metrics log table by default for all transformations and jobs
  512. */
  513. public static final String KETTLE_METRICS_LOG_TABLE = "KETTLE_METRICS_LOG_TABLE";
  514. /**
  515. * The name of the variable that defines the checkpoint log database by default for all jobs
  516. */
  517. public static final String KETTLE_CHECKPOINT_LOG_DB = "KETTLE_CHECKPOINT_LOG_DB";
  518. /**
  519. * The name of the variable that defines the checkpoint log schema by default for all jobs
  520. */
  521. public static final String KETTLE_CHECKPOINT_LOG_SCHEMA = "KETTLE_CHECKPOINT_LOG_SCHEMA";
  522. /**
  523. * The name of the variable that defines the checkpoint log table by default for all jobs
  524. */
  525. public static final String KETTLE_CHECKPOINT_LOG_TABLE = "KETTLE_CHECKPOINT_LOG_TABLE";
  526. /**
  527. * Name of the environment variable to set the location of the shared object file (xml) for transformations and jobs
  528. */
  529. public static final String KETTLE_SHARED_OBJECTS = "KETTLE_SHARED_OBJECTS";
  530. /**
  531. * System wide flag to drive the evaluation of null in ValueMeta. If this setting is set to "Y", an empty string and
  532. * null are different. Otherwise they are not.
  533. */
  534. public static final String KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = "KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL";
  535. /**
  536. * System wide flag to allow non-strict string to number conversion for backward compatibility. If this setting is set
  537. * to "Y", an string starting with digits will be converted successfully into a number. (example: 192.168.1.1 will be
  538. * converted into 192 or 192.168 depending on the decimal symbol). The default (N) will be to throw an error if
  539. * non-numeric symbols are found in the string.
  540. */
  541. public static final String KETTLE_LENIENT_STRING_TO_NUMBER_CONVERSION =
  542. "KETTLE_LENIENT_STRING_TO_NUMBER_CONVERSION";
  543. /**
  544. * System wide flag to ignore timezone while writing date/timestamp value to the database. See PDI-10749 for details.
  545. */
  546. public static final String KETTLE_COMPATIBILITY_DB_IGNORE_TIMEZONE = "KETTLE_COMPATIBILITY_DB_IGNORE_TIMEZONE";
  547. /**
  548. * System wide flag to set the maximum number of log lines that are kept internally by Kettle. Set to 0 to keep all
  549. * rows (default)
  550. */
  551. public static final String KETTLE_MAX_LOG_SIZE_IN_LINES = "KETTLE_MAX_LOG_SIZE_IN_LINES";
  552. /**
  553. * System wide flag to set the maximum age (in minutes) of a log line while being kept internally by Kettle. Set to 0
  554. * to keep all rows indefinitely (default)
  555. */
  556. public static final String KETTLE_MAX_LOG_TIMEOUT_IN_MINUTES = "KETTLE_MAX_LOG_TIMEOUT_IN_MINUTES";
  557. /**
  558. * System wide flag to determine whether standard error will be redirected to Kettle logging facilities. Will redirect
  559. * if the value is equal ignoring case to the string "Y"
  560. */
  561. public static final String KETTLE_REDIRECT_STDERR = "KETTLE_REDIRECT_STDERR";
  562. /**
  563. * System wide flag to determine whether standard out will be redirected to Kettle logging facilities. Will redirect
  564. * if the value is equal ignoring case to the string "Y"
  565. */
  566. public static final String KETTLE_REDIRECT_STDOUT = "KETTLE_REDIRECT_STDOUT";
  567. /**
  568. * This environment variable will set a time-out after which waiting, completed or stopped transformations and jobs
  569. * will be automatically cleaned up. The default value is 1440 (one day).
  570. */
  571. public static final String KETTLE_CARTE_OBJECT_TIMEOUT_MINUTES = "KETTLE_CARTE_OBJECT_TIMEOUT_MINUTES";
  572. /**
  573. * System wide parameter: the maximum number of step performance snapshots to keep in memory. Set to 0 to keep all
  574. * snapshots indefinitely (default)
  575. */
  576. public static final String KETTLE_STEP_PERFORMANCE_SNAPSHOT_LIMIT = "KETTLE_STEP_PERFORMANCE_SNAPSHOT_LIMIT";
  577. /**
  578. * A variable to configure the maximum number of job trackers kept in memory.
  579. */
  580. public static final String KETTLE_MAX_JOB_TRACKER_SIZE = "KETTLE_MAX_JOB_TRACKER_SIZE";
  581. /**
  582. * A variable to configure the maximum number of job entry results kept in memory for logging purposes.
  583. */
  584. public static final String KETTLE_MAX_JOB_ENTRIES_LOGGED = "KETTLE_MAX_JOB_ENTRIES_LOGGED";
  585. /**
  586. * A variable to configure the maximum number of logging registry entries kept in memory for logging purposes.
  587. */
  588. public static final String KETTLE_MAX_LOGGING_REGISTRY_SIZE = "KETTLE_MAX_LOGGING_REGISTRY_SIZE";
  589. /**
  590. * The name of the system wide variable that can contain the name of the SAP Connection factory for the test button in
  591. * the DB dialog. This defaults to
  592. */
  593. public static final String KETTLE_SAP_CONNECTION_FACTORY = "KETTLE_SAP_CONNECTION_FACTORY";
  594. /**
  595. * The default SAP ERP connection factory
  596. */
  597. public static final String KETTLE_SAP_CONNECTION_FACTORY_DEFAULT_NAME =
  598. "org.pentaho.di.trans.steps.sapinput.sap.SAPConnectionFactory";
  599. /**
  600. * Name of the environment variable to specify additional classes to scan for plugin annotations
  601. */
  602. public static final String KETTLE_PLUGIN_CLASSES = "KETTLE_PLUGIN_CLASSES";
  603. /**
  604. * Name of the environment variable to specify additional packaged to scan for plugin annotations (warning: slow!)
  605. */
  606. public static final String KETTLE_PLUGIN_PACKAGES = "KETTLE_PLUGIN_PACKAGES";
  607. /**
  608. * Name of the environment variable that contains the size of the transformation rowset size. This overwrites values
  609. * that you set transformation settings.
  610. */
  611. public static final String KETTLE_TRANS_ROWSET_SIZE = "KETTLE_TRANS_ROWSET_SIZE";
  612. /**
  613. * A general initial version comment
  614. */
  615. public static final String VERSION_COMMENT_INITIAL_VERSION = "Creation of initial version";
  616. /**
  617. * A general edit version comment
  618. */
  619. public static final String VERSION_COMMENT_EDIT_VERSION = "Modification by user";
  620. /**
  621. * The XML file that contains the list of native Kettle steps
  622. */
  623. public static final String XML_FILE_KETTLE_STEPS = "kettle-steps.xml";
  624. /**
  625. * The name of the environment variable that will contain the alternative location of the kettle-steps.xml file
  626. */
  627. public static final String KETTLE_CORE_STEPS_FILE = "KETTLE_CORE_STEPS_FILE";
  628. /**
  629. * The XML file that contains the list of native partition plugins
  630. */
  631. public static final String XML_FILE_KETTLE_PARTITION_PLUGINS = "kettle-partition-plugins.xml";
  632. /**
  633. * The name of the environment variable that will contain the alternative location of the kettle-job-entries.xml file
  634. */
  635. public static final String KETTLE_CORE_JOBENTRIES_FILE = "KETTLE_CORE_JOBENTRIES_FILE";
  636. /**
  637. * The XML file that contains the list of native Kettle Carte Servlets
  638. */
  639. public static final String XML_FILE_KETTLE_SERVLETS = "kettle-servlets.xml";
  640. /**
  641. * The XML file that contains the list of native Kettle value metadata plugins
  642. */
  643. public static final String XML_FILE_KETTLE_VALUEMETA_PLUGINS = "kettle-valuemeta-plugins.xml";
  644. /**
  645. * The name of the environment variable that will contain the alternative location of the kettle-valuemeta-plugins.xml
  646. * file
  647. */
  648. public static final String KETTLE_VALUEMETA_PLUGINS_FILE = "KETTLE_VALUEMETA_PLUGINS_FILE";
  649. /**
  650. * The XML file that contains the list of native Kettle logging plugins
  651. */
  652. public static final String XML_FILE_KETTLE_LOGGING_PLUGINS = "kettle-logging-plugins.xml";
  653. /**
  654. * The name of the environment variable that will contain the alternative location of the kettle-logging-plugins.xml
  655. * file
  656. */
  657. public static final String KETTLE_LOGGING_PLUGINS_FILE = "KETTLE_LOGGING_PLUGINS_FILE";
  658. /**
  659. * The name of the environment variable that will contain the alternative location of the kettle-servlets.xml file
  660. */
  661. public static final String KETTLE_CORE_SERVLETS_FILE = "KETTLE_CORE_SERVLETS_FILE";
  662. /**
  663. * The name of the variable that optionally contains an alternative rowset get timeout (in ms). This only makes a
  664. * difference for extremely short lived transformations.
  665. */
  666. public static final String KETTLE_ROWSET_GET_TIMEOUT = "KETTLE_ROWSET_GET_TIMEOUT";
  667. /**
  668. * The name of the variable that optionally contains an alternative rowset put timeout (in ms). This only makes a
  669. * difference for extremely short lived transformations.
  670. */
  671. public static final String KETTLE_ROWSET_PUT_TIMEOUT = "KETTLE_ROWSET_PUT_TIMEOUT";
  672. /**
  673. * Set this variable to Y if you want to test a more efficient batching row set. (default = N)
  674. */
  675. public static final String KETTLE_BATCHING_ROWSET = "KETTLE_BATCHING_ROWSET";
  676. /**
  677. * Set this variable to Y to disable standard Kettle logging to the console. (stdout)
  678. */
  679. public static final String KETTLE_DISABLE_CONSOLE_LOGGING = "KETTLE_DISABLE_CONSOLE_LOGGING";
  680. /**
  681. * The XML file that contains the list of native Kettle job entries
  682. */
  683. public static final String XML_FILE_KETTLE_JOB_ENTRIES = "kettle-job-entries.xml";
  684. /**
  685. * The XML file that contains the list of native Kettle repository types (DB, File, etc)
  686. */
  687. public static final String XML_FILE_KETTLE_REPOSITORIES = "kettle-repositories.xml";
  688. /**
  689. * The XML file that contains the list of native Kettle database types (MySQL, Oracle, etc)
  690. */
  691. public static final String XML_FILE_KETTLE_DATABASE_TYPES = "kettle-database-types.xml";
  692. /**
  693. * The XML file that contains the list of native extension points (None by default, this is mostly for OEM purposes)
  694. */
  695. public static final String XML_FILE_KETTLE_EXTENSION_POINTS = "kettle-extension-points.xml";
  696. /**
  697. * the value the Pan JVM should return on exit.
  698. */
  699. public static final String KETTLE_TRANS_PAN_JVM_EXIT_CODE = "KETTLE_TRANS_PAN_JVM_EXIT_CODE";
  700. /**
  701. * The name of the variable containing an alternative default number format
  702. */
  703. public static final String KETTLE_DEFAULT_NUMBER_FORMAT = "KETTLE_DEFAULT_NUMBER_FORMAT";
  704. /**
  705. * The name of the variable containing an alternative default bignumber format
  706. */
  707. public static final String KETTLE_DEFAULT_BIGNUMBER_FORMAT = "KETTLE_DEFAULT_BIGNUMBER_FORMAT";
  708. /**
  709. * The name of the variable containing an alternative default integer format
  710. */
  711. public static final String KETTLE_DEFAULT_INTEGER_FORMAT = "KETTLE_DEFAULT_INTEGER_FORMAT";
  712. /**
  713. * The name of the variable containing an alternative default date format
  714. */
  715. public static final String KETTLE_DEFAULT_DATE_FORMAT = "KETTLE_DEFAULT_DATE_FORMAT";
  716. /**
  717. * Compatibility settings for setNrErrors
  718. */
  719. // see PDI-10270 for details.
  720. public static final String KETTLE_COMPATIBILITY_SET_ERROR_ON_SPECIFIC_JOB_ENTRIES =
  721. "KETTLE_COMPATIBILITY_SET_ERROR_ON_SPECIFIC_JOB_ENTRIES";
  722. /**
  723. * The XML file that contains the list of native import rules
  724. */
  725. public static final String XML_FILE_KETTLE_IMPORT_RULES = "kettle-import-rules.xml";
  726. private static String[] emptyPaddedSpacesStrings;
  727. /**
  728. * The release type of this compilation
  729. */
  730. public static final ReleaseType RELEASE = ReleaseType.GA;
  731. /**
  732. * The system environment variable indicating where the alternative location for the Pentaho metastore folder is
  733. * located.
  734. */
  735. public static final String PENTAHO_METASTORE_FOLDER = "PENTAHO_METASTORE_FOLDER";
  736. /**
  737. * The name of the local client MetaStore
  738. *
  739. */
  740. public static final String PENTAHO_METASTORE_NAME = "Pentaho Local Client Metastore";
  741. /**
  742. * rounds double f to any number of places after decimal point Does arithmetic using BigDecimal class to avoid integer
  743. * overflow while rounding
  744. *
  745. * @param f
  746. * The value to round
  747. * @param places
  748. * The number of decimal places
  749. * @return The rounded floating point value
  750. */
  751. public static final double round( double f, int places ) {
  752. return round( f, places, java.math.BigDecimal.ROUND_HALF_EVEN );
  753. }
  754. /**
  755. * rounds double f to any number of places after decimal point Does arithmetic using BigDecimal class to avoid integer
  756. * overflow while rounding
  757. *
  758. * @param f
  759. * The value to round
  760. * @param places
  761. * The number of decimal places
  762. * @param roundingMode
  763. * The mode for rounding, e.g. java.math.BigDecimal.ROUND_HALF_EVEN
  764. * @return The rounded floating point value
  765. */
  766. public static final double round( double f, int places, int roundingMode ) {
  767. // We can't round non-numbers or infinite values
  768. //
  769. if ( f == Double.NaN || f == Double.NEGATIVE_INFINITY || f == Double.POSITIVE_INFINITY ) {
  770. return f;
  771. }
  772. // Do the rounding...
  773. //
  774. java.math.BigDecimal bdtemp = java.math.BigDecimal.valueOf( f );
  775. bdtemp = bdtemp.setScale( places, roundingMode );
  776. return bdtemp.doubleValue();
  777. }
  778. /*
  779. * OLD code: caused a lot of problems with very small and very large numbers. It's a miracle it worked at all. Go
  780. * ahead, have a laugh... public static final float round(double f, int places) { float temp = (float) (f *
  781. * (Math.pow(10, places)));
  782. *
  783. * temp = (Math.round(temp));
  784. *
  785. * temp = temp / (int) (Math.pow(10, places));
  786. *
  787. * return temp;
  788. *
  789. * }
  790. */
  791. /**
  792. * Convert a String into an integer. If the conversion fails, assign a default value.
  793. *
  794. * @param str
  795. * The String to convert to an integer
  796. * @param def
  797. * The default value
  798. * @return The converted value or the default.
  799. */
  800. public static final int toInt( String str, int def ) {
  801. int retval;
  802. try {
  803. retval = Integer.parseInt( str );
  804. } catch ( Exception e ) {
  805. retval = def;
  806. }
  807. return retval;
  808. }
  809. /**
  810. * Convert a String into a long integer. If the conversion fails, assign a default value.
  811. *
  812. * @param str
  813. * The String to convert to a long integer
  814. * @param def
  815. * The default value
  816. * @return The converted value or the default.
  817. */
  818. public static final long toLong( String str, long def ) {
  819. long retval;
  820. try {
  821. retval = Long.parseLong( str );
  822. } catch ( Exception e ) {
  823. retval = def;
  824. }
  825. return retval;
  826. }
  827. /**
  828. * Convert a String into a double. If the conversion fails, assign a default value.
  829. *
  830. * @param str
  831. * The String to convert to a double
  832. * @param def
  833. * The default value
  834. * @return The converted value or the default.
  835. */
  836. public static final double toDouble( String str, double def ) {
  837. double retval;
  838. try {
  839. retval = Double.parseDouble( str );
  840. } catch ( Exception e ) {
  841. retval = def;
  842. }
  843. return retval;
  844. }
  845. /**
  846. * Convert a String into a date. The date format is <code>yyyy/MM/dd HH:mm:ss.SSS</code>. If the conversion fails,
  847. * assign a default value.
  848. *
  849. * @param str
  850. * The String to convert into a Date
  851. * @param def
  852. * The default value
  853. * @return The converted value or the default.
  854. */
  855. public static final Date toDate( String str, Date def ) {
  856. SimpleDateFormat df = new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss.SSS", Locale.US );
  857. try {
  858. return df.parse( str );
  859. } catch ( ParseException e ) {
  860. return def;
  861. }
  862. }
  863. /**
  864. * Determines whether or not a character is considered a space. A character is considered a space in Kettle if it is a
  865. * space, a tab, a newline or a cariage return.
  866. *
  867. * @param c
  868. * The character to verify if it is a space.
  869. * @return true if the character is a space. false otherwise.
  870. */
  871. public static final boolean isSpace( char c ) {
  872. return c == ' ' || c == '\t' || c == '\r' || c == '\n' || Character.isWhitespace( c );
  873. }
  874. /**
  875. * Left trim: remove spaces to the left of a String.
  876. *
  877. * @param str
  878. * The String to left trim
  879. * @return The left trimmed String
  880. */
  881. public static String ltrim( String source ) {
  882. if ( source == null ) {
  883. return null;
  884. }
  885. int from = 0;
  886. while ( from < source.length() && isSpace( source.charAt( from ) ) ) {
  887. from++;
  888. }
  889. return source.substring( from );
  890. }
  891. /**
  892. * Right trim: remove spaces to the right of a string
  893. *
  894. * @param str
  895. * The string to right trim
  896. * @return The trimmed string.
  897. */
  898. public static String rtrim( String source ) {
  899. if ( source == null ) {
  900. return null;
  901. }
  902. int max = source.length();
  903. while ( max > 0 && isSpace( source.charAt( max - 1 ) ) ) {
  904. max--;
  905. }
  906. return source.substring( 0, max );
  907. }
  908. /**
  909. * Trims a string: removes the leading and trailing spaces of a String.
  910. *
  911. * @param str
  912. * The string to trim
  913. * @return The trimmed string.
  914. */
  915. public static final String trim( String str ) {
  916. if ( str == null ) {
  917. return null;
  918. }
  919. int max = str.length() - 1;
  920. int min = 0;
  921. while ( min <= max && isSpace( str.charAt( min ) ) ) {
  922. min++;
  923. }
  924. while ( max >= 0 && isSpace( str.charAt( max ) ) ) {
  925. max--;
  926. }
  927. if ( max < min ) {
  928. return "";
  929. }
  930. return str.substring( min, max + 1 );
  931. }
  932. /**
  933. * Right pad a string: adds spaces to a string until a certain length. If the length is smaller then the limit
  934. * specified, the String is truncated.
  935. *
  936. * @param ret
  937. * The string to pad
  938. * @param limit
  939. * The desired length of the padded string.
  940. * @return The padded String.
  941. */
  942. public static final String rightPad( String ret, int limit ) {
  943. if ( ret == null ) {
  944. return rightPad( new StringBuffer(), limit );
  945. } else {
  946. return rightPad( new StringBuffer( ret ), limit );
  947. }
  948. }
  949. /**
  950. * Right pad a StringBuffer: adds spaces to a string until a certain length. If the length is smaller then the limit
  951. * specified, the String is truncated.
  952. *
  953. * @param ret
  954. * The StringBuffer to pad
  955. * @param limit
  956. * The desired length of the padded string.
  957. * @return The padded String.
  958. */
  959. public static final String rightPad( StringBuffer ret, int limit ) {
  960. int len = ret.length();
  961. int l;
  962. if ( len > limit ) {
  963. ret.setLength( limit );
  964. } else {
  965. for ( l = len; l < limit; l++ ) {
  966. ret.append( ' ' );
  967. }
  968. }
  969. return ret.toString();
  970. }
  971. /**
  972. * Replace values in a String with another.
  973. *
  974. * @param string
  975. * The original String.
  976. * @param repl
  977. * The text to replace
  978. * @param with
  979. * The new text bit
  980. * @return The resulting string with the text pieces replaced.
  981. */
  982. public static final String replace( String string, String repl, String with ) {
  983. StringBuffer str = new StringBuffer( string );
  984. for ( int i = str.length() - 1; i >= 0; i-- ) {
  985. if ( str.substring( i ).startsWith( repl ) ) {
  986. str.delete( i, i + repl.length() );
  987. str.insert( i, with );
  988. }
  989. }
  990. return str.toString();
  991. }
  992. /**
  993. * Alternate faster version of string replace using a stringbuffer as input.
  994. *
  995. * @param str
  996. * The string where we want to replace in
  997. * @param code
  998. * The code to search for
  999. * @param repl
  1000. * The replacement string for code
  1001. */
  1002. public static void repl( StringBuffer str, String code, String repl ) {
  1003. int clength = code.length();
  1004. int i = str.length() - clength;
  1005. while ( i >= 0 ) {
  1006. String look = str.substring( i, i + clength );
  1007. // Look for a match!
  1008. if ( look.equalsIgnoreCase( code ) ) {
  1009. str.replace( i, i + clength, repl );
  1010. }
  1011. i--;
  1012. }
  1013. }
  1014. /**
  1015. * Count the number of spaces to the left of a text. (leading)
  1016. *
  1017. * @param field
  1018. * The text to examine
  1019. * @return The number of leading spaces found.
  1020. */
  1021. public static final int nrSpacesBefore( String field ) {
  1022. int nr = 0;
  1023. int len = field.length();
  1024. while ( nr < len && field.charAt( nr ) == ' ' ) {
  1025. nr++;
  1026. }
  1027. return nr;
  1028. }
  1029. /**
  1030. * Count the number of spaces to the right of a text. (trailing)
  1031. *
  1032. * @param field
  1033. * The text to examine
  1034. * @return The number of trailing spaces found.
  1035. */
  1036. public static final int nrSpacesAfter( String field ) {
  1037. int nr = 0;
  1038. int len = field.length();
  1039. while ( nr < len && field.charAt( field.length() - 1 - nr ) == ' ' ) {
  1040. nr++;
  1041. }
  1042. return nr;
  1043. }
  1044. /**
  1045. * Checks whether or not a String consists only of spaces.
  1046. *
  1047. * @param str
  1048. * The string to check
  1049. * @return true if the string has nothing but spaces.
  1050. */
  1051. public static final boolean onlySpaces( String str ) {
  1052. for ( int i = 0; i < str.length(); i++ ) {
  1053. if ( !isSpace( str.charAt( i ) ) ) {
  1054. return false;
  1055. }
  1056. }
  1057. return true;
  1058. }
  1059. /**
  1060. * determine the OS name
  1061. *
  1062. * @return The name of the OS
  1063. */
  1064. public static final String getOS() {
  1065. return System.getProperty( "os.name" );
  1066. }
  1067. /**
  1068. * Determine the quoting character depending on the OS. Often used for shell calls, gives back " for Windows systems
  1069. * otherwise '
  1070. *
  1071. * @return quoting character
  1072. */
  1073. public static String getQuoteCharByOS() {
  1074. if ( isWindows() ) {
  1075. return "\"";
  1076. } else {
  1077. return "'";
  1078. }
  1079. }
  1080. /**
  1081. * Quote a string depending on the OS. Often used for shell calls.
  1082. *
  1083. * @return quoted string
  1084. */
  1085. public static String optionallyQuoteStringByOS( String string ) {
  1086. String quote = getQuoteCharByOS();
  1087. if ( isEmpty( string ) ) {
  1088. return quote;
  1089. }
  1090. // If the field already contains quotes, we don't touch it anymore, just
  1091. // return the same string...
  1092. // also return it if no spaces are found
  1093. if ( string.indexOf( quote ) >= 0 || ( string.indexOf( ' ' ) < 0 && string.indexOf( '=' ) < 0 ) ) {
  1094. return string;
  1095. } else {
  1096. return quote + string + quote;
  1097. }
  1098. }
  1099. /**
  1100. * @return True if the OS is a Windows derivate.
  1101. */
  1102. public static final boolean isWindows() {
  1103. return getOS().startsWith( "Windows" );
  1104. }
  1105. /**
  1106. * @return True if the OS is a Linux derivate.
  1107. */
  1108. public static final boolean isLinux() {
  1109. return getOS().startsWith( "Linux" );
  1110. }
  1111. /**
  1112. * @return True if the OS is an OSX derivate.
  1113. */
  1114. public static final boolean isOSX() {
  1115. return getOS().toUpperCase().contains( "OS X" );
  1116. }
  1117. /**
  1118. * Determine the hostname of the machine Kettle is running on
  1119. *
  1120. * @return The hostname
  1121. */
  1122. public static final String getHostname() {
  1123. String lastHostname = "localhost";
  1124. try {
  1125. Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
  1126. while ( en.hasMoreElements() ) {
  1127. NetworkInterface nwi = en.nextElement();
  1128. Enumeration<InetAddress> ip = nwi.getInetAddresses();
  1129. while ( ip.hasMoreElements() ) {
  1130. InetAddress in = ip.nextElement();
  1131. lastHostname = in.getHostName();
  1132. // System.out.println(" ip address bound : "+in.getHostAddress());
  1133. // System.out.println(" hostname : "+in.getHostName());
  1134. // System.out.println(" Cann.hostname : "+in.getCanonicalHostName());
  1135. // System.out.println(" ip string : "+in.toString());
  1136. if ( !lastHostname.equalsIgnoreCase( "localhost" ) && !( lastHostname.indexOf( ':' ) >= 0 ) ) {
  1137. return lastHostname;
  1138. }
  1139. }
  1140. }
  1141. } catch ( SocketException e ) {
  1142. return lastHostname;
  1143. }
  1144. return lastHostname;
  1145. }
  1146. /**
  1147. * Determine the hostname of the machine Kettle is running on
  1148. *
  1149. * @return The hostname
  1150. */
  1151. public static final String getHostnameReal() {
  1152. if ( isWindows() ) {
  1153. // Windows will always set the 'COMPUTERNAME' variable
  1154. return System.getenv( "COMPUTERNAME" );
  1155. } else {
  1156. // If it is not Windows then it is most likely a Unix-like operating system
  1157. // such as Solaris, AIX, HP-UX, Linux or MacOS.
  1158. // Most modern shells (such as Bash or derivatives) sets the
  1159. // HOSTNAME variable so lets try that first.
  1160. String hostname = System.getenv( "HOSTNAME" );
  1161. if ( hostname != null ) {
  1162. return hostname;
  1163. } else {
  1164. BufferedReader br;
  1165. try {
  1166. Process pr = Runtime.getRuntime().exec( "hostname" );
  1167. br = new BufferedReader( new InputStreamReader( pr.getInputStream() ) );
  1168. String line;
  1169. if ( ( line = br.readLine() ) != null ) {
  1170. return line;
  1171. }
  1172. pr.waitFor();
  1173. br.close();
  1174. } catch ( IOException e ) {
  1175. return getHostname();
  1176. } catch ( InterruptedException e ) {
  1177. return getHostname();
  1178. }
  1179. }
  1180. }
  1181. return getHostname();
  1182. }
  1183. /**
  1184. * Determins the IP address of the machine Kettle is running on.
  1185. *
  1186. * @return The IP address
  1187. */
  1188. public static final String getIPAddress() throws Exception {
  1189. Enumeration<NetworkInterface> enumInterfaces = NetworkInterface.getNetworkInterfaces();
  1190. while ( enumInterfaces.hasMoreElements() ) {
  1191. NetworkInterface nwi = enumInterfaces.nextElement();
  1192. Enumeration<InetAddress> ip = nwi.getInetAddresses();
  1193. while ( ip.hasMoreElements() ) {
  1194. InetAddress in = ip.nextElement();
  1195. if ( !in.isLoopbackAddress() && in.toString().indexOf( ":" ) < 0 ) {
  1196. return in.getHostAddress();
  1197. }
  1198. }
  1199. }
  1200. return "127.0.0.1";
  1201. }
  1202. /**
  1203. * Get the primary IP address tied to a network interface (excluding loop-back etc)
  1204. *
  1205. * @param networkInterfaceName
  1206. * the name of the network interface to interrogate
  1207. * @return null if the network interface or address wasn't found.
  1208. *
  1209. * @throws SocketException
  1210. * in case of a security or network error
  1211. */
  1212. public static final String getIPAddress( String networkInterfaceName ) throws SocketException {
  1213. NetworkInterface networkInterface = NetworkInterface.getByName( networkInterfaceName );
  1214. Enumeration<InetAddress> ipAddresses = networkInterface.getInetAddresses();
  1215. while ( ipAddresses.hasMoreElements() ) {
  1216. InetAddress inetAddress = ipAddresses.nextElement();
  1217. if ( !inetAddress.isLoopbackAddress() && inetAddress.toString().indexOf( ":" ) < 0 ) {
  1218. String hostname = inetAddress.getHostAddress();
  1219. return hostname;
  1220. }
  1221. }
  1222. return null;
  1223. }
  1224. /**
  1225. * Tries to determine the MAC address of the machine Kettle is running on.
  1226. *
  1227. * @return The MAC address.
  1228. */
  1229. public static final String getMACAddress() throws Exception {
  1230. String ip = getIPAddress();
  1231. String mac = "none";
  1232. String os = getOS();
  1233. String s = "";
  1234. @SuppressWarnings( "unused" )
  1235. Boolean errorOccured = false;
  1236. // System.out.println("os = "+os+", ip="+ip);
  1237. if ( os.equalsIgnoreCase( "Windows NT" )
  1238. || os.equalsIgnoreCase( "Windows 2000" ) || os.equalsIgnoreCase( "Windows XP" )
  1239. || os.equalsIgnoreCase( "Windows 95" ) || os.equalsIgnoreCase( "Windows 98" )
  1240. || os.equalsIgnoreCase( "Windows Me" ) || os.startsWith( "Windows" ) ) {
  1241. try {
  1242. // System.out.println("EXEC> nbtstat -a "+ip);
  1243. Process p = Runtime.getRuntime().exec( "nbtstat -a " + ip );
  1244. // read the standard output of the command
  1245. BufferedReader stdInput = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
  1246. while ( !procDone( p ) ) {
  1247. while ( ( s = stdInput.readLine() ) != null ) {
  1248. // System.out.println("NBTSTAT> "+s);
  1249. if ( s.indexOf( "MAC" ) >= 0 ) {
  1250. int idx = s.indexOf( '=' );
  1251. mac = s.substring( idx + 2 );
  1252. }
  1253. }
  1254. }
  1255. stdInput.close();
  1256. } catch ( Exception e ) {
  1257. errorOccured = true;
  1258. }
  1259. } else if ( os.equalsIgnoreCase( "Linux" ) ) {
  1260. try {
  1261. Process p = Runtime.getRuntime().exec( "/sbin/ifconfig -a" );
  1262. // read the standard output of the command
  1263. BufferedReader stdInput = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
  1264. while ( !procDone( p ) ) {
  1265. while ( ( s = stdInput.readLine() ) != null ) {
  1266. int idx = s.indexOf( "HWaddr" );
  1267. if ( idx >= 0 ) {
  1268. mac = s.substring( idx + 7 );
  1269. }
  1270. }
  1271. }
  1272. stdInput.close();
  1273. } catch ( Exception e ) {
  1274. errorOccured = true;
  1275. }
  1276. } else if ( os.equalsIgnoreCase( "Solaris" ) ) {
  1277. try {
  1278. Process p = Runtime.getRuntime().exec( "/usr/sbin/ifconfig -a" );
  1279. // read the standard output of the command
  1280. BufferedReader stdInput = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
  1281. while ( !procDone( p ) ) {
  1282. while ( ( s = stdInput

Large files files are truncated, but you can click here to view the full file