001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo
018 */
019
020package org.nuxeo.ecm.showcase.content.service;
021
022import org.nuxeo.common.xmap.annotation.XNode;
023import org.nuxeo.common.xmap.annotation.XObject;
024import org.nuxeo.ecm.core.api.NuxeoException;
025import org.nuxeo.runtime.model.ComponentInstance;
026import org.nuxeo.runtime.model.RuntimeContext;
027
028import java.net.URL;
029
030@XObject(value = "content")
031public class ShowcaseContentDescriptor {
032
033    @XNode("@name")
034    protected String name;
035
036    @XNode("filename")
037    protected String filename;
038
039    @XNode("@enable")
040    protected boolean enabled = true;
041
042    protected URL blobUrl;
043
044    public String getName() {
045        return name;
046    }
047
048    public void setName(String name) {
049        this.name = name;
050    }
051
052    public String getFilename() {
053        return filename;
054    }
055
056    public void setFilename(String filename) {
057        this.filename = filename;
058    }
059
060    public URL getBlobUrl() {
061        if (blobUrl == null) {
062            throw new NuxeoException("Unable to find expected file: " + filename);
063        }
064        return blobUrl;
065    }
066
067    public void setBlobUrl(URL blobUrl) {
068        this.blobUrl = blobUrl;
069    }
070
071    public void computeBlobUrl(ComponentInstance component) {
072        try (RuntimeContext ctx = component.getRuntimeContext()) {
073            setBlobUrl(ctx.getResource(filename));
074        }
075    }
076}