001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.component; 020 021import lucee.commons.lang.StringUtil; 022 023public class ImportDefintionImpl implements ImportDefintion { 024 025 private String pack; 026 private String name; 027 private boolean wildcard; 028 private String packAsPath; 029 030 public ImportDefintionImpl(String pack, String name) { 031 this.pack=pack; 032 this.name=name; 033 this.wildcard=name.equals("*"); 034 035 } 036 037 public static ImportDefintion getInstance(String fullname,ImportDefintion defaultValue) { 038 int index=fullname.lastIndexOf('.'); 039 if(index==-1) return defaultValue; 040 String p=fullname.substring(0,index).trim(); 041 String n=fullname.substring(index+1,fullname.length()).trim(); 042 if(StringUtil.isEmpty(p) || StringUtil.isEmpty(n)) 043 return defaultValue; 044 045 return new ImportDefintionImpl(p,n); 046 } 047 048 /** 049 * @return the wildcard 050 */ 051 public boolean isWildcard() { 052 return wildcard; 053 } 054 055 /** 056 * @return the pack 057 */ 058 public String getPackage() { 059 return pack; 060 } 061 062 /** 063 * @return the name 064 */ 065 public String getName() { 066 return name; 067 } 068 069 public String getPackageAsPath() { 070 if(packAsPath==null) { 071 packAsPath=pack.replace('.','/')+"/"; 072 } 073 return packAsPath; 074 } 075 076 public String toString(){ 077 return pack+"."+name; 078 } 079 080}