/**
  * Default constructor
  */
 public AdaptationHandler(InputStreamCreator isCreator, List<AdaptationRule> rules, AdaptedState iState)
 {
     initialState = iState;
     if (rules == null)
         externalRules = new List<AdaptationRule>();
     else
         externalRules = rules;
     currentstring = string.Empty;
     vars = new List<string>();
     flags = new List<string>();
     this.isCreator = isCreator;
 }
 /**
  * @param name
  * @param rules
  * @param initialState
  * @param scorm12
  * @param scorm2004
  */
 public AdaptationProfile(List<AdaptationRule> rules, AdaptedState initialState, string name, bool scorm12,
     bool scorm2004)
 {
     this.name = name;
     this.rules = rules;
     if (initialState == null)
         this.initialState = new AdaptedState();
     else
         this.initialState = initialState;
     flags = new List<string>();
     vars = new List<string>();
     this.scorm2004 = scorm2004;
     this.scorm12 = scorm12;
 }
Ejemplo n.º 3
0
 public AdaptationRule()
 {
     uolState = new List<UOLProperty>();
     gameState = new AdaptedState();
 }
Ejemplo n.º 4
0
    /*
    @Override
    public Object clone() throws CloneNotSupportedException
    {

        AdaptationRule ar = (AdaptationRule) super.clone( );
        ar.description = ( description != null ? new string(description ) : null );
        ar.gameState = (AdaptedState) gameState.clone( );
        ar.id = ( id != null ? new string(id ) : null );
        ar.uolState = new List<UOLProperty>( );
        for( UOLProperty uolp : uolState ) {
            ar.uolState.add( (UOLProperty) uolp.clone( ) );
        }
        return ar;
    }*/
    public void setAdaptedState(AdaptedState state)
    {
        this.gameState = state;
    }
    /*
     *  (non-Javadoc)
     * @see org.xml.sax.ContentHandler#startElement(java.lang.string, java.lang.string, java.lang.string, org.xml.sax.Attributes)
     */
    public override void startElement(string namespaceURI, string sName, string qName, Dictionary<string, string> attrs)
    {
        // Check if it is an scorm adaptation profile
        if (qName.Equals("adaptation"))
        {
            foreach (KeyValuePair<string, string> entry in attrs)
            {
                if (entry.Key.Equals("scorm12"))
                {
                    profile.setScorm12(entry.Value.ToString().Equals("yes"));
                }
                if (entry.Key.Equals("scorm2004"))
                {
                    profile.setScorm2004(entry.Value.ToString().Equals("yes"));
                }
                if (entry.Key.Equals("name"))
                {
                    profile.setName(entry.Value.ToString());
                }
            }
        }

        //Start parsing the initial state
        if (qName.Equals("initial-state"))
        {
            parsing = INITIAL_STATE;
            initialState = new AdaptedState();
        }

        //Start parsing an adaptation rule
        else if (qName.Equals("adaptation-rule"))
        {
            parsing = ADAPTATION_RULE;
            rule_temp = new AdaptationRule();
        }

        //Initial scene
        else if (qName.Equals("initial-scene"))
        {
            foreach (KeyValuePair<string, string> entry in attrs)
            {
                if (entry.Key.Equals("idTarget"))
                {
                    if (parsing == INITIAL_STATE)
                    {
                        initialState.setTargetId(entry.Value.ToString());
                    }
                    else {
                        rule_temp.setInitialScene(entry.Value.ToString());
                    }
                }
            }
        }

        // If the tag activates a flag
        else if (qName.Equals("activate"))
        {
            foreach (KeyValuePair<string, string> entry in attrs)
            {
                if (entry.Key.Equals("flag"))
                {
                    if (parsing == INITIAL_STATE)
                    {
                        initialState.addActivatedFlag(entry.Value.ToString());
                    }
                    else {
                        rule_temp.addActivatedFlag(entry.Value.ToString());
                    }
                    profile.addFlag(entry.Value.ToString());
                }
            }
        }

        // If the tag deactivates a flag
        else if (qName.Equals("deactivate"))
        {
            foreach (KeyValuePair<string, string> entry in attrs)
            {
                if (entry.Key.Equals("flag"))
                {
                    if (parsing == INITIAL_STATE)
                    {
                        initialState.addDeactivatedFlag(entry.Value.ToString());
                    }
                    else {
                        rule_temp.addDeactivatedFlag(entry.Value.ToString());
                    }
                    profile.addFlag(entry.Value.ToString());
                }
            }
        }

        // If the tag set-value a var
        else if (qName.Equals("set-value"))
        {
            string var = null;
            string value = null;
            foreach (KeyValuePair<string, string> entry in attrs)
            {
                if (entry.Key.Equals("var"))
                {
                    var = entry.Value.ToString();
                }
                else if (entry.Key.Equals("value"))
                {
                    value = entry.Value.ToString();
                }
            }

            if (parsing == INITIAL_STATE)
            {
                initialState.addVarValue(var, AdaptedState.VALUE + " " + value);
            }
            else {
                rule_temp.addVarValue(var, AdaptedState.VALUE + " " + value);
            }
            profile.addVar(var);

        }

        // If the tag increment a var
        else if (qName.Equals("increment"))
        {
            string var = null;
            string value = null;
            foreach (KeyValuePair<string, string> entry in attrs)
            {
                if (entry.Key.Equals("var"))
                {
                    var = entry.Value.ToString();
                }
                else if (entry.Key.Equals("value"))
                {
                    value = entry.Value.ToString();
                }

            }

            if (parsing == INITIAL_STATE)
            {
                initialState.addVarValue(var, AdaptedState.INCREMENT + " " + value);
            }
            else {
                rule_temp.addVarValue(var, AdaptedState.INCREMENT + " " + value);
            }
            profile.addVar(var);

        }

        // If the tag decrement a var
        else if (qName.Equals("decrement"))
        {
            string var = null;
            string value = null;
            foreach (KeyValuePair<string, string> entry in attrs)
            {
                if (entry.Key.Equals("var"))
                {
                    var = entry.Value.ToString();
                }
                else if (entry.Key.Equals("value"))
                {
                    value = entry.Value.ToString();
                }

            }

            if (parsing == INITIAL_STATE)
            {
                initialState.addVarValue(var, AdaptedState.DECREMENT + " " + value);
            }
            else {
                rule_temp.addVarValue(var, AdaptedState.DECREMENT + " " + value);
            }
            profile.addVar(var);

        }

        //Property from the UoL
        else if (qName.Equals("property"))
        {
            string id = null;
            string value = null;
            string op = null;
            foreach (KeyValuePair<string, string> entry in attrs)
            {
                if (entry.Key.Equals("id"))
                {
                    id = entry.Value.ToString();
                }
                else if (entry.Key.Equals("value"))
                {
                    value = entry.Value.ToString();
                }
                else if (entry.Key.Equals("operation"))
                {
                    op = entry.Value.ToString();
                }
            }
            rule_temp.addUOLProperty(new UOLProperty(id, value, op));
        }
    }
Ejemplo n.º 6
0
    /**
     * Loads the adaptation profile (set of adaptation rules + initial state)
     * stored in file with path xmlFile in zipFile
     *
     * @param zipFile
     * @param xmlFile
     * @param incidences
     * @return
     */
    public static AdaptationProfile loadAdaptationProfile(InputStreamCreator isCreator, string xmlFile, List<Incidence> incidences)
    {
        AdaptationProfile newProfile = null;
        if (Loader.adventureData != null)
        {
            foreach (Chapter chapter in Loader.adventureData.getChapters())
            {
                if (chapter.getAssessmentProfiles().Count != 0)
                {
                    foreach (AdaptationProfile profile in chapter.getAdaptationProfiles())

                        if (profile.getName().Equals(xmlFile))
                        {
                            newProfile = profile;
                            break;
                        }
                }
            }

        }
        else {

            // Open the file and load the data
            try
            {
                // Set the chapter handler
                List<AdaptationRule> rules = new List<AdaptationRule>();
                AdaptedState initialState = new AdaptedState();
                AdaptationHandler adpParser = new AdaptationHandler(isCreator, rules, initialState);

                //factory.setValidating(true);
                //SAXParser saxParser = factory.newSAXParser();

                // Parse the data and close the data
                string adaptationIS = isCreator.buildInputStream(xmlFile);

                //saxParser.parse(adaptationIS, adpParser);
                //adaptationIS.close();

                adpParser.Parse(adaptationIS);

                // Finally add the new controller to the list
                // Create the new profile
                string name = xmlFile;
                name = name.Substring(name.IndexOf("/") + 1);
                name = name.Substring(0, name.IndexOf("."));
                newProfile = new AdaptationProfile(adpParser.getAdaptationRules(), adpParser.getInitialState(), name, adpParser.isScorm12(), adpParser.isScorm2004());

                newProfile.setFlags(adpParser.getFlags());
                newProfile.setVars(adpParser.getVars());

            }
            catch (Exception e)
            { Debug.LogError(e); }
            //catch (ParserConfigurationException e)
            //{
            //    incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.SAX"), xmlFile, e));
            //}
            //catch (SAXException e)
            //{
            //    incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.SAX"), xmlFile, e));
            //}
            //catch (IOException e)
            //{
            //    incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.IO"), xmlFile, e));
            //}
        }
        return newProfile;
    }
 /**
  * Empty constructor
  */
 public AdaptationProfile()
 {
     name = null;
     rules = new List<AdaptationRule>();
     scorm2004 = false;
     scorm12 = false;
     flags = new List<string>();
     vars = new List<string>();
     initialState = new AdaptedState();
 }
 /**
  * @param initialState
  *            the initialState to set
  */
 public void setInitialState(AdaptedState initialState)
 {
     this.initialState = initialState;
 }
Ejemplo n.º 9
0
 /**
  * Joins two Adapted States. The new resulting adapted state has a merge of
  * active/inactive flags of both states, and the initial scene will be set
  * as the initial scene of the parameter state. With the vars, its do the
  * same action. The new flags/vars will be add at the end of the data
  * structure;
  *
  * @param AdaptedState
  *            mergeState The state which will be merged with the current
  *            object
  *
  */
 public void merge(AdaptedState mergeState)
 {
     if (mergeState.initialScene != null)
         this.initialScene = mergeState.initialScene;
     if (this.allFlagsVars.Count == 0)
     {
         this.allFlagsVars = mergeState.allFlagsVars;
         this.actionsValues = mergeState.actionsValues;
     }
     else
     {
         for (int i = 0; i < mergeState.allFlagsVars.Count; i++)
         {
             this.allFlagsVars.Add(mergeState.allFlagsVars[i]);
             this.actionsValues.Add(mergeState.allFlagsVars[i]);
         }
     }
 }