Check if Class exists

Hi,

is there velocity code to check if a custom class exists in the Wiki?

Regards
Jurjen

Usually we don’t check for the xclass but for xobjects.

If you really need to check for the xclass (what is your use case, I’m curious?) you could run a query with https://extensions.xwiki.org/xwiki/bin/view/Extension/Query%20Module

See https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/DatabaseSchema/ for what to query.

Don’t ask me for the query, I don’t know it :wink:

Hi Vincent,

We run a multi-tennant Wiki. Each wiki has a set of custom extensions. I do not want to have duplicate a page in each extension, but rather check if a class in one of the custom extensions exists. If so I display information.

We are solving it with a function in an API coupled to the UI part of the custom extension.

Regards
Jurjen

The usual solution is to have an extension containing the common pages or Java classes and then have extensions needing them depends on them, as dependencies. In this manner you’re guaranteed to have what’s needed without the need to perform any check.

Hi Vincent,

I understand.

Basically I am just lazy and I want to put a dashboard in a extension that is included in all extensions as a depency. But depending on the installed decencies some of the dashboard functionality is not shown.

Otherwise I have to tailor the dashboard in every extension.