001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.resource; 018 019import java.util.List; 020import java.util.Locale; 021 022import org.apache.wicket.Application; 023import org.apache.wicket.markup.head.HeaderItem; 024import org.apache.wicket.markup.head.JavaScriptHeaderItem; 025import org.apache.wicket.request.resource.JavaScriptResourceReference; 026import org.apache.wicket.request.resource.ResourceReference; 027 028/** 029 * Base class for JavaScript resources that are JQuery plugins. This class already defines a 030 * dependency on JQuery. 031 * 032 * @author papegaaij 033 */ 034public class JQueryPluginResourceReference extends JavaScriptResourceReference 035{ 036 private static final long serialVersionUID = 1L; 037 038 /** 039 * Creates a new {@code JQueryPluginResourceReference} 040 * 041 * @param scope 042 * mandatory parameter 043 * @param name 044 * mandatory parameter 045 */ 046 public JQueryPluginResourceReference(Class<?> scope, String name) 047 { 048 super(scope, name); 049 } 050 051 /** 052 * Creates a new {@code JQueryPluginResourceReference} 053 * 054 * @param scope 055 * mandatory parameter 056 * @param name 057 * mandatory parameter 058 * @param locale 059 * resource locale 060 * @param style 061 * resource style 062 * @param variation 063 * resource variation 064 */ 065 public JQueryPluginResourceReference(Class<?> scope, String name, Locale locale, String style, 066 String variation) 067 { 068 super(scope, name, locale, style, variation); 069 } 070 071 @Override 072 public List<HeaderItem> getDependencies() 073 { 074 final ResourceReference backingLibraryReference; 075 if (Application.exists()) 076 { 077 backingLibraryReference = Application.get() 078 .getJavaScriptLibrarySettings() 079 .getJQueryReference(); 080 } 081 else 082 { 083 backingLibraryReference = JQueryResourceReference.getV3(); 084 } 085 List<HeaderItem> dependencies = super.getDependencies(); 086 dependencies.add(JavaScriptHeaderItem.forReference(backingLibraryReference)); 087 return dependencies; 088 } 089}