| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| EscapeTool |
|
| 1.6666666666666667;1.667 |
| 1 | /* | |
| 2 | * This file is part of dependency-check-core. | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | * | |
| 16 | * Copyright (c) 2014 Jeremy Long. All Rights Reserved. | |
| 17 | */ | |
| 18 | package org.owasp.dependencycheck.reporting; | |
| 19 | ||
| 20 | import java.io.UnsupportedEncodingException; | |
| 21 | import java.net.URLEncoder; | |
| 22 | import java.util.logging.Level; | |
| 23 | import java.util.logging.Logger; | |
| 24 | import org.apache.commons.lang.StringEscapeUtils; | |
| 25 | ||
| 26 | /** | |
| 27 | * An extremely simple wrapper around various escape utils to perform URL and HTML encoding within the reports. This | |
| 28 | * class was created to simplify the velocity configuration and avoid using the "built-in" escape tool. | |
| 29 | * | |
| 30 | * @author Jeremy Long <jeremy.long@owasp.org> | |
| 31 | */ | |
| 32 | public class EscapeTool { | |
| 33 | ||
| 34 | /** | |
| 35 | * The logger. | |
| 36 | */ | |
| 37 | 0 | private static final Logger LOGGER = Logger.getLogger(EscapeTool.class.getName()); |
| 38 | ||
| 39 | /** | |
| 40 | * URL Encodes the provided text. | |
| 41 | * | |
| 42 | * @param text the text to encode | |
| 43 | * @return the URL encoded text | |
| 44 | */ | |
| 45 | public String url(String text) { | |
| 46 | try { | |
| 47 | 0 | return URLEncoder.encode(text, "UTF-8"); |
| 48 | 0 | } catch (UnsupportedEncodingException ex) { |
| 49 | 0 | LOGGER.log(Level.WARNING, "UTF-8 is not supported?"); |
| 50 | 0 | LOGGER.log(Level.INFO, null, ex); |
| 51 | } | |
| 52 | 0 | return ""; |
| 53 | } | |
| 54 | ||
| 55 | /** | |
| 56 | * HTML Encodes the provided text. | |
| 57 | * | |
| 58 | * @param text the text to encode | |
| 59 | * @return the HTML encoded text | |
| 60 | */ | |
| 61 | public String html(String text) { | |
| 62 | 0 | return StringEscapeUtils.escapeHtml(text); |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * XML Encodes the provided text. | |
| 67 | * | |
| 68 | * @param text the text to encode | |
| 69 | * @return the XML encoded text | |
| 70 | */ | |
| 71 | public String xml(String text) { | |
| 72 | 0 | return StringEscapeUtils.escapeXml(text); |
| 73 | } | |
| 74 | } |