Remove dynamic exceptions
[anna.git] / example / core / showLogon / main.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #include <iostream>
10
11 #include <anna/core/core.hpp>
12
13 #include <anna/xml/Node.hpp>
14 #include <anna/xml/Parser.hpp>
15 #include <anna/xml/DocumentFile.hpp>
16 #include <anna/xml/functions.hpp>
17
18 #include <anna/app/Application.hpp>
19
20 #include <anna/core/util/Encoder.hpp>
21
22 class Test : public app::Application {
23 public:
24    Test ();
25    
26    void initialize () noexcept(false);
27    
28 private:
29    void  run () noexcept(false);      
30 };
31
32 using namespace std;
33
34 int main (int argc, const char** argv)
35 {
36    CommandLine& commandLine (CommandLine::instantiate ());
37    Test test;
38
39    try {
40       commandLine.initialize (argv, argc);
41       commandLine.verify ();
42
43       test.start ();
44    }
45    catch (Exception& ex) {
46       cout << ex.asString () << endl;
47    }
48    
49    return 0;
50 }
51
52 Test::Test () : 
53    app::Application ("GenerateLogOn", "Database login keys visualizer", "1.0.0")
54 {
55    CommandLine& commandLine (CommandLine::instantiate ());
56       
57    commandLine.add ("logon", CommandLine::Argument::Mandatory, "XML document with user/password encrypted");
58 }
59
60 void Test::initialize () 
61    noexcept(false)
62 {
63    Encoder::initialize ();   
64    xml::functions::initialize ();
65 }
66
67 void Test::run () 
68    noexcept(false)
69 {
70    CommandLine& commandLine (CommandLine::instantiate ());
71
72    xml::DocumentFile xmlDocument;
73    xml::Parser xmlParser;
74    Encoder encoder;
75    EncodedData edata;  
76    
77    xmlDocument.initialize (commandLine.getValue ("logon"));
78       
79    const xml::Node* root = xmlParser.apply (xmlDocument);
80    
81    edata.initialize (root->find ("User"));   
82    const DataBlock& user = encoder.decode (edata);   
83    cout << "User: " << user.getData () << endl;
84    
85    edata.initialize (root->find ("Password"));
86    const DataBlock& password = encoder.decode (edata);   
87    cout << "Password: " << password.getData () << endl << endl;
88 }
89