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
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 }