001 /*
002 * Databinder: a simple bridge from Wicket to Hibernate
003 * Copyright (C) 2006 Nathan Hamblen nathan@technically.us
004
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either
008 * version 2.1 of the License, or (at your option) any later version.
009 *
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013 * Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public
016 * License along with this library; if not, write to the Free Software
017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
018 */
019 package net.databinder.components;
020
021 import org.apache.wicket.markup.ComponentTag;
022 import org.apache.wicket.markup.html.resources.PackagedResourceReference;
023
024 /**
025 * Component for a stylesheet link. The stylesheet is expected to be named
026 * <ClassName>.css for the class specified in the constructor and be located in
027 * the same package as that class.
028 * @author Nathan Hamblen
029 */
030 public class StyleLink extends PackagedResourceReference {
031
032 /** Builds a StyleLinkbased on the given class. */
033 public StyleLink(String id, Class pageClass) {
034 super(id, pageClass, pageClass.getSimpleName() + ".css", "href");
035 }
036
037 protected StyleLink(String id, Class pageClass, String filename) {
038 super(id, pageClass, filename, "href");
039 }
040
041 /** Sets appropriate href, type, and rel values for the stylesheet. */
042 @Override
043 protected void onComponentTag(ComponentTag tag) {
044 // ensure valid css tag
045 checkComponentTag(tag, "link");
046 tag.put("type", "text/css");
047 tag.put("rel", "stylesheet");
048 super.onComponentTag(tag);
049 }
050 }