Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
imranjoget committed May 8, 2023
1 parent ef08422 commit 1bac177
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
*.class
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Description

This repository is meant to serve as a general template for how to set up new repositories in the JogetOSS organization.
Hash variable type plugin which allows to format numbers.

## Available Formats
* #formatNumber.34567# -> returns 34567
* #formatNumber.{form.number_format.amount} -> return the value of form.number_format.amount field
* #formatNumber.12345[decimal=2]# -> returns 12345.00
* #formatNumber.12345[decimal=2&thousandSeparator=,]# -> returns 12,345.00
* #formatNumber.{form.number_format.amount}[decimal=2]# -> returns the values with 2 decimal places
* #formatNumber.{form.number_format.amount}[decimal=2&thousandSeparator=,]# -> returns the values with 2 decimal places with thousand separator

# Getting Help

Expand Down
95 changes: 95 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.joget.marketplace</groupId>
<artifactId>formatnumber-hash</artifactId>
<packaging>bundle</packaging>
<version>8.0.0</version>
<name>formatnumber-hash</name>
<url>http://www.joget.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<skipTests>false</skipTests>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skipTests>false</skipTests>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<!-- Change package and plugin class here -->
<Export-Package>org.joget.marketplace</Export-Package>
<Private-Package>org.joget.marketplace.*</Private-Package>
<Bundle-Activator>org.joget.marketplace.Activator</Bundle-Activator>
<Import-Package>!*,org.joget.report.dao,org.joget.report.model,org.joget.report.service,org.joget.commons.util,org.joget.plugin.base,org.joget.plugin.property.model,org.joget.plugin.property.service,org.joget.directory.model,org.joget.directory.model.service,org.joget.directory.dao,org.joget.workflow.model,org.joget.workflow.model.dao,org.joget.workflow.model.service,org.joget.workflow.util,org.joget.apps.app.dao,org.joget.apps.app.lib,org.joget.apps.app.model,org.joget.apps.app.service,org.joget.apps.datalist.lib,org.joget.apps.datalist.model,org.joget.apps.datalist.service,org.joget.apps.form.lib,org.joget.apps.form.dao,org.joget.apps.form.model,org.joget.apps.form.service,org.joget.apps.list.service,org.joget.apps.userview.lib,org.joget.apps.userview.model,org.joget.apps.userview.service,org.joget.apps.workflow.lib,javax.servlet,javax.servlet.http,org.osgi.framework;version="1.3.0"</Import-Package>
<!-- End change package and plugin class here -->
<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Directory>dependency</Embed-Directory>
<Embed-StripGroup>true</Embed-StripGroup>
<DynamicImport-Package>*</DynamicImport-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.joget</groupId>
<artifactId>wflow-core</artifactId>
<version>8.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<!-- Change plugin specific dependencies here -->

<!-- End change plugin specific dependencies here -->
</dependencies>
<distributionManagement>
<repository>
<id>internal</id>
<url>https://dev.joget.org/archiva/repository/internal</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>https://dev.joget.org/archiva/repository/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
25 changes: 25 additions & 0 deletions src/main/java/org/joget/marketplace/Activator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.joget.marketplace;

import java.util.ArrayList;
import java.util.Collection;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

public class Activator implements BundleActivator {

protected Collection<ServiceRegistration> registrationList;

public void start(BundleContext context) {
registrationList = new ArrayList<ServiceRegistration>();

//Register plugin here
registrationList.add(context.registerService(FormatNumberHashVariable.class.getName(), new FormatNumberHashVariable(), null));
}

public void stop(BundleContext context) {
for (ServiceRegistration registration : registrationList) {
registration.unregister();
}
}
}
83 changes: 83 additions & 0 deletions src/main/java/org/joget/marketplace/FormatNumberHashVariable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.joget.marketplace;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import org.joget.apps.app.model.DefaultHashVariablePlugin;

public class FormatNumberHashVariable extends DefaultHashVariablePlugin {

@Override
public String processHashVariable(String variableKey) {
String formattedNumber = "";
DecimalFormat decimalFormat = new DecimalFormat();
DecimalFormatSymbols customSymbols = new DecimalFormatSymbols();
if (variableKey.indexOf("[") == -1) {
return variableKey;
} else {
String numberString = variableKey.substring(0, !variableKey.contains("[") ? variableKey.length() - 1 : variableKey.indexOf("["));
String options = variableKey.substring(variableKey.indexOf("["));
int decimalPlaces = 0;
options = options.replaceAll("\\[|\\]", "");
String[] pieces = options.split("&");
for (String opt : pieces) {
if (opt.contains("decimal=")) {
try {
decimalPlaces = Integer.parseInt(opt.substring(opt.indexOf("=") + 1));
decimalFormat.setMaximumFractionDigits(decimalPlaces);
decimalFormat.setMinimumFractionDigits(decimalPlaces);
customSymbols.setGroupingSeparator('\0');
decimalFormat.setDecimalFormatSymbols(customSymbols);
} catch (NumberFormatException e) {

}

} else if (opt.contains("thousandSeparator=")) {
String separator = opt.substring(opt.indexOf("=") + 1);
if (separator != null && !separator.isEmpty()) {
customSymbols.setGroupingSeparator(separator.charAt(0));
decimalFormat.setDecimalFormatSymbols(customSymbols);
}
}
}
formattedNumber = numberString;
formattedNumber = decimalFormat.format(Double.parseDouble(formattedNumber));
}
return formattedNumber;
}

@Override
public String getPrefix() {
return "formatNumber";
}

@Override
public String getName() {
return "Format Number Hash Variable";
}

@Override
public String getVersion() {
return "8.0.0";
}

@Override
public String getDescription() {
return "Format Number Hash Variable";
}

@Override
public String getLabel() {
return "Format Number Hash Variable";
}

@Override
public String getClassName() {
return this.getClass().getName();
}

@Override
public String getPropertyOptions() {
return "";
}

}

0 comments on commit 1bac177

Please sign in to comment.