Java String Format formatMailtoLink(String emailAddress)

Here you can find the source of formatMailtoLink(String emailAddress)

Description

This is to take an email address and convert it to a link.

License

Apache License

Parameter

Parameter Description
emailAddress a parameter

Return

..

Declaration

public static String formatMailtoLink(String emailAddress) 

Method Source Code


//package com.java2s;
/*// www.j  av a2 s.c  om
 * ====================================================================
 * Copyright 2005-2011 Wai-Lun Kwok
 *
 * http://www.kwoksys.com/LICENSE
 *
 * 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.
 * ====================================================================
 */

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * This is to take an email address and convert it to a link.
     *
     * @param emailAddress
     * @return ..
     */
    public static String formatMailtoLink(String emailAddress) {
        if (emailAddress == null || emailAddress.isEmpty()) {
            return "";
        } else {
            return "<a href=\"mailto:" + encode(emailAddress) + "\" target=\"_blank\">" + encode(emailAddress)
                    + "</a>";
        }
    }

    public static String encode(String input) {
        if (input == null || input.isEmpty()) {
            return "";
        }
        return encodeStringBuffer(new StringBuffer(input)).toString();
    }

    public static List encode(List<String> values) {
        List list = new ArrayList();
        if (values != null) {
            for (Iterator<String> iter = values.iterator(); iter.hasNext();) {
                String value = iter.next();
                iter.remove();
                list.add(encode(value));
            }
        }
        return list;
    }

    public static StringBuffer encodeStringBuffer(StringBuffer input) {
        if (input == null || input.length() == 0) {
            return new StringBuffer();
        }

        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            switch (c) {
            case '<':
                buffer.append("&lt;");
                break;
            case '>':
                buffer.append("&gt;");
                break;
            case '&':
                buffer.append("&amp;");
                break;
            case '"':
                buffer.append("&quot;");
                break;
            default:
                buffer.append(c);
            }
        }
        return buffer;
    }
}

Related

  1. formatCommand(String cmd)
  2. formatDescriptors(String descriptorString)
  3. formatError(String errorMsg)
  4. formatJson(String json)
  5. formatLore(String str)
  6. formatMessage(String message)
  7. formatNameToMimeType(final String formatName)
  8. formatParam(String param)
  9. formatProtein(String seq)