001/*
002 * (C) Copyright 2006-2007 Nuxeo SAS <http://nuxeo.com> and others
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Jean-Marc Orliaguet, Chalmers
011 *
012 * $Id$
013 */
014
015package org.nuxeo.theme.jsf.taglib;
016
017import javax.faces.component.UIComponent;
018import javax.faces.webapp.UIComponentELTag;
019
020public abstract class BaseMVCTag extends UIComponentELTag {
021
022    private String resource;
023
024    private String url;
025
026    @Override
027    public abstract String getComponentType();
028
029    @Override
030    public String getRendererType() {
031        // null means the component renders itself
032        return null;
033    }
034
035    @Override
036    protected void setProperties(UIComponent component) {
037        super.setProperties(component);
038
039        if (null != url && null != resource) {
040            throw new IllegalArgumentException("Cannot specify both a URL and a resource.");
041        }
042
043        if (null != resource) {
044            component.getAttributes().put("resource", resource);
045        }
046
047        if (null != url) {
048            if (!url.startsWith("/")) {
049                throw new IllegalArgumentException("The URL must begin with /");
050            }
051            component.getAttributes().put("url", url);
052        }
053
054    }
055
056    @Override
057    public void release() {
058        super.release();
059        resource = null;
060        url = null;
061    }
062
063    /* property accessors */
064    public String getUrl() {
065        return url;
066    }
067
068    public void setUrl(String url) {
069        this.url = url;
070    }
071
072    public String getResource() {
073        return resource;
074    }
075
076    public void setResource(String resource) {
077        this.resource = resource;
078    }
079
080}