public MacroDefinition migrate(MacroDefinition macro, ConversionContext context) { macro.setName("code"); return macro; } }
private String convertWikimarkupToViewFormat(String value, ConversionContext conversionContext, List<RuntimeException> errors) throws XhtmlException, XMLStreamException { return xhtmlUtils.convertStorageToView(xhtmlUtils.convertWikiToStorage(value, conversionContext, errors), conversionContext); } }
public MacroDefinition migrate(MacroDefinition macroDefinition, ConversionContext conversionContext) { Map<String, String> macroParameters = macroDefinition.getParameters(); if (macroParameters.containsKey("reverseSort")) { Map<String, String> modifiedMacroParameters = new HashMap<>(macroDefinition.getParameters()); modifiedMacroParameters.remove("reverseSort"); modifiedMacroParameters.put("reverse", "true"); final MacroDefinitionBuilder builder = MacroDefinition.builder(macroDefinition.getName()) .withMacroBody(macroDefinition.getBody()) .withParameters(modifiedMacroParameters); builder.setDefaultParameterValue(macroDefinition.getDefaultParameterValue()); return builder.build(); } return macroDefinition; } }
public void handle(MacroDefinition macroDefinition) { if (StringUtils.equals("bookmark", macroDefinition.getName())) { parameters.putAll( macroDefinition.getParameters() ); parameters.put("description", macroDefinition.getBodyText()); // TODO: Decide if we really need descriptionExcerpt // parameters.put("descriptionExcerpt", macroDefinition.get); } } }
public MacroDefinition migrate(MacroDefinition macroDefinition, ConversionContext conversionContext) { final String bodyText = macroDefinition.getBodyText(); if (StringUtils.isNotBlank(bodyText)) { macroDefinition.setParameters( new HashMap<String, String>(macroDefinition.getParameters()) { { put("url", StringUtils.strip(bodyText)); } } ); } return macroDefinition; } }
public MacroDefinition migrate(MacroDefinition macroDefinition, ConversionContext context) { macroDefinition = richTextMacroMigration.migrate(macroDefinition, context); Map<String,String> params = macroDefinition.getParameters(); String paramValue = params.get(AbstractTOCMacro.INCLUDE_PARAM); if (StringUtils.isNotBlank(paramValue)) params.put(AbstractTOCMacro.INCLUDE_PARAM, convertRegex(paramValue)); paramValue = params.get(AbstractTOCMacro.EXCLUDE_PARAM); if (StringUtils.isNotBlank(paramValue)) params.put(AbstractTOCMacro.EXCLUDE_PARAM, convertRegex(paramValue)); macroDefinition.setParameters(params); return macroDefinition; }
@Override public MacroDefinition migrate(MacroDefinition macro, ConversionContext context) { String oldValue = macro.getParameter("excerpt"); if (StringUtils.isNotBlank(oldValue)) { ExcerptType excerptParam = ExcerptType.fromOldValue(oldValue); macro.setParameter("excerptType", excerptParam.getValue()); macro.setTypedParameter("excerptType", excerptParam); } macro.setSchemaVersion(macro.getSchemaVersion() + 1); return macro; }
/** * This macro operates on the body of the content entity (e.g. the page) on which the macro is a part of. This * method fetches the content body (which should be in XHTML storage-format), renders that to view-format, then * returns that to be used as the basis of the TOC generation. */ @Override protected String getContent(final Map<String, String> parameters, final String body, final ConversionContext conversionContext) { final ContentEntityObject contentEntity = conversionContext.getEntity(); if (contentEntity == null) { log.warn("There was an error converting the preview content to view - content entity object was null."); return ""; } try { return xhtmlContent.convertStorageToView(contentEntity.getBodyAsString(), conversionContext); } catch (Exception ex) { log.warn("There was an error converting the content for id " + contentEntity.getId() + " to storage format.", ex); return ""; } }
/** * @param macroDefinition macro definition * @return task list name or empty string if no name specified */ public static String getTaskListName(MacroDefinition macroDefinition) { String result = macroDefinition.getParameters().get("title"); if (result == null) result = macroDefinition.getDefaultParameterValue(); return defaultString(result); }
public MacroDefinition migrate(MacroDefinition macro, ConversionContext context) { // convert default url parameters into explicit url parameters to avoid // confusion when there is JQL query with an '=' character (see https://jira.atlassian.com/browse/CONFDEV-5886) Map<String, String> parameters = macro.getParameters(); if (parameters != null) { Set<String> keySet = parameters.keySet(); for (String key : keySet) { if (key.startsWith("http://") || key.startsWith("https://")) { String val = parameters.remove(key); String url = key + '=' + val; parameters.put("url", url); break; } } } return macro; }
@Override public MacroDefinition migrate(MacroDefinition macro, ConversionContext context) { String cql = getCql(macro, context); macro.setParameter("cql", cql); macro.setTypedParameter("cql", cql); log.debug("CQL parameter set to '{}'", cql); macro.setSchemaVersion(2); return macro; }
/** * From the old {@link com.atlassian.renderer.v2.macro.Macro} interface. * Converts the old wiki markup body into storage format XHTML, then delegates to the newer interface. */ @Override public String execute(Map macroParameters, String bodyWikiMarkup, RenderContext renderContext) { // TODO SHouldn't we do something with this list? final List<RuntimeException> wikiMarkupToStorageConversionErrors = newArrayList(); final ConversionContext conversionContext = new DefaultConversionContext(renderContext); final String storageFormatBody = xhtmlContent.convertWikiToStorage( bodyWikiMarkup, conversionContext, wikiMarkupToStorageConversionErrors ); return execute(macroParameters, storageFormatBody, conversionContext); }
private boolean linkingToSelf(final Link link, final ConversionContext conversionContext) { if (conversionContext == null) { return true; } if (isGlobalObject(conversionContext)) { return false; } final ResourceIdentifier resourceIdentifier = link.getDestinationResourceIdentifier(); // If linking to same page then the confluence macro linking mechanism does not // include a resourceIdentifier in the macroDefinition. There could still be a link // input via the storage format though, which is why we still do the checks. if (resourceIdentifier == null) { if (conversionContext.getProperty(MACRO_DEFINITION) != null) { String linkedPageName = ((MacroDefinition) conversionContext.getProperty(MACRO_DEFINITION)) .getDefaultParameterValue(); return isSamePageTitle(conversionContext, linkedPageName); } return true; } // Note that we check content type before we check if it's the same space // because the same space check relies on a page/blog post content type. return isSameContentType(conversionContext, resourceIdentifier) && isSamePageTitle(conversionContext, resourceIdentifier) && isSameSpace(conversionContext, resourceIdentifier) && isSamePostingDateForBlog(conversionContext, resourceIdentifier); }
public static String getParameter(String paramKey, MacroDefinition macro) { String value = macro.getParameter(paramKey); return value != null ? value.trim() : null; } }
private static Optional<Link> getLinkOptionalFromMacro(ConversionContext conversionContext) { return Optional.ofNullable(((MacroDefinition) conversionContext.getProperty(MACRO_DEFINITION)) .getTypedParameter("", Link.class)); } }
public MacroDefinition update(MacroDefinition macroDefinition) { taskListMacroDefinitionHandler.handle(macroDefinition); if (!taskListUpdated && taskListMacroDefinitionHandler.getMatchingTaskList() != null) { MacroBody macroBody = new PlainTextMacroBody(taskListSerializer.serialize(updatedTaskList)); MacroDefinitionBuilder updatedMacroDefinition = MacroDefinition.builder(macroDefinition.getName()) .withMacroBody(macroBody) .withParameters(macroDefinition.getParameters()); updatedMacroDefinition.setDefaultParameterValue(macroDefinition.getDefaultParameterValue()); taskListUpdated = true; return updatedMacroDefinition.build(); } return macroDefinition; } }
@Override public MacroDefinition migrate(MacroDefinition macroDefinition, ConversionContext context) { macroDefinition = richTextMacroMigration.migrate(macroDefinition, context); Map<String,String> params = macroDefinition.getParameters(); String paramValue = params.get(AbstractTOCMacro.INCLUDE_PARAM); if (StringUtils.isNotBlank(paramValue)) params.put(AbstractTOCMacro.INCLUDE_PARAM, convertRegex(paramValue)); paramValue = params.get(AbstractTOCMacro.EXCLUDE_PARAM); if (StringUtils.isNotBlank(paramValue)) params.put(AbstractTOCMacro.EXCLUDE_PARAM, convertRegex(paramValue)); macroDefinition.setParameters(params); return macroDefinition; }
@Override public MacroDefinition migrate(MacroDefinition macro, ConversionContext context) { // Shouldn't need to check existing cql if schema version is being checked - just being a bit defensive while // Confluence core catches up. if (Strings.isNullOrEmpty(macro.getParameter("cql"))) { String cql = getCql(macro); macro.setParameter("cql", cql); macro.setTypedParameter("cql", cql); log.debug("CQL parameter set to '{}'", cql); } macro.setSchemaVersion(2); return macro; }
@Override public String getViewFormat(String authToken, String pageId) throws XMLStreamException, XhtmlException { ContentEntityObject contentEntityObject = getContentEntityObject(pageId); return null == contentEntityObject ? null : xhtmlContent.convertStorageToView(contentEntityObject.getBodyAsString(), new DefaultConversionContext(contentEntityObject.toPageContext())); }
private String renderRichText( Renderable renderable ) throws RenderException { try { return XhtmlUtils.stripParagraphWrapper( xhtmlContent.convertStorageToView( renderable.getText(), renderable.getConversionContext()) ); } catch ( XMLStreamException e ) { throw new RenderException( e.getMessage(), e ); } catch ( XhtmlException e ) { throw new RenderException( e.getMessage(), e ); } } }