001 /** 002 * Implements the CFML Function getmetadata 003 */ 004 package railo.runtime.functions.other; 005 006 import java.util.HashMap; 007 008 import railo.runtime.Component; 009 import railo.runtime.InterfaceImpl; 010 import railo.runtime.Page; 011 import railo.runtime.PageContext; 012 import railo.runtime.component.ComponentLoader; 013 import railo.runtime.exp.ApplicationException; 014 import railo.runtime.exp.PageException; 015 import railo.runtime.ext.function.Function; 016 import railo.runtime.op.Caster; 017 import railo.runtime.type.Struct; 018 019 public final class GetComponentMetaData implements Function { 020 021 public static Struct call(PageContext pc , Object obj) throws PageException { 022 if(obj instanceof Component){ 023 return ((Component)obj).getMetaData(pc); 024 } 025 // load existing meta without loading the cfc 026 try{ 027 Page page = ComponentLoader.loadPage(pc, Caster.toString(obj), null,null); 028 if(page.metaData!=null && page.metaData.get()!=null) return page.metaData.get(); 029 } 030 catch(Throwable t){} 031 032 /*try{ 033 PagePlus page = ComponentLoader.loadPage(pc, Caster.toString(obj), null,null); 034 Struct meta=null; 035 if(page!=null)meta=GetMetaData.getMetaData(page.getPageSource()); 036 if(meta!=null) return meta; 037 038 } 039 catch(Throwable t){}*/ 040 041 042 // load the cfc when metadata was not defined before 043 try{ 044 Component cfc = CreateObject.doComponent(pc, Caster.toString(obj)); 045 return GetMetaData.getMetaData(cfc, pc); 046 } 047 // TODO better solution 048 catch(ApplicationException ae){ 049 try{ 050 InterfaceImpl inter = ComponentLoader.loadInterface(pc, Caster.toString(obj), new HashMap()); 051 return inter.getMetaData(pc); 052 } 053 catch(PageException pe){ 054 throw ae; 055 } 056 } 057 } 058 }