<commit_before>/*=========================================================================
 
Program:   openCherry Platform
Language:  C++
Date:      $Date$
Version:   $Revision$
 
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
 
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.
 
=========================================================================*/

#include "cherryBundleManifest.h"

#include "Poco/AutoPtr.h"
#include "Poco/StringTokenizer.h"
#include "Poco/Util/PropertyFileConfiguration.h"

#include <iostream>

namespace cherry {

BundleManifest::BundleManifest(std::istream* istr)
: POLICY_EAGER("eager"), POLICY_LAZY("lazy")
{
  this->ParseManifest(istr);
}

BundleManifest::~BundleManifest()
{
  
}

bool BundleManifest::operator==(const Object* o) const
{
  if (const IBundleManifest* manifest = dynamic_cast<const IBundleManifest*>(o))
    return this->GetSymbolicName() == manifest->GetSymbolicName();
  
  return false;
}
  
const std::string& 
BundleManifest::GetActivatorClass() const
{
  return m_Activator;
}
  
const std::string& 
BundleManifest::GetActivatorLibrary() const
{
  return m_ActivatorLibrary;
}
  
const std::string&
BundleManifest::GetCopyright() const
{
  return m_Copyright;
}
 
IBundleManifest::ActivationPolicy 
BundleManifest::GetActivationPolicy() const
{
  return m_ActivationPolicy;
}

bool
BundleManifest::IsSystemBundle() const
{
  return m_SystemBundle;
}

const std::string&
BundleManifest::GetName() const
{
  return m_Name;
}
  
const BundleManifest::Dependencies&
BundleManifest::GetRequiredBundles() const
{
  return m_Dependencies;
}
  
const std::string&
BundleManifest::GetSymbolicName() const
{
  return m_SymbolicName;
}
  
const std::string& 
BundleManifest::GetVendor() const
{
  return m_Vendor;
}
  
//const Version& GetVersion() const;
  
void 
BundleManifest::ParseActivator(const std::string& activator)
{
  Poco::StringTokenizer tokenizer(activator, ";", 
      Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
  
  m_Activator = tokenizer[0];
  
  m_ActivatorLibrary = "";
  if (tokenizer.count() > 1)
  {
    Poco::StringTokenizer tokenizer2(tokenizer[1], "=",
        Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
    
    if (tokenizer2.count() == 2 && tokenizer2[0] == "library")
    {
      m_ActivatorLibrary = tokenizer[1];
    }
  }
  
}
  
void 
BundleManifest::ParseManifest(std::istream* istr)
{
  //std::cout << "Start parsing manifest\n";
  Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> config(new Poco::Util::PropertyFileConfiguration(*istr));
  
  if (config->hasProperty(BUNDLE_ACTIVATOR))
      this->ParseActivator(config->getString(BUNDLE_ACTIVATOR));
  else<commit_msg>FIX (#1356): fixed crash parsing empty Bundle-Activator <commit_after>/*=========================================================================
 
Program:   openCherry Platform
Language:  C++
Date:      $Date$
Version:   $Revision$
 
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
 
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.
 
=========================================================================*/

#include "cherryBundleManifest.h"

#include "Poco/AutoPtr.h"
#include "Poco/StringTokenizer.h"
#include "Poco/Util/PropertyFileConfiguration.h"

#include <iostream>

namespace cherry {

BundleManifest::BundleManifest(std::istream* istr)
: POLICY_EAGER("eager"), POLICY_LAZY("lazy")
{
  this->ParseManifest(istr);
}

BundleManifest::~BundleManifest()
{
  
}

bool BundleManifest::operator==(const Object* o) const
{
  if (const IBundleManifest* manifest = dynamic_cast<const IBundleManifest*>(o))
    return this->GetSymbolicName() == manifest->GetSymbolicName();
  
  return false;
}
  
const std::string& 
BundleManifest::GetActivatorClass() const
{
  return m_Activator;
}
  
const std::string& 
BundleManifest::GetActivatorLibrary() const
{
  return m_ActivatorLibrary;
}
  
const std::string&
BundleManifest::GetCopyright() const
{
  return m_Copyright;
}
 
IBundleManifest::ActivationPolicy 
BundleManifest::GetActivationPolicy() const
{
  return m_ActivationPolicy;
}

bool
BundleManifest::IsSystemBundle() const
{
  return m_SystemBundle;
}

const std::string&
BundleManifest::GetName() const
{
  return m_Name;
}
  
const BundleManifest::Dependencies&
BundleManifest::GetRequiredBundles() const
{
  return m_Dependencies;
}
  
const std::string&
BundleManifest::GetSymbolicName() const
{
  return m_SymbolicName;
}
  
const std::string& 
BundleManifest::GetVendor() const
{
  return m_Vendor;
}
  
//const Version& GetVersion() const;
  
void 
BundleManifest::ParseActivator(const std::string& activator)
{
  Poco::StringTokenizer tokenizer(activator, ";", 
      Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
  
  if (tokenizer.count() == 0)
  {
    m_Activator = "";
    m_ActivatorLibrary = "";
    return;
  }

  m_Activator = tokenizer[0];
  m_Activator = activator;
  
  m_ActivatorLibrary = "";
  if (tokenizer.count() > 1)
  {
    Poco::StringTokenizer tokenizer2(tokenizer[1], "=",
        Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
    
    if (tokenizer2.count() == 2 && tokenizer2[0] == "library")
    {
      m_ActivatorLibrary = tokenizer[1];
    }
  }
  
}
  
void 
BundleManifest::ParseManifest(std::istream* istr)
{
  //std::cout << "Start parsing manifest\n";
  Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> config(new Poco::Util::PropertyFileConfiguration(*istr));
  
  if (config->hasProperty(BUNDLE_ACTIVATOR))
      this->ParseActivator(config->getString(BUNDLE_ACTIVATOR));
  else
{'fraction_non_alphanumeric': 0.16365105008077543, 'fraction_numerical': 0.003715670436187399, 'mean_word_length': 5.565217391304348, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7063555', 'n_tokens_mistral': 1979, 'n_tokens_neox': 1976, 'n_words': 390}