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