001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.parsers.creole.ast;
016    
017    /**
018     * @author Miguel Pastor
019     */
020    public abstract class URLNode extends ASTNode {
021    
022            public URLNode() {
023            }
024    
025            public URLNode(int token) {
026                    super(token);
027            }
028    
029            public URLNode(int token, String link) {
030                    this(token);
031    
032                    _link = link;
033            }
034    
035            public URLNode(String link) {
036                    _link = link;
037            }
038    
039            public String getLink() {
040                    return _link;
041            }
042    
043            public String[] getSupportedProtocols() {
044                    return _supportedProtocols;
045            }
046    
047            public boolean isAbsoluteLink() {
048                    for (String supportedProtocol : getSupportedProtocols()) {
049                            if (_link.startsWith(supportedProtocol)) {
050                                    return true;
051                            }
052                    }
053    
054                    return false;
055            }
056    
057            public void setLink(String link) {
058                    _link = link;
059            }
060    
061            public void setSupportedProtocols(String[] supportedProtocols) {
062                    _supportedProtocols = supportedProtocols;
063            }
064    
065            private static final String[] _SUPPORTED_PROTOCOL_LINK =
066                    {"http://", "https://", "ftp://", "mailto:"};
067    
068            private String _link;
069            private String[] _supportedProtocols = _SUPPORTED_PROTOCOL_LINK;
070    
071    }