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 **/ 019/** 020 * Implements the CFML Function getmetadata 021 */ 022package lucee.runtime.functions.other; 023 024import java.util.HashMap; 025 026import lucee.runtime.Component; 027import lucee.runtime.InterfaceImpl; 028import lucee.runtime.PageContext; 029import lucee.runtime.PageContextImpl; 030import lucee.runtime.component.ComponentLoader; 031import lucee.runtime.exp.ApplicationException; 032import lucee.runtime.exp.PageException; 033import lucee.runtime.ext.function.Function; 034import lucee.runtime.op.Caster; 035import lucee.runtime.type.Struct; 036 037public final class GetComponentMetaData implements Function { 038 039 public static Struct call(PageContext pc , Object obj) throws PageException { 040 if(obj instanceof Component){ 041 return ((Component)obj).getMetaData(pc); 042 } 043 // load existing meta without loading the cfc 044 /*try{ 045 Page page = ComponentLoader.loadPage(pc,((PageContextImpl)pc).getCurrentPageSource(null), Caster.toString(obj), null,null); 046 if(page.metaData!=null && page.metaData.get()!=null) return page.metaData.get(); 047 }catch(Throwable t){ 048 ExceptionUtil.rethrowIfNecessary(t);}*/ 049 050 // load the cfc when metadata was not defined before 051 try{ 052 Component cfc = CreateObject.doComponent(pc, Caster.toString(obj)); 053 return cfc.getMetaData(pc); 054 } 055 // TODO better solution 056 catch(ApplicationException ae){ 057 try{ 058 InterfaceImpl inter = ComponentLoader.loadInterface(pc,((PageContextImpl)pc).getCurrentPageSource(null), Caster.toString(obj), new HashMap()); 059 return inter.getMetaData(pc); 060 } 061 catch(PageException pe){ 062 throw ae; 063 } 064 } 065 } 066}