// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov  Date: 08/10/2012 8:47:31
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   ComprobarSiPoseeDemo.java

package project;

import java.io.InputStream;
import java.io.PrintStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;

// Referenced classes of package project:
//            Application1, Crypto

public class ComprobarSiPoseeDemo
{

    public ComprobarSiPoseeDemo()
    {
    }

    public static String modulosConDemo(String idioma, String demos)
    {
        System.out.println("demos: " + demos);
        String aDemos[] = demos.split(";");
        System.out.println("aDemos.length: " + aDemos.length);
        String demosValidas = new String();
label0:
        for(int i = 0; i < aDemos.length; i++)
        {
            fichero = "/project/modulo" + aDemos[i] + ".xml";
            System.out.println("ficherito: " + fichero);
            stream = Application1.crypto.decrypt((java.lang.Object.class).getResourceAsStream(fichero));
            try
            {
                m_dbf = DocumentBuilderFactory.newInstance();
                db1 = m_dbf.newDocumentBuilder();
                doc = db1.parse(stream);
                listOfQuestions = doc.getElementsByTagName("idioma");
                boolean encontrado = false;
                int s = 0;
                do
                {
                    if(s >= listOfQuestions.getLength() || encontrado)
                        continue label0;
                    nextTag = (Element)listOfQuestions.item(s);
                    if(nextTag != null && nextTag.getAttribute("id").compareTo(idioma) == 0)
                    {
                        listOfQuestions = nextTag.getElementsByTagName("grado");
                        if(listOfQuestions != null)
                        {
                            for(int r = 0; r < listOfQuestions.getLength() && !encontrado; r++)
                            {
                                nextTag = (Element)listOfQuestions.item(r);
                                if(nextTag != null && Integer.parseInt(nextTag.getAttribute("en_demo")) > 0)
                                {
                                    demosValidas = demosValidas + aDemos[i] + ";";
                                    encontrado = true;
                                }
                            }

                        }
                    }
                    s++;
                } while(true);
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
        }

        try
        {
            stream.close();
            fichero = null;
            stream = null;
            m_dbf = null;
            db1 = null;
            doc = null;
            listOfQuestions = null;
            nextTag = null;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return demosValidas;
    }

    public static void main(String args[])
    {
        modulosConDemo("3", "2;");
    }

    private static DocumentBuilderFactory m_dbf;
    private static DocumentBuilder db1;
    private static Document doc;
    private static NodeList listOfQuestions;
    private static Element nextTag;
    private static InputStream stream;
    private static String fichero = "";

}