00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00027 #include "profiletoolset.h"
00028
00029 namespace inspectorj {
00030 namespace toolset {
00031
00032 using inspectorj::client::SessionProfile;
00033
00034 ProfileToolSet::ProfileToolSet()
00035 {
00036 }
00037
00038
00039 ProfileToolSet::~ProfileToolSet()
00040 {
00041 }
00042
00043
00047 bool ProfileToolSet::loadProfile(inspectorj::client::SessionProfile& profile, QString fileName) {
00048 return ProfileToolSet::loadProfile(profile, fileName.toLocal8Bit().data());
00049 }
00050
00057 bool ProfileToolSet::loadProfile(inspectorj::client::SessionProfile& profile, char *fileName)
00058 {
00059
00060 TiXmlDocument doc(fileName);
00061 if (doc.LoadFile()) {
00062
00063 TiXmlHandle hDoc(&doc);
00064 TiXmlElement* elem;
00065 TiXmlHandle hRoot(0);
00066
00067 elem = hDoc.FirstChildElement().Element();
00068
00069 if (!elem) return false;
00070
00071 hRoot = TiXmlHandle(elem);
00072
00073
00074 elem = hRoot.FirstChild("profile").Element();
00075 if (!elem) return false;
00076 profile.setName(QString(elem->Attribute("name")));
00077 profile.setFileName(QString(elem->Attribute("file-name")));
00078 hRoot = TiXmlHandle(elem);
00079
00080
00081 elem = hRoot.FirstChild("connection").Element();
00082 if (elem)
00083 {
00084 inspectorj::client::ijConnection conn;
00085 conn.host = elem->Attribute("host");
00086 conn.port = elem->Attribute("port");
00087 profile.setConnection(conn);
00088 } else { return false; }
00089
00090
00091 elem = hRoot.FirstChild("jre-home").Element();
00092 if (elem)
00093 {
00094 QString jreHome(elem->GetText());
00095 profile.setJreHome(jreHome);
00096 } else { return false; }
00097
00098
00099 elem = hRoot.FirstChild("java-options").Element();
00100 if (elem)
00101 {
00102 QString javaOptions(elem->GetText());
00103 profile.setJavaOptions(javaOptions);
00104 } else { return false; }
00105
00106
00107 elem = hRoot.FirstChild("application-args").Element();
00108 if (elem)
00109 {
00110 QString appArgs(elem->GetText());
00111 profile.setApplicationArgs(appArgs);
00112 } else { return false; }
00113
00114
00115 elem = hRoot.FirstChild("application-entry").Element();
00116 if (elem)
00117 {
00118 QString applicationEntry(elem->GetText());
00119 profile.setApplicationEntry(applicationEntry);
00120 } else { return false; }
00121
00122
00123 elem = hRoot.FirstChild("jar-file").Element();
00124 if (elem)
00125 {
00126 QString jarFile(elem->GetText());
00127 if (!jarFile.isEmpty() && jarFile == "true") {
00128 profile.setJarFile(true);
00129 } else {
00130 profile.setJarFile(false);
00131 }
00132 } else { return false; }
00133
00134
00135 elem = hRoot.FirstChild("tomcat-application").Element();
00136 if (elem)
00137 {
00138 QString tomcatApp(elem->GetText());
00139 if (!tomcatApp.isEmpty() && tomcatApp == "true") {
00140 profile.setTomcatApp(true);
00141 } else {
00142 profile.setTomcatApp(false);
00143 }
00144 } else { return false; }
00145
00146
00147 elem = hRoot.FirstChild("external-launch").Element();
00148 if (elem)
00149 {
00150 QString extLaunch(elem->GetText());
00151 if (!extLaunch.isEmpty() && extLaunch == "true") {
00152 profile.setExternalLaunch(true);
00153 } else {
00154 profile.setExternalLaunch(false);
00155 }
00156 } else { return false; }
00157
00158
00159 elem = hRoot.FirstChild("classpath").Element();
00160 if (elem)
00161 {
00162 TiXmlHandle cpRoot(elem);
00163 elem = cpRoot.FirstChild("entry").Element();
00164 QStringList classPaths;
00165 while (elem) {
00166 QString cpEntry(elem->GetText());
00167 classPaths << cpEntry;
00168 elem = elem->NextSiblingElement();
00169 }
00170 profile.setClassPath(classPaths);
00171 } else { return false; }
00172
00173
00174 elem = hRoot.FirstChild("classfilter").Element();
00175 if (elem)
00176 {
00177 TiXmlHandle cfRoot(elem);
00178 elem = cfRoot.FirstChild("entry").Element();
00179 QStringList classFilters;
00180 while (elem) {
00181 QString cfEntry(elem->GetText());
00182 classFilters << cfEntry;
00183 elem = elem->NextSiblingElement();
00184 }
00185 profile.setClassFilters(classFilters);
00186 } else { return false; }
00187
00188 return true;
00189 } else {
00190 return false;
00191 }
00192 }
00193
00200 bool ProfileToolSet::saveProfile(inspectorj::client::SessionProfile &profile, QString dir)
00201 {
00202
00203 QList<void *> ptrs;
00204 TiXmlDocument doc;
00205 TiXmlDeclaration *decl = new TiXmlDeclaration ( "1.0", "", "" );
00206 doc.LinkEndChild( decl );
00207
00208
00209 TiXmlElement *root = new TiXmlElement ("inspectorj");
00210 doc.LinkEndChild(root);
00211
00212
00213 TiXmlComment *comment = new TiXmlComment();
00214 comment->SetValue(" Session Profile for inspectorJ " );
00215 root->LinkEndChild( comment );
00216
00217
00218 TiXmlElement *prof = new TiXmlElement ("profile");
00219 prof->SetAttribute("name", profile.getName().toLocal8Bit().data());
00220 prof->SetAttribute("file-name", profile.getFileName().toLocal8Bit().data());
00221 root->LinkEndChild( prof );
00222
00223
00224 TiXmlElement *conn = new TiXmlElement ("connection");
00225 conn->SetAttribute("host", profile.getConnection().host.toLocal8Bit().data());
00226 conn->SetAttribute("port", profile.getConnection().port.toLocal8Bit().data());
00227 prof->LinkEndChild( conn );
00228
00229
00230 TiXmlElement *jreHome = new TiXmlElement ("jre-home");
00231 TiXmlText *jreHomeText = new TiXmlText (profile.getJreHome().toLocal8Bit().data());
00232 jreHome->LinkEndChild(jreHomeText);
00233 prof->LinkEndChild( jreHome );
00234
00235
00236 TiXmlElement *javaOptions = new TiXmlElement ("java-options");
00237 TiXmlText *javaOptionsText = new TiXmlText (profile.getJavaOptions().toLocal8Bit().data());
00238 javaOptions->LinkEndChild(javaOptionsText);
00239 prof->LinkEndChild( javaOptions );
00240
00241
00242 TiXmlElement *applicationArgs = new TiXmlElement ("application-args");
00243 TiXmlText *applicationArgsText = new TiXmlText (profile.getApplicationArgs().toLocal8Bit().data());
00244 applicationArgs->LinkEndChild(applicationArgsText);
00245 prof->LinkEndChild( applicationArgs );
00246
00247
00248 TiXmlElement *applicationEntry = new TiXmlElement ("application-entry");
00249 TiXmlText *applicationEntryText = new TiXmlText (profile.getApplicationEntry().toLocal8Bit().data());
00250 applicationEntry->LinkEndChild(applicationEntryText);
00251 prof->LinkEndChild( applicationEntry );
00252
00253
00254 TiXmlElement *jarFile = new TiXmlElement ("jar-file");
00255 TiXmlText *jarFileText = new TiXmlText (profile.isJarFile() ? "true" : "false");
00256 jarFile->LinkEndChild(jarFileText);
00257 prof->LinkEndChild( jarFile );
00258
00259
00260 TiXmlElement *tomcatApp = new TiXmlElement ("tomcat-application");
00261 TiXmlText *tomcatAppText = new TiXmlText (profile.isTomcatApp() ? "true" : "false");
00262 tomcatApp->LinkEndChild(tomcatAppText);
00263 prof->LinkEndChild( tomcatApp );
00264
00265
00266 TiXmlElement *externalLaunch = new TiXmlElement ("external-launch");
00267 TiXmlText *externalLaunchText = new TiXmlText (profile.isExternalLaunch() ? "true" : "false");
00268 externalLaunch->LinkEndChild(externalLaunchText);
00269 prof->LinkEndChild( externalLaunch );
00270
00271
00272 TiXmlElement *classPath = new TiXmlElement ("classpath");
00273 TiXmlElement *classPathEntry;
00274 TiXmlText *classPathText;
00275 QStringList cpList = profile.getClassPath();
00276 for (int i = 0; i < cpList.size(); ++i) {
00277 classPathEntry = new TiXmlElement ("entry");
00278 classPathText = new TiXmlText(cpList.at(i).toLocal8Bit().data());
00279 classPathEntry->LinkEndChild(classPathText);
00280 classPath->LinkEndChild(classPathEntry);
00281 }
00282 prof->LinkEndChild( classPath );
00283
00284
00285 TiXmlElement *classFilter = new TiXmlElement ("classfilter");
00286 TiXmlElement *classFilterEntry;
00287 TiXmlText *classFilterText;
00288 QStringList filterList = profile.getClassFilters();
00289 for (int i = 0; i < filterList.size(); ++i) {
00290 classFilterEntry = new TiXmlElement ("entry");
00291 classFilterText = new TiXmlText(filterList.at(i).toLocal8Bit().data());
00292 classFilterEntry->LinkEndChild(classFilterText);
00293 classFilter->LinkEndChild(classFilterEntry);
00294 }
00295 prof->LinkEndChild( classFilter );
00296
00297 QString filePath = dir.append(QDir::separator());
00298 QString fileName = profile.getFileName();
00299 if (fileName.isEmpty()) {
00300 fileName = profile.getName();
00301 }
00302 filePath.append(fileName);
00303 return doc.SaveFile(filePath.toLocal8Bit().data());
00304
00305 }
00306
00307
00308
00309 }
00310 }