1
19
20 package com.liferay.portal.upgrade.v4_3_0.util;
21
22 import com.liferay.portal.kernel.log.Log;
23 import com.liferay.portal.kernel.log.LogFactoryUtil;
24 import com.liferay.portal.kernel.util.Base64;
25 import com.liferay.portal.model.Image;
26 import com.liferay.portal.model.impl.ImageImpl;
27 import com.liferay.portal.service.ImageLocalServiceUtil;
28 import com.liferay.portal.upgrade.util.BaseUpgradeColumnImpl;
29 import com.liferay.portal.upgrade.util.UpgradeColumn;
30
31
37 public class ImageTextUpgradeColumnImpl extends BaseUpgradeColumnImpl {
38
39 public ImageTextUpgradeColumnImpl(UpgradeColumn imageIdColumn) {
40 super("text_");
41
42 _imageIdColumn = imageIdColumn;
43 }
44
45 public Object getNewValue(Object oldValue) throws Exception {
46 _type = null;
47 _height = null;
48 _width = null;
49 _size = null;
50
51 String text = (String)oldValue;
52
53 byte[] bytes = (byte[])Base64.stringToObject(text);
54
55 try {
56 Image image = ImageLocalServiceUtil.getImage(bytes);
57
58 _type = image.getType();
59 _height = new Integer(image.getHeight());
60 _width = new Integer(image.getWidth());
61 _size = new Integer(image.getSize());
62 }
63 catch (Exception e) {
64 if (_log.isWarnEnabled()) {
65 String imageId = (String)_imageIdColumn.getOldValue();
66
67 _log.warn(
68 "Unable to get image data for " + imageId + ": " +
69 e.getMessage());
70 }
71
72 _type = ImageImpl.TYPE_NOT_AVAILABLE;
73 _height = null;
74 _width = null;
75 _size = new Integer(bytes.length);
76 }
77
78 return oldValue;
79 }
80
81 public String getType() {
82 return _type;
83 }
84
85 public Integer getHeight() {
86 return _height;
87 }
88
89 public Integer getWidth() {
90 return _width;
91 }
92
93 public Integer getSize() {
94 return _size;
95 }
96
97 private static Log _log =
98 LogFactoryUtil.getLog(ImageTextUpgradeColumnImpl.class);
99
100 private UpgradeColumn _imageIdColumn;
101 private String _type;
102 private Integer _height;
103 private Integer _width;
104 private Integer _size;
105
106 }