Ejemplo n.º 1
0
static void readPlugins(const string& id, DOMElement* element,
		FreeAX25::Runtime::UniquePointerDict<FreeAX25::Runtime::Plugin>& plugins)
{
	if (element == nullptr) return;
	auto nodeList = element->getElementsByTagName(toX("Plugin"));
	for (uint32_t i = 0; i < nodeList->getLength(); ++i) {
		auto pluginNode = static_cast<DOMElement*>(nodeList->item(i));
		string name  = fmX(pluginNode->getAttribute(toX("name")));
		auto _file = pluginNode->getAttribute(toX("file"));
		string file = (_file != nullptr) ? fmX(_file) : "";
		FreeAX25::Runtime::env().logDebug(
				"Define plugin " + id + "/" + name + "(" + file + ")");
		auto plugin = new FreeAX25::Runtime::Plugin(name, file);

	    { // Get settings:
			auto nodeList = pluginNode->getElementsByTagName(toX("Settings"));
			if (nodeList->getLength() > 0)
				readSettings(
						id + "/" + name,
						static_cast<DOMElement*>(nodeList->item(0)),
						plugin->settings);
	    }

	    { // Get instances:
			auto nodeList = pluginNode->getElementsByTagName(toX("Instances"));
			if (nodeList->getLength() > 0)
				readInstances(
						id + "/" + name,
						static_cast<DOMElement*>(nodeList->item(0)),
						plugin->instances);
	    }
		plugins.insertNew(name, plugin);
	} // end for //
}
std::vector< Result > AllowedChildrenValidator::ValidateAllowedChildren( 
    const QName &parent_qname, 
    const std::vector< QName > &allowed_children, 
    const xc::DOMDocument &document )
{
    xc::DOMNodeList *parents_matching = document.getElementsByTagNameNS(
        toX( parent_qname.namespace_name ),  toX( parent_qname.local_name ) );

    std::vector< Result > results;

    if ( parents_matching->getLength() < 1 )
    
        return results;    

    xc::DOMElement* parent = static_cast< xc::DOMElement* >( parents_matching->item( 0 ) );
    std::vector< xc::DOMElement* > children = xe::GetElementChildren( *parent );

    for ( uint i = 0; i < children.size(); ++i )
    {
        xc::DOMElement *child = children[ i ];
        QName child_qname( fromX( child->getLocalName() ), fromX( child->getNamespaceURI() ) );

        if ( !Util::Contains< QName >( allowed_children, child_qname ) )

            results.push_back( NotAllowedChildResult( *children[ i ] ) );
    }

    return results;
}
Ejemplo n.º 3
0
std::vector< Result > IdsUnique::ValidateXml(
    const xc::DOMDocument &document,
    const fs::path& )
{
    xc::DOMNodeList *elements = document.getElementsByTagName( toX( "*" ) );

    boost::unordered_set< std::string > ids;
    std::vector< Result > results;

    for ( uint i = 0; i < elements->getLength(); ++i )
    {
        xc::DOMElement *element = static_cast< xc::DOMElement* >( elements->item( i ) );
        std::string id = fromX( element->getAttribute( toX( "id" ) ) );

        if ( !id.empty() )
        {
            if ( ids.count( id ) == 0 )
            {
                ids.insert( id );
            }

            else
            {
                results.push_back( 
                    ResultWithNodeLocation( ERROR_XML_ID_NOT_UNIQUE, *element )
                    .AddMessageArgument( id ) 
                    );
            }
        }
    }

    return results;
}
Ejemplo n.º 4
0
static void readSettings(const string& id, DOMElement* element,
		FreeAX25::Runtime::UniquePointerDict<FreeAX25::Runtime::Setting>& settings)
{
	if (element == nullptr) return;
	auto nodeList = element->getElementsByTagName(toX("Setting"));
	for (uint32_t i = 0; i < nodeList->getLength(); ++i) {
		auto settingElement = static_cast<DOMElement*>(nodeList->item(i));
		string name  = fmX(settingElement->getAttribute(toX("name")));
		string value = fmX(settingElement->getTextContent());
		FreeAX25::Runtime::env().logDebug(
				"Setting " + id + "/" + name + " = \"" + value + "\"");
		settings.insertNew(name, new FreeAX25::Runtime::Setting(name, value));
	} // end for //
}
Ejemplo n.º 5
0
std::vector< Result > WellFormedXml::ValidateFile( const fs::path &filepath )
{
    parser.resetDocumentPool();

    ErrorResultCollector collector;
    parser.setErrorHandler( &collector );

    try
    {
        parser.parse( toX( Util::BoostPathToUtf8Path( filepath ) ) );
    }

    catch ( xc::SAXException& exception )
    {
    	collector.AddNewExceptionAsResult( exception );
    }

    catch ( xc::XMLException& exception )
    {
        collector.AddNewExceptionAsResult( exception );
    }    

    catch ( xc::DOMException& exception )
    {
    	collector.AddNewExceptionAsResult( exception );
    }

    return Util::AddPathToResults( collector.GetResults(), filepath );
}
Ejemplo n.º 6
0
void XMLRuntime::read(const string& filename, FreeAX25::Runtime::Configuration& config) {
    XercesDOMParser parser;
    parser.setValidationScheme(XercesDOMParser::Val_Always);
    parser.setDoNamespaces(true);
    parser.setDoSchema(true);
    parser.setDoXInclude(true);
    parser.setHandleMultipleImports(true);
    parser.setValidationSchemaFullChecking(true);
    parser.setCreateEntityReferenceNodes(false);
    parser.setIncludeIgnorableWhitespace(false);

    DOMTreeErrorReporter errReporter;
    parser.setErrorHandler(&errReporter);

    parser.parse(filename.c_str());

    if (errReporter.getSawErrors())
    	throw exception();

    // Now read configuration from the DOM Tree:
    XERCES_CPP_NAMESPACE::DOMDocument* doc = parser.getDocument();
    assert(doc != nullptr);

    auto rootElement = doc->getDocumentElement();
    auto configName = rootElement->getAttribute(toX("name"));
    config.setId(fmX(configName));

    { // Get settings:
		auto nodeList = rootElement->getElementsByTagName(toX("Settings"));
		if (nodeList->getLength() > 0)
			readSettings(
					"",
					static_cast<DOMElement*>(nodeList->item(0)),
					config.settings);
    }

    { // Get plugins:
		auto nodeList = rootElement->getElementsByTagName(toX("Plugins"));
		if (nodeList->getLength() > 0)
			readPlugins(
					"",
					static_cast<DOMElement*>(nodeList->item(0)),
					config.plugins);
    }
}
Ejemplo n.º 7
0
static void readInstances(const string& id, DOMElement* element,
		FreeAX25::Runtime::UniquePointerDict<FreeAX25::Runtime::Instance>& instances)
{
	if (element == nullptr) return;
	auto nodeList = element->getElementsByTagName(toX("Instance"));
	for (uint32_t i = 0; i < nodeList->getLength(); ++i) {
		auto instanceNode = static_cast<DOMElement*>(nodeList->item(i));
		string name  = fmX(instanceNode->getAttribute(toX("name")));
		FreeAX25::Runtime::env().logDebug(
				"Define instance " + id + "/" + name);
		auto instance = new FreeAX25::Runtime::Instance(name);

	    { // Get client endpoints:
			auto nodeList = instanceNode->getElementsByTagName(toX("ClientEndPoint"));
			for (uint32_t i = 0; i < nodeList->getLength(); ++i) {
				auto instanceNode = static_cast<DOMElement*>(nodeList->item(i));
				string name = fmX(instanceNode->getAttribute(toX("name")));
				string url  = fmX(instanceNode->getAttribute(toX("url")));
				FreeAX25::Runtime::env().logDebug(
						"Define client endpoint " + id + "/" + name + " as " + url);
				auto endpoint = new FreeAX25::Runtime::ClientEndPoint(name, url);
				instance->clientEndPoints.insertNew(name, endpoint);
			} // end for //
	    }

	    { // Get server endpoints:
			auto nodeList = instanceNode->getElementsByTagName(toX("ServerEndPoint"));
			for (uint32_t i = 0; i < nodeList->getLength(); ++i) {
				auto instanceNode = static_cast<DOMElement*>(nodeList->item(i));
				string name = fmX(instanceNode->getAttribute(toX("name")));
				string url  = fmX(instanceNode->getAttribute(toX("url")));
				FreeAX25::Runtime::env().logDebug(
						"Define server endpoint " + id + "/" + name + " as " + url);
				auto endpoint = new FreeAX25::Runtime::ServerEndPoint(name, url);
				instance->serverEndPoints.insertNew(name, endpoint);
			} // end for //
	    }

	    { // Get settings:
			auto nodeList = instanceNode->getElementsByTagName(toX("Settings"));
			if (nodeList->getLength() > 0)
				readSettings(
						id + "/" + name,
						static_cast<DOMElement*>(nodeList->item(0)),
						instance->settings);
	    }

		instances.insertNew(name, instance);
	} // end for //
}
Ejemplo n.º 8
0
Lab_Colour ColourPickerConversions::toLab(RGB_Colour colour)
{
    float X = toX(colour.r, colour.g, colour.b);
    float Y = toY(colour.r, colour.g, colour.b);
    float Z = toZ(colour.r, colour.g, colour.b);

    float L = toL(Y);
    float a = toA(X, Y);
    float b = toB(Y, Z);

    return Lab_Colour(L, a, b);
}
Ejemplo n.º 9
0
std::vector< Result > ElementPresentValidator::VerifyElementPresent( 
    const QName &element_qname, 
    const std::vector< QName > &possible_parents,
    const xc::DOMDocument &document )
{
    xc::DOMNodeList *matching_elements = document.getElementsByTagNameNS(
        toX( element_qname.namespace_name ),  toX( element_qname.local_name ) );

    std::vector< Result > results;

    if ( matching_elements->getLength() < 1 )
    {
        xc::DOMNode* parent = xe::GetFirstAvailableElement( possible_parents, document );

        Result result = parent != NULL                                                   ?
                        ResultWithNodeLocation( ERROR_XML_ELEMENT_NOT_PRESENT, *parent ) :
                        Result( ERROR_XML_ELEMENT_NOT_PRESENT );
                        
        result.AddMessageArgument( element_qname.local_name );
        results.push_back( result );
    }

    return results;
}
Ejemplo n.º 10
0
eFlag Tree::processVertexAfterParse(Sit S, Vertex *v, TreeConstructer* tc)
{
  //be careful with this test, it might be moved deeper inside this 
  //function if needed

  if (v -> vt & VT_TOP_FOREIGN) 
    {
      popVertex();
      return OK;
    }

  XSL_OP theOp;
  if (isXSLElement(v))
    {
      XSLElement *x = toX(v);
      theOp = x -> op;

      if (theOp != XSL_IMPORT) updateImportStatus();

      switch(theOp)
        {
	  //catch xsl:use-attribute-sets
	case XSL_ELEMENT:
	case XSL_COPY: 
	  {
	    E( extractUsedSets(S, toE(v)) );
	    popVertex();
	  }; break;
	case XSL_IMPORT:
	  {
	    if (subtrees.getCurrent() -> getStructure() -> getTopLevelFound())
	      {
		Err2(S, E_ELEM_CONTAINS_ELEM, 
		     xslOpNames[XSL_STYLESHEET], 
		     xslOpNames[XSL_IMPORT]);
	      }
	  }; // no break
	case XSL_INCLUDE:
	  {
	    Attribute *a = NZ( x -> atts.find(XSLA_HREF) );
	    GP( Tree ) srcTree; 
	    const Str& base = S.findBaseURI(a -> getSubtreeInfo() ->
					    getBaseURI());		
	    
	    Str absolute;
	    makeAbsoluteURI(S, a -> cont, base, absolute);
	    if (S.getProcessor())
	      {
		E( S.getProcessor() -> readTreeFromURI(S, srcTree, 
						       a -> cont, base, 
						       FALSE) );
		srcTree.keep();
	      }
	    else
	      {
		//Str absolute;
		//makeAbsoluteURI(a -> cont, base, absolute);
		srcTree = new Tree(absolute, FALSE);
		DataLine d;
		E( d.open(S, absolute, DLMODE_READ, /* argList = */ NULL) );
		E( (*srcTree).parse(S, &d) );
		E( d.close(S) );
	      }
	    
	    Element *theSheet=(*srcTree).findStylesheet((*srcTree).getRoot());
	    if (!theSheet)
		Warn1(S, W_NO_STYLESHEET, (char*)(a -> cont));
	    dropCurrentElement(v);
	    if (!theSheet) // to prevent segfault after include/import failure
		break;
	    
	    OutputterObj source;
	    //we start a subtree to record where the nodes come from
	    //when including, we use the old structure
	    //when importing, Tree creates a new one
	    E( startSubtree(S, (*srcTree).getURI(), theOp) );
	    //set extension namespaces for subtree

	    //(*srcTree).speakDebug();

	    //merge it into the current tree
	    E( tc -> parseUsingSAXForAWhile(S, source, absolute, 
					    TRUE, 
					    (Tree*)srcTree,
					    theSheet -> namespaces) );

	    //first we have to deal with ext. and excl. namespaces
	    Attribute *attr;
	    QName q;
	    //exclusions
	    q.setLocal((*srcTree).unexpand("exclude-result-prefixes"));
	    attr = theSheet->atts.find(q);
	    if (attr)
	      E(pushNamespacePrefixes(S, attr->cont, XSLA_EXCL_RES_PREFIXES));
	    //extensions
	    q.setLocal((*srcTree).unexpand("extension-element-prefixes"));
	    attr = theSheet->atts.find(q);
	    if (attr)
	      E(pushNamespacePrefixes(S, attr->cont, XSLA_EXT_ELEM_PREFIXES));

	    if (theSheet)
	      E( theSheet -> contents.copy(S, source) );
	    E( tc -> parseUsingSAXForAWhileDone(S, source, TRUE) );
	    // end the subtree
	    E( endSubtree(S, theOp) );		
	  }; break;
	case XSL_OUTPUT:
	  {
	    int i, attsNumber = x -> atts.number();
	    Attribute *theAtt;
	    for (i = 0; i < attsNumber; i++)
	      {
		theAtt = toA(x -> atts[i]);
		switch(theAtt -> op)
		  {
		  case XSLA_METHOD:
		    {
		      QName q;
		      EQName eq;
		      E( x -> setLogical(S, 
					 q, theAtt -> cont, FALSE) );
		      expandQ(q, eq);
		      E( outputDef.setItemEQName(S, XSLA_METHOD, 
						 eq, v, 
						 v -> getImportPrecedence()) );
		    }; break;
		  case XSLA_CDATA_SECT_ELEMS:
		    {
		      QName q;
		      Bool someRemains;
		      Str listPart;
		      char *p = theAtt -> cont;
		      do
			{
			  someRemains = getWhDelimString(p, listPart);
			  if (someRemains)
			    {
			      E( x -> setLogical(S, 
						 q, listPart, TRUE) );
			      EQName expanded;
			      expandQ(q, expanded);
			      E( outputDef.setItemEQName(S, 
							 XSLA_CDATA_SECT_ELEMS,
							 expanded, v, 
							 v -> getImportPrecedence()) );
			    };
			}
		      while (someRemains);
		    }; break;
		  case XSLA_NONE: //skip other namespaces
		    break;
		  default:
		    {
		      E( outputDef.setItemStr(S, theAtt -> op, theAtt -> cont, 
					      theAtt, 
					      theAtt -> getImportPrecedence()) );
		      
		    };
		  };
	      }
	    popVertex();
	  }; break;
	case XSL_NAMESPACE_ALIAS:
	  {
	    Phrase style, result, sUri, rUri;
	    Attribute *sp = NZ( x -> atts.find(XSLA_STYLESHEET_PREFIX) );
	    Attribute *rp = NZ( x -> atts.find(XSLA_RESULT_PREFIX) );
	    if (sp -> cont == "#default") style = UNDEF_PHRASE;
	    else dict().insert(sp -> cont, style);
	    if (rp -> cont == "#default") result = UNDEF_PHRASE;
	    else dict().insert(rp -> cont, result);

	    int i;
	    i = pendingNS().findNdx(style);
	    if (i != -1)
	      sUri = toNS(pendingNS().operator[](i)) -> uri;
	    else
	      Err1(S, E_EX_NAMESPACE_UNKNOWN, (char*) sp -> cont);

	    i = pendingNS().findNdx(result);
	    if (i != -1)
	      rUri = toNS(pendingNS().operator[](i)) -> uri;
	    else
	      Err1(S, E_EX_NAMESPACE_UNKNOWN, (char*) rp -> cont);

	    aliases().insertAlias(sUri, rUri, result, 
				  v -> getImportPrecedence(), x);
	    popVertex();
	  }; break;
	case XSL_TEMPLATE:
	  {
	    E( insertRule(S, x) );
	    popVertex();
	  }; break;
	case XSL_ATTRIBUTE_SET:
	  {
	    QName name;
	    
	    E( x -> setLogical(S, name,
			       NZ( x -> atts.find(XSLA_NAME)) -> cont, 
			       FALSE) );
	    AttSet *ptr = attSets().insert(name);
	    E( extractUsedSets(S, toE(v)) );
	    if (x -> attSetNames(FALSE))
	      {
		for (int i = 0; i < x -> attSetNames(FALSE) -> number(); i++)
		 ptr -> insertUses(*(x -> attSetNames(FALSE) -> operator[] (i)));
	      }
	    XSLElement *son;
	    for (int i = 0; i < x -> contents.number(); i++)
	      {
		sabassert(isXSLElement(x -> contents[i]) && 
		       toX(x -> contents[i]) -> op == XSL_ATTRIBUTE);
		son = toX(x -> contents[i]);
		E( son -> setLogical(S, name, 
				     NZ( son -> atts.find(XSLA_NAME)) -> cont,
				     FALSE) );
		ptr -> insertAttributeDef(son, name);
	      }
	    popVertex();
	  }; break;
	case XSL_STYLESHEET:
	case XSL_TRANSFORM:
	  {
	    popVertex();
	  }; break;
	case XSL_VARIABLE:
	case XSL_PARAM:
	  {
	    // only look at top-levels
	    Vertex *par = v -> parent;
	    if (par && isXSLElement(par) && 
		(toX(par) -> op == XSL_STYLESHEET || 
		 toX(par) -> op == XSL_TRANSFORM))
	      {
		// is top-level -> insert into directory, 
		//with error if there already is an entry 
		// with the same import precedence
		// find name first
		QName name;
		E( x -> setLogical(S, name, 
				   NZ( x -> atts.find(XSLA_NAME)) -> cont, 
				   FALSE) );
		E( toplevelVars.insert(S, name, x) );
	      }
	    popVertex();
	  }; break;
	case XSL_STRIP_SPACE:
	  {
	    SpaceNameList &foo = 
	      subtrees.getCurrent() -> getStructure() -> strippedNames();
	    E( getSpaceNames(S, *x, NZ(x -> atts.find(XSLA_ELEMENTS)) -> cont, 
			     foo) );
	    popVertex();
	  }; break;
	case XSL_PRESERVE_SPACE:
	  {
	    SpaceNameList &foo = 
	      subtrees.getCurrent() -> getStructure() -> preservedNames();
	    E( getSpaceNames(S, *x, NZ(x -> atts.find(XSLA_ELEMENTS)) -> cont, 
			     foo) );
	    popVertex();
	  }; break;
	default:
	  popVertex();
	}
	//the literal output element may have some xsl features
    }
  else 
    { //isXSLElement
      updateImportStatus();
      if (XSLTree) {
	E( extractUsedSets(S, toE(v)) );
	popVertex();
      }
      else {
	popVertex();
      }
    }
  return OK;
}
Ejemplo n.º 11
0
//----------------------------------------------------------------------------//
float ColourPickerConversions::toX(unsigned char R, unsigned char G, unsigned char B)
{
    return toX(R / 255.0f, G / 255.0f, B / 255.0f);
}
Ejemplo n.º 12
0
void
VisualOutput::doOutput(std::string filename, std::vector<Node*> nodes,
    int generation)
{

  bool redraw = false;
  if (cc != _config->getCC(generation))
    {
      cc = _config->getCC(generation);
      redraw = true;
    }
  if (sb != _config->getSB(generation))
    {
      sb = _config->getSB(generation);
      redraw = true;
    }
  if (hb != _config->getHB(generation))
    {
      hb = _config->getHB(generation);
      redraw = true;
    }

  if (redraw)
    {
      double minlat = _config->getMinLat();
      double maxlat = _config->getMaxLat();
      double minlon = _config->getMinLon();
      double maxlon = _config->getMaxLon();
      for (int i = 0; i < _ysize; i++)
        {
          for (int j = 0; j < _xsize; j++)
            {
              double lon = (double) j / (double) _xsize * (maxlon - minlon)
                  + minlon;
              double lat = (double) i / (double) _ysize * (maxlat - minlat)
                  + minlat;
              _background[(i * _xsize + j) * 3 + 1] = cc->f(cc->toX(lon,
                  minlon, maxlon, 0), cc->toX(lat, minlat, maxlat, 1)) * 255.0;
              _background[(i * _xsize + j) * 3 + 2] = sb->f(sb->toX(lon,
                  minlon, maxlon, 0), sb->toX(lat, minlat, maxlat, 1)) * 255.0;
              _background[(i * _xsize + j) * 3 + 0] = hb->f(hb->toX(lon,
                  minlon, maxlon, 0), hb->toX(lat, minlat, maxlat, 1)) * 255.0;
            }
        }
    }

  for (int i = 0; i < _xsize * _ysize * 3; i++)
    {
      _outputImage[i] = _background[i];
    }

  int x = 0, y = 0;
  for (unsigned int i = 0; i < nodes.size(); i++)
    {
      y = toX(nodes[i]->lat, _config->getMinLat(), _config->getMaxLat(), 1);
      x = toX(nodes[i]->lon, _config->getMinLon(), _config->getMaxLon(), 0);
      _outputImage[(y * _xsize + x) * 3 + 2] = nodes[i]->_r;
      _outputImage[(y * _xsize + x) * 3 + 0] = nodes[i]->_g;
      _outputImage[(y * _xsize + x) * 3 + 1] = nodes[i]->_b;

      _outputImage[(y * _xsize + x + 1) * 3 + 2] = nodes[i]->_r;
      _outputImage[(y * _xsize + x + 1) * 3 + 0] = nodes[i]->_g;
      _outputImage[(y * _xsize + x + 1) * 3 + 1] = nodes[i]->_b;

      _outputImage[((y + 1) * _xsize + x) * 3 + 2] = nodes[i]->_r;
      _outputImage[((y + 1) * _xsize + x) * 3 + 0] = nodes[i]->_g;
      _outputImage[((y + 1) * _xsize + x) * 3 + 1] = nodes[i]->_b;

      _outputImage[((y + 1) * _xsize + x + 1) * 3 + 2] = nodes[i]->_r;
      _outputImage[((y + 1) * _xsize + x + 1) * 3 + 0] = nodes[i]->_g;
      _outputImage[((y + 1) * _xsize + x + 1) * 3 + 1] = nodes[i]->_b;
    }
  _bmpOutputImage->writeImage(filename.c_str(), _outputImage, 1.0);

}