33 */
44package org .commcare .xml ;
55
6+ import org .commcare .cases .util .StringUtils ;
67import org .commcare .resources .model .Resource ;
78import org .commcare .resources .model .ResourceTable ;
89import org .commcare .suite .model .AndroidPackageDependency ;
10+ import org .commcare .suite .model .Credential ;
911import org .commcare .suite .model .Profile ;
1012import org .commcare .util .CommCarePlatform ;
1113import org .javarosa .core .reference .RootTranslator ;
@@ -27,7 +29,11 @@ public class ProfileParser extends ElementParser<Profile> {
2729
2830 private static final String NAME_DEPENDENCIES = "dependencies" ;
2931 private static final String NAME_ANDROID_PACKAGE = "android_package" ;
32+ private static final String NAME_CREDENTIALS = "credentials" ;
33+ private static final String NAME_CREDENTIAL = "credential" ;
3034 private static final String ATTR_ID = "id" ;
35+ private static final String ATTR_CREDENTIAL_LEVEL = "level" ;
36+ private static final String ATTR_CREDENTIAL_TYPE = "type" ;
3137
3238 ResourceTable table ;
3339 String resourceId ;
@@ -244,13 +250,35 @@ private void parseFeatures(Profile profile) throws XmlPullParserException, IOExc
244250 } else if (tag .equals (NAME_DEPENDENCIES )) {
245251 profile .setDependencies (parseDependencies ());
246252 } else if (tag .equals ("sense" )) {
253+ }else if (tag .equals (NAME_CREDENTIALS )) {
254+ profile .setCredentials (parseCredentials ());
247255 }
248256
249257 profile .setFeatureActive (tag , isActive );
250258 //TODO: set feature activation in profile
251259 }
252260 }
253261
262+ private Vector <Credential > parseCredentials ()
263+ throws InvalidStructureException , XmlPullParserException , IOException {
264+ Vector <Credential > appCredentials = new Vector <>();
265+ while (nextTagInBlock (NAME_CREDENTIALS )) {
266+ String tag = parser .getName ().toLowerCase ();
267+ if (tag .equals (NAME_CREDENTIAL )) {
268+ String level = parser .getAttributeValue (null , ATTR_CREDENTIAL_LEVEL );
269+ String type = parser .getAttributeValue (null , ATTR_CREDENTIAL_TYPE );
270+ if (StringUtils .isEmpty (level )) {
271+ throw new InvalidStructureException ("No level defined for credential" );
272+ }
273+ if (StringUtils .isEmpty (type )) {
274+ throw new InvalidStructureException ("No type defined for credential" );
275+ }
276+ appCredentials .add (new Credential (level , type ));
277+ }
278+ }
279+ return appCredentials ;
280+ }
281+
254282 private Vector <AndroidPackageDependency > parseDependencies ()
255283 throws InvalidStructureException , XmlPullParserException , IOException {
256284 Vector <AndroidPackageDependency > appDependencies = new Vector <>();
0 commit comments