|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.testfw.stf.scripteditor.utils; |
|
19 |
|
20 import java.util.ArrayList; |
|
21 import java.util.regex.Matcher; |
|
22 import java.util.regex.Pattern; |
|
23 |
|
24 public class CreativeArgument implements Arguments{ |
|
25 |
|
26 public String getArgumentBinding() { |
|
27 |
|
28 return "none"; |
|
29 } |
|
30 |
|
31 public CreativeArgument(String value, String name, String binding, String nvalue) { |
|
32 this.argumentType = value; |
|
33 this.argumentName = name; |
|
34 this.argumentBinding = binding; |
|
35 this.argumentNextvalue = nvalue; |
|
36 |
|
37 |
|
38 } |
|
39 |
|
40 public ArrayList<String> validate(ArrayList<String> tokenizedLine) { |
|
41 boolean lineCorrect = false; |
|
42 if (this.argumentBinding.equals("none")) { |
|
43 |
|
44 if (this.argumentType.equals("literal")) { |
|
45 |
|
46 String patternString = "^[0-9a-zA-Z\\\\/:=\\s]*$"; |
|
47 |
|
48 lineCorrect = validateArgment(patternString, tokenizedLine.get(0)); |
|
49 |
|
50 } |
|
51 } |
|
52 if (lineCorrect) { |
|
53 createObject(tokenizedLine.get(0)); |
|
54 tokenizedLine.remove(0); |
|
55 |
|
56 } |
|
57 return tokenizedLine; |
|
58 } |
|
59 |
|
60 public String getArgumentName() { |
|
61 return argumentName; |
|
62 } |
|
63 |
|
64 public String getNextValue() { |
|
65 return argumentNextvalue; |
|
66 } |
|
67 |
|
68 private void createObject(String string) { |
|
69 Parser.createdObjectsList.add(string); |
|
70 } |
|
71 |
|
72 private boolean validateArgment(String patternString, |
|
73 String token) { |
|
74 Pattern titlePattern = Pattern |
|
75 .compile(patternString, Pattern.MULTILINE); |
|
76 Matcher regExMatcher = titlePattern.matcher(token); |
|
77 if (regExMatcher.find()) { |
|
78 return true; |
|
79 |
|
80 } |
|
81 return false; |
|
82 } |
|
83 //define argument type (ex. digit, text or name) |
|
84 private String argumentType; |
|
85 |
|
86 //uniqe argument name, it is value of XML argument tag |
|
87 private String argumentName; |
|
88 |
|
89 //define argument binding type (ex. = or space) |
|
90 private String argumentBinding; |
|
91 |
|
92 //define type of value that argument can take (ex. digit or literal) |
|
93 private String argumentNextvalue; |
|
94 |
|
95 public String getArgumenType() { |
|
96 // TODO Auto-generated method stub |
|
97 return argumentType; |
|
98 } |
|
99 } |