/** * {@inheritDoc} * * @see AbstractURIResourceReferenceTypeParser#parse(String) */ @Override public ResourceReference parse(String reference) { // Note that we construct a DocumentResourceReference object so that the user who calls // {@link ResourceReferenceParser#parse} can cast it to a DocumentResourceReference object if the type is of // type Document. return new DocumentResourceReference(reference); } }
/** * @return the anchor name pointing to an anchor defined in the referenced document or null if no anchor has been * specified (in which case the reference points to the top of the document). Note that in XWiki anchors are * automatically created for titles. Example: "TableOfContentAnchor" */ public String getAnchor() { return getParameter(ANCHOR); }
/** * @param queryString see {@link #getQueryString()} */ public void setQueryString(String queryString) { if (!StringUtils.isEmpty(queryString)) { setParameter(QUERY_STRING, queryString); } }
/** * 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)); }
/** * Construct a Document Link reference out of the passed content. * * @param content the string containing the Document link reference * @return the parsed Link Object corresponding to the Document link reference */ private ResourceReference parseDocumentLink(StringBuffer content) { String queryString = null; String text = parseElementAfterString(content, SEPARATOR_QUERYSTRING); if (text != null) { queryString = removeEscapesFromExtraParts(text); } String anchor = null; text = parseElementAfterString(content, SEPARATOR_ANCHOR); if (text != null) { anchor = removeEscapesFromExtraParts(text); } DocumentResourceReference reference = new DocumentResourceReference(removeEscapesFromReferencePart(content.toString())); reference.setTyped(false); reference.setQueryString(queryString); reference.setAnchor(anchor); return reference; }
/** * Generate the footnote reference (link) that should be inserted at the location of the macro, and should point to * the actual footnote at the end of the document. * * @param counter the current footnote counter * @return the generated reference element, displayed as {@code (superscript(link(footnote index)))} */ private Block createFootnoteReferenceBlock(int counter) { Block result = new WordBlock(String.valueOf(counter)); DocumentResourceReference reference = new DocumentResourceReference(null); reference.setAnchor(FOOTNOTE_ID_PREFIX + counter); result = new LinkBlock(Collections.singletonList(result), reference, false); result = new FormatBlock(Collections.singletonList(result), Format.SUPERSCRIPT); result.setParameter(ID_ATTRIBUTE_NAME, FOOTNOTE_REFERENCE_ID_PREFIX + counter); result.setParameter(CLASS_ATTRIBUTE_NAME, "footnoteRef"); return result; }
DocumentResourceReference reference = new DocumentResourceReference(null); reference.setAnchor(FOOTNOTE_REFERENCE_ID_PREFIX + counter); result = new LinkBlock(Collections.singletonList(result), reference, false); result.setParameter(ID_ATTRIBUTE_NAME, FOOTNOTE_ID_PREFIX + counter);
@Override public void transform(Block block, TransformationContext transformationContext) throws TransformationException { // Find all Word blocks and for each of them check if they're a wiki word or not for (WordBlock wordBlock : this.filter.getChildrenByType(block, WordBlock.class, true)) { Matcher matcher = WIKIWORD_PATTERN.matcher(wordBlock.getWord()); if (matcher.matches()) { ResourceReference linkReference = new DocumentResourceReference(wordBlock.getWord()); wordBlock.getParent().replaceChild(new LinkBlock(wordBlock.getChildren(), linkReference, false), wordBlock); } } } }
/** * @param anchor see {@link #getAnchor()} */ public void setAnchor(String anchor) { if (!StringUtils.isEmpty(anchor)) { setParameter(ANCHOR, anchor); } } }
/** * @return the query string for specifying parameters that will be used in the rendered URL or null if no query * string has been specified. Example: "mydata1=5&mydata2=Hello" */ public String getQueryString() { return getParameter(QUERY_STRING); }
DocumentResourceReference reference = new DocumentResourceReference(target);
/** * {@inheritDoc} * @see AbstractTransformation#transform(Block, TransformationContext) */ public void transform(Block block, TransformationContext transformationContext) throws TransformationException { // Find all Word blocks and for each of them check if they're a wiki word or not for (WordBlock wordBlock : this.filter.getChildrenByType(block, WordBlock.class, true)) { Matcher matcher = WIKIWORD_PATTERN.matcher(wordBlock.getWord()); if (matcher.matches()) { ResourceReference linkReference = new DocumentResourceReference(wordBlock.getWord()); wordBlock.getParent().replaceChild(new LinkBlock(wordBlock.getChildren(), linkReference, false), wordBlock); } } } }
@Override public List<Block> execute(TocMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { Block rootBlock = null; WikiModel wikiModel = this.wikiModelProvider.get(); if (parameters.getReference() != null) { if (wikiModel != null) { // Remote TOC always has a PAGE scope since a LOCAL scope would have no meaning parameters.setScope(TocMacroParameters.Scope.PAGE); // Get the referenced source's XDOM rootBlock = getXDOM(new DocumentResourceReference(parameters.getReference()), wikiModel); } else { throw new MacroExecutionException( "The \"reference\" parameter can only be used when a WikiModel implementation is available"); } } TreeParametersBuilder builder = new TreeParametersBuilder(); TreeParameters treeParameters = builder.build(rootBlock, parameters, context); return this.tocTreeBuilder.build(treeParameters); }