%@ page import="com.imcode.imcms.api.*"%>
<%
ContentManagementSystem imcms = ContentManagementSystem.fromRequest( request );
DocumentService documentService = imcms.getDocumentService();
%>
Create a new Category Type and a Category
<%
String categoryTypeName = "API-sample Category Type";
CategoryType categoryType ;
try{
categoryType = documentService.createNewCategoryType( categoryTypeName, 1 );
%>Created category type with name "<%= categoryTypeName %>".
<%
} catch( CategoryTypeAlreadyExistsException ex ) {
categoryType = documentService.getCategoryType( categoryTypeName ) ;
}
String categoryName = "API-sample category";
Category newCategory = new Category( categoryName, categoryType );
try {
documentService.saveCategory( newCategory );
%>Created category with name "<%= newCategory.getName() %>" and type "<%= categoryType.getName() %>".<%
} catch( CategoryAlreadyExistsException ex ) {
%>A category with the name "<%= categoryName %>" already exists within the category type name "<%=categoryTypeName %>". <%
}
%>