sorry, fixing it now On Sat, Jan 31, 2009 at 7:32 PM, Vincent Massol <[email protected]> wrote: > I think you commented out too many tests in this commit... :) > > -Vincent > > On Jan 31, 2009, at 7:22 PM, tmortagne (SVN) wrote: > >> Author: tmortagne >> Date: 2009-01-31 19:22:16 +0100 (Sat, 31 Jan 2009) >> New Revision: 15982 >> >> Modified: >> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/ >> java/org/xwiki/rendering/block/AbstractBlock.java >> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/ >> java/org/xwiki/rendering/block/Block.java >> platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- >> rendering-macro-toc/pom.xml >> platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- >> rendering-macro-toc/src/main/java/org/xwiki/rendering/internal/macro/ >> toc/TocMacro.java >> platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- >> rendering-macro-toc/src/test/java/org/xwiki/rendering/ >> RenderingTests.java >> Log: >> XWIKI-3174: Rename current SectionBlock to HeaderBlock and make >> SectionBlock represent the whole section content >> * improve toc macro execution based on new section block >> >> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/ >> src/main/java/org/xwiki/rendering/block/AbstractBlock.java >> =================================================================== >> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/ >> java/org/xwiki/rendering/block/AbstractBlock.java 2009-01-31 >> 18:02:32 UTC (rev 15981) >> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/ >> java/org/xwiki/rendering/block/AbstractBlock.java 2009-01-31 >> 18:22:16 UTC (rev 15982) >> @@ -20,18 +20,18 @@ >> package org.xwiki.rendering.block; >> >> import java.util.ArrayList; >> +import java.util.Collections; >> import java.util.LinkedHashMap; >> import java.util.List; >> import java.util.Map; >> -import java.util.Collections; >> >> import org.apache.commons.beanutils.ConvertUtils; >> import org.apache.commons.lang.builder.EqualsBuilder; >> import org.apache.commons.lang.builder.HashCodeBuilder; >> >> /** >> - * Implementation for Block operations. All blocks should extend >> this class. Supports the notion of parameters >> - * which can be added to a block (see {...@link #setParameter(String, >> Object)} for more details). >> + * Implementation for Block operations. All blocks should extend >> this class. Supports the notion of parameters which can >> + * be added to a block (see {...@link #setParameter(String, Object)} >> for more details). >> * >> * @version $Id$ >> * @since 1.5M2 >> @@ -70,7 +70,7 @@ >> { >> this.parameters.putAll(parameters); >> } >> - >> + >> /** >> * {...@inheritdoc} >> * >> @@ -194,15 +194,15 @@ >> } >> >> /** >> - * Set a parameter on the current block. A parameter is any >> semantic data associated with a block. >> - * It can be used for various purposes and provide additional >> information to the renderers/listeners. >> - * For example you can pass style information such as >> <code>style="color:red"</code> (in that example >> - * the name would be <code>style</code> and the value >> <code>"color:red"</code>) to indicate that the >> - * current block should be displayed in red. >> + * Set a parameter on the current block. A parameter is any >> semantic data associated with a block. It can be used >> + * for various purposes and provide additional information to >> the renderers/listeners. For example you can pass >> + * style information such as <code>style="color:red"</code> (in >> that example the name would be <code>style</code> >> + * and the value <code>"color:red"</code>) to indicate that the >> current block should be displayed in red. >> + * <p> >> + * Note that there are currently no well-defined known >> parameter names and you'll need to check what the different >> + * renderers/listeners support to know what to use. >> + * </p> >> * >> - * <p>Note that there are currently no well-defined known >> parameter names and you'll need to check what >> - * the different renderers/listeners support to know what to >> use.</p> >> - * >> * @param name the parameter's name >> * @param value the parameter's value >> */ >> @@ -285,7 +285,7 @@ >> >> for (int i = index - 1; i >= 0; --i) { >> Block previousBlock = blocks.get(i); >> - if (previousBlock instanceof HeaderBlock) { >> + if >> (blockClass.isAssignableFrom(previousBlock.getClass())) { >> return (T) previousBlock; >> } >> } >> @@ -317,6 +317,7 @@ >> >> /** >> * {...@inheritdoc} >> + * >> * @see Object#clone() >> */ >> @Override >> @@ -330,7 +331,7 @@ >> throw new RuntimeException("Failed to clone object", e); >> } >> block.parameters = new LinkedHashMap<String, >> String>(getParameters()); >> - // Clone all children blocks. Note that we cannot use an >> iterator since we're going to change the objects >> + // Clone all children blocks. Note that we cannot use an >> iterator since we're going to change the objects >> // themselves. Using an iterator would lead to a >> ConcurrentModificationException >> Object[] objectArray = getChildren().toArray(); >> block.childrenBlocks = new ArrayList<Block>(); >> >> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/ >> src/main/java/org/xwiki/rendering/block/Block.java >> =================================================================== >> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/ >> java/org/xwiki/rendering/block/Block.java 2009-01-31 18:02:32 UTC >> (rev 15981) >> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/ >> java/org/xwiki/rendering/block/Block.java 2009-01-31 18:22:16 UTC >> (rev 15982) >> @@ -84,7 +84,7 @@ >> * @param newBlocks the new blocks to replace the current block >> with >> */ >> void replace(List<Block> newBlocks); >> - >> + >> /** >> * Get the parent block. All blocks have a parent and the top >> level parent is the {...@link XDOM} object. >> * >> @@ -126,7 +126,7 @@ >> <T extends Block> List<T> getChildrenByType(Class<T> blockClass, >> boolean recurse); >> >> /** >> - * Look forward to find a block which inherit or s provided type. >> + * Look forward to find a block which inherit or is provided >> type. >> * >> * @param <T> the class of the Blocks to return >> * @param blockClass the block class to look for >> @@ -135,9 +135,10 @@ >> * @since 1.6M1 >> */ >> <T extends Block> T getPreviousBlockByType(Class<T> blockClass, >> boolean recurse); >> - >> + >> /** >> * {...@inheritdoc} >> + * >> * @see Object#clone() >> */ >> Block clone(); >> >> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/ >> xwiki-rendering-macro-toc/pom.xml >> =================================================================== >> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- >> rendering-macro-toc/pom.xml 2009-01-31 18:02:32 UTC (rev 15981) >> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- >> rendering-macro-toc/pom.xml 2009-01-31 18:22:16 UTC (rev 15982) >> @@ -43,11 +43,11 @@ >> </includes> >> </configuration> >> </plugin> >> - <!-- plugin> >> - Apply the Checkstyle configurations defined in the top >> level pom.xml file >> + <plugin> >> + <!-- Apply the Checkstyle configurations defined in the top >> level pom.xml file --> >> <groupId>org.apache.maven.plugins</groupId> >> <artifactId>maven-checkstyle-plugin</artifactId> >> - </plugin> --> >> + </plugin> >> </plugins> >> </build> >> </project> >> >> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/ >> xwiki-rendering-macro-toc/src/main/java/org/xwiki/rendering/internal/ >> macro/toc/TocMacro.java >> =================================================================== >> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- >> rendering-macro-toc/src/main/java/org/xwiki/rendering/internal/macro/ >> toc/TocMacro.java 2009-01-31 18:02:32 UTC (rev 15981) >> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- >> rendering-macro-toc/src/main/java/org/xwiki/rendering/internal/macro/ >> toc/TocMacro.java 2009-01-31 18:22:16 UTC (rev 15982) >> @@ -31,6 +31,7 @@ >> import org.xwiki.rendering.block.ListItemBlock; >> import org.xwiki.rendering.block.NumberedListBlock; >> import org.xwiki.rendering.block.HeaderBlock; >> +import org.xwiki.rendering.block.SectionBlock; >> import org.xwiki.rendering.internal.util.EnumConverter; >> import org.xwiki.rendering.listener.Link; >> import org.xwiki.rendering.macro.AbstractMacro; >> @@ -108,26 +109,30 @@ >> // Get the root block from scope parameter >> >> Block root; >> - HeaderBlock rootSectionBlock = null; >> >> - if (parameters.getScope() == Scope.LOCAL && >> context.getCurrentMacroBlock() != null) { >> + if (parameters.getScope() == Scope.LOCAL) { >> root = context.getCurrentMacroBlock().getParent(); >> - rootSectionBlock = >> context >> .getCurrentMacroBlock().getPreviousBlockByType(HeaderBlock.class, >> true); >> } else { >> root = context.getXDOM(); >> } >> >> // Get the list of sections in the scope >> >> - List<HeaderBlock> sections = >> root.getChildrenByType(HeaderBlock.class, true); >> + List<HeaderBlock> headers = >> root.getChildrenByType(HeaderBlock.class, true); >> >> - if (!sections.isEmpty()) { >> - // Construct table of content from sections list >> - Block rootBlock = >> - generateTree(sections, parameters.getStart(), >> parameters.getDepth(), parameters.isNumbered(), >> - rootSectionBlock); >> + if (!headers.isEmpty()) { >> + // If the root block is a section, remove it's header >> block for the list of header blocks >> + if (root instanceof SectionBlock) { >> + Block block = root.getChildren().get(0); >> >> - return Arrays.asList(rootBlock); >> + if (block instanceof HeaderBlock) { >> + headers.remove(block); >> + } >> + } >> + >> + // Construct table of content from sections list >> + return Arrays.asList(generateTree(headers, >> parameters.getStart(), parameters.getDepth(), parameters >> + .isNumbered())); >> } >> >> return Collections.emptyList(); >> @@ -142,47 +147,31 @@ >> } >> >> /** >> - * Convert sections into list block tree. >> + * Convert headers into list block tree. >> * >> - * @param sections the sections to convert. >> + * @param headers the headers to convert. >> * @param start the "start" parameter value. >> * @param depth the "depth" parameter value. >> * @param numbered the "numbered" parameter value. >> - * @param rootSectionBlock the section where the toc macro >> search for children sections. >> * @return the root block of generated block tree. >> */ >> - private Block generateTree(List<HeaderBlock> sections, int >> start, int depth, boolean numbered, >> - HeaderBlock rootSectionBlock) >> + private Block generateTree(List<HeaderBlock> headers, int >> start, int depth, boolean numbered) >> { >> - int rootSectionLevel = rootSectionBlock != null ? >> rootSectionBlock.getLevel().getAsInt() : 0; >> - boolean rootSectionFound = false; >> - >> int currentLevel = 0; >> Block currentBlock = null; >> - for (HeaderBlock sectionBlock : sections) { >> - int sectionLevel = sectionBlock.getLevel().getAsInt(); >> + for (HeaderBlock headerBlock : headers) { >> + int headerLevel = headerBlock.getLevel().getAsInt(); >> >> - if (rootSectionBlock != null) { >> - if (rootSectionBlock == sectionBlock) { >> - rootSectionFound = true; >> - continue; >> - } else if (rootSectionBlock.getParent() == >> sectionBlock.getParent() && sectionLevel <= rootSectionLevel) { >> - break; >> - } >> - } else { >> - rootSectionFound = true; >> - } >> + if (headerLevel >= start && headerLevel <= depth) { >> + ListItemBlock itemBlock = >> createTocEntry(headerBlock); >> >> - if (rootSectionFound && sectionLevel >= start && >> sectionLevel <= depth) { >> - ListItemBlock itemBlock = >> createTocEntry(sectionBlock); >> + // Move to next header in toc tree >> >> - // Move to next section in toc tree >> - >> - while (currentLevel < sectionLevel) { >> + while (currentLevel < headerLevel) { >> currentBlock = createChildListBlock(numbered, >> currentBlock); >> ++currentLevel; >> } >> - while (currentLevel > sectionLevel) { >> + while (currentLevel > headerLevel) { >> currentBlock = currentBlock.getParent(); >> --currentLevel; >> } >> >> Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/ >> xwiki-rendering-macro-toc/src/test/java/org/xwiki/rendering/ >> RenderingTests.java >> =================================================================== >> --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- >> rendering-macro-toc/src/test/java/org/xwiki/rendering/ >> RenderingTests.java 2009-01-31 18:02:32 UTC (rev 15981) >> +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki- >> rendering-macro-toc/src/test/java/org/xwiki/rendering/ >> RenderingTests.java 2009-01-31 18:22:16 UTC (rev 15982) >> @@ -37,12 +37,14 @@ >> { >> RenderingTestSuite suite = new RenderingTestSuite("Test Toc >> Macro"); >> >> - suite.addTestsFromResource("macrotoc1", true); >> + /*suite.addTestsFromResource("macrotoc1", true); >> suite.addTestsFromResource("macrotoc2", true); >> suite.addTestsFromResource("macrotoc3", true); >> suite.addTestsFromResource("macrotoc4", true); >> - suite.addTestsFromResource("macrotoc5", true); >> + suite.addTestsFromResource("macrotoc5", true);*/ >> >> + suite.addTestsFromResource("macrotoc4", true); >> + >> return new RenderingPlexusTestSetup(suite); >> } >> } > > _______________________________________________ > devs mailing list > [email protected] > http://lists.xwiki.org/mailman/listinfo/devs >
-- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

