001
014
015 package com.liferay.portal.kernel.atom;
016
017 import java.io.InputStream;
018
019 import java.util.Date;
020
021
024 public abstract class BaseAtomCollectionAdapter<E>
025 implements AtomCollectionAdapter<E> {
026
027 @Override
028 public void deleteEntry(
029 String resourceName, AtomRequestContext atomRequestContext)
030 throws AtomException {
031
032 try {
033 doDeleteEntry(resourceName, atomRequestContext);
034 }
035 catch (Exception e) {
036 Class<?> clazz = e.getClass();
037
038 String className = clazz.getSimpleName();
039
040 if (className.startsWith("NoSuch")) {
041 throw new AtomException(SC_NOT_FOUND);
042 }
043
044 throw new AtomException(SC_INTERNAL_SERVER_ERROR, e);
045 }
046 }
047
048 @Override
049 public E getEntry(
050 String resourceName, AtomRequestContext atomRequestContext)
051 throws AtomException {
052
053 try {
054 return doGetEntry(resourceName, atomRequestContext);
055 }
056 catch (Exception e) {
057 Class<?> clazz = e.getClass();
058
059 String className = clazz.getSimpleName();
060
061 if (className.startsWith("NoSuch")) {
062 throw new AtomException(SC_NOT_FOUND);
063 }
064
065 throw new AtomException(SC_INTERNAL_SERVER_ERROR, e);
066 }
067 }
068
069 @Override
070 public Iterable<E> getFeedEntries(AtomRequestContext atomRequestContext)
071 throws AtomException {
072
073 try {
074 return doGetFeedEntries(atomRequestContext);
075 }
076 catch (Exception e) {
077 Class<?> clazz = e.getClass();
078
079 String className = clazz.getSimpleName();
080
081 if (className.startsWith("NoSuch")) {
082 throw new AtomException(SC_NOT_FOUND);
083 }
084
085 throw new AtomException(SC_INTERNAL_SERVER_ERROR, e);
086 }
087 }
088
089 @Override
090 public String getMediaContentType(E entry) {
091 throw new UnsupportedOperationException();
092 }
093
094 @Override
095 @SuppressWarnings("unused")
096 public String getMediaName(E entry) throws AtomException {
097 throw new UnsupportedOperationException();
098 }
099
100 @Override
101 @SuppressWarnings("unused")
102 public InputStream getMediaStream(E entry) throws AtomException {
103 throw new UnsupportedOperationException();
104 }
105
106 @Override
107 public E postEntry(
108 String title, String summary, String content, Date date,
109 AtomRequestContext atomRequestContext)
110 throws AtomException {
111
112 try {
113 return doPostEntry(
114 title, summary, content, date, atomRequestContext);
115 }
116 catch (Exception e) {
117 Class<?> clazz = e.getClass();
118
119 String className = clazz.getSimpleName();
120
121 if (className.startsWith("NoSuch")) {
122 throw new AtomException(SC_NOT_FOUND);
123 }
124
125 throw new AtomException(SC_INTERNAL_SERVER_ERROR, e);
126 }
127 }
128
129 @Override
130 public E postMedia(
131 String mimeType, String slug, InputStream inputStream,
132 AtomRequestContext atomRequestContext)
133 throws AtomException {
134
135 try {
136 return doPostMedia(mimeType, slug, inputStream, atomRequestContext);
137 }
138 catch (Exception e) {
139 Class<?> clazz = e.getClass();
140
141 String className = clazz.getSimpleName();
142
143 if (className.startsWith("NoSuch")) {
144 throw new AtomException(SC_NOT_FOUND);
145 }
146
147 throw new AtomException(SC_INTERNAL_SERVER_ERROR, e);
148 }
149 }
150
151 @Override
152 public void putEntry(
153 E entry, String title, String summary, String content, Date date,
154 AtomRequestContext atomRequestContext)
155 throws AtomException {
156
157 try {
158 doPutEntry(
159 entry, title, summary, content, date, atomRequestContext);
160 }
161 catch (Exception e) {
162 Class<?> clazz = e.getClass();
163
164 String className = clazz.getSimpleName();
165
166 if (className.startsWith("NoSuch")) {
167 throw new AtomException(SC_NOT_FOUND);
168 }
169
170 throw new AtomException(SC_INTERNAL_SERVER_ERROR, e);
171 }
172 }
173
174 @Override
175 public void putMedia(
176 E entry, String mimeType, String slug, InputStream inputStream,
177 AtomRequestContext atomRequestContext)
178 throws AtomException {
179
180 try {
181 doPutMedia(entry, mimeType, slug, inputStream, atomRequestContext);
182 }
183 catch (Exception e) {
184 Class<?> clazz = e.getClass();
185
186 String className = clazz.getSimpleName();
187
188 if (className.startsWith("NoSuch")) {
189 throw new AtomException(SC_NOT_FOUND);
190 }
191
192 throw new AtomException(SC_INTERNAL_SERVER_ERROR, e);
193 }
194 }
195
196 protected void doDeleteEntry(
197 String resourceName, AtomRequestContext atomRequestContext)
198 throws Exception {
199
200 throw new UnsupportedOperationException();
201 }
202
203 protected abstract E doGetEntry(
204 String resourceName, AtomRequestContext atomRequestContext)
205 throws Exception;
206
207 protected abstract Iterable<E> doGetFeedEntries(
208 AtomRequestContext atomRequestContext)
209 throws Exception;
210
211 protected E doPostEntry(
212 String title, String summary, String content, Date date,
213 AtomRequestContext atomRequestContext)
214 throws Exception {
215
216 throw new UnsupportedOperationException();
217 }
218
219 protected E doPostMedia(
220 String mimeType, String slug, InputStream inputStream,
221 AtomRequestContext atomRequestContext)
222 throws Exception {
223
224 throw new UnsupportedOperationException();
225 }
226
227 protected void doPutEntry(
228 E entry, String title, String summary, String content, Date date,
229 AtomRequestContext atomRequestContext)
230 throws Exception {
231
232 throw new UnsupportedOperationException();
233 }
234
235 protected void doPutMedia(
236 E entry, String mimeType, String slug, InputStream inputStream,
237 AtomRequestContext atomRequestContext)
238 throws Exception {
239
240 throw new UnsupportedOperationException();
241 }
242
243 }