Changeset 6050

Show
Ignore:
Timestamp:
11/14/11 11:57:16 (6 months ago)
Author:
mtld
Message:

added searchengine sitemap generator, support for direct page alternative links

Location:
trunk/pustefix-core/src/main
Files:
2 added
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/pustefix-core/src/main/java/de/schlund/pfixcore/util/TransformerCallback.java

    r5955 r6050  
    409409    } 
    410410     
    411     public static String omitPage(RequestContextImpl requestContext, TargetGenerator gen, String pageName, String lang) throws Exception { 
     411    public static String omitPage(RequestContextImpl requestContext, TargetGenerator gen, String pageName, String lang, String altKey) throws Exception { 
    412412        try { 
    413413            ContextImpl context = requestContext.getParentContext(); 
     
    423423                return langPrefix; 
    424424            } else { 
    425                 String alias = gen.getSiteMap().getAlias(pageName, lang); 
     425                String alias = gen.getSiteMap().getAlias(pageName, lang, altKey); 
    426426                if(langPrefix.length() > 0) { 
    427427                    alias = langPrefix + "/" + alias; 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixcore/workflow/Context.java

    r5888 r6050  
    7878     
    7979    void setPageAlternative(String key); 
     80    String getPageAlternative(); 
    8081 
    8182    void addCookie(Cookie cookie); 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixcore/workflow/ContextImpl.java

    r5888 r6050  
    218218    } 
    219219     
     220    public String getPageAlternative() { 
     221        return getRequestContextForCurrentThreadWithError().getPageAlternative(); 
     222    } 
     223     
    220224    public void setVariant(Variant variant) { 
    221225        getRequestContextForCurrentThreadWithError().setVariantForThisRequestOnly(variant); 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixcore/workflow/SiteMap.java

    r5896 r6050  
    1919package de.schlund.pfixcore.workflow; 
    2020 
     21import java.io.File; 
    2122import java.io.IOException; 
    2223import java.io.StringReader; 
     
    6263    private Set<Resource> fileDependencies = new HashSet<Resource>(); 
    6364    private Map<String, Document> langToDoc = new HashMap<String, Document>(); 
    64     private List<Page> pageList; 
    65     private Map<String, Page> pageNameToPage; 
    66     private Map<String, Map<String, String>> aliasMaps; 
    67     private Map<String, Map<String, String>> pageMaps; 
    68     private Map<String, Page> pageAlternativeToPage; 
    69     private Map<String, Page> pageAliasToPage; 
     65    private List<Page> pageList = new ArrayList<Page>(); 
     66    private Map<String, Page> pageNameToPage = new LinkedHashMap<String, Page>(); 
     67    private Map<String, Map<String, String>> aliasMaps = new HashMap<String, Map<String, String>>(); 
     68    private Map<String, Map<String, String>> pageMaps = new HashMap<String, Map<String, String>>(); 
     69    private Map<String, Page> pageAlternativeToPage = new HashMap<String, Page>(); 
     70    private Map<String, Page> pageAliasToPage = new HashMap<String, Page>(); 
    7071    private boolean provided; 
     72     
     73    public SiteMap(File siteMapFile, File[] siteMapAliasFiles) throws IOException, SAXException { 
     74        if(siteMapFile.exists()) { 
     75            Document siteMapDoc = Xml.parseMutable(siteMapFile); 
     76            readSiteMap(siteMapDoc.getDocumentElement()); 
     77            for(File siteMapAliasFile: siteMapAliasFiles) { 
     78                readSiteMapAliases(Xml.parseMutable(siteMapAliasFile)); 
     79            } 
     80            provided = true; 
     81        } 
     82    } 
    7183     
    7284    public SiteMap(Resource siteMapFile) throws IOException, SAXException, XMLException { 
     
    7688        if(uriStr.endsWith("depend.xml")) uriStr = uriStr.substring(0, uriStr.length() -10) + "sitemap.xml"; 
    7789        siteMapFile = ResourceUtil.getResource(uriStr); 
    78          
    79         pageList = new ArrayList<Page>(); 
    80         pageNameToPage = new HashMap<String, Page>(); 
    81         pageAlternativeToPage = new HashMap<String, Page>(); 
    82         pageAliasToPage = new HashMap<String, Page>(); 
    8390         
    8491        if(siteMapFile.exists()) { 
     
    133140            readSiteMap(siteMapDoc.getDocumentElement()); 
    134141             
    135             aliasMaps = new HashMap<String, Map<String, String>>(); 
    136             pageMaps = new HashMap<String, Map<String, String>>(); 
    137              
    138142            Resource res = ResourceUtil.getResource("/WEB-INF/sitemap-aliases.xml"); 
    139143            if(res.exists()) { 
     
    155159         
    156160    } 
    157     
     161     
    158162    public boolean isProvided() { 
    159163        return provided; 
     
    171175        String name = pageElem.getAttribute("name").trim(); 
    172176        Page page = new Page(name); 
     177        String internal = pageElem.getAttribute("internal").trim(); 
     178        if(internal.length() > 0) { 
     179            page.internal = Boolean.valueOf(internal); 
     180        } 
    173181        pageNameToPage.put(page.name, page); 
    174182        String alias = pageElem.getAttribute("alias").trim(); 
     
    236244    } 
    237245     
    238     public String getAlias(String name, String lang) { 
    239         String alias = null; 
     246    public List<String> getPageNames(boolean excludeInternal) { 
     247        List<String> pageNames = new ArrayList<String>(); 
     248        for(Page page: pageList) { 
     249            getPageNames(page, excludeInternal, pageNames); 
     250        } 
     251        return pageNames; 
     252    } 
     253     
     254    private void getPageNames(Page page, boolean excludeInternal, List<String> pageNames) { 
     255        if(!excludeInternal || !page.internal) { 
     256            pageNames.add(page.name); 
     257            for(Page child: page.pages) { 
     258                getPageNames(child, excludeInternal, pageNames); 
     259            } 
     260        } 
     261    } 
     262     
     263    public String getAlias(final String name, final String lang) { 
     264        String aliasName = name; 
     265        if(pageNameToPage != null) { 
     266            Page page = pageNameToPage.get(name); 
     267            if(page != null && page.alias != null) { 
     268                aliasName = page.alias; 
     269            } 
     270        } 
     271        String aliasTranslated = null; 
    240272        if(lang != null) { 
    241273            if(aliasMaps != null) { 
    242274                Map<String, String> aliases = aliasMaps.get(lang); 
    243275                if(aliases != null) { 
    244                     alias = aliases.get(name); 
    245                 } 
    246                 if(alias == null) { 
     276                    aliasTranslated = aliases.get(aliasName); 
     277                } 
     278                if(aliasTranslated == null) { 
    247279                    int ind = lang.indexOf('_'); 
    248280                    if(ind > -1) { 
    249                         lang = lang.substring(0, ind); 
    250                         aliases = aliasMaps.get(lang); 
     281                        String mainLang = lang.substring(0, ind); 
     282                        aliases = aliasMaps.get(mainLang); 
    251283                        if(aliases != null) { 
    252                             alias = aliases.get(name); 
     284                            aliasTranslated = aliases.get(aliasName); 
    253285                        } 
    254286                    } 
     
    256288            } 
    257289        } 
    258         if(alias == null) { 
    259             if(pageNameToPage != null) { 
    260                 Page page = pageNameToPage.get(name); 
    261                 if(page != null && page.alias != null) { 
    262                     alias = page.alias; 
    263                 } 
    264             } 
    265         } 
    266         if(alias != null) { 
    267             return alias; 
     290        if(aliasTranslated != null) { 
     291            return aliasTranslated; 
    268292        } else { 
    269             return name; 
     293            return aliasName; 
    270294        } 
    271295    } 
    272296     
    273297    public String getAlias(String name, String lang, String pageAlternativeKey) { 
    274         if(pageAlternativeKey == null) { 
     298        if(pageAlternativeKey == null || pageAlternativeKey.equals("")) { 
    275299            return getAlias(name, lang); 
    276300        } else { 
     
    330354                } 
    331355            } 
     356            if(page != null) { 
     357                if(pageAliasToPage != null) { 
     358                    Page p = pageAliasToPage.get(page); 
     359                    if(p != null) page = p.name; 
     360                } 
     361            } 
    332362        } 
    333363        if(page == null) { 
     
    362392    } 
    363393     
    364      
    365     class Page { 
     394 
     395     
     396    public class Page { 
    366397         
    367398        String name; 
     399        boolean internal; 
     400        Map<String, String> customAttributes = new HashMap<String, String>(); 
    368401        String alias; 
    369402        List<Page> pages = new ArrayList<Page>(); 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixcore/workflow/context/RequestContextImpl.java

    r5872 r6050  
    252252    public void setPageAlternative(String key) { 
    253253        pageAlternativeKey = key; 
     254    } 
     255     
     256    public String getPageAlternative() { 
     257        return pageAlternativeKey; 
    254258    } 
    255259     
  • trunk/pustefix-core/src/main/java/org/pustefixframework/test/MockContext.java

    r5915 r6050  
    8282    private Set<String> pageNeedsDataSet = new HashSet<String>(); 
    8383    private Set<String> pageAccessibleSet = new HashSet<String>(); 
    84      
     84    private String pageAltKey; 
    8585     
    8686    public void addCookie(Cookie cookie) { 
     
    331331     
    332332    public void setPageAlternative(String key) { 
     333        this.pageAltKey = key; 
     334    } 
     335     
     336    public String getPageAlternative() { 
     337        return pageAltKey; 
    333338    } 
    334339     
  • trunk/pustefix-core/src/main/resources/META-INF/org/pustefixframework/config/project/parser/project-config.xml

    r6035 r6050  
    4040   
    4141  <!-- Creates request handler for search engine sitemaps --> 
    42   <!-- 
    4342  <handler class="org.pustefixframework.config.project.parser.SiteMapRequestHandlerParsingHandler"> 
    44     <match>/p:project-config/p:application/p:sitemaps-protocol-generator</match> 
     43    <match>/p:project-config/p:searchengine-sitemap</match> 
    4544  </handler> 
    46   --> 
     45   
    4746  <handler class="org.pustefixframework.config.project.parser.StaticPathParsingHandler"> 
    4847    <match>/p:project-config/p:application/p:static//p:path</match> 
     
    7271  </handler> 
    7372   
    74   <!-- Adds Statistics bean --> 
    75   <!-- 
    76   <handler class="org.pustefixframework.config.project.parser.StatisticsParsingHandler"> 
    77     <match>/p:project-config/p:application</match> 
    78   </handler> 
    79   --> 
    8073  <!-- Reads path to depend.xml file --> 
    8174  <handler class="org.pustefixframework.config.project.parser.XMLGeneratorInfoParsingHandler"> 
  • trunk/pustefix-core/src/main/resources/PUSTEFIX-INF/xsl/functions.xsl

    r5849 r6050  
    123123    <xsl:param name="pageName"/> 
    124124    <xsl:param name="language"><xsl:value-of select="$lang"/></xsl:param> 
    125     <func:result select="callback:omitPage($__context__,$__target_gen,$pageName,$language)"/> 
     125    <xsl:param name="altKey"/> 
     126    <func:result select="callback:omitPage($__context__,$__target_gen,$pageName,$language,$altKey)"/> 
    126127  </func:function> 
    127128   
  • trunk/pustefix-core/src/main/resources/PUSTEFIX-INF/xsl/navigation.xsl

    r5750 r6050  
    1212  <xsl:template match="pfx:normal"/> 
    1313  <xsl:template match="pfx:argument"/> 
     14  <xsl:template match="pfx:altkey"/> 
    1415   
    1516  <xsl:template match="pfx:command"> 
     
    157158      <xsl:with-param name="popupfeatures" select="@popupfeatures"/> 
    158159      <xsl:with-param name="popupid" select="@popupid"/> 
     160      <xsl:with-param name="altkey"> 
     161        <xsl:choose> 
     162          <xsl:when test="./pfx:altkey"> 
     163            <xsl:apply-templates select="./pfx:altkey/node()"> 
     164              <xsl:with-param name="thepagename" select="@page"/> 
     165            </xsl:apply-templates> 
     166          </xsl:when> 
     167          <xsl:when test="@altkey"> 
     168            <xsl:value-of select="@altkey"/> 
     169          </xsl:when> 
     170        </xsl:choose> 
     171      </xsl:with-param> 
    159172    </xsl:call-template> 
    160173  </xsl:template> 
     
    207220    <xsl:param name="popupfeatures"/> 
    208221    <xsl:param name="popupid"/> 
     222    <xsl:param name="altkey"/> 
    209223    <xsl:param name="nodata"/> 
    210224    <xsl:param name="args"/> 
     
    245259    </xsl:variable> 
    246260    <xsl:variable name="fulllink"> 
    247       <ixsl:value-of select="$__contextpath"/>/<ixsl:value-of select="pfx:__omitPage({$mypage})"/><ixsl:value-of select="$__sessionIdPath"/> 
     261      <ixsl:variable name="tmpaltkey"> 
     262        <xsl:if test="$altkey"><xsl:copy-of select="$altkey"/></xsl:if> 
     263      </ixsl:variable> 
     264      <ixsl:value-of select="$__contextpath"/>/<ixsl:value-of select="pfx:__omitPage({$mypage}, $lang, $tmpaltkey)"/><ixsl:value-of select="$__sessionIdPath"/> 
    248265      <ixsl:variable name="params"> 
    249266      <xsl:if test="not($frame_impl='')">__frame=<xsl:value-of select="$frame_impl"/></xsl:if>