Search in sources :

Example 1 with Resource

use of org.xwiki.skin.Resource in project xwiki-platform by xwiki.

the class LogoAttachmentExtractor method getLogo.

/**
 * @return an attachment holding the logo of the wiki
 * @throws Exception if an error happens
 */
public Attachment getLogo() throws Exception {
    XWikiContext context = xwikiContextProvider.get();
    String colorTheme = configurationSource.getProperty("colorTheme");
    if (StringUtils.isNotBlank(colorTheme)) {
        DocumentReference colorThemeRef = documentReferenceResolver.resolve(colorTheme);
        XWiki xwiki = context.getWiki();
        XWikiDocument doc = xwiki.getDocument(colorThemeRef, context);
        String logo = doc.getStringValue(LOGO);
        if (StringUtils.isBlank(logo)) {
            logo = doc.getStringValue("logoImage");
        }
        if (isLogoAttachementValid(doc, logo)) {
            XWikiAttachment attachment = doc.getAttachment(logo);
            attachment.setFilename(LOGO);
            return new Attachment(new Document(doc, context), attachment, context);
        }
    }
    String skin = configurationSource.getProperty("skin");
    if (StringUtils.isNotBlank(skin)) {
        DocumentReference skinRef = documentReferenceResolver.resolve(skin);
        XWiki xwiki = context.getWiki();
        XWikiDocument doc = xwiki.getDocument(skinRef, context);
        String logo = doc.getStringValue(LOGO);
        if (isLogoAttachementValid(doc, logo)) {
            XWikiAttachment attachment = doc.getAttachment(logo);
            attachment.setFilename(LOGO);
            return new Attachment(new Document(doc, context), attachment, context);
        }
    }
    XWikiAttachment fakeAttachment = new XWikiAttachment();
    Resource sourceImageIS = internalSkinManager.getCurrentSkin(true).getResource("logo.png");
    InputStream inputStream = environment.getResourceAsStream(sourceImageIS.getPath());
    fakeAttachment.setAttachment_content(new XWikiAttachmentContent());
    fakeAttachment.getAttachment_content().setContent(inputStream);
    fakeAttachment.setFilename(LOGO);
    return new Attachment(null, fakeAttachment, context);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) InputStream(java.io.InputStream) Resource(org.xwiki.skin.Resource) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Attachment(com.xpn.xwiki.api.Attachment) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiAttachmentContent(com.xpn.xwiki.doc.XWikiAttachmentContent)

Example 2 with Resource

use of org.xwiki.skin.Resource in project xwiki-platform by xwiki.

the class AbstractLESSSource method relativeSource.

@Override
public LessSource relativeSource(String filename) throws FileNotFound {
    String template = folder + "/" + filename;
    Resource resource = skin.getResource(template);
    if (resource != null) {
        return new TemplateLESSSource(templateManager, skin, template);
    }
    // The file has not been found
    throw new FileNotFound();
}
Also used : Resource(org.xwiki.skin.Resource)

Aggregations

Resource (org.xwiki.skin.Resource)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 Attachment (com.xpn.xwiki.api.Attachment)1 Document (com.xpn.xwiki.api.Document)1 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 XWikiAttachmentContent (com.xpn.xwiki.doc.XWikiAttachmentContent)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 InputStream (java.io.InputStream)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1