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

📄 licensekey.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public void checkUserLimit ()        throws  MaxUserLimitException    {        // check if the number of users is unlimited.        if (mUserLimit == -1) {            return;        }        // Check if the number of users is not exceeding the fixed limit        try {            // get all the list of site            Enumeration enum = ServicesRegistry.getInstance()                                                .getJahiaSitesService()                                                .getSites();            JahiaSite aSite = null;            int nbItems = 0;            while( enum.hasMoreElements() ){                aSite = (JahiaSite)enum.nextElement();                nbItems = ServicesRegistry.getInstance().                                           getJahiaUserManagerService().                                           getNbUsers (aSite.getID());                //System.out.println ("LICENSE : current nb users = " + nbItems);                if (nbItems > mUserLimit) {                    throw new MaxUserLimitException ();                }            }        }        catch (JahiaException ex) {            throw new MaxUserLimitException ();        }    }    //-------------------------------------------------------------------------    // FH   1 May 2001    //          Initial implementation    /**     * Check if the number of pages in the database is not exceeding the limit     * specified by the license.     *     * @exception   MaxPageLimitException     *      Throws this exception when the number of pages in the database is     *      exceeding the number of pages fixed by the license.     */    public void checkPageLimit ()        throws  MaxPageLimitException    {        // check if the number of pages is unlimited.        if (mPageLimit == -1) {            return;        }        // Check if the number of pages is not exceeding the fixed limit        try {            // get all the list of site            Enumeration enum = ServicesRegistry.getInstance()                                                .getJahiaSitesService()                                                .getSites();            JahiaSite aSite = null;            int nbItems = 0;            while( enum.hasMoreElements() ){                aSite = (JahiaSite)enum.nextElement();                nbItems = ServicesRegistry.getInstance().                                           getJahiaPageService().                                           getRealNbPages (aSite.getID());                //System.out.println ("LICENSE : current nb pages = " + nbItems);                if (nbItems > mPageLimit) {                    throw new MaxPageLimitException ();                }            }        } catch (JahiaException ex) {            throw new MaxPageLimitException ();        }    }    //-------------------------------------------------------------------------    // FH   1 May 2001    //          Initial implementation    /**     * Check if the number of sites in the database is not exceeding the limit     * specified by the license.     *     * @exception   MaxSiteLimitException     *      Throws this exception when the number of sites in the database is     *      exceeding the number of sites fixed by the license.     */    public void checkSiteLimit ()        throws  MaxSiteLimitException    {        // check if the number of sites is unlimited.        if (mSiteLimit == -1) {            return;        }        // Check if the number of users is not exceeding the fixed limit        try {            int nbItems = ServicesRegistry.getInstance().                                           getJahiaSitesService().                                           getNbSites ();            //System.out.println ("LICENSE : current nb sites = " + nbItems);            if (nbItems > mSiteLimit) {                throw new MaxSiteLimitException ();            }        }        catch (JahiaException ex) {            throw new MaxSiteLimitException ();        }    }    //-------------------------------------------------------------------------    // NK   14 June 2001    /**     * Check if the license id is valid again the machine     *     * @exception   InvalidLicenseException     *      Throws this exception when the license can not be check successfully     */    public void checkLicenseID ()        throws  InvalidLicenseException,LicenseException    {        // if the license type is openjoda, doesn't check the license id        if (getLicenseType() == LicenseConstants.OPENJODA_LICENSE_TYPE) {            return;        }        if (LicenseConstants.LICENSEID_NULL.equals(getLicenseID())) {            // the check for the licenseID has been deactivated. Dangerous but            // useful especially to test Jahia...            return;        }        InetAddress inetA = null;        try {            inetA = InetAddress.getLocalHost();            if ( inetA == null ){                throw new LicenseException ("The inet address could not be found");            }        } catch ( UnknownHostException uhe ){            throw new LicenseException ("The inet address could not be found");        }        JahiaConsole.println(CLASS_NAME, " inet address hostname=" + inetA.getHostName() + ", hostAddress=" + inetA.getHostAddress());        if ( !getLicenseID().equals(inetA.getHostAddress()) ){            throw new InvalidLicenseException ("Invalid license ID <" + getLicenseID() + "> for host <" + inetA.getHostAddress() + ">");        }        return;    }    //-------------------------------------------------------------------------    // FH   1 May 2001    //          Initial implementation    /**     * Check if the number of page templates in the database is not exceeding     * the limit specified by the license.     *     * @param siteID     * @exception   MaxSiteLimitException     *      Throws this exception when the number of page templates in the     *      database is exceeding the number of sites fixed by the license.     */    public void checkPageTemplateLimit ()        throws  MaxPageTemplateLimitException    {        // check if the number of page templates is unlimited.        if (mPageTemplateLimit == -1) {            return;        }        // Check if the number of users is not exceeding the fixed limit        try {            // get all the list of site            Enumeration enum = ServicesRegistry.getInstance()                                                .getJahiaSitesService()                                                .getSites();            JahiaSite aSite = null;            int nbItems = 0;            while( enum.hasMoreElements() ){                aSite = (JahiaSite)enum.nextElement();                nbItems = ServicesRegistry.getInstance().                                           getJahiaPageTemplateService().                                           getNbPageTemplates (aSite.getID());                //System.out.println ("LICENSE : current nb of page templates = " + nbItems);                if (nbItems > mPageTemplateLimit) {                    throw new MaxPageTemplateLimitException ();                }            }        } catch (JahiaException ex) {            throw new MaxPageTemplateLimitException ();        }    }    //-------------------------------------------------------------------------    // FH   1 May 2001    //          Initial implementation    /**     * Return the string representation of the license information.     *     * @return     *      Return the string representation of the license information.     */    public String toString ()    {        StringBuffer buffer = new StringBuffer ();        buffer.append ("License details:\n");        buffer.append ("  - Build number        = ");        if (mBuildNumber == -1) {            buffer.append ("-all build numbers-");        } else {            buffer.append (mBuildNumber);        }        buffer.append ("\n");        buffer.append ("  - Release number      = ");        if (mReleaseNumber == -1.0) {            buffer.append ("-all release numbers-");        } else {            buffer.append (mReleaseNumber);        }        buffer.append ("\n");        buffer.append ("  - License Type        = ");        buffer.append (mLicenseType);        buffer.append ("\n");        buffer.append ("  - page limit          = ");        if (mPageLimit == -1) {            buffer.append ("unlimited");        } else {            buffer.append (mPageLimit);        }        buffer.append ("\n");        buffer.append ("  - page template limit = ");        if (mPageTemplateLimit == -1) {            buffer.append ("unlimited");        } else {            buffer.append (mPageTemplateLimit);        }        buffer.append ("\n");        buffer.append ("  - user limit          = ");        if (mUserLimit == -1) {            buffer.append ("unlimited");        } else {            buffer.append (mUserLimit);        }        buffer.append ("\n");        buffer.append ("  - site limit          = ");        if (mSiteLimit == -1) {            buffer.append ("unlimited");        } else {            buffer.append (mSiteLimit);        }        buffer.append ("\n");        return buffer.toString();    }    //--------------------------------------------------------------------------    private int readInteger (DataInputStream stream)        throws  InvalidLicenseFileException    {        try {            // Check the offset            int offset = stream.readInt ();            if (offset <= 0) {                throw new InvalidLicenseFileException();            }            // skip the amount of junk bytes            stream.skipBytes (offset);            // read the desired integer.            int item = stream.readInt();            if ((item < 0) && (item != -1)) {                throw new InvalidLicenseFileException();            }            return item;        }        catch (IOException ex) {            throw new InvalidLicenseFileException();        }    }    //--------------------------------------------------------------------------    private String readString (DataInputStream stream)        throws  InvalidLicenseFileException    {        try {            // Check the offset            int offset = stream.readInt ();            if (offset <= 0) {                throw new InvalidLicenseFileException();            }            // skip the amount of junk bytes            stream.skipBytes (offset);            // host name            int nbBytes = stream.readInt();            byte[] stringAsBytes = new byte[nbBytes];            stream.read(stringAsBytes);            String theString = new String(stringAsBytes,"UTF-16");            return theString;        }        catch (IOException ex) {            throw new InvalidLicenseFileException();        }    }    //--------------------------------------------------------------------------    private double readDouble (DataInputStream stream)        throws  InvalidLicenseFileException    {        try {            // Check the offset            int offset = stream.readInt ();            if (offset <= 0) {                throw new InvalidLicenseFileException();            }            // skip the amount of junk bytes            stream.skipBytes (offset);            // read the desired integer.            double item = stream.readDouble();            if ((item < 0.0) && (item != -1.0)) {                throw new InvalidLicenseFileException();            }            return item;        }        catch (IOException ex) {            throw new InvalidLicenseFileException();        }    }    //--------------------------------------------------------------------------    /**     *     */    public Object clone(){        LicenseKey clone = new LicenseKey ( mLicenseType,                                            mPageLimit,                                            mPageTemplateLimit,                                            mUserLimit,                                            mSiteLimit,                                            mLicenseID,                                            mBuildNumber,                                            mReleaseNumber );        return clone;    }}

⌨️ 快捷键说明

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