1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.image

File ImagePluginAPI.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

0
12
4
1
109
46
6
0.5
3
4
1.5

Classes

Class Line # Actions
ImagePluginAPI 39 12 0% 6 16
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.plugin.image;
21   
22    import org.slf4j.Logger;
23    import org.slf4j.LoggerFactory;
24    import org.xwiki.model.reference.DocumentReference;
25    import org.xwiki.model.reference.DocumentReferenceResolver;
26   
27    import com.xpn.xwiki.XWikiContext;
28    import com.xpn.xwiki.XWikiException;
29    import com.xpn.xwiki.doc.XWikiAttachment;
30    import com.xpn.xwiki.doc.XWikiDocument;
31    import com.xpn.xwiki.plugin.PluginApi;
32    import com.xpn.xwiki.web.Utils;
33   
34    /**
35    * @version $Id: 9107374730990c0260a639c9dbf55c9a1c69921f $
36    * @deprecated the plugin technology is deprecated, consider rewriting as components
37    */
38    @Deprecated
 
39    public class ImagePluginAPI extends PluginApi<ImagePlugin>
40    {
41    /** Logging helper object. */
42    private static final Logger LOG = LoggerFactory.getLogger(ImagePluginAPI.class);
43   
44    /**
45    * Used to resolve a string into a proper Document Reference using the current document's reference to fill the
46    * blanks, except for the page name for which the default page name is used instead and for the wiki name for which
47    * the current wiki is used instead of the current document reference's wiki.
48    */
49    private DocumentReferenceResolver<String> currentMixedDocumentReferenceResolver =
50    Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
51   
52    /**
53    * Creates a new instance of this plugin API.
54    *
55    * @param imagePlugin the underlying image plugin that is exposed by this API
56    * @param context the XWiki context
57    */
 
58  0 toggle public ImagePluginAPI(ImagePlugin imagePlugin, XWikiContext context)
59    {
60  0 super(imagePlugin, context);
61    }
62   
63    /**
64    * Detects the height of an image attached to a wiki page.
65    *
66    * @param pageName the name of a wiki page
67    * @param attachmentName the name of an image attached to the specified page
68    * @return the height of the specified image
69    */
 
70  0 toggle public int getHeight(String pageName, String attachmentName)
71    {
72  0 try {
73  0 return getProtectedPlugin().getHeight(getAttachment(pageName, attachmentName), getXWikiContext());
74    } catch (Exception e) {
75  0 LOG.error(String.format("Failed to detect the height of %s attached to %s.", attachmentName, pageName), e);
76  0 return -1;
77    }
78    }
79   
80    /**
81    * Detects the width of an image attached to a wiki page.
82    *
83    * @param pageName the name of a wiki page
84    * @param attachmentName the name of an image attached to the specified page
85    * @return the width of the specified image
86    */
 
87  0 toggle public int getWidth(String pageName, String attachmentName)
88    {
89  0 try {
90  0 return getProtectedPlugin().getWidth(getAttachment(pageName, attachmentName), getXWikiContext());
91    } catch (Exception e) {
92  0 LOG.error(String.format("Failed to detect the width of %s attached to %s.", attachmentName, pageName), e);
93  0 return -1;
94    }
95    }
96   
97    /**
98    * @param pageName the name of a wiki page
99    * @param attachmentName the name of an attachment of the specified page
100    * @return the specified attachment
101    * @throws XWikiException if retrieving the attachment fails
102    */
 
103  0 toggle private XWikiAttachment getAttachment(String pageName, String attachmentName) throws XWikiException
104    {
105  0 DocumentReference documentReference = this.currentMixedDocumentReferenceResolver.resolve(pageName);
106  0 XWikiDocument document = getXWikiContext().getWiki().getDocument(documentReference, getXWikiContext());
107  0 return document.getAttachment(attachmentName);
108    }
109    }