source: tol/TolJava/WebTOLJavaDEMO/src/java/com/hcarralero/toljava/demo/Interprete.java @ 9887b93

1941-docker-image-to-testdevel
Last change on this file since 9887b93 was 9887b93, checked in by Humberto Carralero <hacarralero@…>, 15 years ago

Importing TolJava

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@3900 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 7.9 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.hcarralero.toljava.demo;
7
8import com.hcarralero.toljava.TOLMachine;
9import com.sun.rave.web.ui.appbase.AbstractPageBean;
10import com.sun.webui.jsf.component.StaticText;
11import com.sun.webui.jsf.component.TextArea;
12import javax.faces.FacesException;
13
14/**
15 * <p>Page bean that corresponds to a similarly named JSP page.  This
16 * class contains component definitions (and initialization code) for
17 * all components that you have defined on this page, as well as
18 * lifecycle methods and event handlers where you may add behavior
19 * to respond to incoming events.</p>
20 *
21 * @version Docs.java
22 * @version Created on Nov 28, 2010, 1:55:24 PM
23 * @author hcarralero
24 */
25
26public class Interprete extends AbstractPageBean {
27    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
28
29    /**
30     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
31     * This method is automatically generated, so any user-specified code inserted
32     * here is subject to being replaced.</p>
33     */
34    private void _init() throws Exception {
35    }
36    private TextArea taCodigo = new TextArea();
37
38    public TextArea getTaCodigo() {
39        return taCodigo;
40    }
41
42    public void setTaCodigo(TextArea ta) {
43        this.taCodigo = ta;
44    }
45    private StaticText stxtResultadoEjecutar = new StaticText();
46
47    public StaticText getStxtResultadoEjecutar() {
48        return stxtResultadoEjecutar;
49    }
50
51    public void setStxtResultadoEjecutar(StaticText st) {
52        this.stxtResultadoEjecutar = st;
53    }
54
55    // </editor-fold>
56
57    /**
58     * <p>Construct a new Page bean instance.</p>
59     */
60    public Interprete() {
61    }
62
63    /**
64     * <p>Callback method that is called whenever a page is navigated to,
65     * either directly via a URL, or indirectly via page navigation.
66     * Customize this method to acquire resources that will be needed
67     * for event handlers and lifecycle methods, whether or not this
68     * page is performing post back processing.</p>
69     *
70     * <p>Note that, if the current request is a postback, the property
71     * values of the components do <strong>not</strong> represent any
72     * values submitted with this request.  Instead, they represent the
73     * property values that were saved for this view when it was rendered.</p>
74     */
75    @Override
76    public void init() {
77        // Perform initializations inherited from our superclass
78        super.init();
79        // Perform application initialization that must complete
80        // *before* managed components are initialized
81        // TODO - add your own initialiation code here
82       
83        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
84        // Initialize automatically managed components
85        // *Note* - this logic should NOT be modified
86        try {
87            _init();
88        } catch (Exception e) {
89            log("Docs Initialization Failure", e);
90            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
91        }
92       
93        // </editor-fold>
94        // Perform application initialization that must complete
95        // *after* managed components are initialized
96        // TODO - add your own initialization code here
97        MenuIzquierdo mi= (MenuIzquierdo)this.getBean("MenuIzquierdo");
98        if (mi!=null) {
99            mi.getTrMenuIzquierdo().setSelected("tnInterprete");
100        }
101    }
102
103    /**
104     * <p>Callback method that is called after the component tree has been
105     * restored, but before any event processing takes place.  This method
106     * will <strong>only</strong> be called on a postback request that
107     * is processing a form submit.  Customize this method to allocate
108     * resources that will be required in your event handlers.</p>
109     */
110    @Override
111    public void preprocess() {
112    }
113
114    /**
115     * <p>Callback method that is called just before rendering takes place.
116     * This method will <strong>only</strong> be called for the page that
117     * will actually be rendered (and not, for example, on a page that
118     * handled a postback and then navigated to a different page).  Customize
119     * this method to allocate resources that will be required for rendering
120     * this page.</p>
121     */
122    @Override
123    public void prerender() {
124    }
125
126    /**
127     * <p>Callback method that is called after rendering is completed for
128     * this request, if <code>init()</code> was called (regardless of whether
129     * or not this was the page that was actually rendered).  Customize this
130     * method to release resources acquired in the <code>init()</code>,
131     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
132     * acquired during execution of an event handler).</p>
133     */
134    @Override
135    public void destroy() {
136    }
137
138    /**
139     * <p>Return a reference to the scoped data bean.</p>
140     *
141     * @return reference to the scoped data bean
142     */
143    protected ApplicationBean1 getApplicationBean1() {
144        return (ApplicationBean1) getBean("ApplicationBean1");
145    }
146
147    /**
148     * <p>Return a reference to the scoped data bean.</p>
149     *
150     * @return reference to the scoped data bean
151     */
152    protected SessionBean1 getSessionBean1() {
153        return (SessionBean1) getBean("SessionBean1");
154    }
155
156    /**
157     * <p>Return a reference to the scoped data bean.</p>
158     *
159     * @return reference to the scoped data bean
160     */
161    protected RequestBean1 getRequestBean1() {
162        return (RequestBean1) getBean("RequestBean1");
163    }
164
165    public String btnEjecutarCodigo_action() {
166        TOLMachine tm= this.getSessionBean1().getTm();
167        String code= (String)this.taCodigo.getText();
168        Object res[]= tm.execute(code);
169        String htmlRes="<html><h1 style=\"text-decoration:underline\">RESULTADOS DE LA EVALUACIÓN</h1>";
170        if (res==null) {
171            htmlRes+="<h2 style=\"color:red\">&nbsp;&nbsp;&nbsp;&nbsp;ERROR DE ACCESO A TOL</h2>";
172        } else {
173            try {
174                int ne= Integer.parseInt((String)res[0]);
175                htmlRes+="<h2 style=\"color:";
176                if (ne>0) {
177                    htmlRes+="red\">&nbsp;&nbsp;&nbsp;&nbsp;Se ha(n) detectado "+ne+" error(es)";
178                } else {
179                    htmlRes+="green\">&nbsp;&nbsp;&nbsp;&nbsp;No se han detectado errores";
180                }
181                htmlRes+= "</h2>";
182                for (int i= 1; i<res.length; ++i) {
183                    String strRes= (String)res[i];
184                    int l= strRes.length();
185                    htmlRes+="<h3";
186                    if (strRes.charAt(0)=='<'&&strRes.charAt(2)=='>'&&(strRes.charAt(1)=='E'||strRes.charAt(1)=='W')&&l>=7) {
187                        char tipo= strRes.charAt(1);
188                        switch (tipo) {
189                            case 'E':
190                            case 'e':
191                                htmlRes+=" style=\"color:red\"";
192                                break;
193                            case 'W':
194                            case 'w':
195                                htmlRes+=" style=\"color:yellow\"";
196                                break;
197                            default:
198                                htmlRes+=" style=\"color:green\"";
199                        }
200                        htmlRes+= ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+strRes.substring(3, l-5);
201                    } else {
202                        htmlRes+= ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+strRes;
203                    }
204                    htmlRes+="</h3>";
205                }
206            } catch (NumberFormatException ex) {
207                htmlRes+="<h2 style=\"color:red\">&nbsp;&nbsp;&nbsp;&nbsp;ERROR DE ACCESO AL NÚMERO DE ERRORES</h2>";
208            }
209        }
210        htmlRes+="</html>";
211        this.stxtResultadoEjecutar.setText(htmlRes);
212        return null;
213    }
214   
215}
216
Note: See TracBrowser for help on using the repository browser.