Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

add custom classes to confluence

mehran haghani
Contributor
July 15, 2013
Hi , how can i add my own java classes to confluence and how can i use their methods thanks

2 answers

0 votes
mehran haghani
Contributor
July 15, 2013

i want to write some classes to format the dates ( something like dateformatter.class) and use their methods inteadof dateformatter methods in vm files

can i modify this built-in class instead of writing new one?

thanks a lot

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 15, 2013

That's a very vague question - you might get a more useful answer if you tell us what you actually need to do, rather than start with the "how".

As a generalised answer though, I'd say "write an add on" - start at https://developer.atlassian.com/display/CONFDEV/Writing+Confluence+Plugins where you'll find you can write whatever you want, as classes, include your own libraries and make direct use of the internals of Confluence.

mehran haghani
Contributor
July 15, 2013

i want to write some classes to format the dates ( something like dateformatter.class) and use their methods inteadof dateformatter methods in vm files

can i modify this built-in class instead of writing new one?

thanks a lot

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 15, 2013

Ok, that's replacing stuff, rather than adding, which is a little more complex. I don't believe plugins can simply replace classes in the core of Confluence, and I don't believe they can subvert and override existing classes either. Via a plugin, they can extend and reuse, but that doesn't mean you can modify existing stuff.

I've got four basic approaches, using the dateformatter example you've given:

  1. Write a plugin that adds your new classes, so that they're available to Confluence generally. Then, go into the .vm files in Confluence, identify where the date formatter is used and change the .vm so that they use your class instead.
  2. Write your classes with the same name as the existing ones in Confluence and then strip them from your Confluence install and push yours in.
  3. Download the source of Confluence, modify the code directly and re-compile it
  4. Question the requirement - what is actually wrong with the date formatting? It might be that the classes support your need and you only actually need to tweak some settings (UI, environment, parameter, etc)
mehran haghani
Contributor
July 15, 2013

i try (2) but when i replace my class , confluence failed to start up


i want to convert Gregorian date to solar date

wich approach is better for this purpose?

if i try (1) how can i call my methods?

thanks

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 15, 2013

For (2), you need to read the log file for the errors. As you are replacing classes, you need to make sure that your new classes implement the same functions as the existing classes, at the very least for all of the calls Confluence makes. With date functions that could get quite messy because there's quite a lot there, and you'll have to replace all the input and output. I'd generally only recommend this approach for small, minor changes that don't actually change much (the only time I've personally used it was to enable the use of fractions in Jira's time-tracking field, which was minor because it was simply more clever parsing of input)

For (1), I already said - you would need to modify the .vm files that format dates so that they use your classes instead of the built-in ones.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events