]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.message/src/org/simantics/message/util/HtmlUtil.java b/bundles/org.simantics.message/src/org/simantics/message/util/HtmlUtil.java
new file mode 100644 (file)
index 0000000..04f3012
--- /dev/null
@@ -0,0 +1,86 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.message.util;\r
+\r
+import java.net.URI;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public final class HtmlUtil {\r
+\r
+    /**\r
+     * Encloses the specified text within a <code>&lt;form&gt;</code> tag.\r
+     * \r
+     * @param text the text to enclose\r
+     * @return the enclosed text \r
+     */\r
+    public static String html(String text) {\r
+        return TagUtil.tag(TagUtil.tag("", "head") + TagUtil.tag(TagUtil.tag(text, "pre"), "body"), "html");\r
+    }\r
+\r
+    /**\r
+     * Produces a standard HTML <code>&lt;a&gt;</code> anchor tag with the specified\r
+     * contents.\r
+     * \r
+     * @param href the <code>href</code> attribute value of the produced anchor\r
+     *        (&lt;a href="<code>href</code>"&gt;&lt;/a&gt;)\r
+     * @param text the <code>text</code> inside the anchor element (&lt;a&gt;\r
+     *        <code>text</code>&lt;/a&gt;)\r
+     * @return the anchor\r
+     */\r
+    public static String a(String href, String text) {\r
+        return TagUtil.tag(text, "a", "href", href);\r
+    }\r
+\r
+    /**\r
+     * Produces a standard HTML <code>&lt;a&gt;</code> anchor tag with the specified\r
+     * contents.\r
+     * \r
+     * @param href the <code>href</code> attribute value of the produced anchor\r
+     *        (&lt;a href="<code>href</code>"&gt;&lt;/a&gt;)\r
+     * @param text the <code>text</code> inside the anchor element (&lt;a&gt;\r
+     *        <code>text</code>&lt;/a&gt;)\r
+     * @return the anchor\r
+     */\r
+    public static String a(URI href, String text) {\r
+        return a(href.toASCIIString(), text);\r
+    }\r
+\r
+    /**\r
+     * Produces a standard HTML <code>&lt;a&gt;</code> anchor tag with the\r
+     * specified contents.\r
+     * \r
+     * @param scheme the <code>&lt;scheme&gt;</code> part of the URI of form\r
+     *        <code>&ltscheme&gt:&lt;scheme-specific-part&gt;</code>\r
+     * @param identifier the <code>&lt;scheme-specific-part&gt;</code> part of\r
+     *        the URI of form\r
+     *        <code>&ltscheme&gt:&lt;scheme-specific-part&gt;</code>\r
+     * @param text the <code>text</code> inside the anchor element (&lt;a&gt;\r
+     *        <code>text</code>&lt;/a&gt;)\r
+     * @return the anchor\r
+     */\r
+    public static String a(String scheme, String identifier, String text) {\r
+        return TagUtil.tag(text, "a", "href", scheme +  ":" + identifier);\r
+    }\r
+\r
+    /**\r
+     * Encloses the specified text within a <code>&lt;p&gt;</code> tag.\r
+     * \r
+     * @param text the text to enclose\r
+     * @return the enclosed text\r
+     */\r
+    public static String p(String text) {\r
+        return TagUtil.tag(text, "p");\r
+    }\r
+\r
+}\r