001/* 002 * Copyright c 2018 Rusi Popov, MDA Tools.net All rights reserved. 003 * 004 * This program and the accompanying materials are made available under the terms of the 005 * Eclipse Public License v2.0 which accompanies this distribution, and is available at 006 * http://www.eclipse.org/legal/epl-v20.html 007 */ 008package net.mdatools.modelant.core.operation.format; 009 010import net.mdatools.modelant.core.api.Operation; 011 012/** 013 * Convert some known HTML tags to corresponding RTF tags 014 * @author Rusi Popov (popovr@mdatools.net) 015 */ 016public class ConvertTextToRtf implements Operation<String> { 017 018 /** 019 * Convert some known HTML tags to corresponding RTF tags 020 * @param text 021 * @return the text including RTF tags 022 * @see net.mdatools.modelant.core.api.Function#execute(java.lang.Object) 023 */ 024 public String execute(String text) throws RuntimeException, IllegalArgumentException { 025 String result; 026 027 result = text.replaceAll( "<p>", "\\\\par " ) 028 .replaceAll( "<ul>", "\\\\par " ) 029 .replaceAll( "</ul>", "\\\\par " ) 030 .replaceAll( "<li> *", "\\\\par " ) 031 032 .replaceAll( "\r\n\u0095", "\\\\par -\t" ) 033 .replaceAll( "\u0095", "-" ) 034 .replaceAll( "\u0092", "'" ) 035 .replaceAll( "\u0093", "'" ) 036 .replaceAll( "\u0094", "'" ) 037 .replaceAll( "\"\t", "-\t" ) 038 .replaceAll( "-- *", "-\t" ) 039 040 .replaceAll( "\r\n *", "\\\\par " ) 041 .replaceAll( "\n *", "\\\\par " ) 042 .replaceAll( "\r *", "\\\\par " ) 043 044 .replaceAll( " +", " " ); 045 return result; 046 } 047}