| /***************************************************************************** |
| * Copyright (c) 2019 CEA LIST. |
| * |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Xavier Le Pallec (for CEA LIST) xlepallec@lilo.org - Bug 558456 |
| * |
| *****************************************************************************/ |
| |
| package org.eclipse.papyrus.uml.diagram.clazz.lf.classtextualedition.webpages; |
| |
| /** |
| * This class is dedicated to load a web page and replacing the loading |
| * mechanisms of a web page by those of {@link ResourceAccessUtils} class. |
| * |
| */ |
| public class HtmlPage { |
| |
| private static HtmlPage instance; |
| |
| private HtmlPage() { |
| // to prevent instantiation |
| } |
| |
| public static HtmlPage getInstance() { |
| if (instance == null) { |
| instance = new HtmlPage(); |
| } |
| return instance; |
| |
| } |
| |
| /** |
| * This static method is used to load a head html file, a list of css files, a |
| * list of (java)scripts and a body html file. The loading mechanisms of a web |
| * page (like script tag) are not possible when dealing with a jar. |
| * |
| * @param headFileName |
| * head html file |
| * @param cssFileNames |
| * a list of css files |
| * @param scriptsFileNames |
| * a list of (java)scripts |
| * @param bodyFileName |
| * a body html file |
| * @return the html string/page |
| */ |
| public String createHtmlContentFromHeadScriptBody(String headFileName, String[] cssFileNames, |
| String[] scriptsFileNames, String bodyFileName) { |
| |
| String htmlContent = ""; //$NON-NLS-1$ |
| htmlContent += ResourceAccessUtils.getInstance().getContentOfFileLocatedInTheJar(headFileName); |
| |
| for (String cssFileName : cssFileNames) |
| htmlContent += "<style>" + ResourceAccessUtils.getInstance().getContentOfFileLocatedInTheJar(cssFileName) + "</style>"; //$NON-NLS-1$ //$NON-NLS-2$ |
| |
| for (String scriptFileName : scriptsFileNames) |
| htmlContent += "<script>" + ResourceAccessUtils.getInstance().getContentOfFileLocatedInTheJar(scriptFileName) + "</script>"; //$NON-NLS-1$ //$NON-NLS-2$ |
| htmlContent += ResourceAccessUtils.getInstance().getContentOfFileLocatedInTheJar(bodyFileName); |
| return htmlContent; |
| } |
| } |