int ModelicaXML::serializeXMLDocumentToFile(mstring xmlFileName) { // fix the file XMLFormatTarget *myFormatTarget = new LocalFileFormatTarget(X(xmlFileName.c_str())); theOutputDesc->setByteStream(myFormatTarget); // serialize a DOMNode to the local file " domSerializer->write(pModelicaXMLDoc, theOutputDesc); myFormatTarget->flush(); delete myFormatTarget; return 0; }
Triggerconf::~Triggerconf () { if( savechanges ){ // // save file // static const XMLCh gLS [] = {chLatin_L, chLatin_S, chNull}; DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(gLS); DOMLSSerializer* writer = ((DOMImplementationLS*)impl)->createLSSerializer(); if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true)) writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true); if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTBOM, true)) writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTBOM, true); XMLFormatTarget* target = new LocalFileFormatTarget (file.c_str ()); target->flush(); DOMLSOutput* output = ((DOMImplementationLS*)impl)->createLSOutput(); output->setByteStream( target ); writer->write( rootnode , output ); writer->release(); delete target; delete output; } // if( savechanges ) // // delete all stuff here // delete parser; delete errhandler; // // now we can safely terminate xerces // XMLPlatformUtils::Terminate(); }
void PMLDocument::writeFile( string filename ){ DOMWriter *writer = m_impl->createDOMWriter(); m_doc->setEncoding( XS("UTF-8") ); m_doc->setActualEncoding( XS("UTF-8") ); writer->setEncoding( XS("UTF-8")); writer->setErrorHandler( m_err ); // use indentation in written file writer->setFeature( XS("format-pretty-print"), true); XMLFormatTarget *outFile = new LocalFileFormatTarget(filename.c_str()); writer->writeNode( outFile, *m_doc ); outFile->flush(); writer->release(); delete outFile; }
int evaluate(int argc, char ** argv) { char * filename = NULL; char * outfile = NULL; unsigned char * keyStr = NULL; bool doDecrypt = true; bool errorsOccured = false; bool doDecryptElement = false; bool useInteropResolver = false; bool encryptFileAsData = false; bool parseXMLInput = true; bool doXMLOutput = false; bool isXKMSKey = false; XSECCryptoKey * kek = NULL; XSECCryptoKey * key = NULL; int keyLen = 0; encryptionMethod kekAlg = ENCRYPT_NONE; encryptionMethod keyAlg = ENCRYPT_NONE; DOMDocument *doc; unsigned char keyBuf[24]; XMLFormatTarget *formatTarget ; #if defined(_WIN32) && defined (XSEC_HAVE_WINCAPI) HCRYPTPROV win32DSSCSP = 0; // Crypto Providers HCRYPTPROV win32RSACSP = 0; CryptAcquireContext(&win32DSSCSP, NULL, NULL, PROV_DSS, CRYPT_VERIFYCONTEXT); CryptAcquireContext(&win32RSACSP, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); #endif if (argc < 2) { printUsage(); return 2; } // Run through parameters int paramCount = 1; while (paramCount < argc - 1) { if (_stricmp(argv[paramCount], "--decrypt-element") == 0 || _stricmp(argv[paramCount], "-de") == 0) { paramCount++; doDecrypt = true; doDecryptElement = true; doXMLOutput = true; parseXMLInput = true; } else if (_stricmp(argv[paramCount], "--interop") == 0 || _stricmp(argv[paramCount], "-i") == 0) { // Use the interop key resolver useInteropResolver = true; paramCount++; } else if (_stricmp(argv[paramCount], "--encrypt-file") == 0 || _stricmp(argv[paramCount], "-ef") == 0) { // Use this file as the input doDecrypt = false; encryptFileAsData = true; doXMLOutput = true; parseXMLInput = false; paramCount++; } else if (_stricmp(argv[paramCount], "--encrypt-xml") == 0 || _stricmp(argv[paramCount], "-ex") == 0) { // Us this file as an XML input file doDecrypt = false; encryptFileAsData = false; doXMLOutput = true; parseXMLInput = true; paramCount++; } else if (_stricmp(argv[paramCount], "--out-file") == 0 || _stricmp(argv[paramCount], "-o") == 0) { if (paramCount +2 >= argc) { printUsage(); return 1; } paramCount++; outfile = argv[paramCount]; paramCount++; } else if (_stricmp(argv[paramCount], "--xkms") == 0 || _stricmp(argv[paramCount], "-x") == 0) { paramCount++; isXKMSKey = true; } #if defined (XSEC_HAVE_WINCAPI) else if (_stricmp(argv[paramCount], "--wincapi") == 0 || _stricmp(argv[paramCount], "-w") == 0) { // Use the interop key resolver WinCAPICryptoProvider * cp = new WinCAPICryptoProvider(); XSECPlatformUtils::SetCryptoProvider(cp); paramCount++; } #endif #if defined (XSEC_HAVE_NSS) else if (_stricmp(argv[paramCount], "--nss") == 0 || _stricmp(argv[paramCount], "-n") == 0) { // NSS Crypto Provider NSSCryptoProvider * cp = new NSSCryptoProvider(); XSECPlatformUtils::SetCryptoProvider(cp); paramCount++; } #endif else if (_stricmp(argv[paramCount], "--key") == 0 || _stricmp(argv[paramCount], "-k") == 0) { // Have a key! paramCount++; bool isKEK = false; XSECCryptoSymmetricKey::SymmetricKeyType loadKeyAs = XSECCryptoSymmetricKey::KEY_NONE; if (_stricmp(argv[paramCount], "kek") == 0) { isKEK = true; paramCount++; if (paramCount >= argc) { printUsage(); return 2; } } if (_stricmp(argv[paramCount], "3DES") == 0 || _stricmp(argv[paramCount], "AES128") == 0 || _stricmp(argv[paramCount], "AES192") == 0 || _stricmp(argv[paramCount], "AES256") == 0 || _stricmp(argv[paramCount], "AES128-GCM") == 0 || _stricmp(argv[paramCount], "AES192-GCM") == 0 || _stricmp(argv[paramCount], "AES256-GCM") == 0) { if (paramCount +2 >= argc) { printUsage(); return 2; } switch(argv[paramCount][4]) { case '\0' : keyLen = 24; loadKeyAs = XSECCryptoSymmetricKey::KEY_3DES_192; keyAlg = ENCRYPT_3DES_CBC; break; case '2' : keyLen = 16; loadKeyAs = XSECCryptoSymmetricKey::KEY_AES_128; if (isKEK) { kekAlg = ENCRYPT_KW_AES128; } else if (strlen(argv[paramCount]) == 6) { keyAlg = ENCRYPT_AES128_CBC; } else { keyAlg = ENCRYPT_AES128_GCM; } break; case '9' : keyLen = 24; loadKeyAs = XSECCryptoSymmetricKey::KEY_AES_192; if (isKEK) { kekAlg = ENCRYPT_KW_AES192; } else if (strlen(argv[paramCount]) == 6) { keyAlg = ENCRYPT_AES192_CBC; } else { keyAlg = ENCRYPT_AES192_GCM; } break; case '5' : keyLen = 32; loadKeyAs = XSECCryptoSymmetricKey::KEY_AES_256; if (isKEK) { kekAlg = ENCRYPT_KW_AES256; } else if (strlen(argv[paramCount]) == 6) { keyAlg = ENCRYPT_AES256_CBC; } else { keyAlg = ENCRYPT_AES256_GCM; } break; } paramCount++; unsigned char keyStr[64]; if (strlen(argv[paramCount]) > 64) { cerr << "Key string too long\n"; return 2; } XSECCryptoSymmetricKey * sk = XSECPlatformUtils::g_cryptoProvider->keySymmetric(loadKeyAs); if (isXKMSKey) { unsigned char kbuf[XSEC_MAX_HASH_SIZE]; CalculateXKMSKEK((unsigned char *) argv[paramCount], (int) strlen(argv[paramCount]), kbuf, XSEC_MAX_HASH_SIZE); sk->setKey(kbuf, keyLen); } else { memset(keyStr, 0, 64); strcpy((char *) keyStr, argv[paramCount]); sk->setKey(keyStr, keyLen); } paramCount++; if (isKEK) kek = sk; else key = sk; } #if defined (XSEC_HAVE_OPENSSL) else if (_stricmp(argv[paramCount], "RSA") == 0) { // RSA private key file if (paramCount + 3 >= argc) { printUsage(); return 2; } if (!isKEK) { cerr << "RSA private keys may only be KEKs\n"; return 2; } BIO * bioKey; if ((bioKey = BIO_new(BIO_s_file())) == NULL) { cerr << "Error opening private key file\n\n"; return 1; } if (BIO_read_filename(bioKey, argv[paramCount + 1]) <= 0) { cerr << "Error opening private key file\n\n"; return 1; } EVP_PKEY * pkey; pkey = PEM_read_bio_PrivateKey(bioKey,NULL,NULL,argv[paramCount + 2]); if (pkey == NULL) { cerr << "Error loading private key\n\n"; return 1; } kek = new OpenSSLCryptoKeyRSA(pkey); kekAlg = ENCRYPT_RSA_15; EVP_PKEY_free(pkey); BIO_free(bioKey); paramCount += 3; } else if (_stricmp(argv[paramCount], "X509") == 0) { // X509 cert used to load an encrypting key if (paramCount + 2 >= argc) { printUsage(); exit (1); } if (!isKEK) { cerr << "X509 private keys may only be KEKs\n"; return 2; } // Load the encrypting key // For now just read a particular file BIO * bioX509; if ((bioX509 = BIO_new(BIO_s_file())) == NULL) { cerr << "Error opening file\n\n"; exit (1); } if (BIO_read_filename(bioX509, argv[paramCount + 1]) <= 0) { cerr << "Error opening X509 Certificate " << argv[paramCount + 1] << "\n\n"; exit (1); } X509 * x ; x = PEM_read_bio_X509_AUX(bioX509,NULL,NULL,NULL); if (x == NULL) { BIO * bio_err; if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); cerr << "Error loading certificate key\n\n"; ERR_print_errors(bio_err); BIO_free(bio_err); exit (1); } // Now load the key EVP_PKEY *pkey; pkey = X509_get_pubkey(x); if (pkey == NULL || pkey->type != EVP_PKEY_RSA) { cerr << "Error extracting RSA key from certificate" << endl; } kek = new OpenSSLCryptoKeyRSA(pkey); kekAlg = ENCRYPT_RSA_15; // Clean up EVP_PKEY_free (pkey); X509_free(x); BIO_free(bioX509); paramCount += 2; } /* argv[1] = "--x509cert" */ #endif /* XSEC_HAVE_OPENSSL */ else { printUsage(); return 2; } } else { cerr << "Unknown option: " << argv[paramCount] << endl; printUsage(); return 2; } } if (paramCount >= argc) { printUsage(); return 2; } if (outfile != NULL) { formatTarget = new LocalFileFormatTarget(outfile); } else { formatTarget = new StdOutFormatTarget(); } filename = argv[paramCount]; if (parseXMLInput) { XercesDOMParser * parser = new XercesDOMParser; Janitor<XercesDOMParser> j_parser(parser); parser->setDoNamespaces(true); parser->setCreateEntityReferenceNodes(true); // Now parse out file xsecsize_t errorCount = 0; try { parser->parse(filename); errorCount = parser->getErrorCount(); if (errorCount > 0) errorsOccured = true; } catch (const XMLException& e) { cerr << "An error occured during parsing\n Message: " << e.getMessage() << endl; errorsOccured = true; } catch (const DOMException& e) { cerr << "A DOM error occured during parsing\n DOMException code: " << e.code << endl; errorsOccured = true; } if (errorsOccured) { cout << "Errors during parse" << endl; return (2); } /* Now that we have the parsed file, get the DOM document and start looking at it */ doc = parser->adoptDocument(); } else { // Create an empty document XMLCh tempStr[100]; XMLString::transcode("Core", tempStr, 99); DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr); doc = impl->createDocument( 0, // root element namespace URI. MAKE_UNICODE_STRING("ADoc"), // root element name NULL);// DOMDocumentType()); // document type object (DTD). } XSECProvider prov; XENCCipher * cipher = prov.newCipher(doc); if (kek != NULL) cipher->setKEK(kek); if (key != NULL) cipher->setKey(key); try { if (doDecrypt) { if (useInteropResolver == true) { // Map out base path of the file char path[_MAX_PATH]; char baseURI[(_MAX_PATH * 2) + 10]; getcwd(path, _MAX_PATH); strcpy(baseURI, "file:///"); // Ugly and nasty but quick if (filename[0] != '\\' && filename[0] != '/' && filename[1] != ':') { strcat(baseURI, path); strcat(baseURI, "/"); } else if (path[1] == ':') { path[2] = '\0'; strcat(baseURI, path); } strcat(baseURI, filename); // Find any ':' and "\" characters int lastSlash = 0; for (unsigned int i = 8; i < strlen(baseURI); ++i) { if (baseURI[i] == '\\') { lastSlash = i; baseURI[i] = '/'; } else if (baseURI[i] == '/') lastSlash = i; } // The last "\\" must prefix the filename baseURI[lastSlash + 1] = '\0'; XMLCh * uriT = XMLString::transcode(baseURI); XencInteropResolver ires(doc, &(uriT[8])); XSEC_RELEASE_XMLCH(uriT); cipher->setKeyInfoResolver(&ires); } // Find the EncryptedData node DOMNode * n = findXENCNode(doc, "EncryptedData"); if (doDecryptElement) { while (n != NULL) { // decrypt cipher->decryptElement(static_cast<DOMElement *>(n)); // Find the next EncryptedData node n = findXENCNode(doc, "EncryptedData"); } } else { XSECBinTXFMInputStream * bis = cipher->decryptToBinInputStream(static_cast<DOMElement *>(n)); Janitor<XSECBinTXFMInputStream> j_bis(bis); XMLByte buf[1024]; xsecsize_t read = bis->readBytes(buf, 1023); while (read > 0) { formatTarget->writeChars(buf, read, NULL); read = bis->readBytes(buf, 1023); } } } else { XENCEncryptedData *xenc = NULL; // Encrypting if (kek != NULL && key == NULL) { XSECPlatformUtils::g_cryptoProvider->getRandom(keyBuf, 24); XSECCryptoSymmetricKey * k = XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_3DES_192); k->setKey(keyBuf, 24); cipher->setKey(k); keyAlg = ENCRYPT_3DES_CBC; keyStr = keyBuf; keyLen = 24; } if (encryptFileAsData) { // Create a BinInputStream #if defined(XSEC_XERCES_REQUIRES_MEMMGR) BinFileInputStream * is = new BinFileInputStream(filename, XMLPlatformUtils::fgMemoryManager); #else BinFileInputStream * is = new BinFileInputStream(filename); #endif xenc = cipher->encryptBinInputStream(is, keyAlg); // Replace the document element DOMElement * elt = doc->getDocumentElement(); doc->replaceChild(xenc->getElement(), elt); elt->release(); } else { // Document encryption cipher->encryptElement(doc->getDocumentElement(), keyAlg); } // Do we encrypt a created key? if (kek != NULL && xenc != NULL) { XENCEncryptedKey *xkey = cipher->encryptKey(keyStr, keyLen, kekAlg); // Add to the EncryptedData xenc->appendEncryptedKey(xkey); } } if (doXMLOutput) { // Output the result XMLCh core[] = { XERCES_CPP_NAMESPACE_QUALIFIER chLatin_C, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_o, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_r, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_e, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(core); #if defined (XSEC_XERCES_DOMLSSERIALIZER) // DOM L3 version as per Xerces 3.0 API DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer(); Janitor<DOMLSSerializer> j_theSerializer(theSerializer); // Get the config so we can set up pretty printing DOMConfiguration *dc = theSerializer->getDomConfig(); dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, false); // Now create an output object to format to UTF-8 DOMLSOutput *theOutput = ((DOMImplementationLS*)impl)->createLSOutput(); Janitor<DOMLSOutput> j_theOutput(theOutput); theOutput->setEncoding(MAKE_UNICODE_STRING("UTF-8")); theOutput->setByteStream(formatTarget); theSerializer->write(doc, theOutput); #else DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter(); Janitor<DOMWriter> j_theSerializer(theSerializer); theSerializer->setEncoding(MAKE_UNICODE_STRING("UTF-8")); if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, false)) theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, false); theSerializer->writeNode(formatTarget, *doc); #endif cout << endl; } } catch (XSECException &e) { char * msg = XMLString::transcode(e.getMsg()); cerr << "An error occured during encryption/decryption operation\n Message: " << msg << endl; XSEC_RELEASE_XMLCH(msg); errorsOccured = true; if (formatTarget != NULL) delete formatTarget; doc->release(); return 2; } catch (XSECCryptoException &e) { cerr << "An error occured during encryption/decryption operation\n Message: " << e.getMsg() << endl; errorsOccured = true; if (formatTarget != NULL) delete formatTarget; doc->release(); #if defined (XSEC_HAVE_OPENSSL) ERR_load_crypto_strings(); BIO * bio_err; if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); ERR_print_errors(bio_err); #endif return 2; } if (formatTarget != NULL) delete formatTarget; doc->release(); return 0; }
void writeHtmlFile(Tag2Html::MP3Collection* mp3Collection) { XMLPlatformUtils::Initialize(); DOMImplementation* domImplementation = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("core")); // <html> DOMDocument* doc = domImplementation->createDocument(0, XMLString::transcode("html"), 0); DOMDocumentType* docType = domImplementation->createDocumentType(XMLString::transcode("html"), XMLString::transcode(""), XMLString::transcode("")); doc->insertBefore(docType, doc->getDocumentElement()); // <head> DOMElement* head = doc->createElement(XMLString::transcode("head")); // <link rel="stylesheet" type="text/css" href="./index.css"> DOMElement* linkStylesheet = doc->createElement(XMLString::transcode("link")); linkStylesheet->setAttribute(XMLString::transcode("rel"), XMLString::transcode("stylesheet")); linkStylesheet->setAttribute(XMLString::transcode("type"), XMLString::transcode("text/css")); linkStylesheet->setAttribute(XMLString::transcode("href"), XMLString::transcode("index.css")); head->appendChild(linkStylesheet); // <title>MP3-Leser</title> DOMElement* title = doc->createElement(XMLString::transcode("title")); title->setTextContent(XMLString::transcode("MP3-Leser")); head->appendChild(title); // <meta http-equiv="Content-Type" content="text/html" charset="utf-8"> DOMElement* meta = doc->createElement(XMLString::transcode("meta")); meta->setAttribute(XMLString::transcode("http-equiv"), XMLString::transcode("Content-Type")); meta->setAttribute(XMLString::transcode("content"), XMLString::transcode("text/html")); meta->setAttribute(XMLString::transcode("charset"), XMLString::transcode("utf-8")); head->appendChild(meta); // <body> DOMElement* body = doc->createElement(XMLString::transcode("body")); // <h1> DOMElement* h1 = doc->createElement(XMLString::transcode("h1")); // Track List ( view <a href="stats.html">stats</a>, <a href="info.html">info</a> ) h1->appendChild(doc->createTextNode(XMLString::transcode("Track List ( view "))); DOMElement* statsLink = doc->createElement(XMLString::transcode("a")); statsLink->setAttribute(XMLString::transcode("href"), XMLString::transcode("stats.html")); statsLink->setTextContent(XMLString::transcode("stats")); h1->appendChild(statsLink); h1->appendChild(doc->createTextNode(XMLString::transcode(", "))); DOMElement* infoLink = doc->createElement(XMLString::transcode("a")); infoLink->setAttribute(XMLString::transcode("href"), XMLString::transcode("info.html")); infoLink->setTextContent(XMLString::transcode("info")); h1->appendChild(infoLink); h1->appendChild(doc->createTextNode(XMLString::transcode(" )"))); body->appendChild(h1); // <table align="center" width="1000"> DOMElement* table = doc->createElement(XMLString::transcode("table")); table->setAttribute(XMLString::transcode("align"), XMLString::transcode("center")); // <thead> DOMElement* tHead = doc->createElement(XMLString::transcode("thead")); // <tr bgcolor="#CCCCCC"> DOMElement* tHeadRow = doc->createElement(XMLString::transcode("tr")); tHeadRow->setAttribute(XMLString::transcode("bgcolor"), XMLString::transcode("#CCCCCC")); // <th>Track</th> DOMElement* tHeadColumnTrack = doc->createElement(XMLString::transcode("th")); tHeadColumnTrack->setTextContent(XMLString::transcode("Track")); tHeadRow->appendChild(tHeadColumnTrack); // <th>Artist</th> DOMElement* tHeadColumnArtist = doc->createElement(XMLString::transcode("th")); tHeadColumnArtist->setTextContent(XMLString::transcode("Artist")); tHeadRow->appendChild(tHeadColumnArtist); // <th>Title</th> DOMElement* tHeadColumnTitle = doc->createElement(XMLString::transcode("th")); tHeadColumnTitle->setTextContent(XMLString::transcode("Title")); tHeadRow->appendChild(tHeadColumnTitle); // <th>Album</th> DOMElement* tHeadColumnAlbum = doc->createElement(XMLString::transcode("th")); tHeadColumnAlbum->setTextContent(XMLString::transcode("Album")); tHeadRow->appendChild(tHeadColumnAlbum); // <th>Year</th> DOMElement* tHeadColumnYear = doc->createElement(XMLString::transcode("th")); tHeadColumnYear->setTextContent(XMLString::transcode("Year")); tHeadRow->appendChild(tHeadColumnYear); // <th>Genre</th> DOMElement* tHeadColumnGenre = doc->createElement(XMLString::transcode("th")); tHeadColumnGenre->setTextContent(XMLString::transcode("Genre")); tHeadRow->appendChild(tHeadColumnGenre); // <th>Comment</th> DOMElement* tHeadColumnComment = doc->createElement(XMLString::transcode("th")); tHeadColumnComment->setTextContent(XMLString::transcode("Comment")); tHeadRow->appendChild(tHeadColumnComment); // <th>Length</th> DOMElement* tHeadColumnLength = doc->createElement(XMLString::transcode("th")); tHeadColumnLength->setTextContent(XMLString::transcode("Length")); tHeadRow->appendChild(tHeadColumnLength); // <th>Filename</th> DOMElement* tHeadColumnFilename = doc->createElement(XMLString::transcode("th")); tHeadColumnFilename->setTextContent(XMLString::transcode("Filename")); tHeadRow->appendChild(tHeadColumnFilename); tHead->appendChild(tHeadRow); table->appendChild(tHead); // <tbody> DOMElement* tBody = doc->createElement(XMLString::transcode("tbody")); ostringstream convert; list<Tag2Html::MP3Infos*> sortedList = mp3Collection->getSortedList(); for (list<Tag2Html::MP3Infos*>::iterator mp3info = sortedList.begin(); mp3info != sortedList.end(); mp3info++) { DOMElement* row = doc->createElement(XMLString::transcode("tr")); convert.str(""); convert << (*mp3info)->track; DOMElement* trackColumn = doc->createElement(XMLString::transcode("td")); trackColumn->setTextContent(XMLString::transcode(convert.str().c_str())); row->appendChild(trackColumn); DOMElement* artistColumn = doc->createElement(XMLString::transcode("td")); artistColumn->setTextContent(XMLString::transcode((*mp3info)->artist.c_str())); row->appendChild(artistColumn); DOMElement* titleColumn = doc->createElement(XMLString::transcode("td")); titleColumn->setTextContent(XMLString::transcode((*mp3info)->title.c_str())); row->appendChild(titleColumn); DOMElement* albumColumn = doc->createElement(XMLString::transcode("td")); albumColumn->setTextContent(XMLString::transcode((*mp3info)->album.c_str())); row->appendChild(albumColumn); convert.str(""); convert << (*mp3info)->year; DOMElement* yearColumn = doc->createElement(XMLString::transcode("td")); yearColumn->setTextContent(XMLString::transcode(convert.str().c_str())); row->appendChild(yearColumn); DOMElement* genreColumn = doc->createElement(XMLString::transcode("td")); genreColumn->setTextContent(XMLString::transcode((*mp3info)->genre.c_str())); row->appendChild(genreColumn); DOMElement* commentColumn = doc->createElement(XMLString::transcode("td")); commentColumn->setTextContent(XMLString::transcode((*mp3info)->comment.c_str())); row->appendChild(commentColumn); DOMElement* lengthColumn = doc->createElement(XMLString::transcode("td")); if ((*mp3info)->length < 3600) { char trackLength[12]; struct tm* timeinfo = new tm(); int seconds = (*mp3info)->length; if (seconds >= 60) { int minutes = seconds / 60; if (minutes >= 60) { timeinfo->tm_hour = minutes / 60; timeinfo->tm_min = minutes / 60; } else { timeinfo->tm_min = seconds / 60; } } timeinfo->tm_sec = seconds % 60; strftime(trackLength, 12, "%H:%M:%S", timeinfo); lengthColumn->setTextContent(XMLString::transcode(trackLength)); } row->appendChild(lengthColumn); DOMElement* filenameColumn = doc->createElement(XMLString::transcode("td")); filenameColumn->setTextContent(XMLString::transcode((*mp3info)->filename.c_str())); row->appendChild(filenameColumn); tBody->appendChild(row); } table->appendChild(tBody); body->appendChild(table); doc->getDocumentElement()->appendChild(head); doc->getDocumentElement()->appendChild(body); DOMWriter* writer = ((DOMImplementationLS*)domImplementation)->createDOMWriter(); if (writer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true)) { writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true); } if (writer->canSetFeature(XMLUni::fgDOMXMLDeclaration, false)) { writer->setFeature(XMLUni::fgDOMXMLDeclaration, false); } XMLFormatTarget *fileFormatTarget = new LocalFileFormatTarget("index.html"); writer->writeNode(fileFormatTarget, *doc); fileFormatTarget->flush(); writer->release(); doc->release(); XMLPlatformUtils::Terminate(); writeCssFile(); writeStatFile(mp3Collection); writeInfoFile(mp3Collection); }
void writeInfoFile(Tag2Html::MP3Collection* mp3Collection) { ostringstream convert; XMLPlatformUtils::Initialize(); DOMImplementation* domImplementation = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("core")); // <html> DOMDocument* doc = domImplementation->createDocument(0, XMLString::transcode("html"), 0); DOMDocumentType* docType = domImplementation->createDocumentType(XMLString::transcode("html"), XMLString::transcode(""), XMLString::transcode("")); doc->insertBefore(docType, doc->getDocumentElement()); // <head> DOMElement* head = doc->createElement(XMLString::transcode("head")); // <link rel="stylesheet" type="text/css" href="./index.css"> DOMElement* headLink = doc->createElement(XMLString::transcode("link")); headLink->setAttribute(XMLString::transcode("rel"), XMLString::transcode("stylesheet")); headLink->setAttribute(XMLString::transcode("type"), XMLString::transcode("text/css")); headLink->setAttribute(XMLString::transcode("href"), XMLString::transcode("index.css")); head->appendChild(headLink); // <title>tag2html info page</title> DOMElement* headTitle = doc->createElement(XMLString::transcode("title")); headTitle->setTextContent(XMLString::transcode("tag2html info page")); head->appendChild(headTitle); // <meta http-equiv="Content-Type" content="text/html" charset="utf-8"> DOMElement* headMeta = doc->createElement(XMLString::transcode("meta")); headMeta->setAttribute(XMLString::transcode("http-equiv"), XMLString::transcode("Content-Type")); headMeta->setAttribute(XMLString::transcode("content"), XMLString::transcode("text/html")); headMeta->setAttribute(XMLString::transcode("charset"), XMLString::transcode("utf-8")); head->appendChild(headMeta); // <body> DOMElement* body = doc->createElement(XMLString::transcode("body")); // <h1>File Info</h1> DOMElement* h1 = doc->createElement(XMLString::transcode("h1")); h1->setTextContent(XMLString::transcode("File Info")); body->appendChild(h1); // <table align="center"> DOMElement* table = doc->createElement(XMLString::transcode("table")); table->setAttribute(XMLString::transcode("align"), XMLString::transcode("center")); // <thead> DOMElement* tHead = doc->createElement(XMLString::transcode("thead")); // <tr bgcolor="#CCCCCC"> DOMElement* tHeadRow = doc->createElement(XMLString::transcode("tr")); tHeadRow->setAttribute(XMLString::transcode("bgcolor"), XMLString::transcode("#CCCCCC")); // <th style="width: 100px; font-weight: bold;">Filename</th> DOMElement* tHeadColumn1 = doc->createElement(XMLString::transcode("th")); tHeadColumn1->setTextContent(XMLString::transcode("Filename")); tHeadRow->appendChild(tHeadColumn1); // <th style="width: 50px; font-weight: bold;">Bitrate</th> DOMElement* tHeadColumn2 = doc->createElement(XMLString::transcode("th")); tHeadColumn2->setTextContent(XMLString::transcode("Bitrate")); tHeadRow->appendChild(tHeadColumn2); // <th style="width: 100px; font-weight: bold;">MPEG Audio Version</th> DOMElement* tHeadColumn3 = doc->createElement(XMLString::transcode("th")); tHeadColumn3->setTextContent(XMLString::transcode("MPEG Audio Version")); tHeadRow->appendChild(tHeadColumn3); // <th style="width: 100px; font-weight: bold;">Layer</th> DOMElement* tHeadColumn4 = doc->createElement(XMLString::transcode("th")); tHeadColumn4->setTextContent(XMLString::transcode("Layer")); tHeadRow->appendChild(tHeadColumn4); // <th style="width: 100px; font-weight: bold;">Error Protection</th> DOMElement* tHeadColumn5 = doc->createElement(XMLString::transcode("th")); tHeadColumn5->setTextContent(XMLString::transcode("Error Protection")); tHeadRow->appendChild(tHeadColumn5); // <th style="width: 100px; font-weight: bold;">Sampling Rate</th> DOMElement* tHeadColumn6 = doc->createElement(XMLString::transcode("th")); tHeadColumn6->setTextContent(XMLString::transcode("Sampling Rate")); tHeadRow->appendChild(tHeadColumn6); // <th style="width: 50px; font-weight: bold;">Private</th> DOMElement* tHeadColumn7 = doc->createElement(XMLString::transcode("th")); tHeadColumn7->setTextContent(XMLString::transcode("Private")); tHeadRow->appendChild(tHeadColumn7); // <th style="width: 100px; font-weight: bold;">Channel Mode</th> DOMElement* tHeadColumn8 = doc->createElement(XMLString::transcode("th")); tHeadColumn8->setTextContent(XMLString::transcode("Channel Mode")); tHeadRow->appendChild(tHeadColumn8); // <th style="width: 100px; font-weight: bold;">Copyright</th> DOMElement* tHeadColumn9 = doc->createElement(XMLString::transcode("th")); tHeadColumn9->setTextContent(XMLString::transcode("Copyright")); tHeadRow->appendChild(tHeadColumn9); // <th style="width: 50px; font-weight: bold;">Original</th> DOMElement* tHeadColumn10 = doc->createElement(XMLString::transcode("th")); tHeadColumn10->setTextContent(XMLString::transcode("Original")); tHeadRow->appendChild(tHeadColumn10); // <th style="width: 100px; font-weight: bold;">Emphasis</th> DOMElement* tHeadColumn11 = doc->createElement(XMLString::transcode("th")); tHeadColumn11->setTextContent(XMLString::transcode("Emphasis")); tHeadRow->appendChild(tHeadColumn11); tHead->appendChild(tHeadRow); table->appendChild(tHead); // <tbody> DOMElement* tBody = doc->createElement(XMLString::transcode("tbody")); list<Tag2Html::MP3Infos*> sortedList = mp3Collection->getSortedList(); for (list<Tag2Html::MP3Infos*>::iterator mp3info = sortedList.begin(); mp3info != sortedList.end(); mp3info++) { // <tr> DOMElement* currentRow = doc->createElement(XMLString::transcode("tr")); // <td>" << mytag->filename << "</td> DOMElement* columnFilename = doc->createElement(XMLString::transcode("td")); columnFilename->setTextContent(XMLString::transcode((*mp3info)->filename.c_str())); currentRow->appendChild(columnFilename); // <td>" << myheader->Bitrate << "</td> DOMElement* columnBitrate = doc->createElement(XMLString::transcode("td")); convert.str(""); convert << (*mp3info)->bitrate << " kbit/s"; columnBitrate->setTextContent(XMLString::transcode(convert.str().c_str())); currentRow->appendChild(columnBitrate); // <td>" << myheader->MPEG_Audio_Version << "</td> DOMElement* columnMPEGAudioVersion = doc->createElement(XMLString::transcode("td")); switch((*mp3info)->version) { case TagLib::MPEG::Header::Version::Version1: columnMPEGAudioVersion->setTextContent(XMLString::transcode("1")); break; case TagLib::MPEG::Header::Version::Version2: columnMPEGAudioVersion->setTextContent(XMLString::transcode("2")); break; case TagLib::MPEG::Header::Version::Version2_5: columnMPEGAudioVersion->setTextContent(XMLString::transcode("2.5")); break; } currentRow->appendChild(columnMPEGAudioVersion); // <td>" << myheader->Layer << "</td> DOMElement* columnLayer = doc->createElement(XMLString::transcode("td")); convert.str(""); convert << (*mp3info)->layer; columnLayer->setTextContent(XMLString::transcode(convert.str().c_str())); currentRow->appendChild(columnLayer); // <td>" << myheader->Error_Protection << "</td> DOMElement* columnErrorProtection = doc->createElement(XMLString::transcode("td")); if ((*mp3info)->protectionEnabled) { columnErrorProtection->setTextContent(XMLString::transcode("yes")); } else { columnErrorProtection->setTextContent(XMLString::transcode("no")); } currentRow->appendChild(columnErrorProtection); // <td>" << myheader->Samplerate << "</td> DOMElement* columnSamplerate = doc->createElement(XMLString::transcode("td")); convert.str(""); convert << (*mp3info)->samplerate << " Hz"; columnSamplerate->setTextContent(XMLString::transcode(convert.str().c_str())); currentRow->appendChild(columnSamplerate); // <td>" << myheader->Private << "</td> DOMElement* columnPrivate = doc->createElement(XMLString::transcode("td")); columnPrivate->setTextContent(XMLString::transcode("")); currentRow->appendChild(columnPrivate); // <td>" << myheader->Channel_Mode << "</td> DOMElement* columnChannelMode = doc->createElement(XMLString::transcode("td")); switch((*mp3info)->channelMode) { case TagLib::MPEG::Header::ChannelMode::DualChannel: columnChannelMode->setTextContent(XMLString::transcode("Dual Channel")); break; case TagLib::MPEG::Header::ChannelMode::JointStereo: columnChannelMode->setTextContent(XMLString::transcode("Joint Stereo")); break; case TagLib::MPEG::Header::ChannelMode::SingleChannel: columnChannelMode->setTextContent(XMLString::transcode("Single Channel")); break; case TagLib::MPEG::Header::ChannelMode::Stereo: columnChannelMode->setTextContent(XMLString::transcode("Stereo")); break; } currentRow->appendChild(columnChannelMode); // <td>" << myheader->Copyright << "</td> DOMElement* columnCopyright = doc->createElement(XMLString::transcode("td")); if ((*mp3info)->isCopyrighted) { columnCopyright->setTextContent(XMLString::transcode("yes")); } else { columnCopyright->setTextContent(XMLString::transcode("no")); } currentRow->appendChild(columnCopyright); // <td>" << myheader->Original << "</td> DOMElement* columnOriginal = doc->createElement(XMLString::transcode("td")); if ((*mp3info)->isOriginal) { columnOriginal->setTextContent(XMLString::transcode("yes")); } else { columnOriginal->setTextContent(XMLString::transcode("no")); } currentRow->appendChild(columnOriginal); // <td>" << myheader->Emphasis << "</td> DOMElement* columnEmphasis = doc->createElement(XMLString::transcode("td")); columnEmphasis->setTextContent(XMLString::transcode("")); currentRow->appendChild(columnEmphasis); tBody->appendChild(currentRow); } table->appendChild(tBody); body->appendChild(table); doc->getDocumentElement()->appendChild(head); doc->getDocumentElement()->appendChild(body); DOMWriter* writer = ((DOMImplementationLS*)domImplementation)->createDOMWriter(); if (writer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true)) { writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true); } if (writer->canSetFeature(XMLUni::fgDOMXMLDeclaration, false)) { writer->setFeature(XMLUni::fgDOMXMLDeclaration, false); } XMLFormatTarget *fileFormatTarget = new LocalFileFormatTarget("info.html"); writer->writeNode(fileFormatTarget, *doc); fileFormatTarget->flush(); writer->release(); doc->release(); XMLPlatformUtils::Terminate(); }
void writeStatFile(Tag2Html::MP3Collection* mp3Collection) { ostringstream convert; XMLPlatformUtils::Initialize(); DOMImplementation* domImplementation = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("core")); // <html> DOMDocument* doc = domImplementation->createDocument(0, XMLString::transcode("html"), 0); DOMDocumentType* docType = domImplementation->createDocumentType(XMLString::transcode("html"), XMLString::transcode(""), XMLString::transcode("")); doc->insertBefore(docType, doc->getDocumentElement()); // <head> DOMElement* head = doc->createElement(XMLString::transcode("head")); // <link rel="stylesheet" type="text/css" href="index.css"> DOMElement* headLink = doc->createElement(XMLString::transcode("link")); headLink->setAttribute(XMLString::transcode("rel"), XMLString::transcode("stylesheet")); headLink->setAttribute(XMLString::transcode("type"), XMLString::transcode("text/css")); headLink->setAttribute(XMLString::transcode("href"), XMLString::transcode("index.css")); head->appendChild(headLink); // <title>tag2html stat page</title> DOMElement* headTitle = doc->createElement(XMLString::transcode("title")); headTitle->setTextContent(XMLString::transcode("tag2html stat page")); head->appendChild(headTitle); // <meta http-equiv="Content-Type" content="text/html" charset="utf-8"> DOMElement* headMeta = doc->createElement(XMLString::transcode("meta")); headMeta->setAttribute(XMLString::transcode("http-equiv"), XMLString::transcode("Content-Type")); headMeta->setAttribute(XMLString::transcode("content"), XMLString::transcode("text/html")); headMeta->setAttribute(XMLString::transcode("charset"), XMLString::transcode("utf-8")); head->appendChild(headMeta); // <body> DOMElement* body = doc->createElement(XMLString::transcode("body")); // <br><br><br> body->appendChild(doc->createElement(XMLString::transcode("br"))); body->appendChild(doc->createElement(XMLString::transcode("br"))); body->appendChild(doc->createElement(XMLString::transcode("br"))); // <table align="center" width="300"> DOMElement* table = doc->createElement(XMLString::transcode("table")); table->setAttribute(XMLString::transcode("align"), XMLString::transcode("center")); table->setAttribute(XMLString::transcode("width"), XMLString::transcode("300")); // <tbody> DOMElement* tbody = doc->createElement(XMLString::transcode("tbody")); // <tr valign="top" bgcolor="#CCCCCC"> DOMElement* tableRow = doc->createElement(XMLString::transcode("tr")); tableRow->setAttribute(XMLString::transcode("valign"), XMLString::transcode("top")); tableRow->setAttribute(XMLString::transcode("bgcolor"), XMLString::transcode("#CCCCCC")); // <td align="center"> DOMElement* tableColumn = doc->createElement(XMLString::transcode("td")); tableColumn->setAttribute(XMLString::transcode("align"), XMLString::transcode("center")); tableRow->appendChild(tableColumn); // <b>Statistics</b> DOMElement* columnStatistics = doc->createElement(XMLString::transcode("b")); columnStatistics->setTextContent(XMLString::transcode("Statistics")); tableColumn->appendChild(columnStatistics); // <tr> DOMElement* tableRow2 = doc->createElement(XMLString::transcode("tr")); // <td> DOMElement* tableColumn2 = doc->createElement(XMLString::transcode("td")); // <table class="nb"> DOMElement* innerTable = doc->createElement(XMLString::transcode("table")); innerTable->setAttribute(XMLString::transcode("class"), XMLString::transcode("nb")); // <tr> DOMElement* rowFileType = doc->createElement(XMLString::transcode("tr")); // <td style="font-weight: bold;">File Type:</td> DOMElement* columnFileType = doc->createElement(XMLString::transcode("td")); columnFileType->setAttribute(XMLString::transcode("style"), XMLString::transcode("font-weight: bold;")); columnFileType->setTextContent(XMLString::transcode("File Type:")); rowFileType->appendChild(columnFileType); // <td>MP3</td> DOMElement* columnFileTypeValue = doc->createElement(XMLString::transcode("td")); columnFileTypeValue->setTextContent(XMLString::transcode("MP3")); rowFileType->appendChild(columnFileTypeValue); // <tr> DOMElement* rowFileCount = doc->createElement(XMLString::transcode("tr")); // <td style="font-weight: bold;">File Count:</td> DOMElement* columnFileCount = doc->createElement(XMLString::transcode("td")); columnFileCount->setAttribute(XMLString::transcode("style"), XMLString::transcode("font-weight: bold;")); columnFileCount->setTextContent(XMLString::transcode("File Count:")); rowFileCount->appendChild(columnFileCount); // <td>" << mystat->mp3_count << "</td> DOMElement* columnFileCountValue = doc->createElement(XMLString::transcode("td")); convert.str(""); convert << mp3Collection->items.size(); columnFileCountValue->setTextContent(XMLString::transcode(convert.str().c_str())); rowFileCount->appendChild(columnFileCountValue); // <tr>\n"; DOMElement* rowArtistCount = doc->createElement(XMLString::transcode("tr")); // <td style="font-weight: bold;">Artist Count:</td> DOMElement* columnArtistCount = doc->createElement(XMLString::transcode("td")); columnArtistCount->setAttribute(XMLString::transcode("style"), XMLString::transcode("font-weight: bold;")); columnArtistCount->setTextContent(XMLString::transcode("Artist Count:")); rowArtistCount->appendChild(columnArtistCount); // <td>" << mystat->art_count << "</td> DOMElement* columnArtistCountValue = doc->createElement(XMLString::transcode("td")); convert.str(""); convert << mp3Collection->getArtistCount(); columnArtistCountValue->setTextContent(XMLString::transcode(convert.str().c_str())); rowArtistCount->appendChild(columnArtistCountValue); // <tr> DOMElement* rowAlbumCount = doc->createElement(XMLString::transcode("tr")); // <td style="font-weight: bold;">Album Count:</td> DOMElement* columnAlbumCount = doc->createElement(XMLString::transcode("td")); columnAlbumCount->setAttribute(XMLString::transcode("style"), XMLString::transcode("font-weight: bold;")); columnAlbumCount->setTextContent(XMLString::transcode("Album Count:")); rowAlbumCount->appendChild(columnAlbumCount); // <td>" << mystat->alb_count << "</td> DOMElement* columnAlbumCountValue = doc->createElement(XMLString::transcode("td")); convert.str(""); convert << mp3Collection->getAlbumCount(); columnAlbumCountValue->setTextContent(XMLString::transcode(convert.str().c_str())); rowAlbumCount->appendChild(columnAlbumCountValue); // <tr> DOMElement* rowTotalSize = doc->createElement(XMLString::transcode("tr")); // <td style="font-weight: bold;">Total Size:</td> DOMElement* columnTotalSize = doc->createElement(XMLString::transcode("td")); columnTotalSize->setAttribute(XMLString::transcode("style"), XMLString::transcode("font-weight: bold;")); columnTotalSize->setTextContent(XMLString::transcode("Total Filesize:")); rowTotalSize->appendChild(columnTotalSize); // <td>" << ( mystat->tot_filesize/(1024*1024)) << " MByte</td> DOMElement* columnTotalSizeValue = doc->createElement(XMLString::transcode("td")); convert.str(""); convert << (mp3Collection->getTotalFilesize() / 1024 / 1024) << " MB"; columnTotalSizeValue->setTextContent(XMLString::transcode(convert.str().c_str())); rowTotalSize->appendChild(columnTotalSizeValue); // <tr> DOMElement* rowTotalLength = doc->createElement(XMLString::transcode("tr")); // <td style="font-weight: bold;">Total Length:</td> DOMElement* columnTotalLength = doc->createElement(XMLString::transcode("td")); columnTotalLength->setAttribute(XMLString::transcode("style"), XMLString::transcode("font-weight: bold;")); columnTotalLength->setTextContent(XMLString::transcode("Total Length:")); rowTotalLength->appendChild(columnTotalLength); // <td> ~ " << mystat->tot_length << "</td> DOMElement* columnTotalLengthValue = doc->createElement(XMLString::transcode("td")); convert.str(""); char statLength[12]; struct tm* timeinfo = new tm(); int seconds = mp3Collection->getTotalLength(); if (seconds >= 60) { int minutes = seconds / 60; if (minutes >= 60) { timeinfo->tm_hour = minutes / 60; timeinfo->tm_min = minutes / 60; } else { timeinfo->tm_min = seconds / 60; } } timeinfo->tm_sec = seconds % 60; strftime(statLength, 12, "%H:%M:%S", timeinfo); columnTotalLengthValue->setTextContent(XMLString::transcode(statLength)); rowTotalLength->appendChild(columnTotalLengthValue); innerTable->appendChild(rowFileType); innerTable->appendChild(rowFileCount); innerTable->appendChild(rowArtistCount); innerTable->appendChild(rowAlbumCount); innerTable->appendChild(rowTotalSize); innerTable->appendChild(rowTotalLength); tableColumn2->appendChild(innerTable); tableRow2->appendChild(tableColumn2); tbody->appendChild(tableRow); tbody->appendChild(tableRow2); table->appendChild(tbody); body->appendChild(table); doc->getDocumentElement()->appendChild(head); doc->getDocumentElement()->appendChild(body); DOMWriter* writer = ((DOMImplementationLS*)domImplementation)->createDOMWriter(); if (writer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true)) { writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true); } if (writer->canSetFeature(XMLUni::fgDOMXMLDeclaration, false)) { writer->setFeature(XMLUni::fgDOMXMLDeclaration, false); } XMLFormatTarget *fileFormatTarget = new LocalFileFormatTarget("stats.html"); writer->writeNode(fileFormatTarget, *doc); fileFormatTarget->flush(); writer->release(); doc->release(); XMLPlatformUtils::Terminate(); }
Triggerconf::Triggerconf(string _filename, bool _autocreateitems, bool _mustexist, bool _savechanges) : file( _filename ), autocreate( _autocreateitems ), savechanges( _savechanges ) { rootnode = NULL; goodstate = true; lasterror = ""; try { XMLPlatformUtils::Initialize(); // // if the file does not exists we create it with the root node // but only if the constructor parameter is fine with this // FileHandle filehandle = XMLPlatformUtils::openFile (file.c_str ()); if (filehandle == NULL && _mustexist == false) { static const XMLCh gLS [] = {chLatin_L, chLatin_S, chNull}; DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(gLS); XMLCh* xroot = XMLString::transcode( ROOT_NAME ); DOMDocument* doc = impl->createDocument( 0, xroot, 0 ); DOMElement* elemrt = doc->getDocumentElement(); DOMLSSerializer* writer = ((DOMImplementationLS*)impl)->createLSSerializer(); XMLString::release (&xroot); if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true)) writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true); if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTBOM, true)) writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTBOM, true); XMLFormatTarget* target = new LocalFileFormatTarget (file.c_str ()); target->flush(); DOMLSOutput* output = ((DOMImplementationLS*)impl)->createLSOutput(); output->setByteStream( target ); writer->write( elemrt, output ); writer->release(); doc->release(); delete output; delete target; } else if (filehandle == NULL && _mustexist == true) { setError ("file " + file + " does not exist"); return; } else { XMLPlatformUtils::closeFile (filehandle); } // // parse the file // parser = new XercesDOMParser (); errhandler = (ErrorHandler*) new HandlerBase (); parser->setErrorHandler (errhandler); parser->parse (file.c_str ()); rootnode = getChildOfType (parser->getDocument (), DOMNode::ELEMENT_NODE); if (rootnode != NULL) { char* xmlstring = XMLString::transcode (rootnode->getNodeName ()); if (((string) ROOT_NAME).compare (xmlstring) == 0) resetError(); else setError("invalid root item in file " + file); XMLString::release (&xmlstring); } else setError("parsing xml file " + file + " failed"); } catch (const XMLException& toCatch) { char* message = XMLString::transcode (toCatch.getMessage()); setError ("failed parsing file " + file + ": " + message); XMLString::release(&message); } catch (const DOMException& toCatch) { char* message = XMLString::transcode (toCatch.msg); setError ("failed parsing file " + file + ": " + message); XMLString::release(&message); } catch (...) { setError( "failed parsing file " + file ); } }