Changeset 5311

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

added xslt component stuff

Location:
branches/xsltcomp-2010-08-11/pfixcore
Files:
10 added
9 modified

Legend:

Unmodified
Added
Removed
  • branches/xsltcomp-2010-08-11/pfixcore/pom.xml

    r5303 r5311  
    55  <artifactId>pfixcore</artifactId> 
    66  <name>pfixcore</name> 
    7   <version>0.13.22-SNAPSHOT</version> 
     7  <version>0.13.22-xsltcomp-SNAPSHOT</version> 
    88  <dependencies> 
    99    <dependency> 
  • branches/xsltcomp-2010-08-11/pfixcore/projects/core/xsl/master.xsl

    r5261 r5311  
    104104      <ixsl:import href="core/xsl/include.xsl"/> 
    105105      <ixsl:import href="core/xsl/functions.xsl"/> 
     106      <ixsl:import href="core/xsl/render.xsl"/> 
    106107 
    107108      <!-- generate user defined imports --> 
     
    128129      <ixsl:param name="navitree" select="$__navitree"/> 
    129130       
    130       <!-- The next three parameters are opaque Java objects. Use them only to pass them to extension functions! --> 
     131      <!-- The next four parameters are opaque Java objects. Use them only to pass them to extension functions! --> 
    131132      <ixsl:param name="__context__"/> 
    132133      <ixsl:param name="__spdoc__"/> 
     
    260261 
    261262      <ixsl:template match="/"> 
     263        <ixsl:call-template name="__render_start__"/> 
    262264        <xsl:choose> 
    263265          <!-- <xsl:when test="//frameset"> --> 
  • branches/xsltcomp-2010-08-11/pfixcore/projects/core/xsl/metatags.xsl

    r3872 r5311  
    99  <xsl:import href="core/xsl/include.xsl"/> 
    1010  <xsl:import href="core/xsl/utils.xsl"/> 
     11  <xsl:import href="core/xsl/render.xsl"/> 
    1112 
    1213  <cus:custom_xsl/> 
  • branches/xsltcomp-2010-08-11/pfixcore/projects/sample1/txt/pages/main_home.xml

    r3873 r5311  
    9797          </table> 
    9898       </pfx:forminput> 
    99          
     99            
     100       <pfx:render href="sample1/txt/common.xml" part="content"/> 
     101       
    100102      </center> 
    101103    </theme> 
  • branches/xsltcomp-2010-08-11/pfixcore/src/de/schlund/pfixcore/util/TransformerCallback.java

    r4854 r5311  
    388388    } 
    389389     
     390    public static String getHandlerPath(String targetgen, String page) { 
     391        TargetGenerator gen = TargetGeneratorFactory.getInstance().getGenerator(targetgen); 
     392        return gen.getNavigation().getHandler(page); 
     393    } 
     394 
    390395} 
  • branches/xsltcomp-2010-08-11/pfixcore/src/de/schlund/pfixcore/workflow/Navigation.java

    r3367 r5311  
    154154    } 
    155155 
     156    public String getHandler(String page) { 
     157        NavigationElement element = pagetonavi.get(page); 
     158        if(element == null) throw new IllegalArgumentException("Page '" + page + "' not found in navigation."); 
     159        return element.getHandler(); 
     160    } 
     161     
     162     
    156163    public class NavigationElement { 
    157164        private ArrayList<NavigationElement> children = new ArrayList<NavigationElement>(); 
  • 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} 
  • branches/xsltcomp-2010-08-11/pfixcore/src/de/schlund/pfixxml/util/Xslt.java

    r4672 r5311  
    268268            if(href.equals("core/xsl/include.xsl")) { 
    269269                if(xsltVersion==XsltVersion.XSLT2) href="core/xsl/include_xslt2.xsl"; 
     270            } else if(href.equals("core/xsl/render.xsl")) { 
     271                if(xsltVersion==XsltVersion.XSLT2) href="core/xsl/render_xslt2.xsl"; 
    270272            } 
    271273             
  • branches/xsltcomp-2010-08-11/pfixcore/src/org/pustefixframework/http/AbstractPustefixXMLRequestHandler.java

    r4661 r5311  
    2828import java.security.MessageDigest; 
    2929import java.security.NoSuchAlgorithmException; 
     30import java.util.Collections; 
    3031import java.util.Enumeration; 
    3132import java.util.HashMap; 
     
    5960import de.schlund.pfixcore.workflow.NavigationInitializationException; 
    6061import de.schlund.pfixxml.PfixServletRequest; 
     62import de.schlund.pfixxml.RenderContext; 
    6163import de.schlund.pfixxml.RenderingException; 
    6264import de.schlund.pfixxml.RequestParam; 
     
    729731                     ((spdoc != null) ? ("pagename=" +  spdoc.getPagename()) : "spdoc==null"));  
    730732        } 
     733        RenderContext renderContext = RenderContext.create(generator.getXsltVersion()); 
     734        paramhash.put("__rendercontext__", renderContext); 
     735        renderContext.setParameters(Collections.unmodifiableMap(paramhash)); 
    731736        try { 
     737            long t1 = System.currentTimeMillis(); 
    732738            Xslt.transform(spdoc.getDocument(), stylevalue, paramhash, new StreamResult(output), getServletEncoding()); 
     739            long t2 = System.currentTimeMillis(); 
     740            System.out.println("TTTTTTTTTTTTTTTTTTTT: " + (t2-t1)); 
    733741        } catch (TransformerException e) { 
    734742            Throwable inner = e.getException(); 
     
    744752                throw e; 
    745753            } 
    746         } 
     754        }  
    747755    } 
    748756