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