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