@@ -0,0 +1,2539 @@
+/*%0A * Copyright 2009-2011 Collaborative Research Centre SFB 632 %0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage annis.gui.servlets;%0A%0A%0Aimport annis.exceptions.AnnisBinaryNotFoundException;%0Aimport annis.exceptions.AnnisServiceFactoryException;%0Aimport annis.service.AnnisService;%0Aimport annis.service.AnnisServiceFactory;%0Aimport annis.service.ifaces.AnnisBinary;%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.ServletOutputStream;%0Aimport javax.servlet.http.*;%0A%0Aimport java.io.IOException;%0A%0Apublic class ExternalFileServlet extends HttpServlet %7B%0A%0A%09private static final long serialVersionUID = -8182635617256833563L;%0A%0A%09@SuppressWarnings(%22unchecked%22)%0A%09public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException %7B%09%09%0A%09%09String binaryParameter = request.getRequestURI().replaceFirst(%22/.+/.+/%22, %22%22);%0A%09%09String%5B%5D split = binaryParameter.split(%22_%22);%0A%09%09%0A%09%09if(split.length %3C 1)%0A%09%09%09throw new RuntimeException(%22Parameter 'id' must no be null.%22);%0A%09%09%0A%09%09String binaryId = split%5B0%5D;%0A%09%09%0A    int foundMp3 = binaryId.lastIndexOf(%22.mp3%22);%0A    if(foundMp3 %3E -1)%0A    %7B%0A      binaryId = binaryId.substring(0, foundMp3);%0A    %7D%0A    %0A%09%09ServletOutputStream out = response.getOutputStream();%0A%0A%09%09//TODO: maybe we should implement Caching%0A    %0A%09%09try %7B%0A%09%09%09AnnisService service = AnnisServiceFactory.getClient(this.getServletContext().getInitParameter(%22AnnisRemoteService.URL%22));%0A%09%09%09AnnisBinary binary = service.getBinary(Long.parseLong(binaryId));%0A%0A      String mimeType = binary.getMimeType();%0A%0A%0A%0A%09%09%09response.setContentType(binary.getMimeType());%0A%09%09%09response.setContentLength(binary.getBytes().length);%0A%09%09%09out.write(binary.getBytes());%0A%09%09%09out.flush();%0A%09%09%7D catch (AnnisServiceFactoryException e) %7B%0A%09%09%09throw new RuntimeException(e.getMessage());%0A%09%09%7D catch (NumberFormatException e) %7B%0A%09%09%09throw new RuntimeException(%22Parameter 'id' must be numeric%22);%0A%09%09%7D catch (AnnisBinaryNotFoundException e) %7B%0A%09%09%09throw new RuntimeException(%22Binary with id '%22 + binaryId + %22' does not exist.%22);%0A%09%09%7D%0A%09%7D%0A%7D%0A

add ExternalFileServlet to annis-gui