Sample ARS Plug-in
1. Code Sample – ARSMatchingSample.java
package yourpackage; import java.util.*; import java.util.regex.*; import com.brekeke.pbx.common.*; public class ARSMatchingSample { private static long lastmodified = 0; private static ArrayList patternlist = null; public static synchronized String regex( String param ) throws Exception { long l = NoteUtils.lastModified( "Regex" ); if( l == 0 ){ return null; } if( lastmodified != l ){ lastmodified = l; String s = NoteUtils.read( "Regex" ); if( s == null ){ return null; } ArrayList al = new ArrayList(); StringTokenizer st = new StringTokenizer( s ); while( st.hasMoreTokens() ){ String token = st.nextToken(); Pattern pt = Pattern.compile( token ); al.add( pt ); } patternlist = al; } for( int i = 0; i < patternlist.size(); i++ ){ Pattern pt = (Pattern) patternlist.get(i); Matcher mt = pt.matcher( param ); if( mt.matches() ){ return mt.group(1); } } return null; } }
This sample program refers to a note called “Regex” and matches using regular expressions. The program processes matching data strings in all rows in order starting from the top row. When the program finds a matched row, it returns the matched character strings inside parenthesis ( ). When the program can not locate a matched row, it returns null. (When null is returned, the patterns are considered mismatched.) The content of the note is cached in the variables. When a note is renewed, the program will re-read the content.
2. Example of ARS Setup
Set the following fields in ARS route’s Patterns > [Matching patterns]. Choose appropriate patterns (IN or OUT) depending on the environment.
[Matching Patterns]
From | |
To | sip:(.+)@ |
User | |
Plugin | yourpackage.ARSMatchingSample regex |
Param | &t1 |
Return | (.+) |
[Deploy Patterns]
From | |
To | sip:&p1@domain.com |
DTMF | |
Target |
In the above example, user SIP ID in To header is set as a parameter “&t1“. The return value “&p1” is drawn out and set in [Deploy Patterns] To header.
3. Example of Notes Setup
Select the menu [Notes]. Brekeke PBX plug-ins can use the text in the notes.
Name | Description |
Name | Name of the note. |
Description | A brief description of the note |
User access level | Access level Select from “No Access”, “Read only”, “Read/Write” |
Note | Text field where you can write your own notes. |
Contents of the note “Regex“:
^1650(.+)$ ^1888(.+)$ ^1800(.+)$
When the number is starting with “1650”, “1888”, or “1800”, the rest of the number in the parentheses will be drawn out as return value.
Related Links: