/* * See the NOTICE file distributed with this work for additional * information regarding copyright ownership. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package com.xpn.xwiki.internal.mandatory; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; import org.xwiki.component.annotation.Component; import org.xwiki.model.reference.DocumentReference; import org.xwiki.model.reference.LocalDocumentReference; import org.xwiki.sheet.SheetBinder; import com.xpn.xwiki.XWiki; import com.xpn.xwiki.doc.AbstractMandatoryClassInitializer; import com.xpn.xwiki.doc.XWikiDocument; import com.xpn.xwiki.objects.classes.BaseClass; /** * Update XWiki.XWikiGroups document with all required informations. * * @version $Id: e5992dba73010e992e6cf02b53caf0b6cc329092 $ * @since 4.3M1 */ @Component @Named("XWiki.XWikiGroups") @Singleton public class XWikiGroupsDocumentInitializer extends AbstractMandatoryClassInitializer { /** * Used to bind a class to a document sheet. */ @Inject @Named("class") private SheetBinder classSheetBinder; /** * Default constructor. */ public XWikiGroupsDocumentInitializer() { super(new LocalDocumentReference(XWiki.SYSTEM_SPACE, "XWikiGroups")); } @Override protected void createClass(BaseClass xclass) { xclass.addTextField("member", "Member", 30); } @Override public boolean updateDocument(XWikiDocument document) { boolean needUpdate = super.updateDocument(document); // Use XWikiGroupSheet to display documents having XWikiGroups objects if no other class sheet is specified. if (this.classSheetBinder.getSheets(document).isEmpty()) { String wikiName = document.getDocumentReference().getWikiReference().getName(); DocumentReference sheet = new DocumentReference(wikiName, XWiki.SYSTEM_SPACE, "XWikiGroupSheet"); needUpdate |= this.classSheetBinder.bind(document, sheet); } return needUpdate; } }