首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

liferay 替JournalArticle添加分类

2013-03-25 
liferay 为JournalArticle添加分类/*** 为网页内容添加分类* @param serviceContext*/ public boolean add

liferay 为JournalArticle添加分类

   /**     * 为网页内容添加分类     * @param serviceContext     */ public boolean addCategoryForJournalArticle(ServiceContext serviceContext,String activityType,String parentsCategoryName,JournalArticle ja) {     try {         //检查producType有没有对应的分类         AssetEntry  jaAssetEntry= AssetEntryLocalServiceUtil.getEntry(JournalArticle.class.getName(), ja.getResourcePrimKey());         AssetCategory assetcat=checkOrGetCategory(activityType,parentsCategoryName,serviceContext);         if(null!=assetcat){             AssetEntryUtil.addAssetCategory(jaAssetEntry.getPrimaryKey(), assetcat.getPrimaryKey());              }    } catch (PortalException e) {        return false;    } catch (SystemException e) {        return false;    }     return true; } private  AssetCategory checkOrGetCategory(String activityType,String parentsCategoryName,ServiceContext serviceContext) throws SystemException{     AssetCategory assetCategory= getAssetCategory("分类名称",parentsCategoryName,serviceContext);      return assetCategory; } /**  * 获取AssetCategory  */ private AssetCategory getAssetCategory(String categoryName ,String parentCategoryName,ServiceContext serviceContext) throws SystemException{         AssetCategory assetc=findAssetCategoryByName(categoryName);         if(null==assetc){             assetc= createAssetCategory(categoryName,parentCategoryName,serviceContext);         }    return assetc; }/**通过名字找category*/ private AssetCategory findAssetCategoryByName(String categoryName) throws SystemException{     AssetCategory assetc=null;    List<AssetCategory> categoryList = null;     categoryList = AssetCategoryLocalServiceUtil.getCategories();     for(AssetCategory asset: categoryList)         {         String categoryN = asset.getName(); //get category Name         if(categoryN.equalsIgnoreCase(categoryName)){             assetc= asset;             break;         }     }     return assetc; } private AssetCategory createAssetCategory(String categoryName,String parentCategoryName,ServiceContext serviceContext){     //如果沒有找到添加新的分類//   assetc=AssetCategoryLocalServiceUtil.createAssetCategory(CounterLocalServiceUtil.increment());//   assetc.setName(categoryName);//   if(!StringUtils.isEmpty(parentCategoryName)){//       AssetCategory passetc=findAssetCategoryByName(parentCategoryName);//       assetc.setParentCategoryId(passetc.getCategoryId());//   }//   AssetCategoryLocalServiceUtil.addAssetCategory(assetc);     return null; }

?

热点排行