Java HTML Encode toHTML(String xhtml)

Here you can find the source of toHTML(String xhtml)

Description

Unfortunately JEditorPane will only display HTML3.2, whereas to embed HTML in an xsd we must use XHTML so it will be valid XML.

License

Open Source License

Parameter

Parameter Description
xhtml a parameter

Declaration

public static String toHTML(String xhtml) 

Method Source Code

//package com.java2s;
/**/* www. java2 s.c  om*/
 * This file is part of the CRISTAL-iSE default user interface.
 * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 3 of the License, or (at
 * your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *
 * http://www.fsf.org/licensing/licenses/lgpl.html
 */

public class Main {
    /**
     * Unfortunately JEditorPane will only display HTML3.2, whereas to embed HTML in an xsd we must
     * use XHTML so it will be valid XML. This method does a quick and dirty removal of stuff that
     * the JEditorPane cannot display
     *
     * @param xhtml
     * @return
     */
    public static String toHTML(String xhtml) {
        int startPos, endPos;
        //remove xml header
        while ((startPos = xhtml.indexOf("<?")) != -1
                && (endPos = xhtml.indexOf("?>")) != -1) {
            xhtml = xhtml.substring(0, startPos)
                    + xhtml.substring(endPos + 2);
        }
        // remove slash in <tags/>
        while ((startPos = xhtml.indexOf("/>")) != -1) {
            xhtml = xhtml.substring(0, startPos)
                    + xhtml.substring(startPos + 1);
        }
        return xhtml;
    }
}

Related

  1. toHTML(String text)
  2. toHtml(String text)
  3. toHtml(String trace)
  4. toHtml(String txt)
  5. toHtml(String value, String defaultValue)
  6. toHtmlChars(String htmlReady)
  7. toHTMLContentString(String s, boolean replaceSpaces, boolean isXhtml)
  8. toHtmlCR(String text)
  9. toHTMLEncode(String string)