diff options
Diffstat (limited to 'Dozentenmodulserver/src/util')
| -rw-r--r-- | Dozentenmodulserver/src/util/XMLCreator.java | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/Dozentenmodulserver/src/util/XMLCreator.java b/Dozentenmodulserver/src/util/XMLCreator.java index 8a8bd701..111a6337 100644 --- a/Dozentenmodulserver/src/util/XMLCreator.java +++ b/Dozentenmodulserver/src/util/XMLCreator.java @@ -5,6 +5,9 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -15,10 +18,13 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.log4j.Logger; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; +import server.BinaryListener; + public class XMLCreator { /* @@ -31,13 +37,17 @@ public class XMLCreator { private ResultSet rs = null; private String vmName; private String filePath = "/srv/openslx/nfs/temp/"; + private String imageName; + private String xmlName; + private static Logger log = Logger.getLogger( BinaryListener.class ); // phone param not existing - private String query = "SELECT m_VLData_imageInfo.image_path ,vorname, nachname, mail, shortdescription, description, m_operatingSystem.name as os, m_VLData_lecture.admin_changeTime as time " - + "FROM bwLehrpool.m_VLData_lecture, bwLehrpool.m_VLData_imageInfo, bwLehrpool.m_user, bwLehrpool.m_operatingSystem " + private String query = "SELECT m_VLData_imageInfo.image_path ,vorname, nachname, mail, shortdescription, description, m_operatingSystem.name as os, m_VLData_lecture.admin_changeTime as time, m_VLData_lecture.name as lectureName, m_user.institution as userInstitution, m_user.loginName as loginName, m_institution.name as institutionName " + + "FROM bwLehrpool.m_VLData_lecture, bwLehrpool.m_VLData_imageInfo, bwLehrpool.m_user, bwLehrpool.m_operatingSystem, bwLehrpool.m_institution " + "WHERE m_user.userID = m_VLData_lecture.admin_owner " + "AND m_VLData_imageInfo.GUID_imageID = m_VLData_lecture.imageID " + "AND m_VLData_imageInfo.content_operatingSystem = m_operatingSystem.operatingSystemID " + + "AND m_user.institution = m_institution.institutionID " + "AND m_VLData_lecture.name = "; public XMLCreator(Connection con) { @@ -61,10 +71,10 @@ public class XMLCreator { boolean success = startCreation(); - if (success) { + if (success) { return true; } - + log.info(new Date() + " - Could not create XML-File '"+vmName+"'. Error in create(String vmName)."); return false; } @@ -85,6 +95,7 @@ public class XMLCreator { if (success) { return true; } + log.info(new Date() + " - Could not create XML-File '"+vmName+"'. Error in create(String vmName)."); return false; } @@ -117,10 +128,10 @@ public class XMLCreator { Element imgName = doc.createElement("image_name"); entry.appendChild(imgName); - String imagePath = rs.getString("image_path").substring( - rs.getString("image_path").lastIndexOf("/")); + imageName = rs.getString("image_path").substring( + rs.getString("image_path").lastIndexOf("/")+1); //+1 um das führende "/" los zu werden - imgName.setAttribute("param", imagePath); + imgName.setAttribute("param", imageName); Element creator = doc.createElement("creator"); entry.appendChild(creator); @@ -138,13 +149,13 @@ public class XMLCreator { Element shortDesc = doc.createElement("short_description"); entry.appendChild(shortDesc); - shortDesc.setAttribute("param", rs.getString("shortdescription")); + shortDesc.setAttribute("param", rs.getString("lectureName")); // TODO append latest change date and time Element longDesc = doc.createElement("long_description"); entry.appendChild(longDesc); longDesc.setAttribute("param", rs.getString("description") - + " last update: " + rs.getString("time")); + + "; last update: " + rs.getString("time")); Element os = doc.createElement("os"); entry.appendChild(os); @@ -189,10 +200,14 @@ public class XMLCreator { .newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); - - StreamResult result = new StreamResult(new File(filePath - + imagePath.replace("vmdk", "xml"))); // see filepath at top of - // class + + //Set XML-filename + DateFormat formatter = new SimpleDateFormat("yyyMMddhhmmss"); + xmlName=formatter.format(new Date()) + "_" + rs.getString("institutionName") + "_" + rs.getString("loginName") + "_" + rs.getString("lectureName") + ".xml"; + + //Write file + StreamResult result = new StreamResult(new File(filePath+ xmlName)); // see filepath at top of class + transformer.transform(source, result); // cleanup @@ -200,6 +215,7 @@ public class XMLCreator { st.close(); // return + log.info(new Date() + " - XML-File '"+xmlName+"' successfully created."); return true; } } |
