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

📄 jahiapage.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /** Increment by one unit the page hit counter. */    public final void incrementCounter () {        mPageInfo.incrementCounter ();    }    //-------------------------------------------------------------------------    /** Try to get the page's update lock.     *     * @param   engineName     *      The engine name who's asking the page's update lock.     * @param   user     *      The user requesting the page's update lock.     *     * @return     *      Return true if the lock could be obtained, otherwise return     *      false,     */    public synchronized boolean getUpdateLock (JahiaUser user)        throws JahiaException    {        // the lock name is dependant of the page ID        String lockName = "PageLock-"+getID();        Hashtable lockParams = mLocksRegistry.getLock (lockName);        if (lockParams == null) {            //System.out.println (">>LOCK>> Lock received on page ["+            //        getID()+"] for user ["+user.getName()+"]");            return MakeLock (lockName, user);        } else {            // The page's lock could not be obtained, check if the lock is            // still valid (not timed out).            if (mLocksRegistry.isLockValid (lockName)) {                // Check if it's the same user who locked the page.                JahiaUser storedUser =                        (JahiaUser)lockParams.get (LOCK_USER_PARAMETER);                if (storedUser.getName().equals (user.getName())) {                    // reset the timeout time                    mLocksRegistry.resetLockTimeout (lockName);                    //System.out.println (">>LOCK>> Lock received on page ["+                    //        getID()+"] for user ["+user.getName()+"]");                    // have fun ... ;)                    return true;                }            } else {                // the lock has been timed out and is available.                return MakeLock (lockName, user);            }        }        //System.out.println (">>LOCK>> Lock could not be received on page ["+        //        getID()+"] for user ["+user.getName()+"]");        // That's too bad ... be patient ;)        return false;    }    //-------------------------------------------------------------------------    private boolean MakeLock (String lockName, JahiaUser user)        throws JahiaSessionExpirationException    {        Hashtable lockParams = new Hashtable ();        if (lockParams == null) {            //JahiaConsole.println (">", "Couldn't create lock parameters.");            return false;        } else {            lockParams.put (LOCK_USER_PARAMETER, user);            lockParams.put (LOCK_PAGE_PARAMETER, new Integer (getID()));            // create the lock in the registry.            int timeout = mParams.getSession().getMaxInactiveInterval();            mLocksRegistry.setLock (lockName, lockParams, timeout);        }        return true;    }    //-------------------------------------------------------------------------    public synchronized void releaseUpdateLock (JahiaUser user)        throws JahiaException    {        String lockName = "PageLock-"+getID();        mLocksRegistry.removeLock (lockName);        //System.out.println (">>LOCK>> Lock released on page ["+getID()+        //        "] for user ["+user.getName()+"]");    }    //-------------------------------------------------------------------------    /** Set the new page defintion ID. The ID must point to a existing page     *  definition.     *     * @param   value   The new page defintion ID.     *     * @exception   JahiaException     *      Throw this exception on any error. Only ERROR type error should     *      be catched, all the other failures should be thrown further.     */    public void setPageTemplateID (int value)        throws  JahiaException,                JahiaTemplateNotFoundException    {        // check if the specified definition exists        ServicesRegistry services = ServicesRegistry.getInstance ();        if (services == null) {            throw new JahiaException ("Services registry error.",                    "Could not access the Services Registry!",                    JahiaException.SERVICE_ERROR, JahiaException.CRITICAL);        }        JahiaPageDefinition template = null;        JahiaPageTemplateService templateService = services.getJahiaPageTemplateService();        if (templateService != null) {            template = templateService.lookupPageTemplate (value);            // set the new definition            mTempPageTemplate = template;            // update the new definition ID in the page infos.            mPageInfo.setPageType (TYPE_DIRECT);            mPageInfo.setPageTemplateID (value);        } else {            throw new JahiaException ("Page templates services error.",                    "Could not access the Page Templates Services.",                    JahiaException.SERVICE_ERROR, JahiaException.CRITICAL);        }    }    //-------------------------------------------------------------------------    public void setPageTemplate (JahiaPageDefinition value) {        if (value != null) {            mTempPageTemplate = value;            mPageInfo.setPageType (TYPE_DIRECT);            mPageInfo.setPageTemplateID (value.getID());        }    }    //-------------------------------------------------------------------------    /** Set the new internal link ID. This ID must be an existing page ID.     *     * @param   value   The new page link ID.     */    public final void setPageLinkID (int value) {        try {            JahiaPage tempPage = mPageService.lookupPage (value);            if (tempPage != null) {                mPageInfo.setPageTemplateID (tempPage.getPageTemplateID());                mPageInfo.setPageType (TYPE_LINK);                mPageInfo.setPageLinkID (value);            }        }        catch (JahiaException ex) {        }    }    //-------------------------------------------------------------------------    /** Change the page type. By changing this information, be aware to change     *  also the according remote URL or page link ID information. See the     *  methods {@link #setPageLinkID setPageLinkID()} and     *  {@link #setRemoteURL setRemoteURL()}.     *     * @param   value   The new page type.     */    public final void setPageType (int value) {        mPageInfo.setPageType (value);    }    //-------------------------------------------------------------------------    /** Set the new parent ID. This method should be used carefully, all the     *  subtree pages will move with the page.     *     * @param   value   The new parent page ID.     */    public final void setParentID (int value) {        mPageInfo.setParentID (value);    }    //-------------------------------------------------------------------------    /** Set the new remote URL. The page type will change accordingly.     *     * @param   value   The new remoteURL.     */    public final void setRemoteURL (String value) {        mPageInfo.setPageType (TYPE_URL);        mPageInfo.setRemoteURL (value);    }    //-------------------------------------------------------------------------    /** Change the page title.     *     * @param   value   String holding the new page title.     */    public final void setTitle (String value) {        mPageInfo.setTitle (value);    }    //-------------------------------------------------------------------------    /** Return the page URL     *  for backward compatibility.     *     * @return  Return the page URL string.     */    public String getUrl ()        throws JahiaException    {        return getURL();    } // end getUrl    //-------------------------------------------------------------------------    /** Return the page URL     *     * @return  Return the page URL string.     */    public String getURL ()        throws JahiaException    {        String outURL = "";        switch (getPageType ()) {            case (TYPE_DIRECT)  :                if (mParams != null) {                    outURL = mParams.composePageUrl (getID());                }                break;            case (TYPE_LINK)    :                if (mParams != null) {                    outURL = mParams.composePageUrl (getPageLinkID());                }                break;            case (TYPE_URL)     :                outURL = getRemoteURL();                break;        }        return outURL;    } // end getURL    //-------------------------------------------------------------------------    /** Return the page path. The page path consist of all the parent pages of     *  the specified page until the site's root page.     *     * @return  Return a enumeration of JahiaPage objects. The returned     *          Enumeration is always non-null, but might have no pages if the     *          specified page has not childs, or if no childs matching the     *          loading flag were found.     */    public Enumeration getPagePath ()        throws JahiaException    {        Vector thePath = mPageService.getPagePath (getID(), mParams);        if (thePath != null) {            return thePath.elements();        }        return null;    } // end getPath    //-------------------------------------------------------------------------    /** Return the page path. The page path consist of all the parent pages of     *  the specified page until the site's root page.     *     * @return  Return a enumeration of JahiaPage objects. The returned     *          Enumeration is always non-null, but might have no pages if the     *          specified page has not childs, or if no childs matching the     *          loading flag were found.     */    public Enumeration getPagePath(int levels)        throws JahiaException    {        Vector thePath = mPageService.getPagePath (getID(), mParams);        if (thePath != null) {              int fromIndex = 0;              if((thePath.size() - levels) > 0) {                 fromIndex = thePath.size() - levels;              }              List theShortPathList = thePath.subList(fromIndex, thePath.size());              Vector theShortPathVector = new Vector(theShortPathList);//            Vector theShortPath = new Vector();//            for (int i = (thePath.size() - levels); i < thePath.size(); i++) {//                theShortPath.add(thePath.get(i));//            }            return theShortPathVector.elements();        }        return null;    } // end getPath    //-------------------------------------------------------------------------    /** Return an enumeration holding all the child pages of the specified page.     *  The loading flag filters the kind of pages to return.     *     * @return  Return an Enumeration of JahiaPage objects. Return null if not     *          the current page has not childs.     *     * @exception   JahiaException     *      Return this exception if any failure occured.     */    public Enumeration getChilds ()        throws JahiaException    {        Vector childs = mPageService.getPageChilds (getID(), PageLoadFlags.ALL, mParams);        if (childs != null) {            return childs.elements();        }        return null;    } // end getChilds    public Enumeration getChilds (JahiaUser user)        throws JahiaException    {        Vector childs = mPageService.getPageChilds (getID(), PageLoadFlags.ALL, user);        // JahiaConsole.println("JahiaPage.getChilds","Nb child found " + childs.size());        if (childs != null) {            return childs.elements();        }        return null;    } // end getChilds    //-------------------------------------------------------------------------    /**     * Compare between two objects, sort by their name     *     * @param Object     * @param Object     */    public int compare(Object c1, Object c2) throws ClassCastException {        return ((JahiaPage)c1)                    .getTitle().toLowerCase()                    .compareTo(((JahiaPage)c2).getTitle().toLowerCase());    }    //-------------------------------------------------------------------------    public String toString () {        StringBuffer output = new StringBuffer ();        output.append ("Detail of page ["+getID()+"] :\n");        output.append ("  - Site ID       ["+getJahiaID()+"]\n");        output.append ("  - Parent ID     ["+getParentID()+"]\n");        output.append ("  - Type          ["+PAGE_TYPE_NAMES[getPageType()]+"]\n");        output.append ("  - Ttitle        ["+getTitle()+"]\n");        output.append ("  - Template ID   ["+getPageTemplateID()+"]\n");        output.append ("  - Remote URL    ["+getRemoteURL()+"]\n");        output.append ("  - Link ID       ["+getPageLinkID()+"]\n");        output.append ("  - Creator       ["+getCreator()+"]\n");        output.append ("  - Creation date ["+getDoc()+"]\n");        output.append ("  - Counter       ["+getCounter()+"]\n");        output.append ("  - ACL ID        ["+getAclID()+"]\n");        return output.toString();    }}

⌨️ 快捷键说明

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