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

📄 jahiahomepagecopy.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////// NK - 17 Dec. 2001 ://package org.jahia.services.homepages;import java.sql.*;import java.util.Hashtable;import java.util.Enumeration;import org.jahia.exceptions.JahiaException;import org.jahia.utils.JahiaConsole;/** * A JahiaHomepageCopy holds information used to define homepage of type Copy. * Home page definition of this type holds extra information like the original page to duplicate, * the parent page id ( where to insert the duplicated page ), and a user or group reference * used to duplicate right for the new user or group. * * @author Khue ng * @see HomepageTypes.HOMEPAGE_COPY * @version 1.0 */public final class JahiaHomepageCopy extends JahiaHomepage{	private static String CLASS_NAME = JahiaHomepageCopy.class.getName();		// the page to copy	private static final String PAGEID = "pageid";		// use this user to duplicate exact right for the new group or user. 	private static final String USER_REF = "user_ref";		// use this group to duplicate exact right for the new group or user. 	private static final String GROUP_REF = "group_ref";		// where to insert the duplicated page ( subtree )	private static final String PARENT_PAGEID = "parent_pageid";	// how deep to copy the subtree	private static final String COPY_DEPTH = "copy_depth";    	private JahiaHomepagesPersistance hpp;	/**	 * Constructor	 *	 * @param Integer id, the unique identifier	 * @param String name, the name	 * @param String descr, the descr	 * @param Integer type, the type	 * @param String sitekey, the site key	 * @param Hashtable props, the properties	 * @param Integer aclID, the acl	 */	JahiaHomepageCopy(	Integer id,						String name,						String descr,						Integer type,						String siteKey,						Hashtable props,						Integer aclID ){			super(id,name,descr,type,siteKey,props,aclID);		}    //-------------------------------------------------------------------------    /**     * Return the internal page id that refers to a Jahia Page.     *     * @return int the internal page id or -1 if not defined.     */    public int getPageID(){    	Integer pageID = (Integer)props.get(PAGEID);    	    	if ( pageID == null ){    		return -1;    	}    	return pageID.intValue();	}	    //-------------------------------------------------------------------------    /**     * Set the page ID     *     * @param int the id     */    public void setPageID(int id){		props.put(PAGEID,new Integer(id));    }    //-------------------------------------------------------------------------    /**     * Return the user ref.     *     * @return String the user ref's key.     */    public String getUserRef(){    	return (String)props.get(USER_REF);	}	    //-------------------------------------------------------------------------    /**     * Set the user ref     *     * @param String the user ref's key     */    public void setUserRef(String userKey) throws JahiaException{		props.put(USER_REF,userKey);    }    //-------------------------------------------------------------------------    /**     * Return the group ref.     *     * @return String the group ref's key.     */    public String getGroupRef(){    	return (String)props.get(GROUP_REF);	}	    //-------------------------------------------------------------------------    /**     * Set the group ref     *     * @param String the group ref's key     */    public void setGroupRef(String groupKey) throws JahiaException{		props.put(GROUP_REF,groupKey);    }    //-------------------------------------------------------------------------    /**     * Return the id of the page to use as parent for the new homepage.     *     * @return int the parent page id, -1 if not defined.     */    public int getParentPageID(){		Integer id = (Integer)props.get(PARENT_PAGEID);   	    	if ( id == null ){    		return -1;    	}    	return id.intValue();	}	    //-------------------------------------------------------------------------    /**     * Set the parent page ID     *     * @param int the parent page id     */    public void setParentPageID(int pageID) throws JahiaException{		props.put(PARENT_PAGEID,new Integer(pageID));    }    //-------------------------------------------------------------------------    /**     * Return the copy depth.     * 0 = all tree.     * -1 = undefined.     * @return int the copy depth, -1 if not defined.     */    public int getCopyDepth(){		Integer depth = (Integer)props.get(COPY_DEPTH);   	    	if ( depth == null ){    		return -1;    	}    	return depth.intValue();	}    //-------------------------------------------------------------------------    /**     * Set the copy depth:     *						0, the entire tree.     *						1, only the original page.     *						n, how deep to copy the subtree.     *     * @param int the copy mode     */    public void setCopyDepth(int depth) throws JahiaException{		if ( depth < 0 ){			throw new JahiaException(	CLASS_NAME+".setCopyDepth()",										"Copy depth value must be bigger or equals to 0",										JahiaException.DATA_ERROR,										JahiaException.ERROR);		}				props.put(COPY_DEPTH,new Integer(depth));    }    //--------------------------------------------------------------------------    /**     * Save its state.     *     */    void save()    throws JahiaException {    	    	hpp.getInstance().save(this);    	saveProperties();    }    //--------------------------------------------------------------------------    /**     * Delete.     *     */    void delete()    throws JahiaException {    	hpp.getInstance().delete(getID());    	deleteProperties();    }	    //-------------------------------------------------------------------------    /**     * Load extra properties from storage     *     */    void loadProperties() throws JahiaException{				if ( props == null )			props = new Hashtable();				String value = null;		value = hpp.getInstance().getProperty(this,USER_REF);		if ( value != null )			props.put(USER_REF,value);		value = hpp.getInstance().getProperty(this,GROUP_REF);		if ( value != null )			props.put(GROUP_REF,value);		value = hpp.getInstance().getProperty(this,PAGEID);		if ( value != null ){			try {				props.put(PAGEID,new Integer(value));			} catch ( Throwable t ){				t.printStackTrace();			}			}		value = hpp.getInstance().getProperty(this,PARENT_PAGEID);		if ( value != null ){			try {				props.put(PARENT_PAGEID,new Integer(value));			} catch ( Throwable t ){				t.printStackTrace();			}			}		value = hpp.getInstance().getProperty(this,COPY_DEPTH);		if ( value != null ){			try {				props.put(COPY_DEPTH,new Integer(value));			} catch ( Throwable t ){				t.printStackTrace();			}			}    }    //-------------------------------------------------------------------------    /**     * Save extra properties in storage     *     */    void saveProperties() throws JahiaException{				deleteProperties();					String value = null;				value = getUserRef();		if ( value != null )			hpp.getInstance().addProperty(this,USER_REF,value);		value = getGroupRef();		if ( value != null )			hpp.getInstance().addProperty(this,GROUP_REF,value);		value = Integer.toString(getPageID());		if ( value != null )			hpp.getInstance().addProperty(this,PAGEID,value);		value = Integer.toString(getParentPageID());		if ( value != null )			hpp.getInstance().addProperty(this,PARENT_PAGEID,value);		value = Integer.toString(getCopyDepth());		if ( value != null )			hpp.getInstance().addProperty(this,COPY_DEPTH,value);    }    //-------------------------------------------------------------------------    /**     * Delete extra properties in storage     *     */    void deleteProperties() throws JahiaException{				hpp.getInstance().deleteProperties(this);	    }    //--------------------------------------------------------------------------    /**     * Return a string representation of the home page and it's internal state.     *     * @return A string representation of this home page.     */    public String toString (){    	    	StringBuffer buff= new StringBuffer("String rep. of a ");    	buff.append(CLASS_NAME);    	buff.append(" bean		:\n");    	buff.append("		 id	:");    	buff.append(getID());    	// TODO . complete    	return buff.toString();    	    }    //--------------------------------------------------------------------------    /**     * Return a clone.     *     * @return Object the clone.     */    public Object clone (){    	    	Hashtable hash = null;    	if ( getProperties() != null ){    		hash = new Hashtable();    		if ( props.get(PAGEID) != null )    			hash.put(PAGEID,new Integer(getPageID()));    		if ( props.get(PARENT_PAGEID) != null )    			hash.put(PARENT_PAGEID,new Integer(getParentPageID()));    		if ( props.get(COPY_DEPTH) != null )    			hash.put(COPY_DEPTH,new Integer(getCopyDepth()));    		if ( props.get(USER_REF) != null )    			hash.put(USER_REF,getUserRef());    		if ( props.get(GROUP_REF) != null )    			hash.put(GROUP_REF,getGroupRef());    	}    	    	JahiaHomepageCopy clone =     			new JahiaHomepageCopy(	new Integer(getID()),	    									getName(),    									getDescr(),    									new Integer(getType()),    									getSiteKey(),    									hash,    									new Integer(getAclID()) ); 		return clone;   									    }}

⌨️ 快捷键说明

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