예제 #1
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;
    }
예제 #2
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);
    }