/** ** Main entery point for debugging/testing */ public static void main(String argv[]) { RTConfig.setCommandLineArgs(argv); Print.setAllOutputToStdout(true); Print.setEncoding(ENCODING_UTF8); String accountID = RTConfig.getString(ARG_ACCOUNT, "demo"); GoogleGeocodeV2 gn = new GoogleGeocodeV2("google", null, null); /* reverse geocode */ if (RTConfig.hasProperty(ARG_REVGEOCODE)) { GeoPoint gp = new GeoPoint(RTConfig.getString(ARG_REVGEOCODE, null)); if (!gp.isValid()) { Print.logInfo("Invalid GeoPoint specified"); System.exit(1); } Print.logInfo("Reverse-Geocoding GeoPoint: " + gp); Print.sysPrintln( "RevGeocode = " + gn.getReverseGeocode(gp, null /*localeStr*/, false /*cache*/)); // Note: Even though the values are printed in UTF-8 character encoding, the // characters may not appear to be property displayed if the console display // does not support UTF-8. System.exit(0); } /* no options */ Print.sysPrintln("No options specified"); System.exit(1); }
public static void main(String argv[]) { RTConfig.setCommandLineArgs(argv); InitJ1587DescriptionProvider(); RTProperties cmdLineProps = RTConfig.getCommandLineProperties(); long fault = EncodeFault(cmdLineProps); Print.sysPrintln("Fault : " + fault + " [0x" + StringTools.toHexString(fault) + "]"); Print.sysPrintln("String: " + GetPropertyString(fault)); Print.sysPrintln("Desc : " + GetFaultDescription(fault, null)); }
/** ** Apply replacements/conditionals and write output */ public static void writeOutputSource(String inputSource, File outputFile) throws IOException { String outputSource = inputSource; if (StringTools.isBlank(outputSource)) { // throw new IOException("Output Source is empty"); return; } /* custom map */ Map<String, String> customMap = new HashMap<String, String>() { @Override public String get(Object key) { String ks = StringTools.trim(key); if (ks.toLowerCase().endsWith(".md5")) { String K = ks.substring(0, ks.length() - ".md5".length()); String V = RTConfig._getString(K, null, true /*dftOK*/); if (V != null) { return StringTools.trim(FileTools.getHash_MD5(V.getBytes())).toUpperCase(); } else { return null; } } else { return null; } } }; /* replace standard runtime vars in text (ie. %{var=value}) */ // -- replace %{var=value} outputSource = RTConfig.insertKeyValues(outputSource, STR_DELIM, END_DELIM, DFT_DELIM, customMap); // -- replace /#{var=value}#/ outputSource = RTConfig.insertKeyValues(outputSource, STR_CDELIM, END_CDELIM, DFT_CDELIM, customMap); /* conditional code? */ outputSource = CompiletimeVars.getConditionalSource(outputSource); /* write output */ if (outputFile != null) { Print.sysPrintln("Output to file: " + outputFile); boolean didWrite = FileTools.writeFile(outputSource.getBytes(), outputFile); if (!didWrite) { throw new IOException("Unable to write output file."); } } else { // -- write to stdout Print.sysPrintln(outputSource); } }
/** ** Main entry point for testing/debugging ** @param argv Comand-line arguments */ public static void main(String argv[]) { RTConfig.setCommandLineArgs(argv); /* decode URI argument strings */ if (RTConfig.hasProperty(ARG_DECODE)) { String a = RTConfig.getString(ARG_DECODE, ""); String s = URIArg.decodeArg(new StringBuffer(), a).toString(); Print.sysPrintln("ASCII: " + s); System.exit(0); } /* encode Base64 strings */ if (RTConfig.hasProperty(ARG_ENCODE)) { String s = RTConfig.getString(ARG_ENCODE, ""); String a = URIArg.encodeArg(new StringBuffer(), s).toString(); Print.sysPrintln("Args: " + a); System.exit(0); } /* RTP decode */ if (RTConfig.hasProperty(ARG_RTPDEC)) { URIArg rtpUrl = new URIArg(RTConfig.getString(ARG_RTPDEC, "")); URIArg decUrl = rtpUrl.rtpDecode("rtp"); Print.sysPrintln("URL: " + decUrl.toString()); System.exit(0); } /* RTP encode */ if (RTConfig.hasProperty(ARG_RTPENC)) { URIArg decUrl = new URIArg(RTConfig.getString(ARG_RTPENC, "")); URIArg rtpUrl = decUrl.rtpEncode("rtp"); Print.sysPrintln("URL: " + rtpUrl.toString()); System.exit(0); } /* no options */ usage(); }
public static void main(String argv[]) { RTConfig.setCommandLineArgs(argv); long ts = DateTime.getCurrentTimeSec(); double C = -5.6; TemperatureSet TSList[] = new TemperatureSet[3]; for (int s = 0; s < TSList.length; s++) { TemperatureSet TS = new TemperatureSet(); for (int i = 0; i < 10; i++) { long tempTS = ts + (12345L * (i + 1) * (s + 1)); double tempC = C + (2.3 * i) + (1.1 * s); Print.logInfo(s + ":" + i + "] Adding " + tempTS + ", " + tempC); TS.addTemperature(tempTS, tempC); } TSList[s] = TS; } String t = TemperatureSet.CreateGoogleDataTableJavaScript(false, TSList); Print.sysPrintln(t); }
/** ** Debug/Testing entry point ** @param argv The command-line args */ public static void main(String argv[]) { RTConfig.setCommandLineArgs(argv); if (RTConfig.hasProperty(ARG_PACKAGE)) { String pkg = RTConfig.getString(ARG_PACKAGE, "org.opengts.util"); String loc = RTConfig.getString(ARG_LOCALE, "en"); String key = RTConfig.getString(ARG_KEY, ""); Locale locale = I18N.getLocale(loc); Print.sysPrintln("Package: " + pkg); Print.sysPrintln("Locale : " + locale + " [" + loc + "]"); Print.sysPrintln("Key : " + key); I18N i18n = I18N.getI18N(pkg, locale); if (i18n != null) { Print.sysPrintln("String : " + i18n.getString(key, "Undefined")); } else { Print.sysPrintln("Package resource not found"); } System.exit(0); } if (RTConfig.hasProperty("test")) { I18N i18n = getI18N(I18N.class, null); i18n.printKeyValues(); String m3 = i18n.getString( "m.m3", "{0}", new Object() { public String toString() { return mainStr; } }); String m2 = i18n.getString("m.m2", "How Now Brown {0}", m3); String m1 = i18n.getString("m.m1", "Message: \\n{0}", m2); Print.sysPrintln(m1); mainStr = "Horse"; Print.sysPrintln(m1); } }
/** ** Main entry point for testing/debugging ** @param argv Comand-line arguments */ public static void main(String argv[]) { RTConfig.setCommandLineArgs(argv); /* help */ if (RTConfig.hasProperty(ARG_HELP)) { _usage(); System.exit(1); // control does not reach here } /* extra args */ String extraArgs = RTConfig.getString(ARG_EXTRA, ""); if (!StringTools.isBlank(extraArgs)) { // Print.logInfo("Extra: " + extraArgs); RTProperties cfgProps = RTConfig.getConfigFileProperties(); if (extraArgs.indexOf(",") > 0) { cfgProps.setProperties(extraArgs, ','); } else { cfgProps.setProperties(extraArgs); } // cfgProps.printProperties(""); } /* special case "expire" */ String ARG_EXPIRE = "expire"; RTProperties expireRTP = RTConfig.getPropertiesForKey(ARG_EXPIRE, false); if (expireRTP != null) { Print.errPrintln("\n'expire' cannot be defined."); System.exit(1); } /* args */ File directory = RTConfig.getFile(ARG_DIR, null); String templateName = StringTools.trim(RTConfig.getString(ARG_OPTIONAL, RTConfig.getString(ARG_TEMPLATE, ""))); boolean isOptional = RTConfig.hasProperty(ARG_OPTIONAL); String packageName = StringTools.trim(RTConfig.getString(ARG_PACKAGE, null)); String outputName = RTConfig.getString(ARG_OUTPUT, ""); boolean overwrite = RTConfig.getBoolean(ARG_OVERWRITE, false); /* cannot specify "-output=inline" if internal template specified */ if (StringTools.isBlank(outputName) || outputName.equalsIgnoreCase("stdout")) { // -- output will be to "stdout" outputName = ""; } else if (outputName.equalsIgnoreCase("inline")) { // -- output will be to input file if (templateName.startsWith(TEMPLATE_)) { // -- @template not allowed with "inline" Print.errPrintln("\nError: Cannot specify '-output=inline' with internal template"); _usage(); System.exit(1); // control does not reach here } else if (isOptional) { // -- optional not allowed with "inline" Print.errPrintln("\nError: Cannot specify '-output=inline' with optional template"); _usage(); System.exit(1); // control does not reach here } else if (!templateName.startsWith("*")) { // -- output to input file outputName = templateName; } } else { // -- output to specified file if (templateName.startsWith("*")) { // -- template specifies a file-glob Print.errPrintln( "\nError: Cannot specify '-output=FILE' for recursize template specification"); _usage(); System.exit(1); // control does not reach here } } /* template name file? */ if (templateName.startsWith("*")) { if (isOptional) { // -- optional not allowed with glob file specification Print.errPrintln("\nError: Cannot specify optional '-template?=[**/]*.java'"); _usage(); System.exit(1); // control does not reach here } } else { File file = (directory != null) ? new File(directory, templateName) : new File(templateName); if (!file.isFile() && isOptional) { // -- templateName doesn't exist and is optional templateName = TEMPLATE_DEFAULT; } } /* random */ Random rand = new Random(); if (!RTConfig.hasProperty("random.16")) { RTConfig.setString("random.16", "0x" + StringTools.toHexString(rand.nextInt() & 0xFFFF, 16)); } if (!RTConfig.hasProperty("random.32")) { RTConfig.setString("random.32", "0x" + StringTools.toHexString(rand.nextInt(), 32)); } if (!RTConfig.hasProperty("random.64")) { RTConfig.setString("random.64", "0x" + StringTools.toHexString(rand.nextLong(), 64)); } /* set current time (subject to change) */ String tzStr = RTConfig.getString("timezone", null); TimeZone tz = !StringTools.isBlank(tzStr) ? DateTime.getTimeZone(tzStr) : DateTime.getDefaultTimeZone(); DateTime now = new DateTime(tz); if (!RTConfig.hasProperty("timetamp")) { RTConfig.setLong("timestamp", now.getTimeSec()); } if (!RTConfig.hasProperty("datetime")) { RTConfig.setString("datetime", now.format("yyyy/MM/dd HH:mm:ss z")); } if (!RTConfig.hasProperty("date")) { RTConfig.setString("date", now.format("yyyy/MM/dd")); } if (!RTConfig.hasProperty("time")) { RTConfig.setString("time", now.format("HH:mm:ss")); } if (!RTConfig.hasProperty("timezone")) { RTConfig.setString("timezone", now.format("z")); } /* special case "daysUntil" */ // %{daysUntil=2012:02:20} <== fixed time String ARG_daysUntil_ = "daysUntil"; Set<String> daysUntil_keys = RTConfig.getPropertyKeys(ARG_daysUntil_, false); for (String daysUntil_key : daysUntil_keys) { String daysUntil_key_date = daysUntil_key + ".date"; RTProperties daysUntilRTP = RTConfig.getPropertiesForKey(daysUntil_key, false); if (daysUntilRTP != null) { // -- get/update the RTProperties where "daysUntil" is defined String daysUntil = daysUntilRTP.getString(daysUntil_key, ""); if (StringTools.isBlank(daysUntil)) { // -- remove keys daysUntilRTP.removeProperty(daysUntil_key); daysUntilRTP.removeProperty(daysUntil_key_date); // Print.sysPrintln(daysUntil_key + " ==> <removed>"); // Print.sysPrintln(daysUntil_key_date + " ==> <removed>"); } else if ((daysUntil.indexOf("/") >= 0) || (daysUntil.indexOf(":") >= 0)) { // -- Change "yyyy:mm:dd" to "DD" // Note: The ':' separator should be used instead of '/', because "2010/10/01" is // syntactically correct (ie. division) and can be compiled into a valid value, // while "2010:10:01" is not, and will be caught by the compiler. if (daysUntil.startsWith("'") || daysUntil.startsWith("\"")) { daysUntil = daysUntil.substring(1); // remove prefixing quote } if (daysUntil.endsWith("'") || daysUntil.endsWith("\"")) { daysUntil = daysUntil.substring(0, daysUntil.length() - 1); // remove trailing quote } try { DateTime nowDT = new DateTime(DateTime.getGMTTimeZone()); DateTime futDT = DateTime.parseArgumentDate(daysUntil, null, true); long nowDay = DateTime.getDayNumberFromDate(nowDT); long futDay = DateTime.getDayNumberFromDate(futDT); long deltaD = futDay - nowDay; if (deltaD == 0L) { // -- today deltaD = 1L; // make it tomorrow } else if (deltaD < 0L) { // -- this means that the date has already passed // deltaD = -1L; // already negative } else { deltaD += 1L; // add one more day } daysUntilRTP.setString(daysUntil_key, String.valueOf(deltaD)); daysUntilRTP.setString(daysUntil_key_date, futDT.format(DateTime.DEFAULT_DATE_FORMAT)); } catch (DateTime.DateParseException dpe) { Print.logException("Unable to parse Date: " + daysUntil, dpe); System.exit(1); } // Print.sysPrintln(daysUntil_key + " ==> " + daysUntilRTP.getString(daysUntil_key // ,"?")); // Print.sysPrintln(daysUntil_key_date + " ==> " + // daysUntilRTP.getString(daysUntil_key_date,"?")); } else { long futSec = DateTime.getCurrentTimeSec() + DateTime.DaySeconds(StringTools.parseLong(daysUntil, 0L)); daysUntilRTP.setString( daysUntil_key_date, (new DateTime(futSec)).format(DateTime.DEFAULT_DATE_FORMAT)); // Print.sysPrintln(daysUntil_key + " ==> " + daysUntilRTP.getString(daysUntil_key // ,"?")); // Print.sysPrintln(daysUntil_key_date + " ==> " + // daysUntilRTP.getString(daysUntil_key_date,"?")); } } } /* special case "daysFromNow" */ // %{daysFromNow=30} <== 30 days from now String ARG_daysFromNow_ = "daysFromNow"; Set<String> daysFromNow_keys = RTConfig.getPropertyKeys(ARG_daysFromNow_, false); for (String daysFromNow_key : daysFromNow_keys) { String daysFromNow_key_date = daysFromNow_key + ".date"; RTProperties daysFromNowRTP = RTConfig.getPropertiesForKey(daysFromNow_key, false); if (daysFromNowRTP != null) { // -- get/update the RTProperties where "daysFromNow" is defined String daysFromNow = daysFromNowRTP.getString(daysFromNow_key, ""); if (StringTools.isBlank(daysFromNow)) { // -- remove keys daysFromNowRTP.removeProperty(daysFromNow_key); daysFromNowRTP.removeProperty(daysFromNow_key_date); // Print.sysPrintln(daysFromNow_key + " ==> <removed>"); // Print.sysPrintln(daysFromNow_key_date + " ==> <removed>"); } else { long futSec = DateTime.getCurrentTimeSec() + DateTime.DaySeconds(StringTools.parseLong(daysFromNow, 0L)); daysFromNowRTP.setString(daysFromNow_key, String.valueOf(futSec)); daysFromNowRTP.setString( daysFromNow_key_date, (new DateTime(futSec)).format(DateTime.DEFAULT_DATE_FORMAT)); // Print.sysPrintln(daysFromNow_key + " ==> " + // daysFromNowRTP.getString(daysFromNow_key ,"?")); // Print.sysPrintln(daysFromNow_key_date + " ==> " + // daysFromNowRTP.getString(daysFromNow_key_date,"?")); } } } /* special case "secondsUntil" */ // %{secondsUntil_abc=2012:02:20} <== fixed time // %{secondsUntil_abc=86400} <== relative time (86400 seconds from now) String ARG_secondsUntil_ = "secondsUntil"; Set<String> secUntil_keys = RTConfig.getPropertyKeys(ARG_secondsUntil_, false); for (String secUntil_key : secUntil_keys) { String secUntil_key_date = secUntil_key + ".date"; RTProperties secUntilRTP = RTConfig.getPropertiesForKey(secUntil_key, false); if (secUntilRTP != null) { // -- get/update the RTProperties where "secondsUntil" is defined String secUntil = secUntilRTP.getString(secUntil_key, ""); if (StringTools.isBlank(secUntil)) { // remove keys secUntilRTP.removeProperty(secUntil_key); secUntilRTP.removeProperty(secUntil_key_date); // Print.sysPrintln(secUntil_key + " ==> <removed>"); // Print.sysPrintln(secUntil_key_date + " ==> <removed>"); } else if ((secUntil.indexOf("/") >= 0) || (secUntil.indexOf(":") >= 0)) { // -- Change "yyyy:mm:dd:HH:MM:SS" to "ssssss" // Note: The ':' separator should be used instead of '/', because "2010/10/01" is // syntactically correct (ie. division) and can be compiled into a valid value, // while "2010:10:01" is not, and will be caught by the compiler. if (secUntil.startsWith("'") || secUntil.startsWith("\"")) { secUntil = secUntil.substring(1); // remove prefixing quote } if (secUntil.endsWith("'") || secUntil.endsWith("\"")) { secUntil = secUntil.substring(0, secUntil.length() - 1); // remove trailing quote } try { long nowSec = DateTime.getCurrentTimeSec(); DateTime futDT = DateTime.parseArgumentDate(secUntil, null, true); long futSec = futDT.getTimeSec(); long deltaS = futSec - nowSec; if (deltaS == 0L) { // -- now deltaS = 1L; // make it 1 second from now } else if (deltaS < 0L) { // -- this means that the time has already passed // deltaS = -1L; // already negative } else { deltaS += 1L; // add one more second } secUntilRTP.setString(secUntil_key, String.valueOf(deltaS)); secUntilRTP.setString(secUntil_key_date, futDT.toString()); } catch (DateTime.DateParseException dpe) { Print.logException("Unable to parse Date: " + secUntil, dpe); System.exit(1); } // Print.sysPrintln(secUntil_key + " ==> " + secUntilRTP.getString(secUntil_key // ,"?")); // Print.sysPrintln(secUntil_key_date + " ==> " + // secUntilRTP.getString(secUntil_key_date,"?")); } else { long futSec = DateTime.getCurrentTimeSec() + StringTools.parseLong(secUntil, 0L); secUntilRTP.setString(secUntil_key_date, (new DateTime(futSec)).toString()); // Print.sysPrintln(secUntil_key + " ==> " + secUntilRTP.getString(secUntil_key // ,"?")); // Print.sysPrintln(secUntil_key_date + " ==> " + // secUntilRTP.getString(secUntil_key_date,"?")); } } } /* special case "secondsFromNow" */ // %{secondsFromNow=30} <== 30 seconds from now String ARG_secondsFromNow_ = "secondsFromNow"; Set<String> secondsFromNow_keys = RTConfig.getPropertyKeys(ARG_secondsFromNow_, false); for (String secondsFromNow_key : secondsFromNow_keys) { String secondsFromNow_key_date = secondsFromNow_key + ".date"; RTProperties secondsFromNowRTP = RTConfig.getPropertiesForKey(secondsFromNow_key, false); if (secondsFromNowRTP != null) { // -- get/update the RTProperties where "secondsFromNow" is defined String secondsFromNow = secondsFromNowRTP.getString(secondsFromNow_key, ""); if (StringTools.isBlank(secondsFromNow)) { // -- remove keys secondsFromNowRTP.removeProperty(secondsFromNow_key); secondsFromNowRTP.removeProperty(secondsFromNow_key_date); // Print.sysPrintln(secondsFromNow_key + " ==> <removed>"); // Print.sysPrintln(secondsFromNow_key_date + " ==> <removed>"); } else { long futSec = DateTime.getCurrentTimeSec() + StringTools.parseLong(secondsFromNow, 0L); secondsFromNowRTP.setString(secondsFromNow_key, String.valueOf(futSec)); secondsFromNowRTP.setString( secondsFromNow_key_date, (new DateTime(futSec)).format(DateTime.DEFAULT_DATE_FORMAT)); // Print.sysPrintln(secondsFromNow_key + " ==> " + // secondsFromNowRTP.getString(secondsFromNow_key ,"?")); // Print.sysPrintln(secondsFromNow_key_date + " ==> " + // secondsFromNowRTP.getString(secondsFromNow_key_date,"?")); } } } /* special case "limit" */ String ARG_limit_ = "limit"; Set<String> limit_keys = RTConfig.getPropertyKeys(ARG_limit_, false); for (String limit_key : limit_keys) { RTProperties limitRTP = RTConfig.getPropertiesForKey(limit_key, false); if (limitRTP != null) { String limit = limitRTP.getString(limit_key, ""); if (StringTools.isBlank(limit)) { limitRTP.removeProperty(limit_key); // Print.sysPrintln(limit_key + " ==> <removed>"); } else { // Print.sysPrintln(limit_key + " ==> " + limit); } } } /* adjust packageName */ if (packageName.equals(JAVA_PACKAGE)) { Print.errPrintln( "\nWarning: 'package' argument cannot equal \"package\" (setting to empty string)."); packageName = ""; } // -------------------------------------- /* internal template (single pass only) */ if (StringTools.isBlank(templateName) || templateName.startsWith(TEMPLATE_)) { try { // -- input source String inputSource = standardTemplate(templateName, packageName); if (StringTools.isBlank(inputSource)) { if (isOptional) { // -- optional "templateName" not defined, use default template inputSource = standardTemplate(null, packageName); // non-blank } else { throw new IOException("Standard template not found: " + templateName); } } // -- write template output File outputFile = CompiletimeVars.getOutputFile(directory, outputName, overwrite); CompiletimeVars.writeOutputSource(inputSource, outputFile); } catch (NoOverwriteException noe) { // -- outputFile exists, quietly ignore Print.sysPrintln(noe.getMessage()); System.exit(0); } catch (IOException ioe) { // -- error writin file Print.errPrintln("\nError writing template: " + ioe.getMessage()); System.exit(1); } System.exit(0); } // -------------------------------------- /* get input file(s) */ File inputFileArray[] = null; if (templateName.startsWith("**/*.")) { // -- all files, in all directories (recursive) String fileGlob = templateName.substring(3); File files[] = FileTools.getFiles(directory, fileGlob, true); inputFileArray = files; } else if (templateName.startsWith("*.")) { // -- all files in specified directory String fileGlob = templateName; File files[] = FileTools.getFiles(directory, fileGlob, false); inputFileArray = files; } else { // -- single specific file File file = (directory != null) ? new File(directory, templateName) : new File(templateName); inputFileArray = new File[] {file}; } /* loop through input files */ boolean singlePass = false; for (File inputFile : inputFileArray) { /* file must exist here */ if (!inputFile.isFile()) { // -- not a file continue; } /* get input source from template file */ String inputSource = CompiletimeVars.readTemplate(inputFile, packageName); if (StringTools.isBlank(inputSource)) { // -- inputSource not available? continue; } /* precheck output file */ File outputFile = null; try { if (StringTools.isBlank(outputName) || outputName.equalsIgnoreCase("stdout")) { // -- output to stdout (multi-pass ok) } else if (outputName.equalsIgnoreCase("inline")) { // -- write back to template file (multi-pass ok) overwrite = true; // assume implied overwrite outputFile = inputFile; } else { // -- output to specified file (single-pass only) outputFile = getOutputFile(directory, outputName, overwrite); singlePass = true; } } catch (NoOverwriteException noe) { // -- outputFile exists, quietly ignore Print.sysPrintln(noe.getMessage()); System.exit(0); } catch (IOException ioe) { Print.errPrintln("\nInvalid output file: " + ioe.getMessage()); System.exit(1); } /* adjust source and write output */ try { CompiletimeVars.writeOutputSource(inputSource, outputFile); if (singlePass) { break; } } catch (IOException ioe) { Print.errPrintln("\nError writing file: " + ioe.getMessage()); System.exit(1); } } /* success */ System.exit(0); }
/** ** Print usage and exit */ private static void _usage() { Print.sysPrintln(""); Print.sysPrintln("Usage:"); Print.sysPrintln(" java ... " + CompiletimeVars.class.getName() + " {options}"); Print.sysPrintln("Options:"); Print.sysPrintln(" -template=@default Create default 'CompileTime' template"); Print.sysPrintln(" -template=<file> Input Java 'template' file (must exist)"); Print.sysPrintln(" -template?=<file> Optional input Java 'template' file (may exist)"); Print.sysPrintln(" -package=<packageName> Optional package name"); Print.sysPrintln(" -output=<file> Output Java file"); Print.sysPrintln(" -overwrite=true Overwrite output file, if it exists"); Print.sysPrintln(""); System.exit(1); }
public static void main(String args[]) { DBConfig.cmdLineInit(args, true); // main String acctID = RTConfig.getString(ARG_ACCOUNT, ""); String roleID = RTConfig.getString(ARG_ROLE, ""); String aclID = RTConfig.getString(ARG_ACL, ""); /* account-id specified? */ if ((acctID == null) || acctID.equals("")) { Print.logError("Account-ID not specified."); usage(); } /* get account */ Account acct = null; try { acct = Account.getAccount(acctID); // may return DBException if (acct == null) { Print.logError("Account-ID does not exist: " + acctID); usage(); } } catch (DBException dbe) { Print.logException("Error loading Account: " + acctID, dbe); // dbe.printException(); System.exit(99); } /* role-id specified? */ if ((roleID == null) || roleID.equals("")) { Print.logError("Role-ID not specified."); usage(); } /* get role */ Role role = null; try { role = Role.getRole(acct, roleID); // may return DBException if (role == null) { Print.logError("Role-ID does not exist: " + acctID + "/" + roleID); usage(); } } catch (DBException dbe) { Print.logException("Error loading Role: " + acctID + "/" + roleID, dbe); // dbe.printException(); System.exit(99); } /* RoleAcl exists? */ boolean aclExists = false; if ((aclID != null) && !aclID.equals("")) { try { aclExists = RoleAcl.exists(acctID, roleID, aclID); } catch (DBException dbe) { Print.logError( "Error determining if RoleAcl exists: " + acctID + "/" + roleID + "/" + aclID); System.exit(99); } } /* option count */ int opts = 0; /* list */ if (RTConfig.getBoolean(ARG_LIST, false)) { opts++; try { String aclList[] = role.getAclsForRole(); for (int i = 0; i < aclList.length; i++) { AccessLevel level = RoleAcl.getAccessLevel(role, aclList[i], AccessLevel.NONE); Print.sysPrintln(" " + aclList[i] + " ==> " + level); } } catch (DBException dbe) { Print.logError("Error getting Acl list: " + dbe); System.exit(99); } System.exit(0); } /* delete */ if (RTConfig.getBoolean(ARG_DELETE, false) && !acctID.equals("") && !roleID.equals("")) { opts++; if (!aclExists) { Print.logWarn("RoleAcl does not exist: " + acctID + "/" + roleID + "/" + aclID); Print.logWarn("Continuing with delete process ..."); } try { RoleAcl.Key aclKey = new RoleAcl.Key(acctID, roleID, aclID); aclKey.delete(true); // also delete dependencies Print.logInfo("RoleAcl deleted: " + acctID + "/" + roleID + "/" + aclID); } catch (DBException dbe) { Print.logError("Error deleting RoleAcl: " + acctID + "/" + roleID + "/" + aclID); dbe.printException(); System.exit(99); } System.exit(0); } /* create */ if (RTConfig.getBoolean(ARG_CREATE, false)) { opts++; if (aclExists) { Print.logWarn("RoleAcl already exists: " + acctID + "/" + roleID + "/" + aclID); } else { try { RoleAcl.createNewRoleAcl(role, aclID); Print.logInfo("Created RoleAcl: " + acctID + "/" + roleID + "/" + aclID); aclExists = true; } catch (DBException dbe) { Print.logError("Error creating RoleAcl: " + acctID + "/" + roleID + "/" + aclID); dbe.printException(); System.exit(99); } } } /* set */ if (RTConfig.hasProperty(ARG_SET)) { opts++; AccessLevel aclLevel = EnumTools.getValueOf(AccessLevel.class, RTConfig.getInt(ARG_SET, -1)); try { RoleAcl.setAccessLevel(role, aclID, aclLevel); Print.logInfo( "Set RoleAcl '" + acctID + "/" + roleID + "/" + aclID + "' to level " + aclLevel); } catch (DBException dbe) { Print.logError("Error setting RoleAcl: " + acctID + "/" + roleID + "/" + aclID); dbe.printException(); System.exit(99); } System.exit(0); } /* edit */ if (RTConfig.getBoolean(ARG_EDIT, false)) { opts++; if (!aclExists) { Print.logError("RoleAcl does not exist: " + acctID + "/" + roleID + "/" + aclID); } else { try { RoleAcl roleAcl = RoleAcl.getRoleAcl(role, aclID, false); // may throw DBException DBEdit editor = new DBEdit(roleAcl); editor.edit(); // may throw IOException } catch (IOException ioe) { if (ioe instanceof EOFException) { Print.logError("End of input"); } else { Print.logError("IO Error"); } } catch (DBException dbe) { Print.logError("Error editing RoleAcl: " + acctID + "/" + roleID + "/" + aclID); dbe.printException(); } } System.exit(0); } /* no options specified */ if (opts == 0) { Print.logWarn("Missing options ..."); usage(); } }