1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.web

File TexAction.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
86% of files have more coverage

Code metrics

2
14
1
1
68
34
3
0.21
14
1
3

Classes

Class Line # Actions
TexAction 40 14 0% 3 17
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.web;
21   
22    import java.io.IOException;
23   
24    import org.slf4j.Logger;
25    import org.slf4j.LoggerFactory;
26    import org.xwiki.formula.ImageData;
27    import org.xwiki.formula.ImageStorage;
28   
29    import com.xpn.xwiki.XWikiContext;
30    import com.xpn.xwiki.XWikiException;
31    import com.xpn.xwiki.util.Util;
32   
33    /**
34    * Returns rendered mathematical formulae to the client. The formulae are images rendered by the
35    * {@link org.xwiki.formula.FormulaRenderer} component, and stored inside an {@link ImageStorage}.
36    *
37    * @version $Id: fcdf41c8b8898f8c4038dbe69911bbda64b9bd30 $
38    * @since 2.0M3
39    */
 
40    public class TexAction extends XWikiAction
41    {
42    /** Logging helper object */
43    private static final Logger LOGGER = LoggerFactory.getLogger(TexAction.class);
44   
 
45  0 toggle @Override
46    public String render(XWikiContext context) throws XWikiException
47    {
48  0 XWikiRequest request = context.getRequest();
49  0 XWikiResponse response = context.getResponse();
50  0 String path = request.getRequestURI();
51    // Expected /xwiki/bin/tex/Current/Document/image_identifier
52  0 String filename = Util.decodeURI(path.substring(path.lastIndexOf("/") + 1), context);
53  0 ImageStorage storage = Utils.getComponent(ImageStorage.class);
54  0 ImageData image = storage.get(filename);
55  0 if (image == null) {
56  0 return "docdoesnotexist";
57    }
58  0 response.setContentLength(image.getData().length);
59  0 response.setContentType(image.getMimeType());
60  0 try {
61  0 response.getOutputStream().write(image.getData());
62    } catch (IOException e) {
63  0 LOGGER.info("Failed to send image to the client");
64    }
65   
66  0 return null;
67    }
68    }