Skin API

Last modified by Eleni Cojocariu on 2026/09/23 12:16

Reference

The four roles of the org.xwiki.skin package. They are Java only: the skin module implements no script service, so there is no $services.skin for a wiki page. Sources: http://www.github.com/xwiki/xwiki-platform/tree/master/xwiki-platform-core/xwiki-platform-skin/xwiki-platform-skin-api/src/main/java/org/xwiki/skin.

SkinManager

The component to inject. It is the only way into the other three.

MemberReturnsWhat it does
getSkin(String id)SkinThe skin with that id.
getCurrentSkin(boolean testRights)SkinThe skin of the current request, resolved through the levels the administration documents. With true the current user's view right is checked on the skin coming from the instance configuration only; a skin coming from the request or from a preference is returned unchecked.
getDefaultSkin()SkinThe skin configured as the instance default.
getDefaultParentSkin()SkinThe skin used as parent by any skin that names no parent of its own.

Skin

Extends ResourceRepository, so it also has every member of the table below.

MemberReturnsWhat it does
getParent()SkinThe parent skin. Narrows ResourceRepository.getParent(), which returns a plain repository.
getOutputSyntax()SyntaxThe syntax the skin renders content into, inherited from the parent skin and defaulting to XHTML 1.0.

ResourceRepository

Somewhere a resource name can be looked up. A skin is one, and so is whatever it inherits from.

MemberReturnsWhat it does
getParent()ResourceRepositoryThe repository used as fallback when this one does not hold the name.
getId()StringThe repository's identifier.
getResource(String resourceName)Resource<?>The named resource, walking the parent chain; null when no repository in the chain holds it.
getLocalResource(String resourceName)Resource<?>The named resource in this repository alone, without the parent chain; null when it does not hold it.

The wildcard in Resource<?> is not a limitation of the lookup, only of what the repository can promise about the input source; the type parameter matters when a concrete implementation is held.

Resource

One file of a skin. Resource<I extends InputSource> is typed by the kind of input source it opens.

MemberReturnsWhat it does
getRepository()ResourceRepositoryThe repository the resource was found in.
getId()StringThe resource's unique identifier.
getPath()StringThe resource's path.
getResourceName()StringThe resource's name, usually a path relative to the repository.
getInputSource()IAn input source for reading the resource. Throws Exception.
getInstant()InstantWhen the resource was last modified, or null when that is unknown. Default method. Throws Exception.
getURL(boolean forceSkinAction)StringA URL for the resource; true forces a dynamic skin URL rather than a static one. Throws Exception.

Getting a skin

A skin id is either a page reference or the name of a filesystem or JAR skin such as flamingo; which kind resolves to what is on the Skin Module.

@Inject
private SkinManager skinManager;

Skin skin = this.skinManager.getSkin("xwiki:Main.MySkin");

The skin in effect for the current request comes from the same component:

// true checks the view right, but only on a skin that came from the configuration.
Skin currentSkin = this.skinManager.getCurrentSkin(true);

Looking a resource up

Either lookup can come back empty:

// Walks the parent chain.
Resource<?> inherited = currentSkin.getResource("myscript.js");

// This skin only.
Resource<?> own = currentSkin.getLocalResource("myscript.js");

if (inherited != null) {
    // Which skin the file came from.
    ResourceRepository source = inherited.getRepository();
}

FAQ

Which classes implement these roles?

DefaultSkinManager, WikiSkin, EnvironmentSkin and ClassLoaderSkin, none of them in this artifact. The Skin Module says where they live and why.

How do I know which skin a file came from?

Resource.getRepository(), which for a resource found through getResource() is the skin that actually held it rather than the one the lookup started from.

Related

Get Connected