]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.message/src/org/simantics/message/util/HtmlUtil.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.message / src / org / simantics / message / util / HtmlUtil.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.message.util;\r
13 \r
14 import java.net.URI;\r
15 \r
16 /**\r
17  * @author Tuukka Lehtonen\r
18  */\r
19 public final class HtmlUtil {\r
20 \r
21     /**\r
22      * Encloses the specified text within a <code>&lt;form&gt;</code> tag.\r
23      * \r
24      * @param text the text to enclose\r
25      * @return the enclosed text \r
26      */\r
27     public static String html(String text) {\r
28         return TagUtil.tag(TagUtil.tag("", "head") + TagUtil.tag(TagUtil.tag(text, "pre"), "body"), "html");\r
29     }\r
30 \r
31     /**\r
32      * Produces a standard HTML <code>&lt;a&gt;</code> anchor tag with the specified\r
33      * contents.\r
34      * \r
35      * @param href the <code>href</code> attribute value of the produced anchor\r
36      *        (&lt;a href="<code>href</code>"&gt;&lt;/a&gt;)\r
37      * @param text the <code>text</code> inside the anchor element (&lt;a&gt;\r
38      *        <code>text</code>&lt;/a&gt;)\r
39      * @return the anchor\r
40      */\r
41     public static String a(String href, String text) {\r
42         return TagUtil.tag(text, "a", "href", href);\r
43     }\r
44 \r
45     /**\r
46      * Produces a standard HTML <code>&lt;a&gt;</code> anchor tag with the specified\r
47      * contents.\r
48      * \r
49      * @param href the <code>href</code> attribute value of the produced anchor\r
50      *        (&lt;a href="<code>href</code>"&gt;&lt;/a&gt;)\r
51      * @param text the <code>text</code> inside the anchor element (&lt;a&gt;\r
52      *        <code>text</code>&lt;/a&gt;)\r
53      * @return the anchor\r
54      */\r
55     public static String a(URI href, String text) {\r
56         return a(href.toASCIIString(), text);\r
57     }\r
58 \r
59     /**\r
60      * Produces a standard HTML <code>&lt;a&gt;</code> anchor tag with the\r
61      * specified contents.\r
62      * \r
63      * @param scheme the <code>&lt;scheme&gt;</code> part of the URI of form\r
64      *        <code>&ltscheme&gt:&lt;scheme-specific-part&gt;</code>\r
65      * @param identifier the <code>&lt;scheme-specific-part&gt;</code> part of\r
66      *        the URI of form\r
67      *        <code>&ltscheme&gt:&lt;scheme-specific-part&gt;</code>\r
68      * @param text the <code>text</code> inside the anchor element (&lt;a&gt;\r
69      *        <code>text</code>&lt;/a&gt;)\r
70      * @return the anchor\r
71      */\r
72     public static String a(String scheme, String identifier, String text) {\r
73         return TagUtil.tag(text, "a", "href", scheme +  ":" + identifier);\r
74     }\r
75 \r
76     /**\r
77      * Encloses the specified text within a <code>&lt;p&gt;</code> tag.\r
78      * \r
79      * @param text the text to enclose\r
80      * @return the enclosed text\r
81      */\r
82     public static String p(String text) {\r
83         return TagUtil.tag(text, "p");\r
84     }\r
85 \r
86 }\r