/** * * Copyright 2003-2007 Jive Software. * * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jivesoftware.smackx; import org.jivesoftware.smack.util.StringUtils; /** * An XHTMLText represents formatted text. This class also helps to build valid * XHTML tags. * * @author Gaston Dombiak */ public class XHTMLText { private static final String NAMESPACE = "http://www.w3.org/1999/xhtml"; private StringBuilder text = new StringBuilder(30); /** * Creates a new XHTMLText with body tag params. * * @param style the XHTML style of the body * @param lang the language of the body */ public XHTMLText(String style, String lang) { appendOpenBodyTag(style, lang); } /** * Appends a tag that indicates that an anchor section begins. * * @param href indicates the URL being linked to * @param style the XHTML style of the anchor */ public void appendOpenAnchorTag(String href, String style) { StringBuilder sb = new StringBuilder(""); text.append(sb.toString()); } /** * Appends a tag that indicates that an anchor section ends. * */ public void appendCloseAnchorTag() { text.append(""); } /** * Appends a tag that indicates that a blockquote section begins. * * @param style the XHTML style of the blockquote */ public void appendOpenBlockQuoteTag(String style) { StringBuilder sb = new StringBuilder("
"); text.append(sb.toString()); } /** * Appends a tag that indicates that a blockquote section ends. * */ public void appendCloseBlockQuoteTag() { text.append(""); } /** * Appends a tag that indicates that a body section begins. * * @param style the XHTML style of the body * @param lang the language of the body */ private void appendOpenBodyTag(String style, String lang) { StringBuilder sb = new StringBuilder(""); text.append(sb.toString()); } /** * Appends a tag that indicates that a body section ends. * */ private String closeBodyTag() { return ""; } /** * Appends a tag that inserts a single carriage return. * */ public void appendBrTag() { text.append("
");
}
/**
* Appends a tag that indicates end of text that is the code for a program.
*
*/
public void appendCloseCodeTag() {
text.append("
");
}
/**
* Appends a tag that indicates emphasis.
*
*/
public void appendOpenEmTag() {
text.append("");
}
/**
* Appends a tag that indicates end of emphasis.
*
*/
public void appendCloseEmTag() {
text.append("");
}
/**
* Appends a tag that indicates a header, a title of a section of the message.
*
* @param level the level of the Header. It should be a value between 1 and 3
* @param style the XHTML style of the blockquote
*/
public void appendOpenHeaderTag(int level, String style) {
if (level > 3 || level < 1) {
return;
}
StringBuilder sb = new StringBuilder(""); text.append(sb.toString()); } /** * Appends a tag that indicates the end of a new paragraph. This is usually rendered * with two carriage returns, producing a single blank line in between the two paragraphs. * */ public void appendCloseParagraphTag() { text.append("
"); } /** * Appends a tag that indicates that an inlined quote section begins. * * @param style the style of the inlined quote */ public void appendOpenInlinedQuoteTag(String style) { StringBuilder sb = new StringBuilder(""); text.append(sb.toString()); } /** * Appends a tag that indicates that an inlined quote section ends. * */ public void appendCloseInlinedQuoteTag() { text.append(""); } /** * Appends a tag that allows to set the fonts for a span of text. * * @param style the style for a span of text */ public void appendOpenSpanTag(String style) { StringBuilder sb = new StringBuilder(""); text.append(sb.toString()); } /** * Appends a tag that indicates that a span section ends. * */ public void appendCloseSpanTag() { text.append(""); } /** * Appends a tag that indicates text which should be more forceful than surrounding text. * */ public void appendOpenStrongTag() { text.append(""); } /** * Appends a tag that indicates that a strong section ends. * */ public void appendCloseStrongTag() { text.append(""); } /** * Appends a given text to the XHTMLText. * * @param textToAppend the text to append */ public void append(String textToAppend) { text.append(StringUtils.escapeForXML(textToAppend)); } /** * Returns the text of the XHTMLText. * * Note: Automatically adds the closing body tag. * * @return the text of the XHTMLText */ public String toString() { return text.toString().concat(closeBodyTag()); } }