📄 makelicense.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .//package org.jahia.tools;import java.io.FileOutputStream;import java.io.FileNotFoundException;import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import java.io.IOException;import java.util.Random;import java.util.zip.CRC32;/** * * @version 1.0 */public class MakeLicense{ private static final String LICENSE_TYPE_OPTION = "-licenseType"; private static final String PAGE_LIMIT_OPTION = "-pageLimit"; private static final String PAGE_TEMPLATE_LIMIT_OPTION = "-templateLimit"; private static final String USER_LIMIT_OPTION = "-userLimit"; private static final String SITE_LIMIT_OPTION = "-siteLimit"; private static final String LICENSE_ID_OPTION = "-licenseID"; private static final String BUILD_OPTION = "-build"; private static final String RELEASE_NUMBER_OPTION = "-release"; private static final String FILENAME_OPTION = "-filename"; private static final String HELP_OPTION = "-help"; private static final int LICENSE_TYPE_OPTION_DEFAULT = 1; // OPENJODA private static final int PAGE_LIMIT_OPTION_DEFAULT = 5; private static final int PAGE_TEMPLATE_LIMIT_OPTION_DEFAULT = 2; private static final int USER_LIMIT_OPTION_DEFAULT = 5; private static final int SITE_LIMIT_OPTION_DEFAULT = 1; private static final String LICENSE_ID_OPTION_DEFAULT = "undefined"; private static final int BUILD_OPTION_DEFAULT = 0; private static final double RELEASE_NUMBER_DEFAULT = 0.0; private static final String LICENSE_DEFAULT_FILENAME = "jahia.license"; private static final String CHAR_ENC = "UTF-16"; //------------------------------------------------------------------------- public static void main (String args[]) { System.out.println ("\nLicense key generator, version 1.0"); System.out.println ("(c) Jahia Ltd 2002\n\n"); // if no parameters are specified, display the tool usage. if ((args.length > 0) && (HELP_OPTION.equals (args[0]))) { DisplayHelp (); return; } // set the default values int licenseType = LICENSE_TYPE_OPTION_DEFAULT; int pageLimit = PAGE_LIMIT_OPTION_DEFAULT; int pageTemplateLimit = PAGE_TEMPLATE_LIMIT_OPTION_DEFAULT; int userLimit = USER_LIMIT_OPTION_DEFAULT; int siteLimit = SITE_LIMIT_OPTION_DEFAULT; String licenseID = LICENSE_ID_OPTION_DEFAULT; int buildNumber = BUILD_OPTION_DEFAULT; String fileName = LICENSE_DEFAULT_FILENAME; double releaseNumber = RELEASE_NUMBER_DEFAULT; // parse the parameters int index = 0; while (index <= args.length-1) { // GET THE LICENSE TYPE if (LICENSE_TYPE_OPTION.equals (args[index])) { index++; if (index <= args.length-1) { licenseType = parseInteger (LICENSE_TYPE_OPTION, args[index]); } else { System.out.println ("Error: option "+LICENSE_TYPE_OPTION+ " without value!"); return; } // GET THE PAGE LIMIT } else if (PAGE_LIMIT_OPTION.equals (args[index])) { index++; if (index <= args.length-1) { pageLimit = parseInteger (PAGE_LIMIT_OPTION, args[index]); } else { System.out.println ("Error: option "+PAGE_TEMPLATE_LIMIT_OPTION+ " without value!"); return; } // GET THE PAGE TEMPALATE LIMIT } else if (PAGE_TEMPLATE_LIMIT_OPTION.equals (args[index])) { index++; if (index <= args.length-1) { pageTemplateLimit = parseInteger (PAGE_TEMPLATE_LIMIT_OPTION, args[index]); } else { System.out.println ("Error: option "+PAGE_TEMPLATE_LIMIT_OPTION+ " without value!"); return; } // GET THE USER LIMIT } else if (USER_LIMIT_OPTION.equals (args[index])) { index++; if (index <= args.length-1) { userLimit = parseInteger (USER_LIMIT_OPTION, args[index]); } else { System.out.println ("Error: option "+ USER_LIMIT_OPTION + " without value!"); return; } // GET THE SITE LIMIT } else if (SITE_LIMIT_OPTION.equals (args[index])) { index++; if (index <= args.length-1) { siteLimit = parseInteger (SITE_LIMIT_OPTION, args[index]); } else { System.out.println ("Error: option "+ SITE_LIMIT_OPTION + " without value!"); return; } // GET THE LICENSE ID } else if (LICENSE_ID_OPTION.equals (args[index])) { index++; if (index <= args.length-1) { licenseID = args[index]; } else { System.out.println ("Error: option "+LICENSE_ID_OPTION+ " without value!"); return; } // GET THE BUILD NUMBER } else if (BUILD_OPTION.equals (args[index])) { index++; if (index <= args.length-1) { buildNumber = parseInteger (BUILD_OPTION, args[index]); } else { System.out.println ("Error: option "+ BUILD_OPTION + " without value!"); return; } // GET THE RELEASE NUMBER } else if (RELEASE_NUMBER_OPTION.equals (args[index])) { index++; if (index <= args.length-1) { releaseNumber = parseDouble (RELEASE_NUMBER_OPTION, args[index]); } else { System.out.println ("Error: option "+ RELEASE_NUMBER_OPTION + " without value!"); return; } // GET THE FILENAME } else if (FILENAME_OPTION.equals (args[index])) { index++; if (index <= args.length-1) { fileName = args[index]; } else { System.out.println ("Error: option "+ FILENAME_OPTION + " without value!"); return; } // ALL OTHER OPTION ARE ERRORS :o) } else { System.out.println ("Error: ["+args[index]+"] is not a valid option.\n"); return; } index++; } // while System.out.println ("License details :"); System.out.println (" license type = " + ((licenseType == -1) ? "all" : Integer.toString(licenseType))); System.out.println (" page limit = " + ((pageLimit == -1) ? "unlimited" : Integer.toString(pageLimit))); System.out.println (" page template limit = " + ((pageTemplateLimit == -1) ? "unlimited" : Integer.toString(pageTemplateLimit))); System.out.println (" user limit = " + ((userLimit == -1) ? "unlimited" : Integer.toString(userLimit))); System.out.println (" site limit = " + ((siteLimit == -1) ? "unlimited" : Integer.toString(siteLimit))); System.out.println (" license id = " + licenseID); System.out.println (" build number = " + ((buildNumber == -1) ? "-all build numbers-" : Integer.toString(buildNumber))); System.out.println (" release number = " + ((releaseNumber == -1.0) ? "-all releases-" : Double.toString(releaseNumber))); System.out.println (" file name = " + fileName); System.out.println (""); // create the random generator Random random = new Random(); byte[] bytes; // create the raw byte stream try { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream outputStream = new DataOutputStream (byteStream); // write the license type to the string addJunkBytes (outputStream, random); outputStream.writeInt (licenseType); // write the page limit to the string addJunkBytes (outputStream, random); outputStream.writeInt (pageLimit); // write the page template limit to the string addJunkBytes (outputStream, random);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -