Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xwiki-platform
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XWiki
xwiki-platform
Commits
0c6c5b26
Commit
0c6c5b26
authored
2 years ago
by
Manuel Leduc
Browse files
Options
Downloads
Patches
Plain Diff
[Misc] ImagePlugin code cleanup
parent
8f4737cf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
xwiki-platform-core/xwiki-platform-image/xwiki-platform-image-processing/xwiki-platform-image-processing-plugin/src/main/java/com/xpn/xwiki/plugin/image/ImagePlugin.java
+30
-30
30 additions, 30 deletions
...src/main/java/com/xpn/xwiki/plugin/image/ImagePlugin.java
with
30 additions
and
30 deletions
xwiki-platform-core/xwiki-platform-image/xwiki-platform-image-processing/xwiki-platform-image-processing-plugin/src/main/java/com/xpn/xwiki/plugin/image/ImagePlugin.java
+
30
−
30
View file @
0c6c5b26
...
...
@@ -33,6 +33,7 @@
import
org.xwiki.cache.CacheException
;
import
org.xwiki.cache.CacheManager
;
import
org.xwiki.cache.config.CacheConfiguration
;
import
org.xwiki.cache.eviction.EntryEvictionConfiguration
;
import
org.xwiki.cache.eviction.LRUEvictionConfiguration
;
import
com.xpn.xwiki.XWikiContext
;
...
...
@@ -88,7 +89,7 @@ public class ImagePlugin extends XWikiDefaultPlugin
* @param name the name of the plugin
* @param className the class name
* @param context the XWiki context
* @see XWikiDefaultPlugin#XWikiDefaultPlugin(String,String,com.xpn.xwiki.XWikiContext)
* @see XWikiDefaultPlugin#XWikiDefaultPlugin(String,
String,
com.xpn.xwiki.XWikiContext)
*/
public
ImagePlugin
(
String
name
,
String
className
,
XWikiContext
context
)
{
...
...
@@ -131,7 +132,7 @@ public void init(XWikiContext context)
}
/**
* Tries to initialize
s
the image cache. If the initialization fails the image cache remains {@code null}.
* Tries to initialize the image cache. If the initialization fails the image cache remains {@code null}.
*
* @param context the XWiki context
*/
...
...
@@ -144,7 +145,7 @@ private void initCache(XWikiContext context)
// Set cache constraints.
LRUEvictionConfiguration
lru
=
new
LRUEvictionConfiguration
();
configuration
.
put
(
LRU
EvictionConfiguration
.
CONFIGURATIONID
,
lru
);
configuration
.
put
(
Entry
EvictionConfiguration
.
CONFIGURATIONID
,
lru
);
String
capacityParam
=
context
.
getWiki
().
Param
(
"xwiki.plugin.image.cache.capacity"
);
if
(!
StringUtils
.
isBlank
(
capacityParam
)
&&
StringUtils
.
isNumeric
(
capacityParam
.
trim
()))
{
...
...
@@ -209,9 +210,7 @@ public XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiConte
float
quality
=
-
1
;
try
{
quality
=
Float
.
parseFloat
(
context
.
getRequest
().
getParameter
(
"quality"
));
}
catch
(
NumberFormatException
e
)
{
// Ignore.
}
catch
(
NullPointerException
e
)
{
}
catch
(
NumberFormatException
|
NullPointerException
e
)
{
// Ignore.
}
...
...
@@ -233,10 +232,10 @@ public XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiConte
* Transforms the given image (i.e. shrinks the image and changes its quality) before it is downloaded.
*
* @param image the image to be downloaded
* @param width the desired image width; this value is taken into account only if it is greater than zero and
less
*
than the current image width
* @param height the desired image height; this value is taken into account only if it is greater than zero and
less
*
than the current image height
* @param width the desired image width; this value is taken into account only if it is greater than zero and
*
less
than the current image width
* @param height the desired image height; this value is taken into account only if it is greater than zero and
*
less
than the current image height
* @param quality the desired compression quality
* @param context the XWiki context
* @return the transformed image
...
...
@@ -267,11 +266,12 @@ private XWikiAttachment downloadImage(XWikiAttachment image, int width, int heig
* Downloads the given image from cache.
*
* @param image the image to be downloaded
* @param width the desired image width; this value is taken into account only if it is greater than zero and less
* than the current image width
* @param height the desired image height; this value is taken into account only if it is greater than zero and less
* than the current image height
* @param keepAspectRatio {@code true} to preserve aspect ratio when resizing the image, {@code false} otherwise
* @param width the desired image width; this value is taken into account only if it is greater than zero and
* less than the current image width
* @param height the desired image height; this value is taken into account only if it is greater than zero and
* less than the current image height
* @param keepAspectRatio {@code true} to preserve aspect ratio when resizing the image, {@code false}
* otherwise
* @param quality the desired compression quality
* @param context the XWiki context
* @return the transformed image
...
...
@@ -296,13 +296,13 @@ private XWikiAttachment downloadImageFromCache(XWikiAttachment image, int width,
* compression quality. This helps decreasing the time needed to download the image attachment.
*
* @param attachment the image to be shrunk
* @param requestedWidth the desired image width; this value is taken into account only if it is greater than
zero
*
and less than the current image width
* @param requestedHeight the desired image height; this value is taken into account only if it is greater than
zero
*
and less than the current image height
* @param keepAspectRatio {@code true} to preserve the image aspect ratio even when both requested dimensions
are
*
properly specified (in this case the image will be resized to best fit the rectangle with the
*
requested
width and height), {@code false} otherwise
* @param requestedWidth the desired image width; this value is taken into account only if it is greater than
*
zero
and less than the current image width
* @param requestedHeight the desired image height; this value is taken into account only if it is greater than
*
zero
and less than the current image height
* @param keepAspectRatio {@code true} to preserve the image aspect ratio even when both requested dimensions
*
are
properly specified (in this case the image will be resized to best fit the rectangle with the
requested
* width and height), {@code false} otherwise
* @param requestedQuality the desired compression quality
* @param context the XWiki context
* @return the modified image attachment
...
...
@@ -332,7 +332,7 @@ private XWikiAttachment shrinkImage(XWikiAttachment attachment, int requestedWid
RenderedImage
shrunkImage
=
this
.
imageProcessor
.
scaleImage
(
image
,
dimensions
[
0
],
dimensions
[
1
]);
// Create an image attachment for the shrunk image.
XWikiAttachment
thumbnail
=
(
XWikiAttachment
)
attachment
.
clone
();
XWikiAttachment
thumbnail
=
attachment
.
clone
();
thumbnail
.
loadAttachmentContent
(
context
);
OutputStream
acos
=
thumbnail
.
getAttachment_content
().
getContentOutputStream
();
...
...
@@ -355,13 +355,13 @@ private XWikiAttachment shrinkImage(XWikiAttachment attachment, int requestedWid
*
* @param currentWidth the current image width
* @param currentHeight the current image height
* @param requestedWidth the desired image width; this value is taken into account only if it is greater than
zero
*
and less than the current image width
* @param requestedHeight the desired image height; this value is taken into account only if it is greater than
zero
*
and less than the current image height
* @param keepAspectRatio {@code true} to preserve the image aspect ratio even when both requested dimensions
are
*
properly specified (in this case the image will be resized to best fit the rectangle with the
*
requested
width and height), {@code false} otherwise
* @param requestedWidth the desired image width; this value is taken into account only if it is greater than
*
zero
and less than the current image width
* @param requestedHeight the desired image height; this value is taken into account only if it is greater than
*
zero
and less than the current image height
* @param keepAspectRatio {@code true} to preserve the image aspect ratio even when both requested dimensions
*
are
properly specified (in this case the image will be resized to best fit the rectangle with the
requested
* width and height), {@code false} otherwise
* @return new width and height values
*/
private
int
[]
reduceImageDimensions
(
int
currentWidth
,
int
currentHeight
,
int
requestedWidth
,
int
requestedHeight
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment