From: G?nther B. <br...@us...> - 2002-05-13 22:46:15
|
Update of /cvsroot/xpg-xml/edu/iicm/xpg/transitions/cvhtml In directory usw-pr-cvs1:/tmp/cvs-serv29183/transitions/cvhtml Modified Files: WriteGeneralFooterTransition.java WriteGeneralHeaderTransition.java Added Files: WriteListTransition.java WritePersonalTransition.java Log Message: CV example to latex and html --- NEW FILE: WriteListTransition.java --- /*********************************************************************** * * Copyright (c) 2001 IICM, Graz University of Technology * Schiesstattgasse 4a, A-8010 Graz, Austria. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License (LGPL) * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***********************************************************************/ package edu.iicm.xpg.transitions.cvhtml; import edu.iicm.xpg.statemachine.Transition; import edu.iicm.xpg.statemachine.State; import edu.iicm.xpg.statemachine.StateMachine; import edu.iicm.xpg.statemachine.Input; import edu.iicm.xpg.statemachine.XMLInput; import edu.iicm.xpg.statemachine.XMLElement; import edu.iicm.xpg.statemachine.DataObject; import edu.iicm.xpg.statemachine.Const; import edu.iicm.xpg.util.Debug; import java.util.Vector; import java.util.Enumeration; //---------------------------------------------------------------------- /** * @author Guenther Brand * @version $Revision: 1.1 $ */ public class WriteListTransition implements Transition { //---------------------------------------------------------------------- /** * @param input the input that triggered this transition * @param from_state the start state for this transition * @param to_state the destination state for this transition * @param machine the state machine that this transition belongs to * @param data user defined data * @return * @exception Exception whatever an implementation can throw */ public String transitionTriggered(Input input,State from_state,State to_state, StateMachine machine,DataObject data) throws Exception { StringBuffer result = (StringBuffer)data.getObject(Const.RESULT_BUFFER); Vector list_items = (Vector)data.removeObject("list items"); String list_title = ((XMLElement)data.removeObject("title")).getValue(); result.append("\n<hr>" + "\n<table>" + "\n <th colspan=\"2\">" + list_title + "</th>"); for (int idx=0; idx < list_items.size(); idx++) { String[] item = (String[])list_items.get(idx); String caption = item[0]; String value = item[1]; result.append("\n <tr>" + "\n <td>"); if ( caption != null ) result.append(caption); result.append("</td><td>" + value + "</td>" + "\n </tr>"); } result.append("\n</table>\n"); return(null); } } --- NEW FILE: WritePersonalTransition.java --- /*********************************************************************** * * Copyright (c) 2001 IICM, Graz University of Technology * Schiesstattgasse 4a, A-8010 Graz, Austria. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License (LGPL) * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***********************************************************************/ package edu.iicm.xpg.transitions.cvhtml; import edu.iicm.xpg.statemachine.Transition; import edu.iicm.xpg.statemachine.State; import edu.iicm.xpg.statemachine.StateMachine; import edu.iicm.xpg.statemachine.Input; import edu.iicm.xpg.statemachine.XMLInput; import edu.iicm.xpg.statemachine.XMLElement; import edu.iicm.xpg.statemachine.DataObject; import edu.iicm.xpg.statemachine.Const; import edu.iicm.xpg.util.Debug; import org.xml.sax.Attributes; import java.util.Vector; import java.util.Enumeration; //---------------------------------------------------------------------- /** * @author Guenther Brand * @version $Revision: 1.1 $ */ public class WritePersonalTransition implements Transition { //---------------------------------------------------------------------- /** * @param input the input that triggered this transition * @param from_state the start state for this transition * @param to_state the destination state for this transition * @param machine the state machine that this transition belongs to * @param data user defined data * @return * @exception Exception whatever an implementation can throw */ public String transitionTriggered(Input input,State from_state,State to_state, StateMachine machine,DataObject data) throws Exception { StringBuffer result = (StringBuffer)data.getObject(Const.RESULT_BUFFER); String name = ((XMLElement)data.getObject("name")).getValue(); Attributes attr = (Attributes)data.getObject("Attributes"); String title = attr.getValue("title"); String lang = attr.getValue("lang"); if ( lang == null ) lang = "en"; if ( title == null ) if ( lang.equals("de") ) title = "Lebenslauf"; else title = "Curriculum Vitae"; result.append("\n<center>\n" + "<h1>" + title + "</h1>\n" + "<h2>" + name + "</h2>\n" + "<br>\n"); if ( lang.equals("de") ) { result.append("\n<table>" + "\n <th colspan=\"2\">Persönliche Daten</th>" + "\n <tr>" + "\n <td>Name</td><td>" + name + "</td>" + "\n </tr>"); writeElemValue( result, "geboren am", (XMLElement)data.getObject("birthdate") ); // result.append(" in " + // ((XMLElement)data.getObject("birthplace")).getValue()); writeElemAttr( result, "Familienstand", (XMLElement)data.getObject("marital"), "status" ); writeElemValue( result, "Adresse", (XMLElement)data.getObject("address") ); XMLElement country = (XMLElement)data.getObject("country"); // if ( country != null ) // result.append(", " + country.getValue()); writeElemValue( result, "Telefon", (XMLElement)data.getObject("phone") ); writeElemValue(result, "Mobil", (XMLElement)data.getObject("mobile") ); writeElemValue( result, "E-mail", (XMLElement)data.getObject("email") ); writeElemValue( result, "Homepage", (XMLElement)data.getObject("homepage") ); } else { result.append("\n<table>" + "\n <th colspan=\"2\">Personal Data</th>" + "\n <tr>" + "\n <td>Name</td><td>" + name + "</td>" + "\n </tr>"); writeElemValue( result, "born on", (XMLElement)data.getObject("birthdate") ); // result.append(" at " + // ((XMLElement)data.getObject("birthplace")).getValue()); writeElemAttr( result, "Marital status", (XMLElement)data.getObject("marital"), "status" ); writeElemValue( result, "Address", (XMLElement)data.getObject("address") ); XMLElement country = (XMLElement)data.getObject("country"); // if ( country != null ) // result.append(", " + country.getValue()); writeElemValue( result, "Phone", (XMLElement)data.getObject("phone") ); writeElemValue(result, "Mobile", (XMLElement)data.getObject("mobile") ); writeElemValue( result, "E-mail", (XMLElement)data.getObject("email") ); writeElemValue( result, "Homepage", (XMLElement)data.getObject("homepage") ); } result.append("\n</table>\n"); return(null); } protected void writeElemValue(StringBuffer result, String caption, XMLElement elem) { if ( elem != null ) result.append("\n <tr>" + "\n <td>" + caption + "</td>" + "<td>" + elem.getValue() + "</td>" + "\n </tr>"); } protected void writeElemAttr(StringBuffer result, String caption, XMLElement elem, String attr) { if ( elem != null ) result.append("\n <tr>" + "\n <td>" + caption + "</td>" + "<td>" + elem.getAttributes().getValue(attr) + "</td>" + "\n </tr>"); } } Index: WriteGeneralFooterTransition.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/transitions/cvhtml/WriteGeneralFooterTransition.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WriteGeneralFooterTransition.java 8 May 2002 15:07:33 -0000 1.2 --- WriteGeneralFooterTransition.java 13 May 2002 22:46:12 -0000 1.3 *************** *** 29,32 **** --- 29,33 ---- import edu.iicm.xpg.statemachine.Input; import edu.iicm.xpg.statemachine.XMLInput; + import edu.iicm.xpg.statemachine.XMLElement; import edu.iicm.xpg.statemachine.DataObject; import edu.iicm.xpg.statemachine.Const; *************** *** 60,64 **** { StringBuffer document = (StringBuffer)data.getObject(Const.RESULT_BUFFER); ! String place = (String)data.getObject("place"); Date today = new Date(); --- 61,65 ---- { StringBuffer document = (StringBuffer)data.getObject(Const.RESULT_BUFFER); ! String place = ((XMLElement)data.getObject("place")).getValue(); Date today = new Date(); *************** *** 67,71 **** String dateOut = dateFormatter.format(today); ! document.append("\n" + place + ", " + dateOut + "\n\n</body>\n</html>"); --- 68,74 ---- String dateOut = dateFormatter.format(today); ! document.append("\n</center>" + ! "\n<br>" + ! "\n" + place + ", " + dateOut + "\n\n</body>\n</html>"); Index: WriteGeneralHeaderTransition.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/transitions/cvhtml/WriteGeneralHeaderTransition.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WriteGeneralHeaderTransition.java 8 May 2002 15:07:33 -0000 1.2 --- WriteGeneralHeaderTransition.java 13 May 2002 22:46:12 -0000 1.3 *************** *** 57,64 **** StringBuffer document = new StringBuffer(); document.append("<html>\n<head>\n" + ! "<title>Curriculum Vitae</title>" + "</head>\n<body>\n"); data.putObject(Const.RESULT_BUFFER, document); return(null); } --- 57,67 ---- StringBuffer document = new StringBuffer(); document.append("<html>\n<head>\n" + ! "<title>Curriculum Vitae</title>\n" + "</head>\n<body>\n"); data.putObject(Const.RESULT_BUFFER, document); + + data.putObject("Attributes", data.getXMLElement().getAttributes()); + return(null); } |