Logo Search packages:      
Sourcecode: pcalendar version File versions  Download package

void net::sf::linuxorg::pcal::engine::Engine::saveToFile ( final File  file,
final char[]  password 
) throws ParserConfigurationException, IOException [inline]

Save the current data to the file specified.

Parameters:
file- a file reference
password- a password to be applied to the file. If null - the file will be saved with the original password (or unencrypted as applicable). If empty string - the password will be removed and the file will be unencrypted.
Returns:
true on success
Exceptions:
ParserConfigurationException
IOException

Definition at line 822 of file Engine.java.

References net::sf::linuxorg::pcal::engine::EngineXMLCrypter::encryptXML(), net::sf::linuxorg::pcal::engine::EngineXMLCrypter::generateSecretKey(), modified, saveToFileDates(), saveToFileDateValues(), saveToFileFileProperties(), and setWorkFile().

Referenced by saveToFile(), net::sf::linuxorg::pcal::engine::EngineTest::testEncryptedLoadSave(), and net::sf::linuxorg::pcal::engine::EngineTest::testLoadSave().

      {
            Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

            Element parent_element = doc.createElement("pcalendar"); //$NON-NLS-1$
            doc.appendChild(parent_element);

            Element element = doc.createElement("version"); //$NON-NLS-1$
            element.appendChild(doc.createTextNode(FILE_VERSION));
            parent_element.appendChild(element);

            element = doc.createElement("data"); //$NON-NLS-1$
            parent_element.appendChild(element);
            parent_element = element;

            saveToFileDates(doc, parent_element);
            saveToFileDateValues(doc, parent_element);
            saveToFileFileProperties(doc, parent_element);

            SecretKey secretKey = null;

            if(password != null) {
                  // new password was specified
                  if(password.length > 0) {
                        secretKey = EngineXMLCrypter.generateSecretKey(password);
                  }
            } else {
                  secretKey = workFileKey;
            }

            if(secretKey != null) {
                  doc = EngineXMLCrypter.encryptXML(doc, secretKey);
            }

            GZIPOutputStream zippedFile;

            FileOutputStream fileStream = new FileOutputStream(file);         

            zippedFile =  new GZIPOutputStream(fileStream);

            OutputFormat formatter = new OutputFormat();
            formatter.setPreserveSpace(true);
            XMLSerializer serializer =
                  new XMLSerializer(zippedFile, formatter);
            serializer.serialize(doc);
            zippedFile.finish();

            setWorkFile(file);
            workFileKey = secretKey;
            modified = false;
      }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index