You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
(39) |
Dec
(10) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(19) |
Feb
(150) |
Mar
(10) |
Apr
|
May
(8) |
Jun
(11) |
Jul
(27) |
Aug
(52) |
Sep
(35) |
Oct
(30) |
Nov
(18) |
Dec
(4) |
2008 |
Jan
(76) |
Feb
(121) |
Mar
(39) |
Apr
(55) |
May
(18) |
Jun
(49) |
Jul
(32) |
Aug
(4) |
Sep
(10) |
Oct
|
Nov
(3) |
Dec
(33) |
2009 |
Jan
(19) |
Feb
(87) |
Mar
(69) |
Apr
(38) |
May
(47) |
Jun
(20) |
Jul
(5) |
Aug
(76) |
Sep
(145) |
Oct
(34) |
Nov
(8) |
Dec
(68) |
2010 |
Jan
(150) |
Feb
(379) |
Mar
(191) |
Apr
(100) |
May
(525) |
Jun
(269) |
Jul
(127) |
Aug
(190) |
Sep
(190) |
Oct
(29) |
Nov
(147) |
Dec
(83) |
2011 |
Jan
(188) |
Feb
(81) |
Mar
(43) |
Apr
(97) |
May
(63) |
Jun
(129) |
Jul
(17) |
Aug
(124) |
Sep
(6) |
Oct
(20) |
Nov
(67) |
Dec
(23) |
2012 |
Jan
(6) |
Feb
(14) |
Mar
(181) |
Apr
(64) |
May
(102) |
Jun
(47) |
Jul
(26) |
Aug
(3) |
Sep
(1) |
Oct
(14) |
Nov
(13) |
Dec
(23) |
2013 |
Jan
(4) |
Feb
(14) |
Mar
(18) |
Apr
(14) |
May
(27) |
Jun
(27) |
Jul
(5) |
Aug
(2) |
Sep
(74) |
Oct
(79) |
Nov
(21) |
Dec
(97) |
2014 |
Jan
(6) |
Feb
(3) |
Mar
(8) |
Apr
|
May
(5) |
Jun
|
Jul
(9) |
Aug
(6) |
Sep
(3) |
Oct
(10) |
Nov
(6) |
Dec
|
2015 |
Jan
|
Feb
|
Mar
(1) |
Apr
(25) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fg...@us...> - 2009-02-15 22:23:17
|
Revision: 1001 http://openutils.svn.sourceforge.net/openutils/?rev=1001&view=rev Author: fgiust Date: 2009-02-15 21:42:05 +0000 (Sun, 15 Feb 2009) Log Message: ----------- Initialized merge tracking via "svnmerge" with revisions "1-960" from https://openutils.svn.sourceforge.net/svnroot/openutils/trunk/openutils-mgnlmedia Property Changed: ---------------- branches/openutils-mgnlmedia-3.6.x/ Property changes on: branches/openutils-mgnlmedia-3.6.x ___________________________________________________________________ Added: svnmerge-integrated + /trunk/openutils-mgnlmedia:1-960 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2009-02-15 22:23:09
|
Revision: 1003 http://openutils.svn.sourceforge.net/openutils/?rev=1003&view=rev Author: fgiust Date: 2009-02-15 22:01:47 +0000 (Sun, 15 Feb 2009) Log Message: ----------- update scm url Modified Paths: -------------- branches/openutils-mgnlmedia-3.6.x/pom.xml Property Changed: ---------------- branches/openutils-mgnlmedia-3.6.x/ Property changes on: branches/openutils-mgnlmedia-3.6.x ___________________________________________________________________ Modified: svn:ignore - .settings .checkstyle .classpath .project target test-output temp-testng-customsuite.xml + .settings .checkstyle .classpath .project target test-output temp-testng-customsuite.xml svnmerge-commit-message.txt Modified: branches/openutils-mgnlmedia-3.6.x/pom.xml =================================================================== --- branches/openutils-mgnlmedia-3.6.x/pom.xml 2009-02-15 21:55:30 UTC (rev 1002) +++ branches/openutils-mgnlmedia-3.6.x/pom.xml 2009-02-15 22:01:47 UTC (rev 1003) @@ -17,6 +17,11 @@ <url>http://www.gnu.org/licenses/gpl-3.0.txt</url> </license> </licenses> + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/branches/openutils-mgnlmedia-3.6.x/</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/branches/openutils-mgnlmedia-3.6.x/</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/branches/openutils-mgnlmedia-3.6.x/</url> + </scm> <build> <resources> <resource> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2009-02-15 22:22:38
|
Revision: 1000 http://openutils.svn.sourceforge.net/openutils/?rev=1000&view=rev Author: fgiust Date: 2009-02-15 21:33:35 +0000 (Sun, 15 Feb 2009) Log Message: ----------- changelog Modified Paths: -------------- trunk/openutils-mgnlmedia/src/site/changes/changes.xml Modified: trunk/openutils-mgnlmedia/src/site/changes/changes.xml =================================================================== --- trunk/openutils-mgnlmedia/src/site/changes/changes.xml 2009-02-15 20:58:20 UTC (rev 999) +++ trunk/openutils-mgnlmedia/src/site/changes/changes.xml 2009-02-15 21:33:35 UTC (rev 1000) @@ -11,5 +11,9 @@ <release version="0.1" date="2008-12-04" description=""> <action type="add" dev="fgiust">first alpha release</action> </release> + <release version="3.6" date="2009-02-15" description=""> + <action type="add" dev="fgiust">Added support for reading CMYK/YCCK jpegs</action> + <action type="update" dev="fgiust">Stable release for Magnolia 3.6.x</action> + </release> </body> </document> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2009-02-15 20:58:31
|
Revision: 999 http://openutils.svn.sourceforge.net/openutils/?rev=999&view=rev Author: fgiust Date: 2009-02-15 20:58:20 +0000 (Sun, 15 Feb 2009) Log Message: ----------- adding support for CMYK/YCCK jpegs Modified Paths: -------------- trunk/openutils-mgnlmedia/pom.xml trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html Added Paths: ----------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/BadImageFormatException.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java trunk/openutils-mgnlmedia/src/test/java/net/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/FileNodeData.java trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtilsTest.java trunk/openutils-mgnlmedia/src/test/resources/images/ trunk/openutils-mgnlmedia/src/test/resources/images/badimage.jpg trunk/openutils-mgnlmedia/src/test/resources/images/badimage.txt trunk/openutils-mgnlmedia/src/test/resources/images/ycck.jpg Property Changed: ---------------- trunk/openutils-mgnlmedia/ Property changes on: trunk/openutils-mgnlmedia ___________________________________________________________________ Modified: svn:ignore - .settings .checkstyle .classpath .project target + .settings .checkstyle .classpath .project target test-output temp-testng-customsuite.xml Modified: trunk/openutils-mgnlmedia/pom.xml =================================================================== --- trunk/openutils-mgnlmedia/pom.xml 2009-02-13 17:53:26 UTC (rev 998) +++ trunk/openutils-mgnlmedia/pom.xml 2009-02-15 20:58:20 UTC (rev 999) @@ -1,4 +1,5 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <groupId>net.sourceforge.openutils</groupId> <artifactId>openutils</artifactId> @@ -56,6 +57,11 @@ <version>2.1</version> </dependency> <dependency> + <groupId>com.drewnoakes</groupId> + <artifactId>metadata-extractor</artifactId> + <version>2.4.0-beta-1</version> + </dependency> + <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <classifier>jdk15</classifier> Added: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/BadImageFormatException.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/BadImageFormatException.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/BadImageFormatException.java 2009-02-15 20:58:20 UTC (rev 999) @@ -0,0 +1,32 @@ +package net.sourceforge.openutils.mgnlmedia.media.utils; + +/** + * @author fgiust + * @version $Id$ + */ +public class BadImageFormatException extends RuntimeException +{ + + /** + * Stable serialVersionUID. + */ + private static final long serialVersionUID = 42L; + + /** + * @param message + */ + public BadImageFormatException(String message) + { + super(message); + } + + /** + * @param message + * @param cause + */ + public BadImageFormatException(String message, Throwable cause) + { + super(message, cause); + } + +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/BadImageFormatException.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-02-13 17:53:26 UTC (rev 998) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-02-15 20:58:20 UTC (rev 999) @@ -51,6 +51,7 @@ import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager; import net.sourceforge.openutils.mgnlmedia.media.lifecycle.MediaModuleLifecycle; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.ClassUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; @@ -364,7 +365,7 @@ } } - private static InputStream getStream(BufferedImage image, String extension) throws IOException + public static InputStream getStream(BufferedImage image, String extension) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); BufferedOutputStream out = new BufferedOutputStream(bos); @@ -497,16 +498,9 @@ } extension = "jpg"; } - BufferedImage original; - try - { - original = ImageIO.read(image.getStream()); - } - catch (IOException e) - { - throw new RuntimeException(e); - } + BufferedImage original = createBufferedImage(image); + String resolutionName = "res-" + resolution; BufferedImage img = ImageUtils.getImageForResolution(original, resolution); @@ -617,4 +611,36 @@ return "jpg"; } } + + /** + * @param image + * @return + */ + public static BufferedImage createBufferedImage(NodeData image) + { + InputStream is = image.getStream(); + try + { + return ImageIO.read(is); + } + catch (IOException e) + { + // CMYK jpeg can't be read be ImageIO + // Caused by: javax.imageio.IIOException: Unsupported Image Type + BufferedImage result = JpegUtils.processNonStandardImage(image); + + if (result == null) + { + // throw the original exception back + throw new BadImageFormatException("Unable to handle " + image.getHandle(), e); + } + return result; + + } + finally + { + IOUtils.closeQuietly(is); + } + } + } Added: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java 2009-02-15 20:58:20 UTC (rev 999) @@ -0,0 +1,198 @@ +package net.sourceforge.openutils.mgnlmedia.media.utils; + +import info.magnolia.cms.core.NodeData; + +import java.awt.Transparency; +import java.awt.color.ColorSpace; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.ComponentColorModel; +import java.awt.image.DataBuffer; +import java.awt.image.DataBufferByte; +import java.awt.image.Raster; +import java.awt.image.WritableRaster; +import java.io.IOException; +import java.io.InputStream; +import java.util.Iterator; + +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.stream.ImageInputStream; + +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.drew.imaging.jpeg.JpegProcessingException; +import com.drew.imaging.jpeg.JpegSegmentReader; + + +/** + * Utility class for handling of CMYK/YCCK jpegs. + * @author fgiust + * @version $Id$ + */ +public class JpegUtils +{ + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(JpegUtils.class); + + /** + * Java's ImageIO can't process 4-component images and Java2D can't apply AffineTransformOp either, so convert + * raster data to RGB. Technique due to MArk Stephens. Free for any use. See + * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4799903 or + * http://www.mail-archive.com/jav...@ca.../msg03247.html + */ + public static BufferedImage createJPEG4(Raster raster, boolean ycckProfile) + { + int w = raster.getWidth(); + int h = raster.getHeight(); + byte[] rgb = new byte[w * h * 3]; + + // if (Adobe_APP14 and transform==2) then YCCK else CMYK + if (ycckProfile) + { // YCCK -- Adobe + + float[] Y = raster.getSamples(0, 0, w, h, 0, (float[]) null); + float[] Cb = raster.getSamples(0, 0, w, h, 1, (float[]) null); + float[] Cr = raster.getSamples(0, 0, w, h, 2, (float[]) null); + float[] K = raster.getSamples(0, 0, w, h, 3, (float[]) null); + + for (int i = 0, imax = Y.length, base = 0; i < imax; i++, base += 3) + { + float k = 220 - K[i], y = 255 - Y[i], cb = 255 - Cb[i], cr = 255 - Cr[i]; + + double val = y + 1.402 * (cr - 128) - k; + val = (val - 128) * .65f + 128; + rgb[base] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5); + + val = y - 0.34414 * (cb - 128) - 0.71414 * (cr - 128) - k; + val = (val - 128) * .65f + 128; + rgb[base + 1] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5); + + val = y + 1.772 * (cb - 128) - k; + val = (val - 128) * .65f + 128; + rgb[base + 2] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5); + } + + } + else + { + // assert xform==0: xform; // CMYK + + int[] C = raster.getSamples(0, 0, w, h, 0, (int[]) null); + int[] M = raster.getSamples(0, 0, w, h, 1, (int[]) null); + int[] Y = raster.getSamples(0, 0, w, h, 2, (int[]) null); + int[] K = raster.getSamples(0, 0, w, h, 3, (int[]) null); + + for (int i = 0, imax = C.length, base = 0; i < imax; i++, base += 3) + { + int c = 255 - C[i]; + int m = 255 - M[i]; + int y = 255 - Y[i]; + int k = 255 - K[i]; + float kk = k / 255f; + + rgb[base] = (byte) (255 - Math.min(255f, c * kk + k)); + rgb[base + 1] = (byte) (255 - Math.min(255f, m * kk + k)); + rgb[base + 2] = (byte) (255 - Math.min(255f, y * kk + k)); + } + } + + // from other image types we know InterleavedRaster's can be + // manipulated by AffineTransformOp, so create one of those. + raster = Raster.createInterleavedRaster( + new DataBufferByte(rgb, rgb.length), + w, + h, + w * 3, + 3, + new int[]{0, 1, 2 }, + null); + + ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); + ColorModel cm = new ComponentColorModel(cs, false, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); + return new BufferedImage(cm, (WritableRaster) raster, true, null); + } + + /** + * @param image + */ + public static BufferedImage processNonStandardImage(NodeData image) + { + InputStream is2 = image.getStream(); + try + { + // Get an ImageReader. + ImageInputStream input = ImageIO.createImageInputStream(is2); + Iterator readers = ImageIO.getImageReaders(input); + if (readers == null || !readers.hasNext()) + { + throw new RuntimeException("No ImageReaders found"); + } + + ImageReader reader = (ImageReader) readers.next(); + reader.setInput(input); + String format = reader.getFormatName(); + + if ("JPEG".equalsIgnoreCase(format) || "JPG".equalsIgnoreCase(format)) + { + Raster raster = reader.readRaster(0, reader.getDefaultReadParam()); + boolean ycckProfile = false; + + // yes, we need to read it once again to extract metadatas + InputStream is3 = image.getStream(); + try + { + + JpegSegmentReader segmentReader = new JpegSegmentReader(is3); + byte[] exifSegment = segmentReader.readSegment(JpegSegmentReader.SEGMENT_APPE); + + switch (exifSegment[11]) + { + case 2 : + ycckProfile = true; + break; + case 1 : + // "YCbCr" + break; + case 0 : + default : + // Unknown (RGB or CMYK) + break; + } + } + catch (JpegProcessingException e1) + { + log.warn("Unable to read color space"); + } + finally + { + IOUtils.closeQuietly(is3); + } + + if (input != null) + { + input.close(); + } + reader.dispose(); + + return createJPEG4(raster, ycckProfile); + } + throw new BadImageFormatException("No ImageReaders found for " + image.getHandle()); + + } + catch (IOException e1) + { + log.error("Unable to handle " + image.getHandle() + ": " + e1.getMessage(), e1); + throw new BadImageFormatException(image.getHandle(), e1); + } + finally + { + IOUtils.closeQuietly(is2); + } + } +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html 2009-02-13 17:53:26 UTC (rev 998) +++ trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html 2009-02-15 20:58:20 UTC (rev 999) @@ -9,16 +9,16 @@ <script type="text/javascript" src="${this.request.contextPath}/.resources/media/js/miframe.js"></script> <script type="text/javascript"> // <![CDATA[ -var viewport; -var nodeid = "${this.nodeid!''}"; -var selectMedia = ${this.selectMedia?string("true", "false")}; -var openPath = "${this.openPath!''}"; -var actMediaHandle = "${this.actMediaHandle!''}"; -var mediaType = "${this.mediaType!''}"; // get tree url -function getTreeUrl() { - var url = "${this.request.contextPath}/.magnolia/trees/media.html?mgnlCK=" + (new Date()).getTime(); +var viewport; +var nodeid = "${this.nodeid!''}"; +var selectMedia = ${this.selectMedia?string("true", "false")}; +var openPath = "${this.openPath!''}"; +var actMediaHandle = "${this.actMediaHandle!''}"; +var mediaType = "${this.mediaType!''}"; // get tree url +function getTreeUrl() { + var url = "${this.request.contextPath}/.magnolia/trees/media.html?mgnlCK=" + (new Date()).getTime(); if (selectMedia) - { + { url += "&selectMedia=true"; } url += "&pathOpen="+ openPath +"&pathCurrent=" + openPath +"&pathSelected=" + openPath; @@ -211,12 +211,12 @@ bodyBorder: false, buttons: [ { - text: "${this.msgs.get('buttons.ok')}", + text: "${this.msgs.get('buttons.ok')}", handler: function() { uploadDlg.hide(); var ch = uploadDlg.body.child(".formToSubmit"); ch.dom.submit(); - } + } }, {text: "${this.msgs.get('buttons.cancel')}", handler: function() {uploadDlg.hide();uploadDlg.destroy();} }], keys: [],//{key: 27, fn: function() {ulDialog.hide();ulDialog.destroy();}, scope: this}] stateful: false @@ -232,7 +232,7 @@ <iframe id="mediaFolderView" name="mediaFolderView" class="x-panel-body" src="" style="width:100%;height:100%;border:none; overflow:auto"></iframe> <div id="formDiv" style="display:none"> - <form class="formToSubmit" action="" enctype="multipart/form-data" method="POST"> + <form class="formToSubmit" action="" enctype="multipart/form-data" method="post"> <input type="hidden" name="command" value="saveZip" /> <input id="parentPath" type="hidden" name="parentPath" value="{parentPath}" /> <input type="file" name="zipFile" /> Added: trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/FileNodeData.java =================================================================== --- trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/FileNodeData.java (rev 0) +++ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/FileNodeData.java 2009-02-15 20:58:20 UTC (rev 999) @@ -0,0 +1,384 @@ +package net.sourceforge.openutils.mgnlmedia.media.utils; + +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.NodeData; +import info.magnolia.cms.security.AccessDeniedException; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Calendar; +import java.util.Collection; + +import javax.jcr.ItemNotFoundException; +import javax.jcr.PathNotFoundException; +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.Value; + +import org.apache.commons.io.IOUtils; + + +/** + * @author fgiust + * @version $Id$ + */ +public class FileNodeData implements NodeData +{ + + private byte[] content; + + public FileNodeData(String classpathLocation) throws IOException + { + InputStream is = getClass().getResourceAsStream(classpathLocation); + if (is == null) + { + throw new IllegalArgumentException("Classpath resource " + classpathLocation + " cannot be found"); + } + try + { + content = IOUtils.toByteArray(is); + } + finally + { + IOUtils.closeQuietly(is); + } + } + + /** + * {@inheritDoc} + */ + public void delete() throws RepositoryException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public String getAttribute(String arg0) + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Collection getAttributeNames() throws RepositoryException + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public boolean getBoolean() + { + // TODO Auto-generated method stub + return false; + } + + /** + * {@inheritDoc} + */ + public long getContentLength() + { + // TODO Auto-generated method stub + return 0; + } + + /** + * {@inheritDoc} + */ + public Calendar getDate() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public double getDouble() + { + // TODO Auto-generated method stub + return 0; + } + + /** + * {@inheritDoc} + */ + public String getHandle() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public HierarchyManager getHierarchyManager() throws RepositoryException + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Property getJCRProperty() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public long getLong() + { + // TODO Auto-generated method stub + return 0; + } + + /** + * {@inheritDoc} + */ + public String getName() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Content getParent() throws AccessDeniedException, ItemNotFoundException, javax.jcr.AccessDeniedException, + RepositoryException + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Content getReferencedContent() throws RepositoryException, PathNotFoundException, RepositoryException + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Content getReferencedContent(String arg0) throws PathNotFoundException, RepositoryException + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public InputStream getStream() + { + return new ByteArrayInputStream(content); + } + + /** + * {@inheritDoc} + */ + public String getString() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public String getString(String arg0) + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public int getType() + { + // TODO Auto-generated method stub + return 0; + } + + /** + * {@inheritDoc} + */ + public Value getValue() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public Value[] getValues() + { + // TODO Auto-generated method stub + return null; + } + + /** + * {@inheritDoc} + */ + public boolean isExist() + { + // TODO Auto-generated method stub + return false; + } + + /** + * {@inheritDoc} + */ + public boolean isGranted(long arg0) + { + // TODO Auto-generated method stub + return false; + } + + /** + * {@inheritDoc} + */ + public int isMultiValue() + { + // TODO Auto-generated method stub + return 0; + } + + /** + * {@inheritDoc} + */ + public void refresh(boolean arg0) throws RepositoryException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void save() throws RepositoryException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setAttribute(String arg0, String arg1) throws RepositoryException, AccessDeniedException, + UnsupportedOperationException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setAttribute(String arg0, Calendar arg1) throws RepositoryException, AccessDeniedException, + UnsupportedOperationException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(String arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(int arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(long arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(InputStream arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(double arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(boolean arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(Calendar arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(Value arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void setValue(Value[] arg0) throws RepositoryException, AccessDeniedException + { + // TODO Auto-generated method stub + + } + +} Property changes on: trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/FileNodeData.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtilsTest.java =================================================================== --- trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtilsTest.java (rev 0) +++ trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtilsTest.java 2009-02-15 20:58:20 UTC (rev 999) @@ -0,0 +1,64 @@ +package net.sourceforge.openutils.mgnlmedia.media.utils; + +import info.magnolia.cms.core.NodeData; + +import java.awt.image.BufferedImage; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; + +import org.apache.commons.io.IOUtils; +import org.testng.Assert; +import org.testng.annotations.Test; + + +/** + * @author fgiust + * @version $Id$ + */ +public class ImageUtilsTest +{ + + @Test + public void testYcck() throws Exception + { + + NodeData cmyk = new FileNodeData("/images/ycck.jpg"); + BufferedImage bufferedImage = ImageUtils.createBufferedImage(cmyk); + Assert.assertNotNull(bufferedImage); + + bufferedImage = ImageUtils.resizeNoCrop(bufferedImage, 100, 100); + + InputStream is = ImageUtils.getStream(bufferedImage, "jpg"); + + File tempFile = File.createTempFile("image", "jpg"); + OutputStream os = new BufferedOutputStream(new FileOutputStream(tempFile)); + IOUtils.copy(is, os); + + IOUtils.closeQuietly(is); + IOUtils.closeQuietly(os); + + tempFile.delete(); + + } + + @Test + public void testBadImageTxt() throws Exception + { + + NodeData cmyk = new FileNodeData("/images/badimage.txt"); + BufferedImage bufferedImage = ImageUtils.createBufferedImage(cmyk); + Assert.assertNull(bufferedImage); + } + + @Test + public void testBadImageJpg() throws Exception + { + + NodeData cmyk = new FileNodeData("/images/badimage.jpg"); + BufferedImage bufferedImage = ImageUtils.createBufferedImage(cmyk); + Assert.assertNull(bufferedImage); + } +} Property changes on: trunk/openutils-mgnlmedia/src/test/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtilsTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlmedia/src/test/resources/images/badimage.jpg =================================================================== (Binary files differ) Property changes on: trunk/openutils-mgnlmedia/src/test/resources/images/badimage.jpg ___________________________________________________________________ Added: svn:mime-type + image/gif Added: trunk/openutils-mgnlmedia/src/test/resources/images/badimage.txt =================================================================== --- trunk/openutils-mgnlmedia/src/test/resources/images/badimage.txt (rev 0) +++ trunk/openutils-mgnlmedia/src/test/resources/images/badimage.txt 2009-02-15 20:58:20 UTC (rev 999) @@ -0,0 +1 @@ +just a sample bad image \ No newline at end of file Property changes on: trunk/openutils-mgnlmedia/src/test/resources/images/badimage.txt ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlmedia/src/test/resources/images/ycck.jpg =================================================================== (Binary files differ) Property changes on: trunk/openutils-mgnlmedia/src/test/resources/images/ycck.jpg ___________________________________________________________________ Added: svn:mime-type + image/gif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 17:53:30
|
Revision: 998 http://openutils.svn.sourceforge.net/openutils/?rev=998&view=rev Author: molaschi Date: 2009-02-13 17:53:26 +0000 (Fri, 13 Feb 2009) Log Message: ----------- [maven-release-plugin] prepare for next development iteration Modified Paths: -------------- trunk/openutils-mgnlmedia/pom.xml Modified: trunk/openutils-mgnlmedia/pom.xml =================================================================== --- trunk/openutils-mgnlmedia/pom.xml 2009-02-13 17:52:57 UTC (rev 997) +++ trunk/openutils-mgnlmedia/pom.xml 2009-02-13 17:53:26 UTC (rev 998) @@ -9,7 +9,7 @@ <packaging>jar</packaging> <artifactId>openutils-mgnlmedia</artifactId> <name>openutils-mgnlmedia</name> - <version>4.0-b1</version> + <version>4.0-b2-SNAPSHOT</version> <licenses> <license> <name>GPLv3</name> @@ -69,10 +69,4 @@ </exclusions> </dependency> </dependencies> - - <scm> - <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmedia-4.0-b1</connection> - <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmedia-4.0-b1</developerConnection> - <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-mgnlmedia-4.0-b1</url> - </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 17:53:01
|
Revision: 997 http://openutils.svn.sourceforge.net/openutils/?rev=997&view=rev Author: molaschi Date: 2009-02-13 17:52:57 +0000 (Fri, 13 Feb 2009) Log Message: ----------- [maven-release-plugin] copy for tag openutils-mgnlmedia-4.0-b1 Added Paths: ----------- tags/openutils-mgnlmedia-4.0-b1/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 17:51:34
|
Revision: 996 http://openutils.svn.sourceforge.net/openutils/?rev=996&view=rev Author: molaschi Date: 2009-02-13 17:51:31 +0000 (Fri, 13 Feb 2009) Log Message: ----------- [maven-release-plugin] prepare for next development iteration Modified Paths: -------------- trunk/openutils-mgnlmessages/pom.xml Modified: trunk/openutils-mgnlmessages/pom.xml =================================================================== --- trunk/openutils-mgnlmessages/pom.xml 2009-02-13 17:51:19 UTC (rev 995) +++ trunk/openutils-mgnlmessages/pom.xml 2009-02-13 17:51:31 UTC (rev 996) @@ -9,7 +9,7 @@ <packaging>jar</packaging> <artifactId>openutils-mgnlmessages</artifactId> <name>openutils-mgnlmessages</name> - <version>4.0-b2</version> + <version>4.0-b3-SNAPSHOT</version> <licenses> <license> <name>GPLv3</name> @@ -82,10 +82,4 @@ </snapshots> </repository> </repositories> - - <scm> - <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmessages-4.0-b2</connection> - <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmessages-4.0-b2</developerConnection> - <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-mgnlmessages-4.0-b2</url> - </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 17:51:29
|
Revision: 995 http://openutils.svn.sourceforge.net/openutils/?rev=995&view=rev Author: molaschi Date: 2009-02-13 17:51:19 +0000 (Fri, 13 Feb 2009) Log Message: ----------- [maven-release-plugin] copy for tag openutils-mgnlmessages-4.0-b2 Added Paths: ----------- tags/openutils-mgnlmessages-4.0-b2/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 17:51:11
|
Revision: 994 http://openutils.svn.sourceforge.net/openutils/?rev=994&view=rev Author: molaschi Date: 2009-02-13 17:51:01 +0000 (Fri, 13 Feb 2009) Log Message: ----------- [maven-release-plugin] prepare release openutils-mgnlmedia-4.0-b1 Modified Paths: -------------- trunk/openutils-mgnlmedia/pom.xml Modified: trunk/openutils-mgnlmedia/pom.xml =================================================================== --- trunk/openutils-mgnlmedia/pom.xml 2009-02-13 17:49:19 UTC (rev 993) +++ trunk/openutils-mgnlmedia/pom.xml 2009-02-13 17:51:01 UTC (rev 994) @@ -9,7 +9,7 @@ <packaging>jar</packaging> <artifactId>openutils-mgnlmedia</artifactId> <name>openutils-mgnlmedia</name> - <version>4.0-SNAPSHOT</version> + <version>4.0-b1</version> <licenses> <license> <name>GPLv3</name> @@ -69,4 +69,10 @@ </exclusions> </dependency> </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmedia-4.0-b1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmedia-4.0-b1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-mgnlmedia-4.0-b1</url> + </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 17:49:29
|
Revision: 993 http://openutils.svn.sourceforge.net/openutils/?rev=993&view=rev Author: molaschi Date: 2009-02-13 17:49:19 +0000 (Fri, 13 Feb 2009) Log Message: ----------- [maven-release-plugin] prepare release openutils-mgnlmessages-4.0-b2 Modified Paths: -------------- trunk/openutils-mgnlmessages/pom.xml Modified: trunk/openutils-mgnlmessages/pom.xml =================================================================== --- trunk/openutils-mgnlmessages/pom.xml 2009-02-13 17:48:24 UTC (rev 992) +++ trunk/openutils-mgnlmessages/pom.xml 2009-02-13 17:49:19 UTC (rev 993) @@ -9,7 +9,7 @@ <packaging>jar</packaging> <artifactId>openutils-mgnlmessages</artifactId> <name>openutils-mgnlmessages</name> - <version>4.0-b2-SNAPSHOT</version> + <version>4.0-b2</version> <licenses> <license> <name>GPLv3</name> @@ -82,4 +82,10 @@ </snapshots> </repository> </repositories> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmessages-4.0-b2</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmessages-4.0-b2</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-mgnlmessages-4.0-b2</url> + </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 17:48:34
|
Revision: 992 http://openutils.svn.sourceforge.net/openutils/?rev=992&view=rev Author: molaschi Date: 2009-02-13 17:48:24 +0000 (Fri, 13 Feb 2009) Log Message: ----------- fixes Modified Paths: -------------- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesManager.java trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java Added Paths: ----------- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/DefaultMessagesManager.java Removed Paths: ------------- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesProvider.java Added: trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/DefaultMessagesManager.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/DefaultMessagesManager.java (rev 0) +++ trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/DefaultMessagesManager.java 2009-02-13 17:48:24 UTC (rev 992) @@ -0,0 +1,350 @@ +/** + * This file Copyright (c) 2003-2009 Magnolia International + * Ltd. (http://www.magnolia-cms.com). All rights reserved. + * + * + * This file is dual-licensed under both the Magnolia + * Network Agreement and the GNU General Public License. + * You may elect to use one or the other of these licenses. + * + * This file is distributed in the hope that it will be + * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. + * Redistribution, except as permitted by whichever of the GPL + * or MNA you select, is prohibited. + * + * 1. For the GPL license (GPL), you can redistribute and/or + * modify this file under the terms of the GNU General + * Public License, Version 3, as published by the Free Software + * Foundation. You should have received a copy of the GNU + * General Public License, Version 3 along with this program; + * if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * 2. For the Magnolia Network Agreement (MNA), this file + * and the accompanying materials are made available under the + * terms of the MNA which accompanies this distribution, and + * is available at http://www.magnolia-cms.com/mna.html + * + * Any modifications to this file must keep this entire header + * intact. + * + */ +package info.magnolia.cms.i18n; + +import info.magnolia.cms.beans.config.ContentRepository; +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.ItemType; +import info.magnolia.cms.util.FactoryUtil; +import info.magnolia.cms.util.NodeDataUtil; +import info.magnolia.cms.util.ObservationUtil; +import info.magnolia.content2bean.Content2BeanUtil; +import info.magnolia.context.MgnlContext; +import org.apache.commons.collections.Transformer; +import org.apache.commons.collections.map.LazyMap; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.observation.EventIterator; +import javax.jcr.observation.EventListener; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; + + +/** + * From this class you get the i18n messages. You should pass a a request, but if you can't the getMessages method will + * handle it properly. The get() methods are easy to use. + * @author philipp + */ +public class DefaultMessagesManager extends MessagesManager +{ + + private final static Logger log = LoggerFactory.getLogger(DefaultMessagesManager.class); + + /** + * The current locale of the application. + */ + private Locale applicationLocale; + + /** + * List of the available locales. + */ + private final Collection availableLocales = new ArrayList(); + + /** + * Map for the messages. + */ + private Map messages; + + private String defaultBasename = DEFAULT_BASENAME; + + public DefaultMessagesManager() + { + // setting default language (en) + setDefaultLocale(FALLBACK_LOCALE); + + initMap(); + } + + // for tests + @Override + void setDefaultBasename(String defaultBasename) + { + this.defaultBasename = defaultBasename; + } + + /** + * Called through the initialization process. (startup of the container) + */ + @Override + public void init() + { + load(); + registerEventListener(); + } + + /** + * The lazy Map creates messages objects with a fall back to the default locale. + */ + protected void initMap() + { + // FIXME use LRU: new LRUMap(20); + // LazyMap will instanciate bundles on demand. + final Map map = LazyMap.decorate(new HashMap(), new Transformer() + { + + // this transformer will wrap the Messages in a MessagesChain which + // will fall back to a Messages instance for the same bundle with + // default locale. + public Object transform(Object input) + { + final MessagesID id = (MessagesID) input; + return newMessages(id); + } + }); + messages = Collections.synchronizedMap(map); + } + + /** + * Initializes a new Messages instances for the given MessagesID. By default, we chain to the same bundle with the + * default Locale. (so untranslated messages show up in the default language) + */ + protected Messages newMessages(MessagesID messagesID) + { + Messages msgs = new DefaultMessagesImpl(messagesID.basename, messagesID.locale); + if (!getDefaultLocale().equals(messagesID.locale)) + { + msgs = new MessagesChain(msgs).chain(getMessages(messagesID.basename, getDefaultLocale())); + } + return msgs; + } + + /** + * Load i18n configuration. + */ + protected void load() + { + + // reading the configuration from the repository, no need for context + HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager(ContentRepository.CONFIG); + + try + { + log.info("Loading i18n configuration - " + I18N_CONFIG_PATH); //$NON-NLS-1$ + + // checks if node exists + if (!hm.isExist(I18N_CONFIG_PATH)) + { + // configNode = ContentUtil.createPath(hm, I18N_CONFIG_PATH, + // ItemType.CONTENT, true); + log.warn(I18N_CONFIG_PATH + " does not exist yet; skipping."); + return; + } + + final Content configNode = hm.getContent(I18N_CONFIG_PATH); //$NON-NLS-1$ + + setDefaultLocale(NodeDataUtil.getString(configNode, FALLBACK_NODEDATA, FALLBACK_LOCALE)); + + // get the available languages - creates it if it does not exist - + // necessary to update to 3.5 + final Content languagesNode; + if (configNode.hasContent(LANGUAGES_NODE_NAME)) + { + languagesNode = configNode.getContent(LANGUAGES_NODE_NAME); + } + else + { + languagesNode = configNode.createContent(LANGUAGES_NODE_NAME, ItemType.CONTENT); + } + + Map languageDefinitions = Content2BeanUtil.toMap(languagesNode, true, LocaleDefinition.class); + + // clear collection for reload + availableLocales.clear(); + + for (Iterator iter = languageDefinitions.values().iterator(); iter.hasNext();) + { + LocaleDefinition ld = (LocaleDefinition) iter.next(); + if (ld.isEnabled()) + { + availableLocales.add(ld.getLocale()); + } + } + } + catch (Exception e) + { + log.error("Failed to load i18n configuration - " + I18N_CONFIG_PATH, e); //$NON-NLS-1$ + } + } + + /** + * Register an event listener: reload configuration when something changes. + */ + private void registerEventListener() + { + log.info("Registering event listener for i18n"); //$NON-NLS-1$ + ObservationUtil.registerChangeListener(ContentRepository.CONFIG, I18N_CONFIG_PATH, new EventListener() + { + + public void onEvent(EventIterator iterator) + { + // reload everything + reload(); + } + }); + } + + /** + * Reload i18n configuration. + */ + public void reload() + { + try + { + // reload all present + for (Iterator iter = messages.values().iterator(); iter.hasNext();) + { + Messages msgs = (Messages) iter.next(); + msgs.reload(); + } + } + catch (Exception e) + { + log.error("Can't reload i18n messages", e); + } + initMap(); + load(); + } + + @Override + public Messages getMessagesInternal(String basename, Locale locale) + { + if (StringUtils.isEmpty(basename)) + { + basename = defaultBasename; + } + return (Messages) messages.get(new MessagesID(basename, locale)); + } + + @Override + public Locale getDefaultLocale() + { + return applicationLocale; + } + + /** + * @param defaultLocale The defaultLocale to set. + * @deprecated since 4.0 - not used and should not be. Use setLocale() on the SystemContext instead. --note: do not + * remove the method, make it private. applicationLocale field is still needed. --and/or remove duplication with + * SystemContext.locale + */ + public void setDefaultLocale(String defaultLocale) + { + this.applicationLocale = new Locale(defaultLocale); + // MgnlContext.getSystemContext().setLocale(applicationLocale); + } + + @Override + public Collection getAvailableLocales() + { + return availableLocales; + } + + public void setMessages(Map messages) + { + this.messages = messages; + } + + /** + * Used as the key in the Map. + * @author Philipp Bracher + * @version $Revision: 21431 $ ($Author: gjoseph $) + */ + public static class MessagesID + { + + private final String basename; + + private final Locale locale; + + public MessagesID(String basename, Locale locale) + { + this.basename = basename; + this.locale = locale; + } + + // generated equals and hashcode methods + @Override + public boolean equals(Object o) + { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + MessagesID that = (MessagesID) o; + + if (basename != null ? !basename.equals(that.basename) : that.basename != null) + return false; + if (locale != null ? !locale.equals(that.locale) : that.locale != null) + return false; + + return true; + } + + @Override + public int hashCode() + { + int result = basename != null ? basename.hashCode() : 0; + result = 31 * result + (locale != null ? locale.hashCode() : 0); + return result; + } + + /** + * Returns the basename. + * @return the basename + */ + public String getBasename() + { + return basename; + } + + /** + * Returns the locale. + * @return the locale + */ + public Locale getLocale() + { + return locale; + } + + } +} Modified: trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesManager.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesManager.java 2009-02-13 16:33:21 UTC (rev 991) +++ trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesManager.java 2009-02-13 17:48:24 UTC (rev 992) @@ -1,360 +1,123 @@ -/** - * This file Copyright (c) 2003-2009 Magnolia International - * Ltd. (http://www.magnolia-cms.com). All rights reserved. - * - * - * This file is dual-licensed under both the Magnolia - * Network Agreement and the GNU General Public License. - * You may elect to use one or the other of these licenses. - * - * This file is distributed in the hope that it will be - * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the - * implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. - * Redistribution, except as permitted by whichever of the GPL - * or MNA you select, is prohibited. - * - * 1. For the GPL license (GPL), you can redistribute and/or - * modify this file under the terms of the GNU General - * Public License, Version 3, as published by the Free Software - * Foundation. You should have received a copy of the GNU - * General Public License, Version 3 along with this program; - * if not, write to the Free Software Foundation, Inc., 51 - * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * 2. For the Magnolia Network Agreement (MNA), this file - * and the accompanying materials are made available under the - * terms of the MNA which accompanies this distribution, and - * is available at http://www.magnolia-cms.com/mna.html - * - * Any modifications to this file must keep this entire header - * intact. - * - */ package info.magnolia.cms.i18n; -import info.magnolia.cms.beans.config.ContentRepository; -import info.magnolia.cms.core.Content; -import info.magnolia.cms.core.HierarchyManager; -import info.magnolia.cms.core.ItemType; import info.magnolia.cms.util.FactoryUtil; -import info.magnolia.cms.util.NodeDataUtil; -import info.magnolia.cms.util.ObservationUtil; -import info.magnolia.content2bean.Content2BeanUtil; import info.magnolia.context.MgnlContext; -import org.apache.commons.collections.Transformer; -import org.apache.commons.collections.map.LazyMap; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javax.jcr.observation.EventIterator; -import javax.jcr.observation.EventListener; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; import java.util.Locale; -import java.util.Map; - /** - * From this class you get the i18n messages. You should pass a a request, but if you can't the getMessages method will - * handle it properly. The get() methods are easy to use. - * - * @author philipp + * + * @author molaschi + * */ -public final class MessagesManager implements MessagesProvider{ - private final static Logger log = LoggerFactory.getLogger(MessagesManager.class); +public abstract class MessagesManager { - /** - * Use this locale if no other provided. - */ - public static final String FALLBACK_LOCALE = "en"; //$NON-NLS-1$ + /** + * Use this locale if no other provided. + */ + public static final String FALLBACK_LOCALE = "en"; //$NON-NLS-1$ - /** - * Use this basename if no other is provided. - */ - public static final String DEFAULT_BASENAME = "info.magnolia.module.admininterface.messages"; //$NON-NLS-1$ + /** + * Use this basename if no other is provided. + */ + public static final String DEFAULT_BASENAME = "info.magnolia.module.admininterface.messages"; //$NON-NLS-1$ - /** - * The node name where the configuration for i18n is stored. - */ - private static final String I18N_CONFIG_PATH = "/server/i18n/system"; //$NON-NLS-1$ + /** + * The node name where the configuration for i18n is stored. + */ + public static final String I18N_CONFIG_PATH = "/server/i18n/system"; //$NON-NLS-1$ - /** - * The name of the property to store the current system language. - */ - private static final String FALLBACK_NODEDATA = "fallbackLanguage"; //$NON-NLS-1$ + /** + * The name of the property to store the current system language. + */ + public static final String FALLBACK_NODEDATA = "fallbackLanguage"; //$NON-NLS-1$ - /** - * Under this node all the available languages are stored. They are showed in the user dialog. - */ - private static final String LANGUAGES_NODE_NAME = "languages"; //$NON-NLS-1$ + /** + * Under this node all the available languages are stored. They are showed + * in the user dialog. + */ + public static final String LANGUAGES_NODE_NAME = "languages"; //$NON-NLS-1$ + public static MessagesManager getInstance() { + return (MessagesManager) FactoryUtil + .getSingleton(MessagesManager.class); + } - public static MessagesProvider getInstance() { - return (MessagesProvider) FactoryUtil.getSingleton(MessagesManager.class); - } + public static Messages getMessages() { + return getMessages(null, getCurrentLocale()); + } - /** - * The current locale of the application. - */ - private Locale applicationLocale; + public static Messages getMessages(String basename) { + return getMessages(basename, getCurrentLocale()); + } - /** - * List of the available locales. - */ - private final Collection availableLocales = new ArrayList(); + public static Messages getMessages(Locale locale) { + return getMessages(null, locale); + } - /** - * Map for the messages. - */ - private Map messages; + public static Messages getMessages(String basename, Locale locale) { + return getInstance().getMessagesInternal(basename, locale); + } - private String defaultBasename = DEFAULT_BASENAME; + public static String get(String key) { + return getMessages().get(key); + } - public MessagesManager() { - // setting default language (en) - setDefaultLocale(FALLBACK_LOCALE); + /** + * Get a message with parameters inside: the value {0} must be a number. + * + * @param key + * key to find + * @param args + * replacement strings + * @return message + */ + public static String get(String key, Object[] args) { + return getMessages().get(key, args); + } - initMap(); - } + /** + * Use a default string. + * + * @param key + * key to find + * @param defaultMsg + * default message + * @return message + */ + public static String getWithDefault(String key, String defaultMsg) { + return getMessages().getWithDefault(key, defaultMsg); + } - // for tests - void setDefaultBasename(String defaultBasename) { - this.defaultBasename = defaultBasename; - } + /** + * Get a message with parameters inside: the value {0} must be a number. Use + * a default message. + * + * @param key + * key to find + * @param args + * replacement strings + * @param defaultMsg + * default message + * @return message + */ + public static String getWithDefault(String key, Object[] args, + String defaultMsg) { + return getMessages().getWithDefault(key, args, defaultMsg); + } - /** - * Called through the initialization process. (startup of the container) - */ - public void init() { - load(); - registerEventListener(); - } + private static Locale getCurrentLocale() { + return MgnlContext.getInstance().getLocale(); + } - /** - * The lazy Map creates messages objects with a fall back to the default locale. - */ - protected void initMap() { - // FIXME use LRU: new LRUMap(20); - // LazyMap will instanciate bundles on demand. - final Map map = LazyMap.decorate(new HashMap(), new Transformer() { - // this transformer will wrap the Messages in a MessagesChain which will fall back to a Messages instance for the same bundle with default locale. - public Object transform(Object input) { - final MessagesID id = (MessagesID) input; - return newMessages(id); - } - }); - messages = Collections.synchronizedMap(map); - } + public abstract void init(); - /** - * Initializes a new Messages instances for the given MessagesID. - * By default, we chain to the same bundle with the default Locale. (so untranslated messages show up in the default language) - */ - protected Messages newMessages(MessagesID messagesID) { - Messages msgs = new DefaultMessagesImpl(messagesID.basename, messagesID.locale); - if (!getDefaultLocale().equals(messagesID.locale)) { - msgs = new MessagesChain(msgs).chain(getMessages(messagesID.basename, getDefaultLocale())); - } - return msgs; - } + public abstract Collection getAvailableLocales(); - /** - * Load i18n configuration. - */ - protected void load() { + public abstract Locale getDefaultLocale(); - // reading the configuration from the repository, no need for context - HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager(ContentRepository.CONFIG); + public abstract Messages getMessagesInternal(String basename, Locale locale); - try { - log.info("Loading i18n configuration - " + I18N_CONFIG_PATH); //$NON-NLS-1$ - - // checks if node exists - if (!hm.isExist(I18N_CONFIG_PATH)) { - // configNode = ContentUtil.createPath(hm, I18N_CONFIG_PATH, ItemType.CONTENT, true); - log.warn(I18N_CONFIG_PATH + " does not exist yet; skipping."); - return; - } - - final Content configNode = hm.getContent(I18N_CONFIG_PATH); //$NON-NLS-1$ - - setDefaultLocale(NodeDataUtil.getString(configNode, FALLBACK_NODEDATA, FALLBACK_LOCALE)); - - // get the available languages - creates it if it does not exist - necessary to update to 3.5 - final Content languagesNode; - if (configNode.hasContent(LANGUAGES_NODE_NAME)) { - languagesNode = configNode.getContent(LANGUAGES_NODE_NAME); - } else { - languagesNode = configNode.createContent(LANGUAGES_NODE_NAME, ItemType.CONTENT); - } - - Map languageDefinitions = Content2BeanUtil.toMap(languagesNode, true, LocaleDefinition.class); - - // clear collection for reload - availableLocales.clear(); - - for (Iterator iter = languageDefinitions.values().iterator(); iter.hasNext();) { - LocaleDefinition ld = (LocaleDefinition) iter.next(); - if (ld.isEnabled()) { - availableLocales.add(ld.getLocale()); - } - } - } - catch (Exception e) { - log.error("Failed to load i18n configuration - " + I18N_CONFIG_PATH, e); //$NON-NLS-1$ - } - } - - /** - * Register an event listener: reload configuration when something changes. - */ - private void registerEventListener() { - log.info("Registering event listener for i18n"); //$NON-NLS-1$ - ObservationUtil.registerChangeListener(ContentRepository.CONFIG, I18N_CONFIG_PATH, new EventListener() { - public void onEvent(EventIterator iterator) { - // reload everything - reload(); - } - }); - } - - /** - * Reload i18n configuration. - */ - public void reload() { - try { - // reload all present - for (Iterator iter = messages.values().iterator(); iter.hasNext();) { - Messages msgs = (Messages) iter.next(); - msgs.reload(); - } - } - catch (Exception e) { - log.error("Can't reload i18n messages", e); - } - initMap(); - load(); - } - - public Messages getMessagesInternal(String basename, Locale locale) { - if (StringUtils.isEmpty(basename)) { - basename = defaultBasename; - } - return (Messages) messages.get(new MessagesID(basename, locale)); - } - - public static Messages getMessages() { - return getMessages(null, getCurrentLocale()); - } - - public static Messages getMessages(String basename) { - return getMessages(basename, getCurrentLocale()); - } - - public static Messages getMessages(Locale locale) { - return getMessages(null, locale); - } - - public static Messages getMessages(String basename, Locale locale) { - return getInstance().getMessagesInternal(basename, locale); - } - - public static String get(String key) { - return getMessages().get(key); - } - - /** - * Get a message with parameters inside: the value {0} must be a number. - * @param key key to find - * @param args replacement strings - * @return message - */ - public static String get(String key, Object[] args) { - return getMessages().get(key, args); - } - - /** - * Use a default string. - * @param key key to find - * @param defaultMsg default message - * @return message - */ - public static String getWithDefault(String key, String defaultMsg) { - return getMessages().getWithDefault(key, defaultMsg); - } - - /** - * Get a message with parameters inside: the value {0} must be a number. Use a default message. - * @param key key to find - * @param args replacement strings - * @param defaultMsg default message - * @return message - */ - public static String getWithDefault(String key, Object[] args, String defaultMsg) { - return getMessages().getWithDefault(key, args, defaultMsg); - } - - private static Locale getCurrentLocale() { - return MgnlContext.getInstance().getLocale(); - } - - public Locale getDefaultLocale() { - return applicationLocale; - } - - /** - * @param defaultLocale The defaultLocale to set. - * @deprecated since 4.0 - not used and should not be. Use setLocale() on the SystemContext instead. - * --note: do not remove the method, make it private. applicationLocale field is still needed. - * --and/or remove duplication with SystemContext.locale - */ - public void setDefaultLocale(String defaultLocale) { - this.applicationLocale = new Locale(defaultLocale); - //MgnlContext.getSystemContext().setLocale(applicationLocale); - } - - public Collection getAvailableLocales() { - return availableLocales; - } - - /** - * Used as the key in the Map. - * @author Philipp Bracher - * @version $Revision: 21431 $ ($Author: gjoseph $) - */ - static private class MessagesID { - private final String basename; - private final Locale locale; - - public MessagesID(String basename, Locale locale) { - this.basename = basename; - this.locale = locale; - } - - // generated equals and hashcode methods - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - MessagesID that = (MessagesID) o; - - if (basename != null ? !basename.equals(that.basename) : that.basename != null) return false; - if (locale != null ? !locale.equals(that.locale) : that.locale != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = basename != null ? basename.hashCode() : 0; - result = 31 * result + (locale != null ? locale.hashCode() : 0); - return result; - } - } + abstract void setDefaultBasename(String basename); } Deleted: trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesProvider.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesProvider.java 2009-02-13 16:33:21 UTC (rev 991) +++ trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesProvider.java 2009-02-13 17:48:24 UTC (rev 992) @@ -1,16 +0,0 @@ -package info.magnolia.cms.i18n; - -import java.util.Locale; - -/** - * @author molaschi - * @version $Id: $ - */ -public interface MessagesProvider { - - Locale getDefaultLocale(); - - void init(); - - Messages getMessagesInternal(String basename, Locale locale); -} Modified: trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java 2009-02-13 16:33:21 UTC (rev 991) +++ trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java 2009-02-13 17:48:24 UTC (rev 992) @@ -1,271 +1,33 @@ package info.magnolia.cms.i18n; -import info.magnolia.cms.beans.config.ContentRepository; -import info.magnolia.cms.core.Content; -import info.magnolia.cms.core.HierarchyManager; -import info.magnolia.cms.core.ItemType; -import info.magnolia.cms.util.NodeDataUtil; -import info.magnolia.cms.util.ObservationUtil; -import info.magnolia.content2bean.Content2BeanUtil; -import info.magnolia.context.MgnlContext; +import net.sourceforge.openutils.mgnlmessages.i18n.ModulePropertyMessagesImpl; +import net.sourceforge.openutils.mgnlmessages.i18n.RepositoryMessagesImpl; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map; -import javax.jcr.observation.EventIterator; -import javax.jcr.observation.EventListener; - -import org.apache.commons.collections.Transformer; -import org.apache.commons.collections.map.LazyMap; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - /** * @author molaschi * @version $Id: $ */ -public class OpenutilsMgnlMessagesManager implements MessagesProvider +public class OpenutilsMgnlMessagesManager extends DefaultMessagesManager { /** - * Logger. + * {@inheritDoc} */ - private Logger log = LoggerFactory.getLogger(OpenutilsMgnlMessagesManager.class); - - /** - * The node name where the configuration for i18n is stored. - */ - private static final String I18N_CONFIG_PATH = "/server/i18n/system"; //$NON-NLS-1$ - - /** - * The name of the property to store the current system language. - */ - private static final String FALLBACK_NODEDATA = "fallbackLanguage"; //$NON-NLS-1$ - - /** - * Under this node all the available languages are stored. They are showed in the user dialog. - */ - private static final String LANGUAGES_NODE_NAME = "languages"; //$NON-NLS-1$ - - private Locale defaultLocale = new Locale(MessagesManager.FALLBACK_LOCALE); - - Map messages; - - private final Collection availableLocales = new ArrayList(); - - /** - * - */ - public OpenutilsMgnlMessagesManager() + @Override + protected Messages newMessages(MessagesID messagesID) { - initMap(); - } + Messages msgs = new MessagesChain(new RepositoryMessagesImpl(messagesID.getBasename(), messagesID.getLocale())); + ((MessagesChain) msgs).chain(new ModulePropertyMessagesImpl(messagesID.getLocale())); + ((MessagesChain) msgs).chain(new DefaultMessagesImpl(messagesID.getBasename(), messagesID.getLocale())); - public void init() - { - load(); - registerEventListener(); - } - - /** - * The lazy Map creates messages objects with a fall back to the default locale. - */ - protected void initMap() - { - // FIXME use LRU: new LRUMap(20); - // LazyMap will instanciate bundles on demand. - final Map map = LazyMap.decorate(new HashMap(), new Transformer() + if (!getDefaultLocale().equals(messagesID.getLocale())) { - - // this transformer will wrap the Messages in a MessagesChain which will fall back to a Messages instance - // for the same bundle with default locale. - public Object transform(Object input) - { - final MessagesID id = (MessagesID) input; - return newMessages(id); - } - }); - messages = Collections.synchronizedMap(map); - } - - /** - * Initializes a new Messages instances for the given MessagesID. By default, we chain to the same bundle with the - * default Locale. (so untranslated messages show up in the default language) - */ - protected Messages newMessages(MessagesID messagesID) - { - Messages msgs = new DefaultMessagesImpl(messagesID.basename, messagesID.locale); - if (!getDefaultLocale().equals(messagesID.locale)) - { - msgs = new MessagesChain(msgs).chain(getMessagesInternal(messagesID.basename, getDefaultLocale())); + msgs = ((MessagesChain) msgs).chain(MessagesManager.getMessages( + messagesID.getBasename(), + getDefaultLocale())); } return msgs; } - /** - * {@inheritDoc} - */ - public Locale getDefaultLocale() - { - return defaultLocale; - } - - /** - * {@inheritDoc} - */ - public Messages getMessagesInternal(String basename, Locale locale) - { - if (StringUtils.isEmpty(basename)) - { - basename = MessagesManager.DEFAULT_BASENAME; - } - return (Messages) messages.get(new MessagesID(basename, locale)); - } - - /** - * Load i18n configuration. - */ - protected void load() - { - - // reading the configuration from the repository, no need for context - HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager(ContentRepository.CONFIG); - - try - { - log.info("Loading i18n configuration - " + I18N_CONFIG_PATH); //$NON-NLS-1$ - - // checks if node exists - if (!hm.isExist(I18N_CONFIG_PATH)) - { - // configNode = ContentUtil.createPath(hm, I18N_CONFIG_PATH, ItemType.CONTENT, true); - log.warn(I18N_CONFIG_PATH + " does not exist yet; skipping."); - return; - } - - final Content configNode = hm.getContent(I18N_CONFIG_PATH); //$NON-NLS-1$ - - defaultLocale = new Locale(NodeDataUtil.getString( - configNode, - FALLBACK_NODEDATA, - MessagesManager.FALLBACK_LOCALE)); - - // get the available languages - creates it if it does not exist - necessary to update to 3.5 - final Content languagesNode; - if (configNode.hasContent(LANGUAGES_NODE_NAME)) - { - languagesNode = configNode.getContent(LANGUAGES_NODE_NAME); - } - else - { - languagesNode = configNode.createContent(LANGUAGES_NODE_NAME, ItemType.CONTENT); - } - - Map languageDefinitions = Content2BeanUtil.toMap(languagesNode, true, LocaleDefinition.class); - - // clear collection for reload - availableLocales.clear(); - - for (Iterator iter = languageDefinitions.values().iterator(); iter.hasNext();) - { - LocaleDefinition ld = (LocaleDefinition) iter.next(); - if (ld.isEnabled()) - { - availableLocales.add(ld.getLocale()); - } - } - } - catch (Exception e) - { - log.error("Failed to load i18n configuration - " + I18N_CONFIG_PATH, e); //$NON-NLS-1$ - } - } - - /** - * Register an event listener: reload configuration when something changes. - */ - private void registerEventListener() - { - log.info("Registering event listener for i18n"); //$NON-NLS-1$ - ObservationUtil.registerChangeListener(ContentRepository.CONFIG, I18N_CONFIG_PATH, new EventListener() - { - - public void onEvent(EventIterator iterator) - { - // reload everything - reload(); - } - }); - } - - /** - * Reload i18n configuration. - */ - public void reload() - { - try - { - // reload all present - for (Iterator iter = messages.values().iterator(); iter.hasNext();) - { - Messages msgs = (Messages) iter.next(); - msgs.reload(); - } - } - catch (Exception e) - { - log.error("Can't reload i18n messages", e); - } - initMap(); - load(); - } - - static private class MessagesID - { - - private final String basename; - - private final Locale locale; - - public MessagesID(String basename, Locale locale) - { - this.basename = basename; - this.locale = locale; - } - - // generated equals and hashcode methods - @Override - public boolean equals(Object o) - { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - - MessagesID that = (MessagesID) o; - - if (basename != null ? !basename.equals(that.basename) : that.basename != null) - return false; - if (locale != null ? !locale.equals(that.locale) : that.locale != null) - return false; - - return true; - } - - @Override - public int hashCode() - { - int result = basename != null ? basename.hashCode() : 0; - result = 31 * result + (locale != null ? locale.hashCode() : 0); - return result; - } - } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 16:33:25
|
Revision: 991 http://openutils.svn.sourceforge.net/openutils/?rev=991&view=rev Author: molaschi Date: 2009-02-13 16:33:21 +0000 (Fri, 13 Feb 2009) Log Message: ----------- fix bug Modified Paths: -------------- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java Modified: trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java 2009-02-13 16:30:59 UTC (rev 990) +++ trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java 2009-02-13 16:33:21 UTC (rev 991) @@ -65,7 +65,7 @@ */ public OpenutilsMgnlMessagesManager() { - + initMap(); } public void init() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 16:31:02
|
Revision: 990 http://openutils.svn.sourceforge.net/openutils/?rev=990&view=rev Author: molaschi Date: 2009-02-13 16:30:59 +0000 (Fri, 13 Feb 2009) Log Message: ----------- new release to support magnolia 4.0.x Modified Paths: -------------- trunk/openutils-mgnlmedia/src/main/resources/META-INF/magnolia/media.xml Modified: trunk/openutils-mgnlmedia/src/main/resources/META-INF/magnolia/media.xml =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/META-INF/magnolia/media.xml 2009-02-13 16:24:47 UTC (rev 989) +++ trunk/openutils-mgnlmedia/src/main/resources/META-INF/magnolia/media.xml 2009-02-13 16:30:59 UTC (rev 990) @@ -10,11 +10,11 @@ <dependencies> <dependency> <name>adminInterface</name> - <version>3.1/*</version> + <version>4</version> </dependency> <dependency> <name>cache</name> - <version>3.1/*</version> + <version>4</version> </dependency> </dependencies> <repositories> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 16:24:50
|
Revision: 989 http://openutils.svn.sourceforge.net/openutils/?rev=989&view=rev Author: molaschi Date: 2009-02-13 16:24:47 +0000 (Fri, 13 Feb 2009) Log Message: ----------- new release to support magnolia 4.0.x Modified Paths: -------------- trunk/openutils-mgnlmedia/pom.xml trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/configuration/MediaConfigurationManager.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/dialog/DialogSelectMedia.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/lifecycle/MediaModuleLifecycle.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaLoadZipFilePage.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MessagesTemplatedMVCHandler.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/save/MediaCustomSaveHandler.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/MediaModuleVersionHandler.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/RemoveResolutionsNodeTask.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/RenameThumbToImageTask.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/JcrBrowserWithNodeTypeTreeConfiguration.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTreeConfiguration.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTreeMVCHandler.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/AudioTypeHandler.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/BaseTypeHandler.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/ImageTypeHandler.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/VideoTypeHandler.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/YouTubeVideoTypeHandler.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java trunk/openutils-mgnlmedia/src/main/resources/info/magnolia/cms/gui/control/MediaTreeFooter.ftl trunk/openutils-mgnlmedia/src/main/resources/mgnl-resources/media/js/mootips.js trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.html Added Paths: ----------- trunk/openutils-mgnlmedia/src/main/resources/info/magnolia/cms/gui/control/MediaTreeAddress.ftl Modified: trunk/openutils-mgnlmedia/pom.xml =================================================================== --- trunk/openutils-mgnlmedia/pom.xml 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/pom.xml 2009-02-13 16:24:47 UTC (rev 989) @@ -9,7 +9,7 @@ <packaging>jar</packaging> <artifactId>openutils-mgnlmedia</artifactId> <name>openutils-mgnlmedia</name> - <version>0.2-SNAPSHOT</version> + <version>4.0-SNAPSHOT</version> <licenses> <license> <name>GPLv3</name> @@ -38,12 +38,12 @@ <dependency> <groupId>info.magnolia</groupId> <artifactId>magnolia-core</artifactId> - <version>3.6.3</version> + <version>4.0-rc3</version> </dependency> <dependency> <groupId>info.magnolia</groupId> <artifactId>magnolia-module-admininterface</artifactId> - <version>3.6.3</version> + <version>4.0-rc3</version> </dependency> <dependency> <groupId>net.sourceforge.openutils</groupId> Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/configuration/MediaConfigurationManager.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/configuration/MediaConfigurationManager.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/configuration/MediaConfigurationManager.java 2009-02-13 16:24:47 UTC (rev 989) @@ -50,6 +50,8 @@ import net.sourceforge.openutils.mgnlmedia.media.pages.MediaFolderViewPage; import net.sourceforge.openutils.mgnlmedia.media.types.MediaTypeHandler; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -236,7 +238,6 @@ /** * {@inheritDoc} */ - @Override public boolean accept(Content content) { try @@ -260,7 +261,6 @@ /** * {@inheritDoc} */ - @Override public int compare(Content o1, Content o2) { if (sorting.equals(MediaFolderViewPage.SORT_BY_FILENAME)) @@ -337,6 +337,41 @@ return medias; } + @SuppressWarnings("unchecked") + public Collection<Content> search(String text, final String type) throws RepositoryException + { + QueryManager qm = MgnlContext.getQueryManager(MediaModuleLifecycle.REPO); + StringBuilder sb = new StringBuilder(); + sb.append("//*[jcr:contains(.,'"); + sb.append(StringUtils.replace(text, "'", "''")); + sb.append("')] order by @jcr:score descending"); + Query q = qm.createQuery(sb.toString(), Query.XPATH); + QueryResult qr = q.execute(); + Collection c = qr.getContent(MediaConfigurationManager.MGNL_MEDIA_TYPE); + + if (!StringUtils.isBlank(type)) + { + CollectionUtils.filter(c, new Predicate() + { + + /** + * {@inheritDoc} + */ + public boolean evaluate(Object object) + { + if (object instanceof Content) + { + return NodeDataUtil.getString((Content) object, "type").equals(type); + } + return false; + } + + }); + } + + return c; + } + /** * Get the type configuration for a media * @param media media Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/dialog/DialogSelectMedia.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/dialog/DialogSelectMedia.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/dialog/DialogSelectMedia.java 2009-02-13 16:24:47 UTC (rev 989) @@ -19,7 +19,6 @@ import freemarker.template.TemplateException; import freemarker.template.TemplateMethodModel; -import freemarker.template.TemplateModel; import freemarker.template.TemplateModelException; import info.magnolia.cms.core.Content; import info.magnolia.cms.core.HierarchyManager; @@ -298,7 +297,6 @@ /** * {@inheritDoc} */ - @Override public Object exec(List arguments) throws TemplateModelException { if (arguments != null && arguments.size() == 3 && arguments.get(0) instanceof HttpServletRequest) @@ -309,7 +307,7 @@ req.setAttribute(name, value); } - return TemplateModel.NOTHING; + return TemplateMethodModel.NOTHING; } } @@ -325,7 +323,6 @@ /** * {@inheritDoc} */ - @Override public Object exec(List arguments) throws TemplateModelException { if (arguments != null && arguments.size() == 2 && arguments.get(0) instanceof HttpServletRequest) Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/lifecycle/MediaModuleLifecycle.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/lifecycle/MediaModuleLifecycle.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/lifecycle/MediaModuleLifecycle.java 2009-02-13 16:24:47 UTC (rev 989) @@ -30,18 +30,17 @@ */ public class MediaModuleLifecycle implements ModuleLifecycle { - /** - * + * */ public static final String REPO = "media"; private Logger log = LoggerFactory.getLogger(MediaModuleLifecycle.class); /** + * * {@inheritDoc} */ - @Override public void start(ModuleLifecycleContext ctx) { log.info("Starting module media"); @@ -49,9 +48,9 @@ } /** + * * {@inheritDoc} */ - @Override public void stop(ModuleLifecycleContext ctx) { log.info("Stopping module media"); Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.java 2009-02-13 16:24:47 UTC (rev 989) @@ -54,6 +54,7 @@ import org.apache.commons.chain.Command; import org.apache.commons.lang.StringUtils; +import org.apache.jackrabbit.util.ISO9075; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -113,6 +114,8 @@ private boolean develop; + private String search; + /** * @param name * @param request @@ -151,7 +154,10 @@ types = MediaConfigurationManager.getInstance().getTypes().values(); } - fillNumberOfMediaPerType(); + if (!StringUtils.isBlank(path)) + { + fillNumberOfMediaPerType(); + } if (sorting == null) { @@ -167,7 +173,9 @@ QueryManager qm = MgnlContext.getQueryManager(MediaModuleLifecycle.REPO); try { - Query q = qm.createQuery(path.substring(1) + "/*[type='" + mtc.getName() + "']", Query.XPATH); + Query q = qm.createQuery( + ISO9075.encodePath(path.substring(1)) + "/*[type='" + mtc.getName() + "']", + Query.XPATH); QueryResult qr = q.execute(); numberOfMedia.put(mtc.getName(), qr.getContent(MediaConfigurationManager.MEDIA.getSystemName()).size()); @@ -186,25 +194,48 @@ public String show() { HierarchyManager hm = MgnlContext.getInstance().getHierarchyManager(MediaModuleLifecycle.REPO); + MediaTypeConfiguration mtc = MediaConfigurationManager.getInstance().getTypes().get(type); - try + Collection<Content> mediasOfType = null; + medias = new ArrayList<MediaBean>(); + + develop = SystemProperty.getBooleanProperty("magnolia.develop"); + + if (!StringUtils.isBlank(path)) { - Content folder = hm.getContent(this.getPath()); + try + { + Content folder = hm.getContent(this.getPath()); - writable = folder.isGranted(Permission.WRITE); + writable = folder.isGranted(Permission.WRITE); + canPublish = writable && ActivationManagerFactory.getActivationManager().hasAnyActiveSubscriber(); - canPublish = writable && ActivationManagerFactory.getActivationManager().hasAnyActiveSubscriber(); + mediasOfType = MediaConfigurationManager.getInstance().getMediaNodes(folder, type, sorting); - develop = SystemProperty.getBooleanProperty("magnolia.develop"); + } + catch (RepositoryException ex) + { + log.error("Exception caught", ex); + } + } + else if (!StringUtils.isBlank(search)) + { + try + { + writable = false; + canPublish = false; - medias = new ArrayList<MediaBean>(); + mediasOfType = MediaConfigurationManager.getInstance().search(search, type); - MediaTypeConfiguration mtc = MediaConfigurationManager.getInstance().getTypes().get(type); - Collection<Content> mediasOfType = MediaConfigurationManager.getInstance().getMediaNodes( - folder, - type, - sorting); + } + catch (RepositoryException ex) + { + log.error("Exception caught", ex); + } + } + if (mediasOfType != null) + { for (Content media : mediasOfType) { MediaBean mb = new MediaBean(); @@ -218,17 +249,23 @@ mb.setDescription(mtc.getHandler().getDescription(media)); mb.setUuid(media.getUUID()); - mb.getUsedInWebPages().addAll( - MediaConfigurationManager.getInstance().getUsedInWebPages(media.getUUID())); + try + { + mb.setWritable(media.getParent().isGranted(Permission.WRITE)); + mb.setCanPublish(mb.isWritable() + && ActivationManagerFactory.getActivationManager().hasAnyActiveSubscriber()); + mb.getUsedInWebPages().addAll( + MediaConfigurationManager.getInstance().getUsedInWebPages(media.getUUID())); + } + catch (RepositoryException ex) + { + log.error("Exception caught", ex); + } medias.add(mb); } + } - } - catch (RepositoryException ex) - { - log.error("Exception caught", ex); - } return super.show(); } @@ -557,6 +594,10 @@ private List<String> usedInWebPages = new ArrayList<String>(); + private boolean canPublish; + + private boolean writable; + /** * Returns the metaData. * @return the metaData @@ -719,6 +760,42 @@ this.usedInWebPages = usedInWebPages; } + /** + * Returns the canPublish. + * @return the canPublish + */ + public boolean isCanPublish() + { + return canPublish; + } + + /** + * Sets the canPublish. + * @param canPublish the canPublish to set + */ + public void setCanPublish(boolean canPublish) + { + this.canPublish = canPublish; + } + + /** + * Returns the writable. + * @return the writable + */ + public boolean isWritable() + { + return writable; + } + + /** + * Sets the writable. + * @param writable the writable to set + */ + public void setWritable(boolean writable) + { + this.writable = writable; + } + } /** @@ -883,4 +960,22 @@ this.develop = develop; } + /** + * Returns the search. + * @return the search + */ + public String getSearch() + { + return search; + } + + /** + * Sets the search. + * @param search the search to set + */ + public void setSearch(String search) + { + this.search = search; + } + } Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaLoadZipFilePage.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaLoadZipFilePage.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaLoadZipFilePage.java 2009-02-13 16:24:47 UTC (rev 989) @@ -23,16 +23,20 @@ import info.magnolia.cms.core.ItemType; import info.magnolia.cms.core.NodeData; import info.magnolia.cms.core.Path; +import info.magnolia.cms.i18n.Messages; import info.magnolia.cms.security.AccessDeniedException; import info.magnolia.cms.util.NodeDataUtil; import info.magnolia.context.MgnlContext; +import info.magnolia.module.admininterface.TemplatedMVCHandler; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import java.util.zip.ZipInputStream; import javax.jcr.RepositoryException; import javax.servlet.http.HttpServletRequest; @@ -41,6 +45,7 @@ import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager; import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaTypeConfiguration; import net.sourceforge.openutils.mgnlmedia.media.lifecycle.MediaModuleLifecycle; +import net.sourceforge.openutils.mgnlmedia.media.types.MediaTypeHandler; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MessagesTemplatedMVCHandler.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MessagesTemplatedMVCHandler.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MessagesTemplatedMVCHandler.java 2009-02-13 16:24:47 UTC (rev 989) @@ -17,13 +17,13 @@ */ package net.sourceforge.openutils.mgnlmedia.media.pages; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import info.magnolia.cms.i18n.Messages; import info.magnolia.module.admininterface.TemplatedMVCHandler; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - /** * @author molaschi * @version $Id$ Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/save/MediaCustomSaveHandler.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/save/MediaCustomSaveHandler.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/save/MediaCustomSaveHandler.java 2009-02-13 16:24:47 UTC (rev 989) @@ -22,7 +22,7 @@ import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.security.AccessDeniedException; import info.magnolia.context.MgnlContext; -import info.magnolia.module.admininterface.CustomSaveHandler; +import info.magnolia.module.admininterface.FieldSaveHandler; import javax.jcr.RepositoryException; @@ -37,13 +37,12 @@ * @author molaschi * @version $Id$ */ -public class MediaCustomSaveHandler implements CustomSaveHandler +public class MediaCustomSaveHandler implements FieldSaveHandler { /** * {@inheritDoc} */ - @Override public void save(Content parentNode, Content configNode, String name, MultipartForm form, int type, int valueType, int isRichEditValue, int encoding) throws RepositoryException, AccessDeniedException { Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/MediaModuleVersionHandler.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/MediaModuleVersionHandler.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/MediaModuleVersionHandler.java 2009-02-13 16:24:47 UTC (rev 989) @@ -17,9 +17,14 @@ */ package net.sourceforge.openutils.mgnlmedia.media.setup; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.Task; import it.openutils.mgnltasks.SimpleModuleVersionHandler; +import java.util.ArrayList; +import java.util.List; + /** * @author manuel * @version $Id @@ -27,4 +32,18 @@ public class MediaModuleVersionHandler extends SimpleModuleVersionHandler { + /** + * {@inheritDoc} + */ + @Override + protected List getStartupTasks(InstallContext installContext) + { + List<Task> tasks = new ArrayList<Task>(); + + // tasks.add(new RemoveResolutionsNodeTask()); + // tasks.add(new RenameThumbToImageTask()); + + return tasks; + } + } Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/RemoveResolutionsNodeTask.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/RemoveResolutionsNodeTask.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/RemoveResolutionsNodeTask.java 2009-02-13 16:24:47 UTC (rev 989) @@ -17,6 +17,10 @@ */ package net.sourceforge.openutils.mgnlmedia.media.setup; +import java.util.Collection; + +import javax.jcr.RepositoryException; + import info.magnolia.cms.core.Content; import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.core.ItemType; @@ -26,11 +30,6 @@ import info.magnolia.module.InstallContext; import info.magnolia.module.delta.AbstractTask; import info.magnolia.module.delta.TaskExecutionException; - -import java.util.Collection; - -import javax.jcr.RepositoryException; - import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager; import net.sourceforge.openutils.mgnlmedia.media.lifecycle.MediaModuleLifecycle; @@ -54,7 +53,6 @@ /** * {@inheritDoc} */ - @Override public void execute(InstallContext installContext) throws TaskExecutionException { HierarchyManager hm = installContext.getHierarchyManager(MediaModuleLifecycle.REPO); Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/RenameThumbToImageTask.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/RenameThumbToImageTask.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/setup/RenameThumbToImageTask.java 2009-02-13 16:24:47 UTC (rev 989) @@ -56,7 +56,6 @@ /** * {@inheritDoc} */ - @Override public void execute(InstallContext installContext) throws TaskExecutionException { HierarchyManager hm = installContext.getHierarchyManager(MediaModuleLifecycle.REPO); Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/JcrBrowserWithNodeTypeTreeConfiguration.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/JcrBrowserWithNodeTypeTreeConfiguration.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/JcrBrowserWithNodeTypeTreeConfiguration.java 2009-02-13 16:24:47 UTC (rev 989) @@ -44,7 +44,7 @@ { // TODO Auto-generated method stub super.prepareTree(tree, browseMode, request); - + tree.addItemType(MediaConfigurationManager.MEDIA); tree.addItemType(MediaConfigurationManager.RESOLUTIONS); @@ -54,7 +54,6 @@ /** * {@inheritDoc} */ - @Override public String renderHtml(TreeColumn treeColumn, Content content) { try Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTreeConfiguration.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTreeConfiguration.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTreeConfiguration.java 2009-02-13 16:24:47 UTC (rev 989) @@ -49,7 +49,6 @@ /** * {@inheritDoc} */ - @Override public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest request) { final Messages msgs = getMessages(); @@ -209,7 +208,6 @@ /** * {@inheritDoc} */ - @Override public void prepareFunctionBar(Tree tree, boolean browseMode, HttpServletRequest request) { tree.addFunctionBarItem(FunctionBarItem.getRefreshFunctionBarItem(tree, getMessages(), request)); @@ -218,7 +216,6 @@ /** * {@inheritDoc} */ - @Override public void prepareTree(Tree tree, boolean browseMode, HttpServletRequest request) { final Messages msgs = getMessages(); Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTreeMVCHandler.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTreeMVCHandler.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTreeMVCHandler.java 2009-02-13 16:24:47 UTC (rev 989) @@ -17,11 +17,16 @@ */ package net.sourceforge.openutils.mgnlmedia.media.tree; +import info.magnolia.cms.core.ItemType; +import info.magnolia.context.Context; import info.magnolia.module.admininterface.AdminTreeMVCHandler; +import info.magnolia.module.admininterface.commands.ActivationCommand; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager; + import org.apache.commons.chain.Command; Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/AudioTypeHandler.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/AudioTypeHandler.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/AudioTypeHandler.java 2009-02-13 16:24:47 UTC (rev 989) @@ -44,7 +44,6 @@ /** * {@inheritDoc} */ - @Override public void init(Content typeDefinitionNode) { @@ -53,7 +52,6 @@ /** * {@inheritDoc} */ - @Override public String getUrl(Content media) { NodeData file = media.getNodeData("audio"); @@ -67,7 +65,6 @@ /** * {@inheritDoc} */ - @Override public String getUrl(Content media, Map<String, String> options) { return getUrl(media); @@ -76,7 +73,6 @@ /** * {@inheritDoc} */ - @Override public String getFilename(Content media) { NodeData file = media.getNodeData("audio"); @@ -86,7 +82,6 @@ /** * {@inheritDoc} */ - @Override public String getExtension(Content media) { NodeData file = media.getNodeData("audio"); @@ -96,7 +91,6 @@ /** * {@inheritDoc} */ - @Override public String getFullFilename(Content media) { return getFilename(media) + "." + getExtension(media); @@ -105,7 +99,6 @@ /** * {@inheritDoc} */ - @Override public String getThumbnailUrl(Content media) { return "/.resources/media/icons/audioThumb.jpg"; @@ -114,7 +107,6 @@ /** * {@inheritDoc} */ - @Override public String getPreviewUrl(Content media) { return getUrl(media); @@ -143,7 +135,6 @@ /** * {@inheritDoc} */ - @Override public String getNewNodeName(MultipartForm form) { return form.getParameter("audio_" + FileProperties.PROPERTY_FILENAME); @@ -152,7 +143,6 @@ /** * {@inheritDoc} */ - @Override public boolean onSavingPropertyMedia(Content media, Content parentNode, Content configNode, String name, MultipartForm form, int type, int valueType, int isRichEditValue, int encoding) throws RepositoryException, AccessDeniedException Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/BaseTypeHandler.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/BaseTypeHandler.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/BaseTypeHandler.java 2009-02-13 16:24:47 UTC (rev 989) @@ -64,7 +64,6 @@ /** * {@inheritDoc} */ - @Override public String getTitle(Content media) { return getPropertyLocalized(media, "title"); @@ -73,7 +72,6 @@ /** * {@inheritDoc} */ - @Override public String getTags(Content media) { return getPropertyLocalized(media, "tags"); @@ -82,7 +80,6 @@ /** * {@inheritDoc} */ - @Override public String getDescription(Content media) { return getPropertyLocalized(media, "description"); @@ -91,7 +88,6 @@ /** * {@inheritDoc} */ - @Override public String getAbstract(Content media) { return getPropertyLocalized(media, "abstract"); @@ -101,7 +97,6 @@ * {@inheritDoc} */ @SuppressWarnings("unchecked") - @Override public boolean onPostSave(Content media) { try Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/ImageTypeHandler.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/ImageTypeHandler.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/ImageTypeHandler.java 2009-02-13 16:24:47 UTC (rev 989) @@ -55,7 +55,6 @@ /** * {@inheritDoc} */ - @Override public void init(Content typeDefinitionNode) { @@ -64,7 +63,6 @@ /** * {@inheritDoc} */ - @Override public String getFilename(Content media) { NodeData file = media.getNodeData("image"); @@ -74,7 +72,6 @@ /** * {@inheritDoc} */ - @Override public String getExtension(Content media) { NodeData file = media.getNodeData("image"); @@ -84,7 +81,6 @@ /** * {@inheritDoc} */ - @Override public String getFullFilename(Content media) { return getFilename(media) + "." + getExtension(media); @@ -93,7 +89,6 @@ /** * {@inheritDoc} */ - @Override public String getUrl(Content media) { NodeData file = media.getNodeData("image"); @@ -107,7 +102,6 @@ /** * {@inheritDoc} */ - @Override public String getUrl(Content media, Map<String, String> options) { return getUrl(media); @@ -116,7 +110,6 @@ /** * {@inheritDoc} */ - @Override public String getThumbnailUrl(Content media) { if (!ImageUtils.checkOrCreateResolution(media, "thumbnail")) @@ -132,7 +125,6 @@ /** * {@inheritDoc} */ - @Override public String getPreviewUrl(Content media) { if (!ImageUtils.checkOrCreateResolution(media, "preview")) @@ -174,7 +166,6 @@ /** * {@inheritDoc} */ - @Override public void saveFromZipFile(Content media, File f, String cleanFileName, String extension) throws AccessDeniedException, RepositoryException { @@ -189,7 +180,6 @@ /** * {@inheritDoc} */ - @Override public String getNewNodeName(MultipartForm form) { return form.getParameter("image_" + FileProperties.PROPERTY_FILENAME); @@ -198,7 +188,6 @@ /** * {@inheritDoc} */ - @Override public boolean onSavingPropertyMedia(final Content media, final Content parentNode, final Content configNode, final String name, final MultipartForm form, final int type, final int valueType, final int isRichEditValue, final int encoding) throws RepositoryException, AccessDeniedException Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/VideoTypeHandler.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/VideoTypeHandler.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/VideoTypeHandler.java 2009-02-13 16:24:47 UTC (rev 989) @@ -47,7 +47,6 @@ /** * {@inheritDoc} */ - @Override public void init(Content typeDefinitionNode) { @@ -56,7 +55,6 @@ /** * {@inheritDoc} */ - @Override public String getUrl(Content media) { NodeData file = media.getNodeData("video"); @@ -70,7 +68,6 @@ /** * {@inheritDoc} */ - @Override public String getUrl(Content media, Map<String, String> options) { return getUrl(media); @@ -79,7 +76,6 @@ /** * {@inheritDoc} */ - @Override public String getFilename(Content media) { NodeData file = media.getNodeData("video"); @@ -89,7 +85,6 @@ /** * {@inheritDoc} */ - @Override public String getExtension(Content media) { NodeData file = media.getNodeData("video"); @@ -99,7 +94,6 @@ /** * {@inheritDoc} */ - @Override public String getFullFilename(Content media) { return getFilename(media) + "." + getExtension(media); @@ -108,7 +102,6 @@ /** * {@inheritDoc} */ - @Override public String getThumbnailUrl(Content media) { if (!ImageUtils.checkOrCreateResolution(media, "thumbnail")) @@ -124,7 +117,6 @@ /** * {@inheritDoc} */ - @Override public String getPreviewUrl(Content media) { return getUrl(media); @@ -153,7 +145,6 @@ /** * {@inheritDoc} */ - @Override public String getNewNodeName(MultipartForm form) { return form.getParameter("video_" + FileProperties.PROPERTY_FILENAME); @@ -162,7 +153,6 @@ /** * {@inheritDoc} */ - @Override public boolean onSavingPropertyMedia(Content media, Content parentNode, Content configNode, String name, MultipartForm form, int type, int valueType, int isRichEditValue, int encoding) throws RepositoryException, AccessDeniedException Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/YouTubeVideoTypeHandler.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/YouTubeVideoTypeHandler.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/types/impl/YouTubeVideoTypeHandler.java 2009-02-13 16:24:47 UTC (rev 989) @@ -54,7 +54,6 @@ /** * {@inheritDoc} */ - @Override public void init(Content typeDefinitionNode) { @@ -63,7 +62,6 @@ /** * {@inheritDoc} */ - @Override public String getUrl(Content media) { return media.getNodeData("videoUrl").getString(); @@ -72,7 +70,6 @@ /** * {@inheritDoc} */ - @Override public String getUrl(Content media, Map<String, String> options) { return getUrl(media); @@ -81,7 +78,6 @@ /** * {@inheritDoc} */ - @Override public String getFilename(Content media) { return getUrl(media); @@ -90,7 +86,6 @@ /** * {@inheritDoc} */ - @Override public String getExtension(Content media) { return null; @@ -99,7 +94,6 @@ /** * {@inheritDoc} */ - @Override public String getFullFilename(Content media) { return null; @@ -108,7 +102,6 @@ /** * {@inheritDoc} */ - @Override public String getThumbnailUrl(Content media) { if (!ImageUtils.checkOrCreateResolution(media, "thumbnail")) @@ -124,7 +117,6 @@ /** * {@inheritDoc} */ - @Override public String getPreviewUrl(Content media) { return getUrl(media); @@ -148,7 +140,6 @@ /** * {@inheritDoc} */ - @Override public String getNewNodeName(MultipartForm form) { String videoUrl = form.getParameter("videoUrl"); @@ -176,7 +167,6 @@ /** * {@inheritDoc} */ - @Override public boolean onSavingPropertyMedia(Content media, Content parentNode, Content configNode, String name, MultipartForm form, int type, int valueType, int isRichEditValue, int encoding) throws RepositoryException, AccessDeniedException Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-02-13 16:24:47 UTC (rev 989) @@ -27,7 +27,6 @@ import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; -import java.awt.Transparency; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.io.BufferedOutputStream; @@ -87,7 +86,7 @@ private static int getType(ColorModel cm) { - if (cm.getTransparency() == Transparency.BITMASK) + if (cm.getTransparency() == ColorModel.BITMASK) { if (cm.isAlphaPremultiplied()) { @@ -98,7 +97,7 @@ return BufferedImage.TYPE_4BYTE_ABGR; } } - if (cm.getTransparency() == Transparency.TRANSLUCENT) + if (cm.getTransparency() == ColorModel.TRANSLUCENT) { if (cm.isAlphaPremultiplied()) { @@ -449,7 +448,6 @@ /** * {@inheritDoc} */ - @Override public void exec() { HierarchyManager hm = MgnlContext.getHierarchyManager(MediaModuleLifecycle.REPO); Added: trunk/openutils-mgnlmedia/src/main/resources/info/magnolia/cms/gui/control/MediaTreeAddress.ftl =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/info/magnolia/cms/gui/control/MediaTreeAddress.ftl (rev 0) +++ trunk/openutils-mgnlmedia/src/main/resources/info/magnolia/cms/gui/control/MediaTreeAddress.ftl 2009-02-13 16:24:47 UTC (rev 989) @@ -0,0 +1,2 @@ +<img src="${contextPath}/.resources/0.gif" height="3px"/> +<input id="${tree.javascriptTree}SearchBar" type="text" onkeydown="if (mgnlIsKeyEnter(event)) parent.search(this.value);" class="mgnlDialogControlEdit" style="width:100%;" value="" /> \ No newline at end of file Modified: trunk/openutils-mgnlmedia/src/main/resources/info/magnolia/cms/gui/control/MediaTreeFooter.ftl =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/info/magnolia/cms/gui/control/MediaTreeFooter.ftl 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/resources/info/magnolia/cms/gui/control/MediaTreeFooter.ftl 2009-02-13 16:24:47 UTC (rev 989) @@ -21,7 +21,11 @@ ${menu.html} </#if> -<#if tree.browseMode && !selectMedia> +<#if tree.browseMode && selectMedia?exists && selectMedia> + <#include "MediaTreeAddress.ftl"/> +</#if> + +<#if tree.browseMode && (!selectMedia?exists || !selectMedia)> <#include "TreeAddressBar.ftl"/> </#if> Modified: trunk/openutils-mgnlmedia/src/main/resources/mgnl-resources/media/js/mootips.js =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/mgnl-resources/media/js/mootips.js 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/resources/mgnl-resources/media/js/mootips.js 2009-02-13 16:24:47 UTC (rev 989) @@ -17,6 +17,29 @@ leaveTip : function() { $clear(this.timer); this.timer = this.hide.delay(this.options.hideDelay, this); + }, + + position : function(event) { + var size = window.getSize(), scroll = window.getScroll(); + var tip = { + x :this.tip.offsetWidth, + y :this.tip.offsetHeight + }; + var props = { + x :'left', + y :'top' + }; + for ( var z in props) { + var pos = event.page[z] + this.options.offsets[z]; + if ((pos + tip[z] - scroll[z]) > size[z]) { + pos = pos - ((pos + tip[z] - scroll[z]) - size[z]); + if (pos < 0) + { + pos = 0; + } + } + this.tip.setStyle(props[z], pos); + } } }); \ No newline at end of file Modified: trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html 2009-02-13 16:24:47 UTC (rev 989) @@ -29,6 +29,21 @@ return url; } +function search(textToSearch) { + viewport.getComponent('center-panel').setTitle("Search results for : "+ textToSearch); + + var url = "${this.request.contextPath}/.magnolia/pages/mediaFolderView.html?search="+ textToSearch + "&mgnlCK=" + (new Date()).getTime(); + if (selectMedia) + { + url += "&selectMedia=true&actMediaHandle="+ actMediaHandle; + } + if (mediaType != null && mediaType != 'null') + { + url += "&mediaType=" + mediaType; + } + frames['mediaFolderView'].location.href = url; +} + Ext.onReady(function(){ Ext.state.Manager.setProvider(new Ext.state.CookieProvider()); Modified: trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.html =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.html 2009-02-13 16:01:55 UTC (rev 988) +++ trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.html 2009-02-13 16:24:47 UTC (rev 989) @@ -25,7 +25,7 @@ function performAction(action, source, dest) { - if (action == "move" && dest == "${this.path}") + if (action == "move" && dest == "${this.path!""}") { alert("Non è possibile spostare all'interno dello stesso nodo."); return; @@ -88,7 +88,8 @@ <body> <form action="" style="display:none" id="actionForm"> <input type="hidden" id="actionCmd" name="command" value="delete" /> - <input type="hidden" id="actionPath" name="path" value="${this.path}" /> + <input type="hidden" id="actionPath" name="path" value="${this.path!""}" /> + <input type="hidden" id="actionSearch" name="search" value="${this.search!""}" /> <input type="hidden" id="actionNode" name="node" /> <input type="hidden" id="actionDest" name="dest" /> <input type="hidden" name="type" value="${this.type}" /> @@ -102,14 +103,14 @@ </#if> <div class="voice ${actual}"> <#if this.request.parameterMap['selectMedia']?exists> - <a href="?type=${type.name}&path=${this.path}&selectMedia=true"> + <a href="?type=${type.name}&path=${this.path!""}&selectMedia=true&search=${this.search!""}"> <img src="${this.request.contextPath}${type.menuIcon}" border="0" align="absmiddle" /> - ${this.msgs.get('media.types.' + type.name)} (${this.numberOfMedia[type.name]!'0'}) + ${this.msgs.get('media.types.' + type.name)} <#if this.numberOfMedia?exists>(${this.numberOfMedia[type.name]!'0'})</#if> </a> <#else> - <a href="?type=${type.name}&path=${this.path}"> + <a href="?type=${type.name}&path=${this.path!""}&search=${this.search!""}"> <img src="${this.request.contextPath}${type.menuIcon}" border="0" align="absmiddle" /> - ${this.msgs.get('media.types.' + type.name)} (${this.numberOfMedia[type.name]!'0'}) + ${this.msgs.get('media.types.' + type.name)} <#if this.numberOfMedia?exists>(${this.numberOfMedia[type.name]!'0'})</#if> </a> </#if> </div> @@ -150,7 +151,7 @@ ${this.msgs.get('media.select')} </a> <#else> - <#if this.canPublish && media.metaData.activationStatus < 2> + <#if media.canPublish && media.metaData.activationStatus < 2> <a href="javascript:$empty()" onclick="performAction('activate', '${media.handle}','')" title="pubblica"> <img src="${this.request.contextPath}/.resources/icons/16/arrow_right_green.gif" border="0" align="middle" /> </a> @@ -159,7 +160,7 @@ </#if> </#if> <#else> - <#if this.writable> + <#if media.writable> <a href="javascript:$empty()" onclick="openDialog('${media.handle}')" title="${this.msgs.get('media.edit')}"> <img src="${this.request.contextPath}/.resources/media/icons/edit.gif" border="0" align="middle" /> </a> @@ -186,7 +187,7 @@ <img src="${this.request.contextPath}/.resources/icons/16/copy_inactive.gif" border="0" align="middle" /> </a> </#if> - <#if this.canPublish> + <#if media.canPublish> <a href="javascript:$empty()" onclick="performAction('activate', '${media.handle}','')" title="${this.msgs.get('media.activate')}"> <img src="${this.request.contextPath}/.resources/icons/16/arrow_right_green.gif" border="0" align="middle" /> </a> @@ -196,7 +197,7 @@ align="middle" /> </a> </#if> - <#if this.canPublish && media.metaData.activationStatus = 2> + <#if media.canPublish && media.metaData.activationStatus = 2> <a href="javascript:$empty()" onclick="performAction('deactivate', '${media.handle}','')" title="${this.msgs.get('media.deactivate')}"> <img src="${this.request.contextPath}/.resources/icons/16/arrow_left_red.gif" border="0" align="middle" /> </a> @@ -214,7 +215,7 @@ <#else> <#assign pages = ""> <#list media.usedInWebPages as page> - <#assign pages = pages + "<a href='${this.request.contextPath}" + page +".html' target='_blank'>"+ page +"</a><br/>"> + <#assign pages = pages + "<a href='${this.request.contextPath}" + page +".html' target='_blank'>"+ page +"</a><br/>"> </#list> <span class="tips" rel="${pages}">${this.msgs.get('media.pages')} (${media.usedInWebPages?size})</span> </#if> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 16:02:00
|
Revision: 988 http://openutils.svn.sourceforge.net/openutils/?rev=988&view=rev Author: molaschi Date: 2009-02-13 16:01:55 +0000 (Fri, 13 Feb 2009) Log Message: ----------- [maven-release-plugin] prepare for next development iteration Modified Paths: -------------- trunk/openutils-mgnlmessages/pom.xml Modified: trunk/openutils-mgnlmessages/pom.xml =================================================================== --- trunk/openutils-mgnlmessages/pom.xml 2009-02-13 16:01:39 UTC (rev 987) +++ trunk/openutils-mgnlmessages/pom.xml 2009-02-13 16:01:55 UTC (rev 988) @@ -9,7 +9,7 @@ <packaging>jar</packaging> <artifactId>openutils-mgnlmessages</artifactId> <name>openutils-mgnlmessages</name> - <version>4.0-b1</version> + <version>4.0-b2-SNAPSHOT</version> <licenses> <license> <name>GPLv3</name> @@ -82,10 +82,4 @@ </snapshots> </repository> </repositories> - - <scm> - <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmessages-4.0-b1</connection> - <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmessages-4.0-b1</developerConnection> - <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-mgnlmessages-4.0-b1</url> - </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 16:01:43
|
Revision: 987 http://openutils.svn.sourceforge.net/openutils/?rev=987&view=rev Author: molaschi Date: 2009-02-13 16:01:39 +0000 (Fri, 13 Feb 2009) Log Message: ----------- [maven-release-plugin] copy for tag openutils-mgnlmessages-4.0-b1 Added Paths: ----------- tags/openutils-mgnlmessages-4.0-b1/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 16:00:20
|
Revision: 986 http://openutils.svn.sourceforge.net/openutils/?rev=986&view=rev Author: molaschi Date: 2009-02-13 16:00:15 +0000 (Fri, 13 Feb 2009) Log Message: ----------- [maven-release-plugin] prepare release openutils-mgnlmessages-4.0-b1 Modified Paths: -------------- trunk/openutils-mgnlmessages/pom.xml Modified: trunk/openutils-mgnlmessages/pom.xml =================================================================== --- trunk/openutils-mgnlmessages/pom.xml 2009-02-13 15:58:34 UTC (rev 985) +++ trunk/openutils-mgnlmessages/pom.xml 2009-02-13 16:00:15 UTC (rev 986) @@ -1,5 +1,4 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> <parent> <groupId>net.sourceforge.openutils</groupId> <artifactId>openutils</artifactId> @@ -10,7 +9,7 @@ <packaging>jar</packaging> <artifactId>openutils-mgnlmessages</artifactId> <name>openutils-mgnlmessages</name> - <version>4.0-SNAPSHOT</version> + <version>4.0-b1</version> <licenses> <license> <name>GPLv3</name> @@ -83,4 +82,10 @@ </snapshots> </repository> </repositories> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmessages-4.0-b1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlmessages-4.0-b1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-mgnlmessages-4.0-b1</url> + </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 15:58:42
|
Revision: 985 http://openutils.svn.sourceforge.net/openutils/?rev=985&view=rev Author: molaschi Date: 2009-02-13 15:58:34 +0000 (Fri, 13 Feb 2009) Log Message: ----------- remove empty package Removed Paths: ------------- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/manager/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 15:57:52
|
Revision: 984 http://openutils.svn.sourceforge.net/openutils/?rev=984&view=rev Author: molaschi Date: 2009-02-13 15:57:45 +0000 (Fri, 13 Feb 2009) Log Message: ----------- new release to support magnolia 4.0.x Modified Paths: -------------- trunk/openutils-mgnlmessages/pom.xml trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesManager.java trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/SimpleMessagesImpl.java trunk/openutils-mgnlmessages/src/main/resources/META-INF/magnolia/messages.xml trunk/openutils-mgnlmessages/src/site/apt/index.apt trunk/openutils-mgnlmessages/src/site/changes/changes.xml Added Paths: ----------- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesProvider.java trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/manager/ Modified: trunk/openutils-mgnlmessages/pom.xml =================================================================== --- trunk/openutils-mgnlmessages/pom.xml 2009-02-13 11:59:07 UTC (rev 983) +++ trunk/openutils-mgnlmessages/pom.xml 2009-02-13 15:57:45 UTC (rev 984) @@ -1,4 +1,5 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> <parent> <groupId>net.sourceforge.openutils</groupId> <artifactId>openutils</artifactId> @@ -9,7 +10,7 @@ <packaging>jar</packaging> <artifactId>openutils-mgnlmessages</artifactId> <name>openutils-mgnlmessages</name> - <version>1.2-SNAPSHOT</version> + <version>4.0-SNAPSHOT</version> <licenses> <license> <name>GPLv3</name> @@ -38,12 +39,12 @@ <dependency> <groupId>info.magnolia</groupId> <artifactId>magnolia-core</artifactId> - <version>3.6.3</version> + <version>4.0-rc3</version> </dependency> <dependency> <groupId>info.magnolia</groupId> <artifactId>magnolia-module-admininterface</artifactId> - <version>3.6.3</version> + <version>4.0-rc3</version> </dependency> <dependency> <groupId>net.sourceforge.openutils</groupId> Modified: trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesManager.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesManager.java 2009-02-13 11:59:07 UTC (rev 983) +++ trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesManager.java 2009-02-13 15:57:45 UTC (rev 984) @@ -1,6 +1,6 @@ /** - * This file Copyright (c) 2003-2008 Magnolia International - * Ltd. (http://www.magnolia.info). All rights reserved. + * This file Copyright (c) 2003-2009 Magnolia International + * Ltd. (http://www.magnolia-cms.com). All rights reserved. * * * This file is dual-licensed under both the Magnolia @@ -25,7 +25,7 @@ * 2. For the Magnolia Network Agreement (MNA), this file * and the accompanying materials are made available under the * terms of the MNA which accompanies this distribution, and - * is available at http://www.magnolia.info/mna.html + * is available at http://www.magnolia-cms.com/mna.html * * Any modifications to this file must keep this entire header * intact. @@ -33,16 +33,23 @@ */ package info.magnolia.cms.i18n; -import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.beans.config.ContentRepository; import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.core.ItemType; +import info.magnolia.cms.util.FactoryUtil; import info.magnolia.cms.util.NodeDataUtil; import info.magnolia.cms.util.ObservationUtil; import info.magnolia.content2bean.Content2BeanUtil; -import info.magnolia.context.Context; import info.magnolia.context.MgnlContext; +import org.apache.commons.collections.Transformer; +import org.apache.commons.collections.map.LazyMap; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.jcr.observation.EventIterator; +import javax.jcr.observation.EventListener; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -51,52 +58,33 @@ import java.util.Locale; import java.util.Map; -import javax.jcr.observation.EventIterator; -import javax.jcr.observation.EventListener; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; -import javax.servlet.jsp.jstl.core.Config; -import net.sourceforge.openutils.mgnlmessages.i18n.RepositoryMessagesImpl; - -import org.apache.commons.collections.Transformer; -import org.apache.commons.collections.map.LazyMap; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - /** * From this class you get the i18n messages. You should pass a a request, but if you can't the getMessages method will * handle it properly. The get() methods are easy to use. + * * @author philipp */ -public final class MessagesManager -{ +public final class MessagesManager implements MessagesProvider{ + private final static Logger log = LoggerFactory.getLogger(MessagesManager.class); /** - * Use this locale if no other provided + * Use this locale if no other provided. */ public static final String FALLBACK_LOCALE = "en"; //$NON-NLS-1$ /** - * Use this basename if no other is provided + * Use this basename if no other is provided. */ public static final String DEFAULT_BASENAME = "info.magnolia.module.admininterface.messages"; //$NON-NLS-1$ /** - * Logger. + * The node name where the configuration for i18n is stored. */ - protected static Logger log = LoggerFactory.getLogger(AbstractMessagesImpl.class); - - /** - * The node name where the configuration for i18n is stored - */ private static final String I18N_CONFIG_PATH = "/server/i18n/system"; //$NON-NLS-1$ /** - * The name of the property to store the current system language + * The name of the property to store the current system language. */ private static final String FALLBACK_NODEDATA = "fallbackLanguage"; //$NON-NLS-1$ @@ -105,107 +93,89 @@ */ private static final String LANGUAGES_NODE_NAME = "languages"; //$NON-NLS-1$ - /** - * The current locale of the application - */ - private static Locale applicationLocale; - /** - * List of the available locales - */ - private static Collection availableLocales = new ArrayList(); + public static MessagesProvider getInstance() { + return (MessagesProvider) FactoryUtil.getSingleton(MessagesManager.class); + } /** - * The context used for the messages + * The current locale of the application. */ - private static ServletContext context; + private Locale applicationLocale; /** - * LRU Map for the messages + * List of the available locales. */ - private static Map messages; + private final Collection availableLocales = new ArrayList(); /** - * Util has no public constructor + * Map for the messages. */ - private MessagesManager() - { - } + private Map messages; - static - { + private String defaultBasename = DEFAULT_BASENAME; + + public MessagesManager() { // setting default language (en) - MessagesManager.setDefaultLocale(FALLBACK_LOCALE); + setDefaultLocale(FALLBACK_LOCALE); - initLRUMap(); + initMap(); } + // for tests + void setDefaultBasename(String defaultBasename) { + this.defaultBasename = defaultBasename; + } + /** - * Called through the initialization process (startup of the container) - * @param context servlet context + * Called through the initialization process. (startup of the container) */ - public static void init(ServletContext context) - { - MessagesManager.context = context; - - // setting fallback - context.setAttribute(Config.FMT_FALLBACK_LOCALE + ".application", FALLBACK_LOCALE); //$NON-NLS-1$ - // setting basename - context.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".application", MessagesManager.DEFAULT_BASENAME); //$NON-NLS-1$ - // for Resin and other J2EE Containers - context.setAttribute(Config.FMT_LOCALIZATION_CONTEXT, MessagesManager.DEFAULT_BASENAME); - + public void init() { load(); registerEventListener(); } /** - * The lazzy LRU Map creates messages objects with a faul back to the default locale. + * The lazy Map creates messages objects with a fall back to the default locale. */ - private static void initLRUMap() - { - // FIXME use LRU - // Map map = new LRUMap(20); - Map map = new HashMap(); - map = LazyMap.decorate(map, new Transformer() - { - - public Object transform(Object input) - { - MessagesID id = (MessagesID) input; - // check http://jira.magnolia.info/browse/MAGNOLIA-1060 - // We are now chaining current user (LOCALE) messages with system default messages - // so that it fallsback to default locale if string is not found instead of displaying broken - // ???LABELS??? - Messages msgs = new MessagesChain(new RepositoryMessagesImpl(id.basename, id.locale)) - .chain(new DefaultMessagesImpl(id.basename, id.locale)); - if (!MessagesManager.getDefaultLocale().equals(id.locale)) - { - msgs = new MessagesChain(msgs).chain(MessagesManager.getMessages(id.basename, MessagesManager - .getDefaultLocale())); - } - return msgs; + protected void initMap() { + // FIXME use LRU: new LRUMap(20); + // LazyMap will instanciate bundles on demand. + final Map map = LazyMap.decorate(new HashMap(), new Transformer() { + // this transformer will wrap the Messages in a MessagesChain which will fall back to a Messages instance for the same bundle with default locale. + public Object transform(Object input) { + final MessagesID id = (MessagesID) input; + return newMessages(id); } }); messages = Collections.synchronizedMap(map); } /** + * Initializes a new Messages instances for the given MessagesID. + * By default, we chain to the same bundle with the default Locale. (so untranslated messages show up in the default language) + */ + protected Messages newMessages(MessagesID messagesID) { + Messages msgs = new DefaultMessagesImpl(messagesID.basename, messagesID.locale); + if (!getDefaultLocale().equals(messagesID.locale)) { + msgs = new MessagesChain(msgs).chain(getMessages(messagesID.basename, getDefaultLocale())); + } + return msgs; + } + + /** * Load i18n configuration. */ - public static void load() - { + protected void load() { // reading the configuration from the repository, no need for context - HierarchyManager hm = ContentRepository.getHierarchyManager(ContentRepository.CONFIG); + HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager(ContentRepository.CONFIG); - try - { - log.info("Config : loading i18n configuration - " + I18N_CONFIG_PATH); //$NON-NLS-1$ + try { + log.info("Loading i18n configuration - " + I18N_CONFIG_PATH); //$NON-NLS-1$ // checks if node exists - if (!hm.isExist(I18N_CONFIG_PATH)) - { + if (!hm.isExist(I18N_CONFIG_PATH)) { // configNode = ContentUtil.createPath(hm, I18N_CONFIG_PATH, ItemType.CONTENT, true); log.warn(I18N_CONFIG_PATH + " does not exist yet; skipping."); return; @@ -213,51 +183,40 @@ final Content configNode = hm.getContent(I18N_CONFIG_PATH); //$NON-NLS-1$ - MessagesManager.setDefaultLocale(NodeDataUtil.getString(configNode, FALLBACK_NODEDATA, FALLBACK_LOCALE)); + setDefaultLocale(NodeDataUtil.getString(configNode, FALLBACK_NODEDATA, FALLBACK_LOCALE)); // get the available languages - creates it if it does not exist - necessary to update to 3.5 final Content languagesNode; - if (configNode.hasContent(LANGUAGES_NODE_NAME)) - { + if (configNode.hasContent(LANGUAGES_NODE_NAME)) { languagesNode = configNode.getContent(LANGUAGES_NODE_NAME); - } - else - { + } else { languagesNode = configNode.createContent(LANGUAGES_NODE_NAME, ItemType.CONTENT); } Map languageDefinitions = Content2BeanUtil.toMap(languagesNode, true, LocaleDefinition.class); // clear collection for reload - MessagesManager.availableLocales.clear(); + availableLocales.clear(); - for (Iterator iter = languageDefinitions.values().iterator(); iter.hasNext();) - { + for (Iterator iter = languageDefinitions.values().iterator(); iter.hasNext();) { LocaleDefinition ld = (LocaleDefinition) iter.next(); - if (ld.isEnabled()) - { + if (ld.isEnabled()) { availableLocales.add(ld.getLocale()); } } } - catch (Exception e) - { - log.error("Config : Failed to load i18n configuration - " + I18N_CONFIG_PATH, e); //$NON-NLS-1$ + catch (Exception e) { + log.error("Failed to load i18n configuration - " + I18N_CONFIG_PATH, e); //$NON-NLS-1$ } } /** * Register an event listener: reload configuration when something changes. */ - private static void registerEventListener() - { - + private void registerEventListener() { log.info("Registering event listener for i18n"); //$NON-NLS-1$ - ObservationUtil.registerChangeListener(ContentRepository.CONFIG, I18N_CONFIG_PATH, new EventListener() - { - - public void onEvent(EventIterator iterator) - { + ObservationUtil.registerChangeListener(ContentRepository.CONFIG, I18N_CONFIG_PATH, new EventListener() { + public void onEvent(EventIterator iterator) { // reload everything reload(); } @@ -267,59 +226,56 @@ /** * Reload i18n configuration. */ - public static void reload() - { - try - { - reloadBundles(); + public void reload() { + try { + // reload all present + for (Iterator iter = messages.values().iterator(); iter.hasNext();) { + Messages msgs = (Messages) iter.next(); + msgs.reload(); + } } - catch (Exception e) - { - log.error("can't reload i18n messages", e); + catch (Exception e) { + log.error("Can't reload i18n messages", e); } - initLRUMap(); + initMap(); load(); } - public static Messages getMessages() - { - return getMessages(MessagesManager.DEFAULT_BASENAME, MgnlContext.getLocale()); + public Messages getMessagesInternal(String basename, Locale locale) { + if (StringUtils.isEmpty(basename)) { + basename = defaultBasename; + } + return (Messages) messages.get(new MessagesID(basename, locale)); } - public static Messages getMessages(String basename) - { - return getMessages(basename, MgnlContext.getLocale()); + public static Messages getMessages() { + return getMessages(null, getCurrentLocale()); } - public static Messages getMessages(Locale locale) - { - return getMessages(MessagesManager.DEFAULT_BASENAME, locale); + public static Messages getMessages(String basename) { + return getMessages(basename, getCurrentLocale()); } - public static Messages getMessages(String basename, Locale locale) - { - if (StringUtils.isEmpty(basename)) - { - basename = MessagesManager.DEFAULT_BASENAME; - } - return (Messages) messages.get(new MessagesID(basename, locale)); + public static Messages getMessages(Locale locale) { + return getMessages(null, locale); } - public static String get(String key) - { - return MgnlContext.getMessages().get(key); + public static Messages getMessages(String basename, Locale locale) { + return getInstance().getMessagesInternal(basename, locale); } + public static String get(String key) { + return getMessages().get(key); + } + /** - * Get a message with parameters inside: the value {0} must be a number + * Get a message with parameters inside: the value {0} must be a number. * @param key key to find * @param args replacement strings * @return message */ - - public static String get(String key, Object[] args) - { - return MgnlContext.getMessages().get(key, args); + public static String get(String key, Object[] args) { + return getMessages().get(key, args); } /** @@ -328,10 +284,8 @@ * @param defaultMsg default message * @return message */ - - public static String getWithDefault(String key, String defaultMsg) - { - return MgnlContext.getMessages().getWithDefault(key, defaultMsg); + public static String getWithDefault(String key, String defaultMsg) { + return getMessages().getWithDefault(key, defaultMsg); } /** @@ -341,116 +295,66 @@ * @param defaultMsg default message * @return message */ - public static String getWithDefault(String key, Object[] args, String defaultMsg) - { - return MgnlContext.getMessages().getWithDefault(key, args, defaultMsg); + public static String getWithDefault(String key, Object[] args, String defaultMsg) { + return getMessages().getWithDefault(key, args, defaultMsg); } - /** - * @return Returns the defaultLocale. - */ - public static Locale getDefaultLocale() - { - return applicationLocale; + private static Locale getCurrentLocale() { + return MgnlContext.getInstance().getLocale(); } - /** - * Deprectated! Use MgnlContext - * @return Returns the current locale for the current user - * @deprecated - */ - public static Locale getCurrentLocale(HttpServletRequest request) - { - try - { - return MgnlContext.getLocale(); - } - catch (Exception e) - { - return getDefaultLocale(); - } + public Locale getDefaultLocale() { + return applicationLocale; } /** * @param defaultLocale The defaultLocale to set. + * @deprecated since 4.0 - not used and should not be. Use setLocale() on the SystemContext instead. + * --note: do not remove the method, make it private. applicationLocale field is still needed. + * --and/or remove duplication with SystemContext.locale */ - public static void setDefaultLocale(String defaultLocale) - { - MessagesManager.applicationLocale = new Locale(defaultLocale); - MgnlContext.getSystemContext().setLocale(applicationLocale); - - if (context != null) - { - context.setAttribute(Config.FMT_LOCALE + ".application", defaultLocale); //$NON-NLS-1$ - } + public void setDefaultLocale(String defaultLocale) { + this.applicationLocale = new Locale(defaultLocale); + //MgnlContext.getSystemContext().setLocale(applicationLocale); } - /** - * @return Returns the availableLocals. - */ - public static Collection getAvailableLocales() - { + public Collection getAvailableLocales() { return availableLocales; } /** - * Set the user language in the session - * @param language lagnguage to ste - * @param session current session - * @deprecated since 3.5, use MgnlContext instead (this is not used - can be safely removed) - */ - public static void setUserLanguage(String language, HttpSession session) - { - MgnlContext.setAttribute(Config.FMT_LOCALE + ".session", language, Context.SESSION_SCOPE); //$NON-NLS-1$ - } - - public static void reloadBundles() throws Exception - { - // reload all present - for (Iterator iter = messages.values().iterator(); iter.hasNext();) - { - Messages msgs = (Messages) iter.next(); - msgs.reload(); - } - } - - /** - * Getter for <code>context</code>. - * @return Returns the context. - */ - public static ServletContext getContext() - { - return context; - } - - /** - * Used as the key in the LRUMap + * Used as the key in the Map. * @author Philipp Bracher - * @version $Revision: 878 $ ($Author: manuel $) + * @version $Revision: 21431 $ ($Author: gjoseph $) */ - static private class MessagesID - { + static private class MessagesID { + private final String basename; + private final Locale locale; - String basename; - - Locale locale; - - public MessagesID(String basename, Locale locale) - { + public MessagesID(String basename, Locale locale) { this.basename = basename; this.locale = locale; } + // generated equals and hashcode methods @Override - public int hashCode() - { - return basename.hashCode(); + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MessagesID that = (MessagesID) o; + + if (basename != null ? !basename.equals(that.basename) : that.basename != null) return false; + if (locale != null ? !locale.equals(that.locale) : that.locale != null) return false; + + return true; } @Override - public boolean equals(Object id) - { - return ((MessagesID) id).basename.equals(basename) && ((MessagesID) id).locale.equals(locale); + public int hashCode() { + int result = basename != null ? basename.hashCode() : 0; + result = 31 * result + (locale != null ? locale.hashCode() : 0); + return result; } } } Added: trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesProvider.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesProvider.java (rev 0) +++ trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/MessagesProvider.java 2009-02-13 15:57:45 UTC (rev 984) @@ -0,0 +1,16 @@ +package info.magnolia.cms.i18n; + +import java.util.Locale; + +/** + * @author molaschi + * @version $Id: $ + */ +public interface MessagesProvider { + + Locale getDefaultLocale(); + + void init(); + + Messages getMessagesInternal(String basename, Locale locale); +} Added: trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java (rev 0) +++ trunk/openutils-mgnlmessages/src/main/java/info/magnolia/cms/i18n/OpenutilsMgnlMessagesManager.java 2009-02-13 15:57:45 UTC (rev 984) @@ -0,0 +1,271 @@ +package info.magnolia.cms.i18n; + +import info.magnolia.cms.beans.config.ContentRepository; +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.ItemType; +import info.magnolia.cms.util.NodeDataUtil; +import info.magnolia.cms.util.ObservationUtil; +import info.magnolia.content2bean.Content2BeanUtil; +import info.magnolia.context.MgnlContext; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; + +import javax.jcr.observation.EventIterator; +import javax.jcr.observation.EventListener; + +import org.apache.commons.collections.Transformer; +import org.apache.commons.collections.map.LazyMap; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author molaschi + * @version $Id: $ + */ +public class OpenutilsMgnlMessagesManager implements MessagesProvider +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(OpenutilsMgnlMessagesManager.class); + + /** + * The node name where the configuration for i18n is stored. + */ + private static final String I18N_CONFIG_PATH = "/server/i18n/system"; //$NON-NLS-1$ + + /** + * The name of the property to store the current system language. + */ + private static final String FALLBACK_NODEDATA = "fallbackLanguage"; //$NON-NLS-1$ + + /** + * Under this node all the available languages are stored. They are showed in the user dialog. + */ + private static final String LANGUAGES_NODE_NAME = "languages"; //$NON-NLS-1$ + + private Locale defaultLocale = new Locale(MessagesManager.FALLBACK_LOCALE); + + Map messages; + + private final Collection availableLocales = new ArrayList(); + + /** + * + */ + public OpenutilsMgnlMessagesManager() + { + + } + + public void init() + { + load(); + registerEventListener(); + } + + /** + * The lazy Map creates messages objects with a fall back to the default locale. + */ + protected void initMap() + { + // FIXME use LRU: new LRUMap(20); + // LazyMap will instanciate bundles on demand. + final Map map = LazyMap.decorate(new HashMap(), new Transformer() + { + + // this transformer will wrap the Messages in a MessagesChain which will fall back to a Messages instance + // for the same bundle with default locale. + public Object transform(Object input) + { + final MessagesID id = (MessagesID) input; + return newMessages(id); + } + }); + messages = Collections.synchronizedMap(map); + } + + /** + * Initializes a new Messages instances for the given MessagesID. By default, we chain to the same bundle with the + * default Locale. (so untranslated messages show up in the default language) + */ + protected Messages newMessages(MessagesID messagesID) + { + Messages msgs = new DefaultMessagesImpl(messagesID.basename, messagesID.locale); + if (!getDefaultLocale().equals(messagesID.locale)) + { + msgs = new MessagesChain(msgs).chain(getMessagesInternal(messagesID.basename, getDefaultLocale())); + } + return msgs; + } + + /** + * {@inheritDoc} + */ + public Locale getDefaultLocale() + { + return defaultLocale; + } + + /** + * {@inheritDoc} + */ + public Messages getMessagesInternal(String basename, Locale locale) + { + if (StringUtils.isEmpty(basename)) + { + basename = MessagesManager.DEFAULT_BASENAME; + } + return (Messages) messages.get(new MessagesID(basename, locale)); + } + + /** + * Load i18n configuration. + */ + protected void load() + { + + // reading the configuration from the repository, no need for context + HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager(ContentRepository.CONFIG); + + try + { + log.info("Loading i18n configuration - " + I18N_CONFIG_PATH); //$NON-NLS-1$ + + // checks if node exists + if (!hm.isExist(I18N_CONFIG_PATH)) + { + // configNode = ContentUtil.createPath(hm, I18N_CONFIG_PATH, ItemType.CONTENT, true); + log.warn(I18N_CONFIG_PATH + " does not exist yet; skipping."); + return; + } + + final Content configNode = hm.getContent(I18N_CONFIG_PATH); //$NON-NLS-1$ + + defaultLocale = new Locale(NodeDataUtil.getString( + configNode, + FALLBACK_NODEDATA, + MessagesManager.FALLBACK_LOCALE)); + + // get the available languages - creates it if it does not exist - necessary to update to 3.5 + final Content languagesNode; + if (configNode.hasContent(LANGUAGES_NODE_NAME)) + { + languagesNode = configNode.getContent(LANGUAGES_NODE_NAME); + } + else + { + languagesNode = configNode.createContent(LANGUAGES_NODE_NAME, ItemType.CONTENT); + } + + Map languageDefinitions = Content2BeanUtil.toMap(languagesNode, true, LocaleDefinition.class); + + // clear collection for reload + availableLocales.clear(); + + for (Iterator iter = languageDefinitions.values().iterator(); iter.hasNext();) + { + LocaleDefinition ld = (LocaleDefinition) iter.next(); + if (ld.isEnabled()) + { + availableLocales.add(ld.getLocale()); + } + } + } + catch (Exception e) + { + log.error("Failed to load i18n configuration - " + I18N_CONFIG_PATH, e); //$NON-NLS-1$ + } + } + + /** + * Register an event listener: reload configuration when something changes. + */ + private void registerEventListener() + { + log.info("Registering event listener for i18n"); //$NON-NLS-1$ + ObservationUtil.registerChangeListener(ContentRepository.CONFIG, I18N_CONFIG_PATH, new EventListener() + { + + public void onEvent(EventIterator iterator) + { + // reload everything + reload(); + } + }); + } + + /** + * Reload i18n configuration. + */ + public void reload() + { + try + { + // reload all present + for (Iterator iter = messages.values().iterator(); iter.hasNext();) + { + Messages msgs = (Messages) iter.next(); + msgs.reload(); + } + } + catch (Exception e) + { + log.error("Can't reload i18n messages", e); + } + initMap(); + load(); + } + + static private class MessagesID + { + + private final String basename; + + private final Locale locale; + + public MessagesID(String basename, Locale locale) + { + this.basename = basename; + this.locale = locale; + } + + // generated equals and hashcode methods + @Override + public boolean equals(Object o) + { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + MessagesID that = (MessagesID) o; + + if (basename != null ? !basename.equals(that.basename) : that.basename != null) + return false; + if (locale != null ? !locale.equals(that.locale) : that.locale != null) + return false; + + return true; + } + + @Override + public int hashCode() + { + int result = basename != null ? basename.hashCode() : 0; + result = 31 * result + (locale != null ? locale.hashCode() : 0); + return result; + } + } + +} Modified: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/SimpleMessagesImpl.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/SimpleMessagesImpl.java 2009-02-13 11:59:07 UTC (rev 983) +++ trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/SimpleMessagesImpl.java 2009-02-13 15:57:45 UTC (rev 984) @@ -84,7 +84,7 @@ stream = ClasspathResourcesUtil.getStream("/" + StringUtils.replace(basename, ".", "/") + "_" - + MessagesManager.getDefaultLocale().getLanguage() + + MessagesManager.getInstance().getDefaultLocale().getLanguage() + ".properties", false); } if (stream == null) Modified: trunk/openutils-mgnlmessages/src/main/resources/META-INF/magnolia/messages.xml =================================================================== --- trunk/openutils-mgnlmessages/src/main/resources/META-INF/magnolia/messages.xml 2009-02-13 11:59:07 UTC (rev 983) +++ trunk/openutils-mgnlmessages/src/main/resources/META-INF/magnolia/messages.xml 2009-02-13 15:57:45 UTC (rev 984) @@ -7,10 +7,16 @@ <class>net.sourceforge.openutils.mgnlmessages.lifecycle.MessagesModuleLifecycle</class> <versionHandler>net.sourceforge.openutils.mgnlmessages.setup.MessagesModuleVersionHandler</versionHandler> <version>${project.version}</version> + <properties> + <property> + <name>info.magnolia.cms.i18n.MessagesManager</name> + <value>info.magnolia.cms.i18n.OpenutilsMgnlMessagesManager</value> + </property> + </properties> <dependencies> <dependency> <name>adminInterface</name> - <version>3.1/*</version> + <version>4</version> </dependency> </dependencies> <repositories> Modified: trunk/openutils-mgnlmessages/src/site/apt/index.apt =================================================================== --- trunk/openutils-mgnlmessages/src/site/apt/index.apt 2009-02-13 11:59:07 UTC (rev 983) +++ trunk/openutils-mgnlmessages/src/site/apt/index.apt 2009-02-13 15:57:45 UTC (rev 984) @@ -2,6 +2,7 @@ openutils-mgnlmessages -------------------------- Fabrizio Giustina + Manuel Molaschi -------------------------- About openutils-mgnlmessages @@ -16,20 +17,13 @@ Installation - <<This module currently requires magnolia 3.6.x>> + <<This module currently requires magnolia 4.0.x>> The module needs to be installed as usual, by declaring an additional dependency into your pom or by manually dropping the jar into magnolia. - Unfortunately, for Magnolia 3.6 this module requires also patching one of the magnolia core classes, info.magnolia.cms.i18n.MessagesManager, - since there was no way to cleanly extend/replace it. - You may do that by copying the patched java source (you can find it in the module sources) to your java source folder for - your webapp (the compiled class file must end up in WEB-INF/classes in order to override the one found in the magnolia jars) + - This limitation will be removed after the module will be updated to magnolia 4.0, which allows the configuration of a - custom message manager. - - Released versions {{{http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-mgnlmessages}http://www.mvnrepository.com/artifact/net.sourceforge.openutils/openutils-mgnlmessages}} Modified: trunk/openutils-mgnlmessages/src/site/changes/changes.xml =================================================================== --- trunk/openutils-mgnlmessages/src/site/changes/changes.xml 2009-02-13 11:59:07 UTC (rev 983) +++ trunk/openutils-mgnlmessages/src/site/changes/changes.xml 2009-02-13 15:57:45 UTC (rev 984) @@ -6,8 +6,12 @@ <properties> <title>Changes</title> <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> + <author email="molaschi(at)users.sourceforge.net">Manuel Molaschi</author> </properties> <body> + <release version="4.0" date="2009-02-13" description=""> + <action type="update" dev="molaschi">Updated to magnolia 4.0.x.</action> + </release> <release version="1.1" date="2009-01-31" description=""> <action type="fix" dev="fgiust">minor bugfixes and basic documentation added</action> </release> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 13:22:22
|
Revision: 982 http://openutils.svn.sourceforge.net/openutils/?rev=982&view=rev Author: molaschi Date: 2009-02-13 11:46:37 +0000 (Fri, 13 Feb 2009) Log Message: ----------- branching 3.6.x development Added Paths: ----------- branches/openutils-mgnlmedia-3.6.x/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2009-02-13 13:22:18
|
Revision: 983 http://openutils.svn.sourceforge.net/openutils/?rev=983&view=rev Author: molaschi Date: 2009-02-13 11:59:07 +0000 (Fri, 13 Feb 2009) Log Message: ----------- branching openutils-mgnlmessages for magnolia 3.6.x compatibility Added Paths: ----------- branches/openutils-mgnlmessages-3.6.x/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2009-02-01 08:55:29
|
Revision: 981 http://openutils.svn.sourceforge.net/openutils/?rev=981&view=rev Author: fgiust Date: 2009-02-01 08:55:23 +0000 (Sun, 01 Feb 2009) Log Message: ----------- fix main page Modified Paths: -------------- trunk/openutils-mgnlstruts11/src/site/apt/index.apt trunk/openutils-mgnlstruts11/src/site/site.xml Modified: trunk/openutils-mgnlstruts11/src/site/apt/index.apt =================================================================== --- trunk/openutils-mgnlstruts11/src/site/apt/index.apt 2009-02-01 08:36:41 UTC (rev 980) +++ trunk/openutils-mgnlstruts11/src/site/apt/index.apt 2009-02-01 08:55:23 UTC (rev 981) @@ -1,28 +1,29 @@ -------------------------- - openutils-mgnlmedia + openutils-mgnlstruts11 -------------------------- Fabrizio Giustina -------------------------- -About openutils-mgnlmedia +About openutils-mgnlstruts11 - openutils-mgnlmedia is a custom {{{http://www.magnolia.info}magnolia}} module for the management of multimedia assets - like images and videos. + openutils-mgnlstruts11 is a custom {{{http://www.magnolia.info}magnolia}} module which integrates the + Struts 1.1 framework into magnolia-powered websites. - <<This module requires magnolia 3.6.x, and will not work on any earlier version!>> + After installed into magnolia, this module will allow you to use any available Struts action/forward as a Magnolia paragraph. - Configuration - First of all drop the openutils-mgnlstripes jar and the stripes jar into WEB-INF/lib, or (better) if you are using maven + First of all drop the openutils-mgnlstruts11 jar and the struts jar into WEB-INF/lib, or (better) if you are using maven just declare the following dependency: +----------------------------------------------+ <dependency> <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-mgnlmedia</artifactId> - <version>0.1</version> + <artifactId>openutils-mgnlstruts11</artifactId> + <version>...</version> </dependency> +----------------------------------------------+ + + Modified: trunk/openutils-mgnlstruts11/src/site/site.xml =================================================================== --- trunk/openutils-mgnlstruts11/src/site/site.xml 2009-02-01 08:36:41 UTC (rev 980) +++ trunk/openutils-mgnlstruts11/src/site/site.xml 2009-02-01 08:55:23 UTC (rev 981) @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<project name="Openutils mgnlmedia"> +<project name="Openutils mgnlstruts11"> <publishDate position="navigation-bottom" format="yyyy-MM-dd" /> <version position="navigation-bottom" /> <bannerRight> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2009-02-01 08:36:45
|
Revision: 980 http://openutils.svn.sourceforge.net/openutils/?rev=980&view=rev Author: fgiust Date: 2009-02-01 08:36:41 +0000 (Sun, 01 Feb 2009) Log Message: ----------- remove description (shows up in child without a custom index page) Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-01-31 23:02:13 UTC (rev 979) +++ trunk/pom.xml 2009-02-01 08:36:41 UTC (rev 980) @@ -7,7 +7,6 @@ <packaging>pom</packaging> <version>10</version> <name>openutils</name> - <description>openutils parent POM</description> <url>http://openutils.sourceforge.net</url> <issueManagement> <system>sourceforge</system> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2009-01-31 23:02:18
|
Revision: 979 http://openutils.svn.sourceforge.net/openutils/?rev=979&view=rev Author: fgiust Date: 2009-01-31 23:02:13 +0000 (Sat, 31 Jan 2009) Log Message: ----------- added breadcrumbs for layout consistency Modified Paths: -------------- trunk/src/site/site.xml Modified: trunk/src/site/site.xml =================================================================== --- trunk/src/site/site.xml 2009-01-31 22:59:43 UTC (rev 978) +++ trunk/src/site/site.xml 2009-01-31 23:02:13 UTC (rev 979) @@ -4,7 +4,8 @@ <version position="bottom" /> <bannerRight> <name>Openutils</name> - <src>http://openutils.sourceforge.net/images/openutils-logo.png</src> + <src>http://openutils.sourceforge.net/images/openutils-logo.png + </src> <href>http://openutils.sourceforge.net</href> </bannerRight> <bannerLeft> @@ -16,6 +17,9 @@ <head> <link rel="icon" href="images/favicon.ico" /> </head> + <breadcrumbs> + <item name="openutils" href="http://openutils.sourceforge.net/" /> + </breadcrumbs> <menu ref="modules" inherit="bottom" /> </body> <skin> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2009-01-31 22:59:46
|
Revision: 978 http://openutils.svn.sourceforge.net/openutils/?rev=978&view=rev Author: fgiust Date: 2009-01-31 22:59:43 +0000 (Sat, 31 Jan 2009) Log Message: ----------- module order Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-01-31 22:56:12 UTC (rev 977) +++ trunk/pom.xml 2009-01-31 22:59:43 UTC (rev 978) @@ -234,19 +234,19 @@ <module>openutils-configuration-dataobjects</module> <module>openutils-configuration-services</module> <module>openutils-hibernate-security</module> + <module>openutils-spring-rmibernate</module> + <module>openutils-elfunctions</module> <module>openutils-mgnlspring</module> <module>openutils-mgnlstripes</module> <module>openutils-mgnltasks</module> <module>openutils-mgnlbootstrapsync</module> <module>openutils-mgnlext</module> <module>openutils-mgnlcontrols</module> - <module>openutils-spring-rmibernate</module> <module>openutils-mgnlmessages</module> <module>openutils-mgnlcas</module> <module>openutils-mgnlgroovy</module> <module>openutils-mgnlstruts11</module> <module>openutils-mgnlmedia</module> - <module>openutils-elfunctions</module> <!-- <module>openutils-mgnlrating</module> --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |