container.setMenuItems(categories);
return container;
}
*/
static public DropDownMenu[] makeDdmCategory(String siteId, Long categoryParentId, Long siteProfileClassId, Long siteProfileClassDefaultId) throws Exception {
DropDownMenu categories[] = null;
Vector<DropDownMenu> categoryList = new Vector<DropDownMenu>();
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
String sql = "select category " +
"from Category category " +
"left join category.site site " +
"where site.siteId = :siteId " +
"and category.categoryParentId = :categoryParentId " +
"order by category.seqNum";
Query query = em.createQuery(sql);
query.setParameter("siteId", siteId);
query.setParameter("categoryParentId", categoryParentId.longValue());
Iterator<?> iterator = query.getResultList().iterator();
while (iterator.hasNext()) {
Category category = (Category) iterator.next();
CategoryLanguage categoryLanguage = null;
for (CategoryLanguage language : category.getCategoryLanguages()) {
if (language.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClassDefaultId)) {
categoryLanguage = language;
}
}
DropDownMenu childMenus[] = makeDdmCategory(siteId, category.getCatId(), siteProfileClassId, siteProfileClassDefaultId);
DropDownMenu ddm = new DropDownMenu();
ddm.setMenuKey(Format.getLong(category.getCatId()));
ddm.setMenuName(categoryLanguage.getCatShortTitle());
if (siteProfileClassId != siteProfileClassDefaultId) {
Iterator<?> categoryLanguages = category.getCategoryLanguages().iterator();
boolean found = false;
while (categoryLanguages.hasNext()) {
categoryLanguage = (CategoryLanguage) categoryLanguages.next();
if (categoryLanguage.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClassId)) {
found = true;
break;
}
}
if (found) {
if (categoryLanguage.getCatShortTitle() != null) {
ddm.setMenuName(categoryLanguage.getCatShortTitle());
}
}
}
ddm.setMenuItems(childMenus);
categoryList.add(ddm);
}
categories = new DropDownMenu[categoryList.size()];
categoryList.copyInto(categories);
return categories;