Search in sources :

Example 1 with Skin

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;
}
Also used : Skin(org.xwiki.skin.Skin) Syntax(org.xwiki.rendering.syntax.Syntax)

Example 2 with Skin

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;
}
Also used : Skin(org.xwiki.skin.Skin)

Example 3 with 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);
}
Also used : XWikiURLFactory(com.xpn.xwiki.web.XWikiURLFactory) Skin(org.xwiki.skin.Skin) WikiSkin(com.xpn.xwiki.internal.skin.WikiSkin) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException)

Example 4 with Skin

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);
    }
}
Also used : Skin(org.xwiki.skin.Skin) WikiSkin(com.xpn.xwiki.internal.skin.WikiSkin) Syntax(org.xwiki.rendering.syntax.Syntax) MutableRenderingContext(org.xwiki.rendering.internal.transformation.MutableRenderingContext) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException)

Example 5 with Skin

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;
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) Skin(org.xwiki.skin.Skin) Template(org.xwiki.template.Template)

Aggregations

Skin (org.xwiki.skin.Skin)7 WikiSkin (com.xpn.xwiki.internal.skin.WikiSkin)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 NamingException (javax.naming.NamingException)2 URIException (org.apache.commons.httpclient.URIException)2 HibernateException (org.hibernate.HibernateException)2 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)2 JobException (org.xwiki.job.JobException)2 QueryException (org.xwiki.query.QueryException)2 ParseException (org.xwiki.rendering.parser.ParseException)2 Syntax (org.xwiki.rendering.syntax.Syntax)2 Template (org.xwiki.template.Template)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 XWikiURLFactory (com.xpn.xwiki.web.XWikiURLFactory)1 URL (java.net.URL)1