Skip to content
Snippets Groups Projects
Commit 915e4045 authored by Guillaume Delhumeau's avatar Guillaume Delhumeau
Browse files

XWIKI-11803: Create a new mechanism to overwrite a skin file.

parent 853eac48
No related merge requests found
/*
* 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.Named;
import javax.inject.Singleton;
import org.xwiki.component.annotation.Component;
import org.xwiki.model.reference.EntityReference;
import org.xwiki.model.reference.LocalDocumentReference;
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.classes.BaseClass;
/**
* Update XWiki.XWikiSkinFileOverrideClass document with all required properties. This XClass is used to override a skin
* file by attaching an instance of it to the skin document.
*
* @version $Id$
* @since 7.0RC1
*/
@Component
@Named("XWiki.XWikiSkinFileOverrideClass")
@Singleton
public class XWikiSkinFileOverrideClassDocumentInitializer extends AbstractMandatoryDocumentInitializer
{
/**
* The reference to the mandatory document.
*/
public static final EntityReference DOCUMENT_REFERENCE
= new LocalDocumentReference(XWiki.SYSTEM_SPACE, "XWikiSkinFileOverrideClass");
/**
* The name of the property storing the path of the file to overwrite.
*/
public static final String PROPERTY_PATH = "path";
/**
* The name of the property holding the content.
*/
public static final String PROPERTY_CONTENT = "content";
/**
* Default constructor.
*/
public XWikiSkinFileOverrideClassDocumentInitializer()
{
super(DOCUMENT_REFERENCE);
}
@Override
public boolean updateDocument(XWikiDocument document)
{
boolean needsUpdate = false;
BaseClass bclass = document.getXClass();
needsUpdate |= bclass.addTextField(PROPERTY_PATH, "Path", 255);
needsUpdate |= bclass.addTemplateField(PROPERTY_CONTENT, "Content");
needsUpdate |= setClassDocumentFields(document, "XWiki Skin File Override Class");
return needsUpdate;
}
}
......@@ -42,6 +42,7 @@
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.internal.mandatory.XWikiSkinFileOverrideClassDocumentInitializer;
import com.xpn.xwiki.objects.BaseObject;
import com.xpn.xwiki.objects.BaseProperty;
......@@ -127,6 +128,18 @@ public Resource<?> getResource(String resourceName, Skin skin)
private Resource<?> getSkinResourceFromDocumentSkin(String resource, XWikiDocument skinDocument, Skin skin)
{
if (skinDocument != null) {
// Try to find a XWikiSkinFileOverrideClass object
BaseObject obj = skinDocument.getXObject(XWikiSkinFileOverrideClassDocumentInitializer.DOCUMENT_REFERENCE,
XWikiSkinFileOverrideClassDocumentInitializer.PROPERTY_PATH, resource, false);
if (obj != null) {
ObjectPropertyReference reference = new ObjectPropertyReference(
XWikiSkinFileOverrideClassDocumentInitializer.PROPERTY_CONTENT,
obj.getReference());
return new ObjectPropertyWikiResource(getPath(reference), skin, reference,
skinDocument.getAuthorReference(), this.xcontextProvider,
obj.getLargeStringValue(XWikiSkinFileOverrideClassDocumentInitializer.PROPERTY_CONTENT));
}
// Try parsing the object property
BaseProperty<ObjectPropertyReference> property = getSkinResourceProperty(resource, skinDocument);
if (property != null) {
......
......@@ -29,6 +29,7 @@ com.xpn.xwiki.internal.mandatory.XWikiGlobalRightsDocumentInitializer
com.xpn.xwiki.internal.mandatory.XWikiGroupsDocumentInitializer
com.xpn.xwiki.internal.mandatory.XWikiPreferencesDocumentInitializer
com.xpn.xwiki.internal.mandatory.XWikiRightsDocumentInitializer
com.xpn.xwiki.internal.mandatory.XWikiSkinFileOverrideClassDocumentInitializer
com.xpn.xwiki.internal.mandatory.XWikiSkinsDocumentInitializer
com.xpn.xwiki.internal.mandatory.XWikiUsersDocumentInitializer
com.xpn.xwiki.internal.model.reference.CurrentEntityReferenceValueProvider
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment