-
-
Save stephanbruijnis/5c289db9697170cf6875c00347a24bfa to your computer and use it in GitHub Desktop.
Replace {tokens} by their attribute value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file was generated by Mendix Studio Pro. | |
// | |
// WARNING: Only the following code will be retained when actions are regenerated: | |
// - the import list | |
// - the code between BEGIN USER CODE and END USER CODE | |
// - the code between BEGIN EXTRA CODE and END EXTRA CODE | |
// Other code you write will be lost the next time you deploy the project. | |
// Special characters, e.g., é, ö, à, etc. are supported in comments. | |
package myfirstmodule.actions; | |
import com.mendix.systemwideinterfaces.core.IContext; | |
import com.mendix.webui.CustomJavaAction; | |
import com.mendix.systemwideinterfaces.core.IMendixObject; | |
import java.util.regex.*; | |
public class JA_ReplaceObjectTokens extends CustomJavaAction<java.lang.String> | |
{ | |
private IMendixObject MxObject; | |
private java.lang.String StringToReplace; | |
public JA_ReplaceObjectTokens(IContext context, IMendixObject MxObject, java.lang.String StringToReplace) | |
{ | |
super(context); | |
this.MxObject = MxObject; | |
this.StringToReplace = StringToReplace; | |
} | |
@java.lang.Override | |
public java.lang.String executeAction() throws Exception | |
{ | |
// BEGIN USER CODE | |
Pattern pattern = Pattern.compile("\\{(.+?)\\}"); | |
Matcher matcher = pattern.matcher(StringToReplace); | |
StringBuffer buffer = new StringBuffer(); | |
while (matcher.find()) { | |
String replacement = MxObject.getValue(getContext(),matcher.group(1)); | |
if (replacement != null) { | |
matcher.appendReplacement(buffer, ""); | |
buffer.append(replacement); | |
} | |
} | |
matcher.appendTail(buffer); | |
return buffer.toString(); | |
// END USER CODE | |
} | |
/** | |
* Returns a string representation of this action | |
*/ | |
@java.lang.Override | |
public java.lang.String toString() | |
{ | |
return "JA_ReplaceObjectTokens"; | |
} | |
// BEGIN EXTRA CODE | |
// END EXTRA CODE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment