⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 licensekey.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// $Id: LicenseKey.java,v 1.3 2002/06/06 12:41:10 pvollenweider Exp $////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//package org.jahia.security.license;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.DataInputStream;import java.io.IOException;import java.io.File;import java.io.EOFException;import java.io.ByteArrayInputStream;import java.util.zip.CRC32;import java.util.Enumeration;import java.net.InetAddress;import java.net.UnknownHostException;import org.jahia.security.license.InvalidLicenseFileException;import org.jahia.security.license.LicenseException;import org.jahia.security.license.MaxUserLimitException;import org.jahia.security.license.MaxPageLimitException;import org.jahia.security.license.MaxSiteLimitException;import org.jahia.security.license.MaxPageTemplateLimitException;import org.jahia.services.sites.*;import org.jahia.registries.ServicesRegistry;import org.jahia.exceptions.JahiaException;import org.jahia.utils.JahiaConsole;/** * This exception is thrown when the license file is not valid. * * @author  Fulco Houkes * @version 1.0 */public final class LicenseKey implements Cloneable{    private static final String CLASS_NAME = "LicenseKey";    /** the license type. */    private int mLicenseType;    /** maximum number of pages that can be created. */    private int mPageLimit;    /** maximum number of page templates that can be created. */    private int mPageTemplateLimit;    /** maximum number of users that can be created. */    private int mUserLimit;    /** maximum number of sites that can be created. */    private int mSiteLimit;    /** the license id **/    private String mLicenseID;    /** buid number */    private int mBuildNumber;    /** release number */    private double mReleaseNumber;    //-------------------------------------------------------------------------    /**     * for cloning purpose     * @author NK     */    private LicenseKey( int licenseType,                        int pageLimit,                        int pageTemplateLimit,                        int userLimit,                        int siteLimit,                        String licenseID,                        int buildNumber,                        double releaseNumber ){        mLicenseType 	= licenseType;        mPageLimit 		= pageLimit;        mPageTemplateLimit =  pageTemplateLimit;        mUserLimit 		= userLimit;        mSiteLimit 		= siteLimit;        mLicenseID 		= licenseID;        mBuildNumber 	= buildNumber;        mReleaseNumber 	= releaseNumber;    };    //-------------------------------------------------------------------------    // FH   1 May 2001    //          Initial implementation    // FH   2 May 2001    //          Added the release number info    /**     * Construct a license information object by extracting the license     * information out of the specified license file.     *     * @exception   InvalidLicenseException     *      Throws this exception when the specified license file is     *      not valid.     */    public LicenseKey (String filename)        throws  LicenseException    {        try {            // open the license file            File file = new File (filename);            // create the input streams            FileInputStream fstream = new FileInputStream (file);            DataInputStream stream = new DataInputStream (fstream);            // create the raw byte stream from the file size by removing the            // checksum bytes and it's offset.            int streamSize = (new Long(file.length() - 10)).intValue();            byte[] bytes = new byte[streamSize];            int index = 0;            // get the crc offset            short crcOffset = stream.readShort ();            // read the <crcOffset> bytes before the crc info            for (int i=0; i<crcOffset; i++) {                bytes[index] = stream.readByte();                index++;            }            // read the stored CRC number            long storedChecksum = stream.readLong ();            // read the remaining bytes of the file.            try {                while (index < bytes.length) {                    bytes[index] = stream.readByte();                    index++;                }            }            catch (EOFException ex) {                throw new InvalidLicenseFileException ();            }            // Close the file            fstream.close ();            // free memory of unused objects            stream = null;            fstream = null;            file = null;            // compute the stream CRC            CRC32 crc = new CRC32();            crc.update (bytes);            long streamChecksum = crc.getValue ();            // check if the stored CRC number is the same as the stream one.            if (streamChecksum != storedChecksum) {                throw new InvalidLicenseFileException ();            }            //Read the license info            ByteArrayInputStream byteStream = new ByteArrayInputStream (bytes);            stream = new DataInputStream (byteStream);            try {                mLicenseType		= readInteger (stream);            } catch ( Throwable t ){                throw new InvalidLicenseException ("Invalid license type");            }            try{                mPageLimit          = readInteger (stream);            } catch ( Throwable t1 ){                throw new InvalidLicenseException ("Invalid page limit");            }            try {                mPageTemplateLimit  = readInteger (stream);            } catch ( Throwable t2 ){                throw new InvalidLicenseException ("Invalid template page limit");            }            try {                mUserLimit          = readInteger (stream);            } catch ( Throwable t3 ){                throw new InvalidLicenseException ("Invalid user limit");            }            try {                mSiteLimit          = readInteger (stream);            } catch ( Throwable t4 ){                throw new InvalidLicenseException ("Invalid site limit");            }            try {                mLicenseID			= readString (stream);            } catch ( Throwable t5 ){                throw new InvalidLicenseException ("Invalid license ID");            }            try {                mBuildNumber        = readInteger (stream);            } catch ( Throwable t6 ){                throw new InvalidLicenseException ("Invalid build number");            }            try {                mReleaseNumber      = readDouble (stream);            } catch ( Throwable t7 ){                throw new InvalidLicenseException ("Invalid release Number");            }        }        catch (Throwable t) {            throw new InvalidLicenseFileException (t.getMessage());        }    }    //-------------------------------------------------------------------------    // NK   11 June 2001    /**     * Return the license type.     *     * @return     *      return the license type.     */    public int getLicenseType () {        return mLicenseType;    }    //-------------------------------------------------------------------------    // FH   1 May 2001    //          Initial implementation    /**     * Return the maximum allowed pages in the system.     *     * @return     *      return the maximum number of pages.     */    public int getPageLimit () {        return mPageLimit;    }    //-------------------------------------------------------------------------    // FH   1 May 2001    //          Initial implementation    /**     * Return the maximum allowed page templates in the system.     *     * @return     *      return the maximum number of page templates.     */    public int getPageTemplateLimit () {        return mPageTemplateLimit;    }    //-------------------------------------------------------------------------    // FH   1 May 2001    //          Initial implementation    /**     * Return the maximum allowed users in the system.     *     * @return     *      return the maximum number of users.     */    public int getUserLimit () {        return mUserLimit;    }    //-------------------------------------------------------------------------    // FH   1 May 2001    //          Initial implementation    /**     * Return the maximum allowed sites in the system.     *     * @return     *      return the maximum number of sites.     */    public int getSiteLimit () {        return mSiteLimit;    }    //-------------------------------------------------------------------------    // NK   14 June 2001    /**     * Return the license id     *     * @return     *      return the license id     */    public String getLicenseID () {        return mLicenseID;    }    //-------------------------------------------------------------------------    // FH   1 May 2001    //          Initial implementation    /**     * Return the allowed build number.     *     * @return     *      return the allowed build number.     */    public int getBuildNumber () {        return mBuildNumber;    }    //-------------------------------------------------------------------------    // FH   2 May 2001    //          Initial implementation    /**     * Return the allowed release number.     *     * @return     *      return the allowed release number.     */    public double getReleaseNumber () {        return mReleaseNumber;    }    //-------------------------------------------------------------------------    /**     * Return true if the current Jahia License Type match the one to check     *     * @param 	int the license type     * @param   int the license type relational comparator 1(<),2(<=),3(=),4(>=),5(>)     * @see LicenseConstants     * @return boolean true if license type comparison match     * @author  NK     */    public boolean compareLicense(int licenseType, int relComp) {        if ( (licenseType == -1) || relComp == -1 ){            return true;        }        if ( relComp == LicenseConstants.RELCOMP_EQUAL ){            return ( getLicenseType() == licenseType );        }        if ( relComp == LicenseConstants.RELCOMP_SMALLER ){            return ( getLicenseType() < licenseType );        }        if ( relComp == LicenseConstants.RELCOMP_SMALLER_OR_EQUAL ){            return ( getLicenseType() <= licenseType );        }        if ( relComp == LicenseConstants.RELCOMP_BIGGER_OR_EQUAL ){            return ( getLicenseType() >= licenseType );        }        if ( relComp == LicenseConstants.RELCOMP_BIGGER ){            return ( getLicenseType() > licenseType );        }        return false;    }    //-------------------------------------------------------------------------    // FH   1 May 2001    //          Initial implementation    /**     * Check if the number of users in the database is not exceeding the limit     * specified by the license.     *     * @exception   MaxUserLimitException     *      Throws this exception when the number of users in the database is     *      exceeding the number of users fixed by the license.     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -