Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#195: Fix migration of show-if/hide-if macro #196

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package com.xwiki.confluencepro.converters.internal;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.xwiki.contrib.confluence.filter.internal.input.ConfluenceConverter;
import org.xwiki.contrib.confluence.filter.internal.macros.AbstractMacroConverter;

/**
* Converter used for hide-if and show-if macro.
*
* @version $Id$
* @since 1.23.2
*/
public abstract class AbstractShowIfHideIfMacroConverter extends AbstractMacroConverter
{
private static final String GROUP_ID_PARAM = "groupIds";

private static final String GROUP_ID_SEPARATOR = ",";

@Inject
private ConfluenceConverter converter;

@Override
protected String toXWikiParameterValue(String confluenceParameterName, String confluenceParameterValue,
String confluenceId, Map<String, String> parameters, String confluenceContent)
{
if (confluenceParameterName.equals(GROUP_ID_PARAM)) {
return Arrays.stream(confluenceParameterValue.split(GROUP_ID_SEPARATOR))
.map(i -> converter.convertGroupReference(i).orElse(i)).collect(Collectors.joining(GROUP_ID_SEPARATOR));
}
return super.toXWikiParameterValue(confluenceParameterName, confluenceParameterValue, confluenceId, parameters,
confluenceContent);
}

@Override
protected String toXWikiParameterName(String confluenceParameterName, String id,
Map<String, String> confluenceParameters, String confluenceContent)
{
if (confluenceParameterName.equals(GROUP_ID_PARAM)) {
return "groups";
}
if (confluenceParameterName.equals("specialUsername")) {
return "authenticationType";
}
return super.toXWikiParameterName(confluenceParameterName, id, confluenceParameters, confluenceContent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package com.xwiki.confluencepro.converters.internal;

import javax.inject.Named;
import javax.inject.Singleton;

import org.xwiki.component.annotation.Component;

/**
* Convert hide-if macro with correct parameters.
*
* @version $Id$
* @since 1.23.2
*/
@Component
@Singleton
@Named("hide-if")
public class HideIfMacroConverter extends AbstractShowIfHideIfMacroConverter
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package com.xwiki.confluencepro.converters.internal;

import javax.inject.Named;
import javax.inject.Singleton;

import org.xwiki.component.annotation.Component;

/**
* Convert show-if macro with correct parameters.
*
* @version $Id$
* @since 1.23.2
*/
@Component
@Singleton
@Named("show-if")
public class ShowIfMacroConverter extends AbstractShowIfHideIfMacroConverter
{
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
com.xwiki.confluencepro.converters.internal.DateMacroConverter
com.xwiki.confluencepro.converters.internal.HideIfMacroConverter
com.xwiki.confluencepro.converters.internal.LivesearchMacroConverter
com.xwiki.confluencepro.converters.internal.MSStreamConverter
com.xwiki.confluencepro.converters.internal.MultiExcerptMacroConverter
Expand All @@ -7,5 +8,6 @@ com.xwiki.confluencepro.converters.internal.PagetreesearchMacroConverter
com.xwiki.confluencepro.converters.internal.TaskMacroConverter
com.xwiki.confluencepro.converters.internal.TaskListMacroConverter
com.xwiki.confluencepro.converters.internal.ProfileMacroConverter
com.xwiki.confluencepro.converters.internal.ShowIfMacroConverter
com.xwiki.confluencepro.converters.internal.ViewFileConverter
com.xwiki.confluencepro.converters.internal.ListLabelsMacroConverter