diff options
| author | unknown | 2014-03-28 12:49:02 +0100 |
|---|---|---|
| committer | unknown | 2014-03-28 12:49:02 +0100 |
| commit | ddd6cc7400e00586d52840deb0ec8df98f69de4a (patch) | |
| tree | 2e9c2344b0b0d8cdf097adc4020a1b79b68a4793 /Dozentenmodulserver/src | |
| parent | Authentifizierung über Masterserver funktioniert nun (diff) | |
| download | tutor-module-ddd6cc7400e00586d52840deb0ec8df98f69de4a.tar.gz tutor-module-ddd6cc7400e00586d52840deb0ec8df98f69de4a.tar.xz tutor-module-ddd6cc7400e00586d52840deb0ec8df98f69de4a.zip | |
-XML Creator eingebaut
-Dateiname angepasst -> Uploader funktioniert nun wieder
Diffstat (limited to 'Dozentenmodulserver/src')
| -rw-r--r-- | Dozentenmodulserver/src/server/Server.java | 132 | ||||
| -rw-r--r-- | Dozentenmodulserver/src/server/ServerHandler.java | 25 | ||||
| -rw-r--r-- | Dozentenmodulserver/src/sql/SQL.java | 4 | ||||
| -rw-r--r-- | Dozentenmodulserver/src/util/XMLCreator.java | 213 |
4 files changed, 354 insertions, 20 deletions
diff --git a/Dozentenmodulserver/src/server/Server.java b/Dozentenmodulserver/src/server/Server.java index 18362ab7..9994fcb4 100644 --- a/Dozentenmodulserver/src/server/Server.java +++ b/Dozentenmodulserver/src/server/Server.java @@ -42,7 +42,7 @@ public class Server { public String getPathOfImage(String name) throws org.apache.thrift.TException; - public boolean writeVLdata(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu) throws org.apache.thrift.TException; + public boolean writeVLdata(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath) throws org.apache.thrift.TException; public List<Image> getImageList() throws org.apache.thrift.TException; @@ -70,7 +70,7 @@ public class Server { public void getPathOfImage(String name, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; - public void writeVLdata(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void writeVLdata(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; public void getImageList(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; @@ -178,13 +178,13 @@ public class Server { throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "getPathOfImage failed: unknown result"); } - public boolean writeVLdata(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu) throws org.apache.thrift.TException + public boolean writeVLdata(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath) throws org.apache.thrift.TException { - send_writeVLdata(imagename, firstname, lastname, university, Mail, Tel, Fak, license, internet, ram, cpu); + send_writeVLdata(imagename, firstname, lastname, university, Mail, Tel, Fak, license, internet, ram, cpu, imagePath); return recv_writeVLdata(); } - public void send_writeVLdata(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu) throws org.apache.thrift.TException + public void send_writeVLdata(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath) throws org.apache.thrift.TException { writeVLdata_args args = new writeVLdata_args(); args.setImagename(imagename); @@ -198,6 +198,7 @@ public class Server { args.setInternet(internet); args.setRam(ram); args.setCpu(cpu); + args.setImagePath(imagePath); sendBase("writeVLdata", args); } @@ -525,9 +526,9 @@ public class Server { } } - public void writeVLdata(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + public void writeVLdata(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { checkReady(); - writeVLdata_call method_call = new writeVLdata_call(imagename, firstname, lastname, university, Mail, Tel, Fak, license, internet, ram, cpu, resultHandler, this, ___protocolFactory, ___transport); + writeVLdata_call method_call = new writeVLdata_call(imagename, firstname, lastname, university, Mail, Tel, Fak, license, internet, ram, cpu, imagePath, resultHandler, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } @@ -544,7 +545,8 @@ public class Server { private boolean internet; private long ram; private long cpu; - public writeVLdata_call(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + private String imagePath; + public writeVLdata_call(String imagename, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { super(client, protocolFactory, transport, resultHandler, false); this.imagename = imagename; this.firstname = firstname; @@ -557,6 +559,7 @@ public class Server { this.internet = internet; this.ram = ram; this.cpu = cpu; + this.imagePath = imagePath; } public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { @@ -573,6 +576,7 @@ public class Server { args.setInternet(internet); args.setRam(ram); args.setCpu(cpu); + args.setImagePath(imagePath); args.write(prot); prot.writeMessageEnd(); } @@ -1004,7 +1008,7 @@ public class Server { public writeVLdata_result getResult(I iface, writeVLdata_args args) throws org.apache.thrift.TException { writeVLdata_result result = new writeVLdata_result(); - result.success = iface.writeVLdata(args.imagename, args.firstname, args.lastname, args.university, args.Mail, args.Tel, args.Fak, args.license, args.internet, args.ram, args.cpu); + result.success = iface.writeVLdata(args.imagename, args.firstname, args.lastname, args.university, args.Mail, args.Tel, args.Fak, args.license, args.internet, args.ram, args.cpu, args.imagePath); result.setSuccessIsSet(true); return result; } @@ -1403,7 +1407,7 @@ public class Server { } public void start(I iface, writeVLdata_args args, org.apache.thrift.async.AsyncMethodCallback<Boolean> resultHandler) throws TException { - iface.writeVLdata(args.imagename, args.firstname, args.lastname, args.university, args.Mail, args.Tel, args.Fak, args.license, args.internet, args.ram, args.cpu,resultHandler); + iface.writeVLdata(args.imagename, args.firstname, args.lastname, args.university, args.Mail, args.Tel, args.Fak, args.license, args.internet, args.ram, args.cpu, args.imagePath,resultHandler); } } @@ -3855,6 +3859,7 @@ public class Server { private static final org.apache.thrift.protocol.TField INTERNET_FIELD_DESC = new org.apache.thrift.protocol.TField("internet", org.apache.thrift.protocol.TType.BOOL, (short)-9); private static final org.apache.thrift.protocol.TField RAM_FIELD_DESC = new org.apache.thrift.protocol.TField("ram", org.apache.thrift.protocol.TType.I64, (short)-10); private static final org.apache.thrift.protocol.TField CPU_FIELD_DESC = new org.apache.thrift.protocol.TField("cpu", org.apache.thrift.protocol.TType.I64, (short)-11); + private static final org.apache.thrift.protocol.TField IMAGE_PATH_FIELD_DESC = new org.apache.thrift.protocol.TField("imagePath", org.apache.thrift.protocol.TType.STRING, (short)-12); private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); static { @@ -3873,6 +3878,7 @@ public class Server { public boolean internet; // required public long ram; // required public long cpu; // required + public String imagePath; // required /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { @@ -3886,7 +3892,8 @@ public class Server { LICENSE((short)-8, "license"), INTERNET((short)-9, "internet"), RAM((short)-10, "ram"), - CPU((short)-11, "cpu"); + CPU((short)-11, "cpu"), + IMAGE_PATH((short)-12, "imagePath"); private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); @@ -3923,6 +3930,8 @@ public class Server { return RAM; case -11: // CPU return CPU; + case -12: // IMAGE_PATH + return IMAGE_PATH; default: return null; } @@ -3993,6 +4002,8 @@ public class Server { new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64 , "int"))); tmpMap.put(_Fields.CPU, new org.apache.thrift.meta_data.FieldMetaData("cpu", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64 , "int"))); + tmpMap.put(_Fields.IMAGE_PATH, new org.apache.thrift.meta_data.FieldMetaData("imagePath", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(writeVLdata_args.class, metaDataMap); } @@ -4011,7 +4022,8 @@ public class Server { boolean license, boolean internet, long ram, - long cpu) + long cpu, + String imagePath) { this(); this.imagename = imagename; @@ -4029,6 +4041,7 @@ public class Server { setRamIsSet(true); this.cpu = cpu; setCpuIsSet(true); + this.imagePath = imagePath; } /** @@ -4061,6 +4074,9 @@ public class Server { this.internet = other.internet; this.ram = other.ram; this.cpu = other.cpu; + if (other.isSetImagePath()) { + this.imagePath = other.imagePath; + } } public writeVLdata_args deepCopy() { @@ -4084,6 +4100,7 @@ public class Server { this.ram = 0; setCpuIsSet(false); this.cpu = 0; + this.imagePath = null; } public String getImagename() { @@ -4346,6 +4363,30 @@ public class Server { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __CPU_ISSET_ID, value); } + public String getImagePath() { + return this.imagePath; + } + + public writeVLdata_args setImagePath(String imagePath) { + this.imagePath = imagePath; + return this; + } + + public void unsetImagePath() { + this.imagePath = null; + } + + /** Returns true if field imagePath is set (has been assigned a value) and false otherwise */ + public boolean isSetImagePath() { + return this.imagePath != null; + } + + public void setImagePathIsSet(boolean value) { + if (!value) { + this.imagePath = null; + } + } + public void setFieldValue(_Fields field, Object value) { switch (field) { case IMAGENAME: @@ -4436,6 +4477,14 @@ public class Server { } break; + case IMAGE_PATH: + if (value == null) { + unsetImagePath(); + } else { + setImagePath((String)value); + } + break; + } } @@ -4474,6 +4523,9 @@ public class Server { case CPU: return Long.valueOf(getCpu()); + case IMAGE_PATH: + return getImagePath(); + } throw new IllegalStateException(); } @@ -4507,6 +4559,8 @@ public class Server { return isSetRam(); case CPU: return isSetCpu(); + case IMAGE_PATH: + return isSetImagePath(); } throw new IllegalStateException(); } @@ -4623,6 +4677,15 @@ public class Server { return false; } + boolean this_present_imagePath = true && this.isSetImagePath(); + boolean that_present_imagePath = true && that.isSetImagePath(); + if (this_present_imagePath || that_present_imagePath) { + if (!(this_present_imagePath && that_present_imagePath)) + return false; + if (!this.imagePath.equals(that.imagePath)) + return false; + } + return true; } @@ -4749,6 +4812,16 @@ public class Server { return lastComparison; } } + lastComparison = Boolean.valueOf(isSetImagePath()).compareTo(other.isSetImagePath()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetImagePath()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.imagePath, other.imagePath); + if (lastComparison != 0) { + return lastComparison; + } + } return 0; } @@ -4840,6 +4913,14 @@ public class Server { sb.append("cpu:"); sb.append(this.cpu); first = false; + if (!first) sb.append(", "); + sb.append("imagePath:"); + if (this.imagePath == null) { + sb.append("null"); + } else { + sb.append(this.imagePath); + } + first = false; sb.append(")"); return sb.toString(); } @@ -4973,6 +5054,14 @@ public class Server { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; + case -12: // IMAGE_PATH + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.imagePath = iprot.readString(); + struct.setImagePathIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; default: org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } @@ -4988,6 +5077,11 @@ public class Server { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); + if (struct.imagePath != null) { + oprot.writeFieldBegin(IMAGE_PATH_FIELD_DESC); + oprot.writeString(struct.imagePath); + oprot.writeFieldEnd(); + } oprot.writeFieldBegin(CPU_FIELD_DESC); oprot.writeI64(struct.cpu); oprot.writeFieldEnd(); @@ -5086,7 +5180,10 @@ public class Server { if (struct.isSetCpu()) { optionals.set(10); } - oprot.writeBitSet(optionals, 11); + if (struct.isSetImagePath()) { + optionals.set(11); + } + oprot.writeBitSet(optionals, 12); if (struct.isSetImagename()) { oprot.writeString(struct.imagename); } @@ -5120,12 +5217,15 @@ public class Server { if (struct.isSetCpu()) { oprot.writeI64(struct.cpu); } + if (struct.isSetImagePath()) { + oprot.writeString(struct.imagePath); + } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, writeVLdata_args struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; - BitSet incoming = iprot.readBitSet(11); + BitSet incoming = iprot.readBitSet(12); if (incoming.get(0)) { struct.imagename = iprot.readString(); struct.setImagenameIsSet(true); @@ -5170,6 +5270,10 @@ public class Server { struct.cpu = iprot.readI64(); struct.setCpuIsSet(true); } + if (incoming.get(11)) { + struct.imagePath = iprot.readString(); + struct.setImagePathIsSet(true); + } } } diff --git a/Dozentenmodulserver/src/server/ServerHandler.java b/Dozentenmodulserver/src/server/ServerHandler.java index 9715b0a4..44f0c216 100644 --- a/Dozentenmodulserver/src/server/ServerHandler.java +++ b/Dozentenmodulserver/src/server/ServerHandler.java @@ -15,10 +15,14 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; + import org.apache.commons.io.FileUtils; import org.apache.thrift.TException; import sql.SQL; +import util.XMLCreator; public class ServerHandler implements Server.Iface { @@ -74,7 +78,7 @@ public class ServerHandler implements Server.Iface { @Override public boolean writeVLdata(String imagename, String firstname, String lastname, String university, String Mail, String Tel, - String Fak, boolean license, boolean internet, long ram, long cpu) + String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath) throws TException { String login="tete"; @@ -82,8 +86,8 @@ public class ServerHandler implements Server.Iface { int pk_person=sql.setPerson(con, login, lastname, firstname, Mail, new Date(), pk_institution); - sql.setImageData(con, pk_person, license, internet, cpu, ram, imagename); - + sql.setImageData(con, pk_person, license, internet, cpu, ram, imagename, imagePath); + // TODO Auto-generated method stub return true; } @@ -184,7 +188,20 @@ public class ServerHandler implements Server.Iface { System.out.println(startDate); sql.setLectureData(con, pk_person, pk_image, imageversion, name, desc, shortdesc, startDate, endDate, isActive); - + XMLCreator xml=new XMLCreator(con, name); + try { + xml.create(name); + System.out.println("creator durch"); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (TransformerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } return false; } diff --git a/Dozentenmodulserver/src/sql/SQL.java b/Dozentenmodulserver/src/sql/SQL.java index 301c7d88..7eca6952 100644 --- a/Dozentenmodulserver/src/sql/SQL.java +++ b/Dozentenmodulserver/src/sql/SQL.java @@ -160,7 +160,7 @@ public class SQL { return -1;
}
- public boolean setImageData(Connection con, int pk_person, boolean license, boolean internet, long cpu, long ram, String imagename)
+ public boolean setImageData(Connection con, int pk_person, boolean license, boolean internet, long cpu, long ram, String imagename, String imagePath)
{
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
@@ -180,7 +180,7 @@ public class SQL { Statement stm=con.createStatement();
Random random=new Random();
int uid=random.nextInt();
- stm.executeUpdate("INSERT INTO `bwLehrpool`.`m_VLData_imageInfo`(`GUID_imageID`,`imageVersion`,`image_name`,`image_path`,`image_lastCall`,`image_create_time`,`image_update_time`,`image_owner`,`image_change_by`,`rec_create_time`,`rec_change_time`,`rec_owner`,`rec_change_by`,`content_operatingSystem`,`status_isCompressed`,`status_isSecure`,`status_isOptimzed`,`status_isValid`,`status_isReady`,`status_isDeleted`,`status_isLastOfficialVersion`,`cond_hasLicenseRestriction`,`cond_hasInternetRestriction`,`cond_minRAM`,`cond_minCPUs`)VALUES('"+uid+"',1,'"+imagename+"','/srv/openslx/nfs/temp/','"+formatter.format(new Date())+"','"+formatter.format(new Date())+"','"+formatter.format(new Date())+"','"+pk_person+"','"+pk_person+"','"+formatter.format(new Date())+"','"+formatter.format(new Date())+"','"+pk_person+"','"+pk_person+"',1,1,1,1,1,1,0,0,'"+license_bol+"','"+internet_bol+"','"+ram+"','"+cpu+"');");
+ stm.executeUpdate("INSERT INTO `bwLehrpool`.`m_VLData_imageInfo`(`GUID_imageID`,`imageVersion`,`image_name`,`image_path`,`image_lastCall`,`image_create_time`,`image_update_time`,`image_owner`,`image_change_by`,`rec_create_time`,`rec_change_time`,`rec_owner`,`rec_change_by`,`content_operatingSystem`,`status_isCompressed`,`status_isSecure`,`status_isOptimzed`,`status_isValid`,`status_isReady`,`status_isDeleted`,`status_isLastOfficialVersion`,`cond_hasLicenseRestriction`,`cond_hasInternetRestriction`,`cond_minRAM`,`cond_minCPUs`)VALUES('"+uid+"',1,'"+imagename+"','"+imagePath+"','"+formatter.format(new Date())+"','"+formatter.format(new Date())+"','"+formatter.format(new Date())+"','"+pk_person+"','"+pk_person+"','"+formatter.format(new Date())+"','"+formatter.format(new Date())+"','"+pk_person+"','"+pk_person+"',1,1,1,1,1,1,0,0,'"+license_bol+"','"+internet_bol+"','"+ram+"','"+cpu+"');");
con.commit();
} catch (SQLException e) {
diff --git a/Dozentenmodulserver/src/util/XMLCreator.java b/Dozentenmodulserver/src/util/XMLCreator.java new file mode 100644 index 00000000..0efb2465 --- /dev/null +++ b/Dozentenmodulserver/src/util/XMLCreator.java @@ -0,0 +1,213 @@ +package util; +import java.io.File; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +public class XMLCreator { + + + /* This class offers methods to create XML files for the (old) version of managing VMware *.vmdks */ + + + + private Connection con = null; + private Statement st = null; + private ResultSet rs = null; + private String vmName; + private String filePath = "/srv/openslx/nfs/temp/"; + + + //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 " + + "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_VLData_lecture.name = "; + + + + public XMLCreator(Connection con) + { + this.con = con; + } + + public XMLCreator(Connection con, String vmName) + { + this.con = con; + this.vmName = vmName; + } + + + public boolean create() throws SQLException, ParserConfigurationException, TransformerException + { + + //System.out.println(query); + + if(con == null || vmName == null) + { + return false; + } + query += "'" + this.vmName + "';"; + + boolean success = startCreation(); + + if(success) + { + return true; + } + + return false; + + } + + //overload method for dynamic setting of param vmName instead of static context above + public boolean create(String vmName) throws SQLException, ParserConfigurationException, TransformerException + { + //System.out.println(query); + + if(con == null || vmName == null) + { + return false; + } + query += "'" + vmName + "';"; + + boolean success = startCreation(); + + if(success) + { + return true; + } + return false; + } + + + private boolean startCreation() throws SQLException, ParserConfigurationException, TransformerException + { + //get needed data from database + st = con.createStatement(); + rs = st.executeQuery(query); + rs.next(); + + //factory + DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); + + // root elements - dynamic content + Document doc = docBuilder.newDocument(); + Element rootElement = doc.createElement("settings"); + doc.appendChild(rootElement); + + Element entry = doc.createElement("eintrag"); + rootElement.appendChild(entry); + + Element prio = doc.createElement("priority"); + entry.appendChild(prio); + prio.setAttribute("param", "0"); + + Comment fComment = doc.createComment("Diesen Abschnitt ergänzen"); + entry.appendChild(fComment); + + Element imgName = doc.createElement("image_name"); + entry.appendChild(imgName); + String imagePath=rs.getString("image_path").substring(rs.getString("image_path").lastIndexOf("/")); + + imgName.setAttribute("param", imagePath); + + Element creator = doc.createElement("creator"); + entry.appendChild(creator); + creator.setAttribute("param", (rs.getString("vorname") + " " + rs.getString("nachname"))); + + Element email = doc.createElement("email"); + entry.appendChild(email); + email.setAttribute("param", rs.getString("mail")); + + //TODO check whether necessary + Element phone = doc.createElement("phone"); + entry.appendChild(phone); + phone.setAttribute("param", ""); + + Element shortDesc = doc.createElement("short_description"); + entry.appendChild(shortDesc); + shortDesc.setAttribute("param", rs.getString("shortdescription")); + + //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")); + + Element os = doc.createElement("os"); + entry.appendChild(os); + os.setAttribute("param", rs.getString("os")); + + Comment sComment = doc.createComment("Diesen Abschnitt ergänzen"); + entry.appendChild(sComment); + + + //static content following - second part of xml descriptor + + + Element netwParam = doc.createElement("network"); + entry.appendChild(netwParam); + netwParam.setAttribute("param", "nat"); + + Element netcParam = doc.createElement("netcard"); + entry.appendChild(netcParam); + netcParam.setAttribute("param", "e1000"); + + + Element vm = doc.createElement("virtualmachine"); + entry.appendChild(vm); + vm.setAttribute("param", "vmware"); + + //TODO Fallunterscheidung + Element icon = doc.createElement("icon"); + entry.appendChild(icon); + icon.setAttribute("param", "windows"); + + Element active = doc.createElement("active"); + entry.appendChild(active); + active.setAttribute("param", "true"); + + Element pools = doc.createElement("pools"); + entry.appendChild(pools); + pools.setAttribute("param", "default"); + + Element enable3d = doc.createElement("enable3d"); + entry.appendChild(enable3d); + enable3d.setAttribute("param", "true"); + + + + //write virtual document to file + TransformerFactory transformerFactory = TransformerFactory.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 + transformer.transform(source, result); + + //cleanup + rs.close(); + st.close(); + + //return + return true; + } +} |
