use of org.xwiki.skin.Skin in project xwiki-platform by xwiki.
the class AbstractSkin method getOutputSyntax.
@Override
public Syntax getOutputSyntax() {
Syntax targetSyntax = null;
String targetSyntaxString = getOutputSyntaxString();
if (StringUtils.isNotEmpty(targetSyntaxString)) {
targetSyntax = parseSyntax(this, targetSyntaxString);
if (targetSyntax != null) {
return targetSyntax;
}
}
Skin parent = getParent();
if (parent != null) {
targetSyntax = parent.getOutputSyntax();
}
// Fallback to the XHTML 1.0 syntax for backward compatibility
return targetSyntax != null ? targetSyntax : Syntax.XHTML_1_0;
}
use of org.xwiki.skin.Skin in project xwiki-platform by xwiki.
the class EnvironmentSkin method createParent.
@Override
protected Skin createParent() {
Skin skin;
String parentId = getProperties().getString("parent");
if (parentId != null) {
if (parentId.isEmpty()) {
// There is explicitly no parent (make sure to not fallback on default parent skin)
skin = VOID;
} else {
skin = this.skinManager.getSkin(parentId);
}
} else {
skin = null;
}
return skin;
}
use of org.xwiki.skin.Skin in project xwiki-platform by xwiki.
the class XWiki method getSkinFile.
public String getSkinFile(String filename, boolean forceSkinAction, XWikiContext context) {
XWikiURLFactory urlf = context.getURLFactory();
try {
// Try in the specified skin
Skin skin = getInternalSkinManager().getCurrentSkin(true);
if (skin != null) {
Resource<?> resource = skin.getResource(filename);
if (resource != null) {
return resource.getURL(forceSkinAction);
}
} else {
// Try in the current parent skin
Skin parentSkin = getInternalSkinManager().getCurrentParentSkin(true);
if (parentSkin != null) {
Resource<?> resource = parentSkin.getResource(filename);
if (resource != null) {
return resource.getURL(forceSkinAction);
}
}
}
// Look for a resource file
if (resourceExists("/resources/" + filename)) {
URL url = urlf.createResourceURL(filename, forceSkinAction, context);
return urlf.getURL(url, context);
}
} catch (Exception e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Exception while getting skin file [" + filename + "]", e);
}
}
// If all else fails, use the default base skin, even if the URLs could be invalid.
URL url;
if (forceSkinAction) {
url = urlf.createSkinURL(filename, "skins", getDefaultBaseSkin(context), context);
} else {
url = urlf.createSkinURL(filename, getDefaultBaseSkin(context), context);
}
return urlf.getURL(url, context);
}
use of org.xwiki.skin.Skin in project xwiki-platform by xwiki.
the class XWiki method parseTemplate.
/**
* @param template the name of the template
* @param skinId the id of the skin from which to load the template
* @param context see {@link XWikiContext}
* @deprecated since 7.0M1, use {@link TemplateManager#renderFromSkin(String, Skin)} instead
*/
@Deprecated
public String parseTemplate(String template, String skinId, XWikiContext context) {
MutableRenderingContext mutableRenderingContext = getMutableRenderingContext();
Syntax currentTargetSyntax = mutableRenderingContext.getTargetSyntax();
try {
// Force rendering with XHTML 1.0 syntax for retro-compatibility
mutableRenderingContext.setTargetSyntax(Syntax.XHTML_1_0);
Skin skin = getInternalSkinManager().getSkin(skinId);
return getTemplateManager().renderFromSkin(template, skin);
} catch (Exception e) {
LOGGER.error("Error while evaluating velocity template [{}] skin [{}]", template, skinId, e);
Object[] args = { template, skinId };
XWikiException xe = new XWikiException(XWikiException.MODULE_XWIKI_RENDERING, XWikiException.ERROR_XWIKI_RENDERING_VELOCITY_EXCEPTION, "Error while evaluating velocity template [{0}] from skin [{1}]", e, args);
return Util.getHTMLExceptionMessage(xe, context);
} finally {
mutableRenderingContext.setTargetSyntax(currentTargetSyntax);
}
}
use of org.xwiki.skin.Skin in project xwiki-platform by xwiki.
the class DefaultVelocityManager method getVelocityEngineMacrosTemplate.
/**
* @return the key used to cache the Velocity Engines. We have one Velocity Engine per skin which has a macros.vm
* file on the filesystem. Right now we don't support macros.vm defined in custom skins in wiki pages.
*/
private Template getVelocityEngineMacrosTemplate() {
Template template = null;
Map<String, Template> templateCache = null;
Skin currentSkin = this.skinManager.getCurrentSkin(true);
// Generating this key is very expensive so we cache it in the context
ExecutionContext econtext = this.execution.getContext();
if (econtext != null) {
templateCache = (Map<String, Template>) econtext.getProperty(VELOCITYENGINE_CACHEKEY_NAME);
if (templateCache == null) {
templateCache = new HashMap<>();
econtext.setProperty(VELOCITYENGINE_CACHEKEY_NAME, templateCache);
} else {
template = templateCache.get(currentSkin.getId());
}
}
if (template == null) {
template = this.templates.get().getTemplate("macros.vm");
if (templateCache != null) {
templateCache.put(currentSkin.getId(), template);
}
}
return template;
}
Aggregations