/** * {@inheritDoc} * * @see org.xwiki.rendering.block.FatherBlock#before(org.xwiki.rendering.listener.Listener) */ public void before(Listener listener) { listener.beginHeader(getLevel(), getId(), getParameters()); }
/** * {@inheritDoc} * * @see org.xwiki.rendering.listener.Listener#endHeader(org.xwiki.rendering.listener.HeaderLevel, java.lang.String, * java.util.Map) */ public void endHeader(HeaderLevel level, String id, Map<String, String> parameters) { this.stack.push(new HeaderBlock(generateListFromStack(), level, parameters, id)); }
/** * @return the {@link SectionBlock} corresponding to this header */ public SectionBlock getSection() { return (SectionBlock) getParent(); }
int l = baseLevel + header.getLevel().getAsInt(); HeaderBlock nheader = new HeaderBlock( header.getChildren(), HeaderLevel.parseInt(l), header.getParameters(), header.getId() ); header.getParent().replaceChild(nheader, header);
/** * Filter the headers from a document XDOM based on xwiki.section.depth property from xwiki.cfg file. * * @return the filtered headers */ private List<HeaderBlock> getFilteredHeaders() { List<HeaderBlock> filteredHeaders = new ArrayList<HeaderBlock>(); // get the headers List<HeaderBlock> headers = getXDOM().getChildrenByType(HeaderBlock.class, true); // get the maximum header level int sectionDepth = 2; XWikiContext context = getXWikiContext(); if (context != null) { sectionDepth = (int) context.getWiki().getSectionEditingDepth(); } // filter the headers for (HeaderBlock header : headers) { if (header.getLevel().getAsInt() <= sectionDepth) { filteredHeaders.add(header); } } return filteredHeaders; }
XDOM xdom = (XDOM) header.getRoot(); int sectionLevel = header.getLevel().getAsInt(); for (int level = 1; level < sectionLevel && blocks.size() == 1 && blocks.get(0) instanceof SectionBlock; ++level) { blocks = blocks.get(0).getChildren(); Block section = header.getSection(); section.getParent().replaceChild(blocks, section);
/** * @return the sections in the current document * @throws XWikiException */ public List<DocumentSection> getSections() throws XWikiException { if (is10Syntax()) { return getSections10(); } else { List<DocumentSection> splitSections = new ArrayList<DocumentSection>(); List<HeaderBlock> headers = getFilteredHeaders(); int sectionNumber = 1; for (HeaderBlock header : headers) { // put -1 as index since there is no way to get the position of the header in the source int documentSectionIndex = -1; // Need to do the same thing than 1.0 content here String documentSectionLevel = StringUtils.repeat("1.", header.getLevel().getAsInt() - 1) + "1"; DocumentSection docSection = new DocumentSection(sectionNumber++, documentSectionIndex, documentSectionLevel, renderXDOM(new XDOM(header.getChildren()), getSyntax())); splitSections.add(docSection); } return splitSections; } }
@Override public boolean match(Block block) { return ((HeaderBlock) block).getId().equals(parameters.getSectionId()); } }), Block.Axes.DESCENDANT);
HeaderBlock titleBlock = new HeaderBlock(gadget.getTitle(), HeaderLevel.LEVEL1); titleBlock.setParameter(CLASS, "gadget-title");
/** * Return the content of a section. * * @param sectionNumber the index (+1) of the section in the list of all sections in the document. * @return the content of a section or null if the section can't be found. * @throws XWikiException error when trying to extract section content */ public String getContentOfSection(int sectionNumber) throws XWikiException { String content = null; if (is10Syntax()) { content = getContentOfSection10(sectionNumber); } else { List<HeaderBlock> headers = getFilteredHeaders(); if (headers.size() >= sectionNumber) { SectionBlock section = headers.get(sectionNumber - 1).getSection(); content = renderXDOM(new XDOM(Collections.<Block> singletonList(section)), getSyntax()); } } return content; }
HeaderBlock heading = blocks.get(0); if (heading.getLevel().getAsInt() <= displayConfiguration.getTitleHeadingDepth()) { XDOM headingXDOM = new XDOM(Collections.<Block> singletonList(heading)); try {
/** * Create a new toc list item based on section title. * * @param headerBlock the {@link HeaderBlock}. * @return the new list item block. */ private ListItemBlock createTocEntry(HeaderBlock headerBlock, String documentReference) { // Create the link to target the header anchor DocumentResourceReference reference = new DocumentResourceReference(documentReference); reference.setAnchor(headerBlock.getId()); LinkBlock linkBlock = new LinkBlock(this.tocBlockFilter.generateLabel(headerBlock), reference, false); return new ListItemBlock(Collections.singletonList(linkBlock)); }
/** * Get the content to display (either the entire document content or the content of a specific section). * * @param document the source document * @param parameters the display parameters * @return the content as an XDOM tree */ private XDOM getContent(DocumentModelBridge document, final DocumentDisplayerParameters parameters) { XDOM content = parameters.isContentTranslated() ? getTranslatedContent(document) : document.getXDOM(); if (parameters.getSectionId() != null) { HeaderBlock headerBlock = content.getFirstBlock(new CompositeBlockMatcher(new ClassBlockMatcher(HeaderBlock.class), new BlockMatcher() { @Override public boolean match(Block block) { return ((HeaderBlock) block).getId().equals(parameters.getSectionId()); } }), Block.Axes.DESCENDANT); if (headerBlock == null) { throw new RuntimeException("Cannot find section [" + parameters.getSectionId() + "] in document [" + this.defaultEntityReferenceSerializer.serialize(document.getDocumentReference()) + "]"); } else { content = new XDOM(headerBlock.getSection().getChildren(), content.getMetaData()); } } return content; }
/** * {@inheritDoc} * * @see org.xwiki.rendering.block.FatherBlock#after(org.xwiki.rendering.listener.Listener) */ public void after(Listener listener) { listener.endHeader(getLevel(), getId(), getParameters()); } }
public String extractTitle() { String title = ""; try { if (is10Syntax()) { title = extractTitle10(); } else { List<HeaderBlock> blocks = getXDOM().getChildrenByType(HeaderBlock.class, true); if (blocks.size() > 0) { HeaderBlock header = blocks.get(0); if (header.getLevel().compareTo(HeaderLevel.LEVEL2) <= 0) { XDOM headerXDOM = new XDOM(Collections.<Block> singletonList(header)); // transform TransformationContext context = new TransformationContext(headerXDOM, getSyntax()); Utils.getComponent(TransformationManager.class).performTransformations(headerXDOM, context); // render Block headerBlock = headerXDOM.getChildren().get(0); if (headerBlock instanceof HeaderBlock) { title = renderXDOM(new XDOM(headerBlock.getChildren()), Syntax.XHTML_1_0); } } } } } catch (Exception e) { // Don't stop when there's a problem rendering the title. } return title; }
public void endHeader(int level, WikiParameters params) { List<Block> children = generateListFromStack(); HeaderLevel headerLevel = HeaderLevel.parseInt(level); Map<String, String> parameters = convertParameters(params); WikiPrinter printer = new DefaultWikiPrinter(); this.plainTextBlockRenderer.render(children, printer); String id = this.idGenerator.generateUniqueId("H", printer.toString()); this.stack.push(new HeaderBlock(children, headerLevel, parameters, id)); }
if (header.getLevel().getAsInt() <= titleHeaderDepth) { XDOM headerXDOM = new XDOM(Collections.<Block> singletonList(header));
Block currentBlock = null; for (HeaderBlock headerBlock : headers) { int headerLevel = headerBlock.getLevel().getAsInt();
HeaderBlock header = rootSection.getHeaderBlock(); if (header != null) { parameters.start = header.getLevel().getAsInt() + 1;