Show
Ignore:
Timestamp:
08/20/10 14:31:13 (21 months ago)
Author:
mtld
Message:

added xslt component stuff

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/xsltcomp-2010-08-11/pfixcore/src/de/schlund/pfixxml/targets/TargetGenerator.java

    r4017 r5311  
    5555 
    5656import de.schlund.pfixcore.util.Meminfo; 
     57import de.schlund.pfixcore.workflow.Navigation; 
    5758import de.schlund.pfixcore.workflow.NavigationFactory; 
     59import de.schlund.pfixcore.workflow.NavigationInitializationException; 
    5860import de.schlund.pfixxml.IncludeDocumentFactory; 
    5961import de.schlund.pfixxml.XMLException; 
     
    7274import de.schlund.pfixxml.targets.cachestat.SPCacheStatistic; 
    7375import de.schlund.pfixxml.util.TransformerHandlerAdapter; 
     76import de.schlund.pfixxml.util.XMLUtils; 
    7477import de.schlund.pfixxml.util.Xml; 
    7578import de.schlund.pfixxml.util.XsltVersion; 
     
    121124 
    122125    private FileResource config_path; 
    123  
     126     
     127    private Navigation navigation; 
     128     
    124129    //-- 
    125130 
     
    162167    } 
    163168 
     169    public Navigation getNavigation() { 
     170        return navigation; 
     171    } 
     172     
    164173    //-- targets 
    165174 
     
    172181    public Target getTarget(String key) { 
    173182        synchronized (alltargets) { 
    174             return (Target) alltargets.get(key); 
     183            Target target = (Target) alltargets.get(key); 
     184            if(target == null && key.contains("$")) { 
     185                Target compTarget = createTargetForComponent(key); 
     186                return compTarget; 
     187            } 
     188            return target; 
    175189        } 
    176190    } 
     
    322336            throw new RuntimeException("Could not get instance of SAXTransformerFactory!"); 
    323337        } 
    324  
     338try { 
     339    XMLUtils.serialize(config); 
     340} catch(Exception x) { 
     341    x.printStackTrace(); 
     342} 
    325343        Element root = (Element) config.getElementsByTagName("make").item(0); 
    326344         
     
    448466            allstructs.put(nameattr, struct); 
    449467        } 
     468         
     469         
     470        try { 
     471            navigation = NavigationFactory.getInstance().getNavigation(this.config_path,getXsltVersion()); 
     472        } catch (NavigationInitializationException e) { 
     473            throw new XMLException("Error reading page navigation."); 
     474        } 
     475         
    450476        LOG.warn("\n=====> Preliminaries took " + (System.currentTimeMillis() - start) + "ms. Now looping over " + allstructs.keySet().size() + " targets"); 
    451477        start = System.currentTimeMillis(); 
     
    534560            virtual.addParam(XSLPARAM_TG, tgParam); 
    535561            virtual.addParam(XSLPARAM_TKEY, key); 
     562            System.out.println(">>>>>>>>>>>>>>>>>> "+tgParam+" "+key); 
    536563            try { 
    537                 virtual.addParam(XSLPARAM_NAVITREE, NavigationFactory.getInstance().getNavigation(this.config_path,getXsltVersion()).getNavigationXMLElement()); 
     564                virtual.addParam(XSLPARAM_NAVITREE, navigation.getNavigationXMLElement()); 
    538565            } catch (Exception e) { 
    539566                throw new XMLException("Cannot get navigation tree", e); 
     
    555582        } 
    556583    } 
    557  
     584     
     585    private TargetRW createTargetForComponent(String componentKey) { 
     586 
     587        String[] comps = splitComponentKey(componentKey); 
     588        String href = comps[0]; 
     589        String part = comps[1]; 
     590        String module = ""; 
     591        if(comps.length>2) module = comps[2]; 
     592        String search = ""; 
     593        if(comps.length>3) search = comps[3]; 
     594         
     595        System.out.println("NNNNNNNNNNNNNNNNNN: " + componentKey); 
     596        //sample1_txt_pages_main_foo@content::foo:bar:baz.xml 
     597        Themes themes = global_themes; 
     598         
     599        if(getTargetRW(name) != null) throw new RuntimeException("Target already exists");  
     600         
     601        String tgParam = config_path.toString(); 
     602         
     603        XMLVirtualTarget xmlTarget = (XMLVirtualTarget)createTarget(TargetType.XML_VIRTUAL, componentKey + ".xml", themes); 
     604        Target xmlSource = createTarget(TargetType.XML_LEAF, "core/xml/component.xml", null); 
     605        Target xslSource = createTarget(TargetType.XSL_VIRTUAL, "metatags.xsl", null); 
     606        xmlTarget.setXMLSource(xmlSource); 
     607        xmlTarget.setXSLSource(xslSource); 
     608        xmlTarget.addParam(XSLPARAM_TG, tgParam); 
     609        xmlTarget.addParam(XSLPARAM_TKEY, componentKey + ".xml"); 
     610        xmlTarget.addParam("component_href", href); 
     611        xmlTarget.addParam("component_part", part); 
     612        xmlTarget.addParam("component_module", module); 
     613        xmlTarget.addParam("component_search", search); 
     614         
     615        XSLVirtualTarget xslTarget = (XSLVirtualTarget)createTarget(TargetType.XSL_VIRTUAL, componentKey + ".xsl", themes); 
     616        xmlSource = xmlTarget; 
     617        xslSource = createTarget(TargetType.XSL_VIRTUAL, "master.xsl", null); 
     618        xslTarget.setXMLSource(xmlSource); 
     619        xslTarget.setXSLSource(xslSource); 
     620        xslTarget.addParam(XSLPARAM_TG, tgParam); 
     621        xslTarget.addParam(XSLPARAM_TKEY, componentKey + ".xsl"); 
     622         
     623        return xslTarget; 
     624    } 
     625     
     626     
     627     
     628     
     629     
    558630    // ******************************************************************************************* 
    559631    private TargetRW getTargetRW(String key) { 
     
    879951        return this.config_path; 
    880952    } 
     953     
     954    public static String createComponentKey(String href, String part, String module, String search) { 
     955        if(href == null || href.equals("")) throw new IllegalArgumentException("Argument 'href' must not be empty"); 
     956        if(part == null || part.equals("")) throw new IllegalArgumentException("Argument 'part' must not be empty"); 
     957        if(module == null) module = ""; 
     958        if(search == null) search = ""; 
     959        String targetKey = encode(href) + "$" + encode(part) + "$" + encode(module) + "$" + encode(search); 
     960        return targetKey; 
     961    } 
     962     
     963    public static String encode(String str) { 
     964        str = str.replace("%", "%" + Integer.toHexString('%')); 
     965        str = str.replace("$", "%" + Integer.toHexString('$')); 
     966        str = str.replace("+", "%" + Integer.toHexString('+')); 
     967        str = str.replace("/", "+"); 
     968        return str; 
     969    } 
     970     
     971    public static String decode(String str) { 
     972        str = str.replace("+", "/"); 
     973        str = str.replace("%" + Integer.toHexString('+'), "+"); 
     974        str = str.replace("%" + Integer.toHexString('$'), "$"); 
     975        str = str.replace("%" + Integer.toHexString('%'), "%"); 
     976        return str; 
     977    } 
     978     
     979    public static String[] splitComponentKey(String componentKey) { 
     980        String[] comps = componentKey.split("\\$"); 
     981        for(int i=0; i<comps.length; i++) { 
     982            comps[i] = decode(comps[i]); 
     983        } 
     984        return comps; 
     985    } 
    881986 
    882987}