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