Java tutorial
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2015, Markus Staudt <info@braffdev.com> * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ package com.braffdev.server.core.utilities; import org.apache.commons.lang3.exception.ExceptionUtils; import com.braffdev.server.core.Constants; import com.braffdev.server.core.container.Container; /** * */ public class ServerUtilities { /** * @param container * @param url * @return */ public static String toContextURL(Container container, String url) { StringBuilder builder = new StringBuilder(); if (!Constants.Container.NAME_MAIN.equals(container.getName())) { builder.append("/"); builder.append(container.getName()); } if (!url.startsWith("/")) { builder.append("/"); } builder.append(url); return builder.toString(); } /** * Returns a String representation of the given Throwable that can be used for displaying it in web browsers.<br /> * In detail line breaks (\n) are being replaced by <br /> <br/> * and line feeds (\t) are being replaced by &nbsp;&nbsp;&nbsp; * * @param e * @return */ public static String getStackTraceForWeb(Throwable e) { String stackTrace = ExceptionUtils.getStackTrace(e); stackTrace = stackTrace.replace("\n", "<br />"); return stackTrace.replace("\t", " "); } }