Hey Sergiu,
line 58 is failing checkstyle for being 2 characters too long.
* @return HTML code linking to the pulled resource (eg: <script
type="text/javascript" src="/this/url.js"></script>)
Thanks again,
Caleb
sdumitriu (SVN) wrote:
> Author: sdumitriu
> Date: 2009-10-10 01:04:21 +0200 (Sat, 10 Oct 2009)
> New Revision: 24354
>
> Added:
>
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/AbstractResourceSkinExtensionPlugin.java
> Modified:
>
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/CssResourceSkinExtensionPlugin.java
>
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/JsResourceSkinExtensionPlugin.java
> Log:
> XSKINX-29: Refactor duplicate code
> Refactor JsResourceSkinExtensionPlugin and CssResourceSkinExtensionPlugin.
> Patch from Caleb James DeLisle, applied with several changes.
>
>
> Added:
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/AbstractResourceSkinExtensionPlugin.java
> ===================================================================
> ---
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/AbstractResourceSkinExtensionPlugin.java
> (rev 0)
> +++
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/AbstractResourceSkinExtensionPlugin.java
> 2009-10-09 23:04:21 UTC (rev 24354)
> @@ -0,0 +1,102 @@
> +/*
> + * See the NOTICE file distributed with this work for additional
> + * information regarding copyright ownership.
> + *
> + * This is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as
> + * published by the Free Software Foundation; either version 2.1 of
> + * the License, or (at your option) any later version.
> + *
> + * This software is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this software; if not, write to the Free
> + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
> + */
> +package com.xpn.xwiki.plugin.skinx;
> +
> +import java.util.Collections;
> +import java.util.Set;
> +
> +import com.xpn.xwiki.XWikiContext;
> +import com.xpn.xwiki.XWikiException;
> +
> +/**
> + * Skin Extension plugin to use extension files from JAR resources.
> + * @version $Id$
> + */
> +public abstract class AbstractResourceSkinExtensionPlugin extends
> AbstractSkinExtensionPlugin
> +{
> + /**
> + * XWiki plugin constructor.
> + *
> + * @param name The name of the plugin, which can be used for retrieving
> the plugin API from velocity. Unused.
> + * @param className The canonical classname of the plugin. Unused.
> + * @param context The current request context.
> + * @see
> com.xpn.xwiki.plugin.XWikiDefaultPlugin#XWikiDefaultPlugin(String,String,com.xpn.xwiki.XWikiContext)
> + */
> + public AbstractResourceSkinExtensionPlugin(String name, String
> className, XWikiContext context)
> + {
> + super(name, className, context);
> + }
> +
> + /**
> + * Get the action which the url should specify for calling this resource.
> + *
> + * @return String Action name.
> + */
> + protected abstract String getAction();
> +
> + /**
> + * Takes a URL string and outputs a link which will cause the browser to
> load the url.
> + *
> + * @param url String representation of the url to load (eg:
> "/this/url.js")
> + * @return HTML code linking to the pulled resource (eg: <script
> type="text/javascript" src="/this/url.js"></script>)
> + */
> + protected abstract String generateLink(String url);
> +
> + /**
> + * {...@inheritdoc}
> + *
> + * @see AbstractSkinExtensionPlugin#getLink(String, XWikiContext)
> + */
> + public String getLink(String resourceName, XWikiContext context)
> + {
> + // If the current user has access to Main.WebHome, we will use this
> document in the URL
> + // to serve the resource. This way, the resource can be efficiently
> cached, since it has a
> + // common URL for any page.
> + try {
> + String page = context.getWiki().getDefaultWeb(context) + "." +
> context.getWiki().getDefaultPage(context);
> + if (!context.getWiki().getRightService().hasAccessLevel("view",
> context.getUser(), page, context)) {
> + page = context.getDoc().getFullName();
> + }
> + return generateLink(context.getWiki().getURL(page, getAction(),
> + "resource=" + resourceName +
> parametersAsQueryString(resourceName, context), context));
> + } catch (XWikiException e) {
> + // Do nothing here; we can't access the wiki, so don't link to
> this resource at all.
> + return "";
> + }
> + }
> +
> + /**
> + * {...@inheritdoc}
> + * <p>
> + * There is no support for always used resource-based extensions yet.
> + * </p>
> + *
> + * @see AbstractSkinExtensionPlugin#getAlwaysUsedExtensions(XWikiContext)
> + */
> + @Override
> + public Set<String> getAlwaysUsedExtensions(XWikiContext context)
> + {
> + // There is no mean to define an always used extension for something
> else than a document extension now,
> + // so for resources-based extensions, we return an emtpy set.
> + // An idea for the future could be to have an API for plugins and
> components to register always used resources
> + // extensions.
> + return Collections.emptySet();
> + }
> +}
>
>
> Property changes on:
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/AbstractResourceSkinExtensionPlugin.java
> ___________________________________________________________________
> Name: svn:keywords
> + Id
> Name: svn:eol-style
> + native
>
> Modified:
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/CssResourceSkinExtensionPlugin.java
> ===================================================================
> ---
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/CssResourceSkinExtensionPlugin.java
> 2009-10-09 18:28:50 UTC (rev 24353)
> +++
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/CssResourceSkinExtensionPlugin.java
> 2009-10-09 23:04:21 UTC (rev 24354)
> @@ -20,11 +20,7 @@
> */
> package com.xpn.xwiki.plugin.skinx;
>
> -import java.util.Collections;
> -import java.util.Set;
> -
> import com.xpn.xwiki.XWikiContext;
> -import com.xpn.xwiki.XWikiException;
>
> /**
> * Skin Extension plugin to use css files from JAR resources.
> @@ -32,7 +28,7 @@
> * @version $Id$
> * @since 1.3
> */
> -public class CssResourceSkinExtensionPlugin extends
> AbstractSkinExtensionPlugin
> +public class CssResourceSkinExtensionPlugin extends
> AbstractResourceSkinExtensionPlugin
> {
> /**
> * XWiki plugin constructor.
> @@ -45,7 +41,6 @@
> public CssResourceSkinExtensionPlugin(String name, String className,
> XWikiContext context)
> {
> super(name, className, context);
> - init(context);
> }
>
> /**
> @@ -61,47 +56,22 @@
>
> /**
> * {...@inheritdoc}
> - *
> - * @see AbstractSkinExtensionPlugin#getLink(String, XWikiContext)
> + *
> + * @see AbstractSkinExtensionPlugin#getAction()
> */
> - @Override
> - public String getLink(String documentName, XWikiContext context)
> + protected String getAction()
> {
> - String result = "";
> - // If the current user has access to Main.WebHome, we will use this
> document in the URL
> - // to serve the css resource. This way, the resource can be
> efficiently cached, since it has a
> - // common URL for any page.
> - try {
> - String page = context.getWiki().getDefaultWeb(context) + "." +
> context.getWiki().getDefaultPage(context);
> - if (!context.getWiki().getRightService().hasAccessLevel("view",
> context.getUser(), page, context)) {
> - page = context.getDoc().getFullName();
> - }
> - String url =
> - context.getWiki().getURL(page, "ssx",
> - "resource=" + documentName +
> parametersAsQueryString(documentName, context), context);
> - result = "<link rel='stylesheet' type='text/css' href='" + url +
> "'/>";
> - } catch (XWikiException e) {
> - // Do nothing here; we can't access the wiki, so don't link to
> this resource at all.
> - }
> - return result;
> + return "ssx";
> }
>
> /**
> * {...@inheritdoc}
> - * <p>
> - * There is no support for always used resource-based extensions yet.
> - * </p>
> - *
> - * @see AbstractSkinExtensionPlugin#getAlwaysUsedExtensions(XWikiContext)
> + *
> + * @see AbstractSkinExtensionPlugin#generateLink()
> */
> - @Override
> - public Set<String> getAlwaysUsedExtensions(XWikiContext context)
> + protected String generateLink(String url)
> {
> - // There is no mean to define an always used extension for something
> else than a document extension now,
> - // so for resources-based extensions, we return an emtpy set.
> - // An idea for the future could be to have an API for plugins and
> components to register always used resources
> - // extensions.
> - return Collections.emptySet();
> + return "<link rel='stylesheet' type='text/css' href='" + url +
> "'/>\n";
> }
>
> /**
>
> Modified:
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/JsResourceSkinExtensionPlugin.java
> ===================================================================
> ---
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/JsResourceSkinExtensionPlugin.java
> 2009-10-09 18:28:50 UTC (rev 24353)
> +++
> platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/JsResourceSkinExtensionPlugin.java
> 2009-10-09 23:04:21 UTC (rev 24354)
> @@ -20,11 +20,7 @@
> */
> package com.xpn.xwiki.plugin.skinx;
>
> -import java.util.Collections;
> -import java.util.Set;
> -
> import com.xpn.xwiki.XWikiContext;
> -import com.xpn.xwiki.XWikiException;
>
> /**
> * Skin Extension plugin that allows pulling javascript files from JAR
> resources.
> @@ -32,7 +28,7 @@
> * @version $Id$
> * @since 1.3
> */
> -public class JsResourceSkinExtensionPlugin extends
> AbstractSkinExtensionPlugin
> +public class JsResourceSkinExtensionPlugin extends
> AbstractResourceSkinExtensionPlugin
> {
> /**
> * XWiki plugin constructor.
> @@ -44,57 +40,42 @@
> */
> public JsResourceSkinExtensionPlugin(String name, String className,
> XWikiContext context)
> {
> - super("jsrx", className, context);
> - init(context);
> + super(name, className, context);
> }
>
> /**
> * {...@inheritdoc}
> *
> - * @see AbstractSkinExtensionPlugin#getLink(String, XWikiContext)
> + * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#getName()
> */
> @Override
> - public String getLink(String documentName, XWikiContext context)
> + public String getName()
> {
> - String result = "";
> - // If the current user has access to Main.WebHome, we will use this
> document in the URL
> - // to serve the js resource. This way, the resource can be
> efficiently cached, since it has a
> - // common URL for any page.
> - try {
> - String page = context.getWiki().getDefaultWeb(context) + "." +
> context.getWiki().getDefaultPage(context);
> - if (!context.getWiki().getRightService().hasAccessLevel("view",
> context.getUser(), page, context)) {
> - page = context.getDoc().getFullName();
> - }
> - String url =
> - context.getWiki().getURL(page, "jsx",
> - "resource=" + documentName +
> parametersAsQueryString(documentName, context), context);
> - result = "<script type=\"text/javascript\" src=\"" + url +
> "\"></script>";
> - } catch (XWikiException e) {
> - // Do nothing here; we can't access the wiki, so don't link to
> this resource at all.
> - }
> - return result;
> + return "jsrx";
> }
>
> /**
> * {...@inheritdoc}
> - * <p>
> - * There is no support for always used resource-based extensions yet.
> - * </p>
> - *
> - * @see AbstractSkinExtensionPlugin#getAlwaysUsedExtensions(XWikiContext)
> + *
> + * @see AbstractSkinExtensionPlugin#getAction()
> */
> - @Override
> - public Set<String> getAlwaysUsedExtensions(XWikiContext context)
> + protected String getAction()
> {
> - // There is no mean to define an always used extension for something
> else than a document extension now,
> - // so for resources-based extensions, we return an emtpy set.
> - // An idea for the future could be to have an API for plugins and
> components to register always used resources
> - // extensions.
> - return Collections.emptySet();
> + return "jsx";
> }
>
> /**
> * {...@inheritdoc}
> + *
> + * @see AbstractSkinExtensionPlugin#generateLink()
> + */
> + protected String generateLink(String url)
> + {
> + return "<script type=\"text/javascript\" src=\"" + url +
> "\"></script>\n";
> + }
> +
> + /**
> + * {...@inheritdoc}
> * <p>
> * We must override this method since the plugin manager only calls it
> for classes that provide their own
> * implementation, and not an inherited one.
>
> _______________________________________________
> notifications mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/notifications
>
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs