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

XWIKI-18604: Expose the Icon Theme through the REST API #1620

Merged
merged 3 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions xwiki-platform-core/xwiki-platform-icon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@
<module>xwiki-platform-icon-default</module>
<module>xwiki-platform-icon-script</module>
<module>xwiki-platform-icon-ui</module>
<module>xwiki-platform-icon-rest</module>
<!-- Icon Themes -->
<module>xwiki-platform-icon-fontawesome</module>
</modules>
<profiles>
<profile>
<id>integration-tests</id>
<modules>
<module>xwiki-platform-icon-test</module>
</modules>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;

import org.xwiki.component.annotation.Role;
import org.xwiki.stability.Unstable;

/**
* Component to render an icon, depending on the current icon theme set on the preferences.
Expand Down Expand Up @@ -195,4 +196,33 @@ default Map<String, Object> getMetaData(String iconName, String iconSetName, boo
* @since 6.4M1
*/
List<String> getIconNames(String iconSetName) throws IconException;

/**
* Checks if the provided icon name exists in the current icon set.
*
* @param iconName an icon name (for instance, {@code add})
* @return {@code true} if the icon name exists in the current icon set, {@code false} otherwise
* @throws IconException in case of error when accessing the current icon set
* @since 13.4RC1
*/
@Unstable
default boolean hasIcon(String iconName) throws IconException
{
return getIconNames().contains(iconName);
}

/**
* Checks if the provided icon name exists in the a given icon set.
*
* @param iconSetName an icon set name (for instance, {@code Silk})
* @param iconName an icon name (for instance, {@code add})
* @return {@code true} if the icon name exists in the current icon set, {@code false} otherwise
* @throws IconException in case of error when accessing the current icon set
* @since 13.4RC1
*/
@Unstable
default boolean hasIcon(String iconSetName, String iconName) throws IconException
{
return getIconNames(iconSetName).contains(iconName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.List;
import java.util.Map;

import org.xwiki.stability.Unstable;

/**
* A collection of icons, with some properties to display them.
*
Expand Down Expand Up @@ -256,4 +258,17 @@ public List<String> getIconNames()
{
return new ArrayList<>(iconMap.keySet());
}

/**
* Checks if the provided icon name exists in the icon set.
*
* @param iconName an icon name (for instance, @{code add})
* @return {@code true} if the icon name exists in the icon set, {@code false} otherwise
* @since 13.4RC1
*/
@Unstable
public boolean hasIcon(String iconName)
manuelleduc marked this conversation as resolved.
Show resolved Hide resolved
{
return this.iconMap.containsKey(iconName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ public List<String> getIconNames(String iconSetName) throws IconException
return iconSetManager.getIconSet(iconSetName).getIconNames();
}

@Override
public boolean hasIcon(String iconName) throws IconException
{
return this.iconSetManager.getCurrentIconSet().hasIcon(iconName);
}

@Override
public boolean hasIcon(String iconSetName, String iconName) throws IconException
{
return this.iconSetManager.getIconSet(iconSetName).hasIcon(iconName);
}

/**
* @param iconName name of the icon
* @return the current icon set if the icon name is inside, otherwise the default icon set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.xwiki.test.junit5.mockito.MockComponent;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -244,4 +245,24 @@ public void getMetaDataWithoutFallback() throws Exception
// Verify
assertTrue(metadata.isEmpty());
}

@Test
void hasIcon() throws Exception
{
IconSet testIconSet = new IconSet("testIconSet");
testIconSet.addIcon("iconA", null);
when(this.iconSetManager.getCurrentIconSet()).thenReturn(testIconSet);
assertTrue(this.iconManager.hasIcon("iconA"));
assertFalse(this.iconManager.hasIcon("iconB"));
}

@Test
void hasIconWithIconSet() throws Exception
{
IconSet testIconSet = new IconSet("testIconSet");
testIconSet.addIcon("iconA", null);
when(this.iconSetManager.getIconSet("testIconSet")).thenReturn(testIconSet);
assertTrue(this.iconManager.hasIcon("testIconSet", "iconA"));
assertFalse(this.iconManager.hasIcon("testIconSet", "iconB"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
* 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-icon</artifactId>
<version>13.4-SNAPSHOT</version>
</parent>
<artifactId>xwiki-platform-icon-rest</artifactId>
<name>XWiki Platform - Icon - REST - Parent POM</name>
<packaging>pom</packaging>
<description>Services to access XWiki Icons through a RESTful API.</description>
<properties>
<!-- Name to display by the Extension Manager -->
<xwiki.extension.name>Icon REST Services</xwiki.extension.name>
</properties>
<modules>
<module>xwiki-platform-icon-rest-api</module>
<module>xwiki-platform-icon-rest-default</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
* 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-icon-rest</artifactId>
<version>13.4-SNAPSHOT</version>
</parent>
<artifactId>xwiki-platform-icon-rest-api</artifactId>
<name>XWiki Platform - Icon - REST - API</name>
<packaging>jar</packaging>
<description>The API of the Icon REST services.</description>
<properties>
<xwiki.extension.name>Icon REST Services API</xwiki.extension.name>
</properties>
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</dependency>
<dependency>
<groupId>org.xwiki.commons</groupId>
<artifactId>xwiki-commons-stability</artifactId>
<version>${commons.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<generatePackage>org.xwiki.icon.rest.model.jaxb</generatePackage>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- Apply the Checkstyle configurations defined in the top level pom.xml file -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<!-- Specify the "default" execution id so that the "blocker" one is always executed -->
<id>default</id>
<configuration>
<excludes>org/xwiki/icon/rest/model/jaxb/*.java</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 org.xwiki.icon.rest;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;

import org.xwiki.icon.rest.model.jaxb.Icons;
import org.xwiki.stability.Unstable;

/**
* Exposes the wiki icon themes and their icons through REST.
*
* @version $Id$
* @since 13.4RC1
*/
@Path("/wikis/{wikiName}/iconThemes")
@Unstable
public interface IconThemesResource
{
/**
* Returns the icons metadata of the requested icons list, for a given icon theme.
*
* @param wikiName the name of the wiki holding the icons
* @param iconTheme the name of the icon theme holding the icons
* @param names a list of icon names to return
* @return the list of resolved icons metadata
*/
@GET
@Path("/{iconTheme}/icons")
Icons getIconsByTheme(@PathParam("wikiName") String wikiName, @PathParam("iconTheme") String iconTheme,
@QueryParam("name") List<String> names);

/**
* Returns the icons metadata of the requested icons list, for the default icon theme.
*
* @param wikiName the name of the wiki holding the icons
* @param names a list of icon names to return
* @return the list of resolved icons metadata
*/
@GET
@Path("/icons")
Icons getIcons(@PathParam("wikiName") String wikiName, @QueryParam("name") List<String> names);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*
* 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.
*
-->

<!--
This enables the simple binding mode in JAXB.
See https://javaee.github.io/jaxb-v2/doc/user-guide/ch05.html#simple
-->
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc">
<jaxb:globalBindings>
<xjc:simple/>
</jaxb:globalBindings>
</jaxb:bindings>