protected static BaseClass getXWikiGroupRelationClass(XWikiContext context) throws XWikiException { XWikiDocument doc; XWiki xwiki = context.getWiki(); boolean needsUpdate = false; try { doc = xwiki.getDocument("XWiki.GroupRelationClass", context); } catch (Exception e) { doc = new XWikiDocument(); doc.setSpace("XWiki"); doc.setName("GroupRelationClass"); needsUpdate = true; } BaseClass bclass = doc.getxWikiClass(); bclass.setName("XWiki.GroupRelationClass"); needsUpdate |= bclass.addTextField("name", "Name", 30); needsUpdate |= bclass.addTextField("parentpage", "Parent", 30); needsUpdate |= bclass.addTextAreaField("description", "Description", 40, 5); String content = doc.getContent(); if ((content == null) || (content.equals(""))) { needsUpdate = true; doc.setContent("1 XWikiGroup"); doc.setSyntax(Syntax.XWIKI_1_0); } if (needsUpdate) xwiki.saveDocument(doc, context); return bclass; }
private BaseClass getSubscriptionClass(XWikiContext context) throws XWikiException { XWikiDocument doc; XWiki xwiki = context.getWiki(); boolean needsUpdate = false; try { doc = xwiki.getDocument(CelementsCalendarPlugin.SUBSCRIPTION_CLASS, context); } catch (Exception e) { doc = new XWikiDocument(); doc.setSpace(CelementsCalendarPlugin.SUBSCRIPTION_CLASS_SPACE); doc.setName(CelementsCalendarPlugin.SUBSCRIPTION_CLASS_DOC); needsUpdate = true; } BaseClass bclass = doc.getxWikiClass(); bclass.setName(CelementsCalendarPlugin.SUBSCRIPTION_CLASS); needsUpdate |= bclass.addTextField("subscriber", "subscriber", 30); needsUpdate |= bclass.addBooleanField("doSubscribe", "doSubscribe", "yesno"); String content = doc.getContent(); if ((content == null) || (content.equals(""))) { needsUpdate = true; doc.setContent(" "); } if (needsUpdate) { xwiki.saveDocument(doc, context); } return bclass; }
/** * Check if class template document exists in this context and update. Create if not exists. * * @param context the XWiki context. * @throws XWikiException error when saving document. */ protected void checkClassTemplateDocument(XWikiContext context) throws XWikiException { if (this.checkingClassTemplate) { return; } this.checkingClassTemplate = true; try { XWikiDocument doc; XWiki xwiki = context.getWiki(); boolean needsUpdate = false; try { doc = xwiki.getDocument(getClassTemplateFullName(), context); } catch (Exception e) { doc = new XWikiDocument(); doc.setSpace(getClassTemplateSpace()); doc.setName(getClassTemplateName()); needsUpdate = true; } if (doc.getObject(getClassFullName()) == null) { doc.createNewObject(getClassFullName(), context); needsUpdate = true; } if (doc.isNew()) { String content = getResourceDocumentContent( DOCUMENTCONTENT_TEMPLATE_PREFIX + getClassTemplateFullName() + DOCUMENTCONTENT_EXT); doc.setContent(content != null ? content : getClassTemplateDefaultContent()); doc.setSyntax(Syntax.XWIKI_1_0); doc.setParent(getClassFullName()); } needsUpdate |= updateClassTemplateDocument(doc); if (doc.isNew() || needsUpdate) { xwiki.saveDocument(doc, context); } } finally { this.checkingClassTemplate = false; } }
/** * Check if class document exists in this context and update. Create if not exists. * * @param context the XWiki context. * @throws XWikiException error when saving document. */ protected void checkClassDocument(XWikiContext context) throws XWikiException { if (this.checkingClass) { return; } this.checkingClass = true; try { XWikiDocument doc; XWiki xwiki = context.getWiki(); boolean needsUpdate = false; try { doc = xwiki.getDocument(getClassFullName(), context); } catch (Exception e) { doc = new XWikiDocument(); doc.setSpace(getClassSpace()); doc.setName(getClassName()); doc.setCreator(XWikiRightService.SUPERADMIN_USER); doc.setAuthor(doc.getCreator()); needsUpdate = true; } if (doc.isNew()) { doc.setParent(DEFAULT_XWIKICLASS_PARENT); } this.baseClass = doc.getXClass(); needsUpdate |= updateBaseClass(this.baseClass); if (doc.isNew() || needsUpdate) { xwiki.saveDocument(doc, context); } } finally { this.checkingClass = false; } }
/** * Check if class sheet document exists in this context and update. Create if not exists. * * @param context the XWiki context. * @throws XWikiException error when saving document. */ protected void checkClassSheetDocument(XWikiContext context) throws XWikiException { if (this.checkingClassSheet) { return; } this.checkingClassSheet = true; try { XWikiDocument doc; XWiki xwiki = context.getWiki(); boolean needsUpdate = false; try { doc = xwiki.getDocument(getClassSheetFullName(), context); } catch (Exception e) { doc = new XWikiDocument(); doc.setSpace(getClassSheetSpace()); doc.setName(getClassSheetName()); needsUpdate = true; } if (doc.isNew()) { String documentContentPath = DOCUMENTCONTENT_SHEET_PREFIX + getClassSheetFullName() + DOCUMENTCONTENT_EXT; String content = getResourceDocumentContent(documentContentPath); doc.setContent(content != null ? content : getClassSheetDefaultContent()); doc.setSyntax(Syntax.XWIKI_1_0); doc.setParent(getClassFullName()); } if (doc.isNew() || needsUpdate) { xwiki.saveDocument(doc, context); } } finally { this.checkingClassSheet = false; } }
private BaseClass getCalendarClass(XWikiContext context) throws XWikiException { XWikiDocument doc; XWiki xwiki = context.getWiki(); boolean needsUpdate = false; try { doc = xwiki.getDocument(CelementsCalendarPlugin.CLASS_CALENDAR, context); } catch (Exception e) { doc = new XWikiDocument(); doc.setSpace(CelementsCalendarPlugin.CLASS_CALENDAR_SPACE); doc.setName(CelementsCalendarPlugin.CLASS_CALENDAR_DOC); needsUpdate = true; } BaseClass bclass = doc.getxWikiClass(); bclass.setName(CelementsCalendarPlugin.CLASS_CALENDAR); needsUpdate |= bclass.addTextField( CelementsCalendarPlugin.PROPERTY_CALENDAR_SPACE, CelementsCalendarPlugin.PROPERTY_CALENDAR_SPACE, 30); String hql = "select doc.fullName from XWikiDocument as doc, BaseObject as obj,"; hql += " IntegerProperty as int "; hql += "where obj.name=doc.fullName "; hql += "and not doc.fullName='$doc.getFullName()' "; hql += "and obj.className='" + CelementsCalendarPlugin.CLASS_CALENDAR + "' "; hql += "and int.id.id=obj.id "; hql += "and int.id.name='" + CelementsCalendarPlugin.PROPERTY_IS_SUBSCRIBABLE + "' "; hql += "and int.value='1' "; hql += "order by doc.fullName asc"; needsUpdate |= bclass.addDBListField( CelementsCalendarPlugin.PROPERTY_SUBSCRIBE_TO, CelementsCalendarPlugin.PROPERTY_SUBSCRIBE_TO, 5, true, hql); needsUpdate |= bclass.addTextField( CelementsCalendarPlugin.PROPERTY_OVERVIEW_COLUMN_CONFIG, CelementsCalendarPlugin.PROPERTY_OVERVIEW_COLUMN_CONFIG, 30); needsUpdate |= bclass.addTextField( CelementsCalendarPlugin.PROPERTY_EVENT_COLUMN_CONFIG, CelementsCalendarPlugin.PROPERTY_EVENT_COLUMN_CONFIG, 30); needsUpdate |= bclass.addNumberField( CelementsCalendarPlugin.PROPERTY_EVENT_PER_PAGE, CelementsCalendarPlugin.PROPERTY_EVENT_PER_PAGE, 5, "integer"); needsUpdate |= bclass.addBooleanField( CelementsCalendarPlugin.PROPERTY_HAS_MORE_LINK, CelementsCalendarPlugin.PROPERTY_HAS_MORE_LINK, "yesno"); needsUpdate |= bclass.addBooleanField( CelementsCalendarPlugin.PROPERTY_IS_SUBSCRIBABLE, CelementsCalendarPlugin.PROPERTY_IS_SUBSCRIBABLE, "yesno"); String content = doc.getContent(); if ((content == null) || (content.equals(""))) { needsUpdate = true; doc.setContent(" "); } if (needsUpdate) { xwiki.saveDocument(doc, context); } return bclass; }
private BaseClass getCalendarEventClass(XWikiContext context) throws XWikiException { XWikiDocument doc; XWiki xwiki = context.getWiki(); boolean needsUpdate = false; try { doc = xwiki.getDocument(CelementsCalendarPlugin.CLASS_EVENT, context); } catch (Exception e) { doc = new XWikiDocument(); doc.setSpace(CelementsCalendarPlugin.CLASS_EVENT_SPACE); doc.setName(CelementsCalendarPlugin.CLASS_EVENT_DOC); needsUpdate = true; } BaseClass bclass = doc.getxWikiClass(); bclass.setName(CelementsCalendarPlugin.CLASS_EVENT); needsUpdate |= bclass.addTextField( CelementsCalendarPlugin.PROPERTY_LANG, CelementsCalendarPlugin.PROPERTY_LANG, 30); needsUpdate |= bclass.addTextField( CelementsCalendarPlugin.PROPERTY_TITLE, CelementsCalendarPlugin.PROPERTY_TITLE, 30); needsUpdate |= bclass.addTextAreaField( CelementsCalendarPlugin.PROPERTY_TITLE_RTE, CelementsCalendarPlugin.PROPERTY_TITLE_RTE, 80, 15); needsUpdate |= bclass.addTextAreaField( CelementsCalendarPlugin.PROPERTY_DESCRIPTION, CelementsCalendarPlugin.PROPERTY_DESCRIPTION, 80, 15); needsUpdate |= bclass.addTextField( CelementsCalendarPlugin.PROPERTY_LOCATION, CelementsCalendarPlugin.PROPERTY_LOCATION, 30); needsUpdate |= bclass.addTextAreaField( CelementsCalendarPlugin.PROPERTY_LOCATION_RTE, CelementsCalendarPlugin.PROPERTY_LOCATION_RTE, 80, 15); needsUpdate |= bclass.addDateField( CelementsCalendarPlugin.PROPERTY_EVENT_DATE, CelementsCalendarPlugin.PROPERTY_EVENT_DATE, null, 0); needsUpdate |= bclass.addDateField( CelementsCalendarPlugin.PROPERTY_EVENT_DATE_END, CelementsCalendarPlugin.PROPERTY_EVENT_DATE_END, null, 0); needsUpdate |= bclass.addBooleanField( CelementsCalendarPlugin.PROPERTY_EVENT_IS_SUBSCRIBABLE, CelementsCalendarPlugin.PROPERTY_EVENT_IS_SUBSCRIBABLE, "yesno"); if (!"internal".equals(bclass.getCustomMapping())) { needsUpdate = true; bclass.setCustomMapping("internal"); } String content = doc.getContent(); if ((content == null) || (content.equals(""))) { needsUpdate = true; doc.setContent(" "); } if (needsUpdate) { xwiki.saveDocument(doc, context); } return bclass; }