| ImageTextUpgradeColumnImpl.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.portal.upgrade.v4_3_0.util;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.upgrade.util.BaseUpgradeColumnImpl;
28 import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
29 import com.liferay.portal.kernel.util.Base64;
30 import com.liferay.portal.model.Image;
31 import com.liferay.portal.model.impl.ImageImpl;
32 import com.liferay.portal.service.ImageLocalServiceUtil;
33
34 /**
35 * <a href="ImageTextUpgradeColumnImpl.java.html"><b><i>View Source</i></b></a>
36 *
37 * @author Brian Wing Shun Chan
38 */
39 public class ImageTextUpgradeColumnImpl extends BaseUpgradeColumnImpl {
40
41 public ImageTextUpgradeColumnImpl(UpgradeColumn imageIdColumn) {
42 super("text_");
43
44 _imageIdColumn = imageIdColumn;
45 }
46
47 public Object getNewValue(Object oldValue) throws Exception {
48 _type = null;
49 _height = null;
50 _width = null;
51 _size = null;
52
53 String text = (String)oldValue;
54
55 byte[] bytes = (byte[])Base64.stringToObject(text);
56
57 try {
58 Image image = ImageLocalServiceUtil.getImage(bytes);
59
60 _type = image.getType();
61 _height = new Integer(image.getHeight());
62 _width = new Integer(image.getWidth());
63 _size = new Integer(image.getSize());
64 }
65 catch (Exception e) {
66 if (_log.isWarnEnabled()) {
67 String imageId = (String)_imageIdColumn.getOldValue();
68
69 if (_log.isWarnEnabled()) {
70 _log.warn(
71 "Unable to get image data for " + imageId + ": " +
72 e.getMessage());
73 }
74 }
75
76 _type = ImageImpl.TYPE_NOT_AVAILABLE;
77 _height = null;
78 _width = null;
79 _size = new Integer(bytes.length);
80 }
81
82 return oldValue;
83 }
84
85 public String getType() {
86 return _type;
87 }
88
89 public Integer getHeight() {
90 return _height;
91 }
92
93 public Integer getWidth() {
94 return _width;
95 }
96
97 public Integer getSize() {
98 return _size;
99 }
100
101 private static Log _log =
102 LogFactoryUtil.getLog(ImageTextUpgradeColumnImpl.class);
103
104 private UpgradeColumn _imageIdColumn;
105 private String _type;
106 private Integer _height;
107 private Integer _width;
108 private Integer _size;
109
110 }