Example #1
0
/* void GetNodeBox (in nsIDOMElement node, out long x, out long y, out long w, out long h); */
NS_IMETHODIMP nsDomAttUtil::GetEleBox(nsIDOMElement *node, PRInt32 *x , PRInt32 *y , PRInt32 *w , PRInt32 *h )
{
     nsCOMPtr<nsIDOMDocument> oDoc(nsnull);
     if(node!=nsnull)
	  node->GetOwnerDocument(getter_AddRefs(oDoc));
     if(oDoc!=nsnull)
     {
	  nsCOMPtr<nsIDOMNSDocument> nsdoc=do_QueryInterface(oDoc);
	  nsCOMPtr<nsIBoxObject> box;
	  nsresult rv=nsdoc->GetBoxObjectFor(node,getter_AddRefs(box));
	  if (NS_FAILED(rv))
	  {
	       return rv;
	  }
	  PRInt32 m_x,m_y,m_h,m_w;
	  box->GetX(&m_x);
	  box->GetY(&m_y);
	  box->GetHeight(&m_h);
	  box->GetWidth(&m_w);
	  *x=m_x;
	  *y=m_y;
	  *w=m_w;
	  *h=m_h;
	  return NS_OK;
     }else
     {
	  return NS_ERROR_FAILURE;
     }
}
Example #2
0
/* long GetNodeUrlCount (in nsIDOMNode node); */
NS_IMETHODIMP nsDomAttUtil::GetNodeUrlCount(nsIDOMNode *node, PRInt32 *_retval )
{
     nsresult rv;
     nsCOMPtr<nsIXpathUtil> xpathUtil=do_CreateInstance("@nyapc.com/XPCOM/nsXpathUtil;1",&rv);
     if (NS_FAILED(rv))
     {
	  return rv;
     }
     nsCOMPtr<nsIDOMDocument> oDoc(nsnull);
     node->GetOwnerDocument(getter_AddRefs(oDoc));
     if(oDoc!=nsnull)
     {
	  xpathUtil->SetDocument(oDoc);
	  nsCOMPtr<nsISupportsArray> nodeArr(nsnull);
	  nsCString xpath(".//a[@href]");
	  xpathUtil->GetSubNodes(node,xpath,getter_AddRefs(nodeArr));
	  if(nodeArr!=nsnull)
	  {
	       PRUint32 arrlen=0;
	       nodeArr->Count(&arrlen);
	       *_retval=arrlen;
	  }else
	  {
	       *_retval=0;
	  }
     }else
     {
	  *_retval=0;
     }
     return NS_OK;
}
std::auto_ptr<QDomDocument> GImageMappingsExporter::ExportImageMappings(QSharedPointer<GImageMappings> oImageMappings)
{

	std::auto_ptr<QDomDocument> oDoc(new QDomDocument);

    QDomElement oElementImageMappings(oDoc->createElement(GImageMappings::CXMLTag));

               		
    // Iterate through the Images and export them
	QList<GImageMap *> oImageList(oImageMappings->GetAllImageMaps());

	QList<GImageMap *>::iterator oImageIterator(oImageList.begin());

	GImageMap* oImage;

	while (oImageIterator != oImageList.end())
	{ 
		oImage = *oImageIterator;
		oDoc = ExportImage(oImage, oDoc, &oElementImageMappings);
		++oImageIterator;
	}      

	// Append generated elements into Document  
	oDoc->appendChild(oElementImageMappings);

	return oDoc;
}
Example #4
0
void nsDomAttUtil::GetComLayoutInfo(nsIDOMElement* node,std::map<std::string,std::string> &lmap)
{
     nsCOMPtr<nsIDOMDocument> oDoc(nsnull);
     if(node!=nsnull)
	  node->GetOwnerDocument(getter_AddRefs(oDoc));
     if(oDoc!=nsnull)
     {
	  nsCOMPtr<nsIDOMViewCSS> viewCSS(nsnull);
	  nsCOMPtr<nsIDOMDocumentView> domView = do_QueryInterface(oDoc);
	  if(domView!=nsnull)
	  {
	       nsCOMPtr<nsIDOMAbstractView> abstractView;
	       domView->GetDefaultView(getter_AddRefs(abstractView));
	       if(abstractView!=nsnull)
	       {
		    viewCSS=do_QueryInterface(abstractView);
	       }
	  }
	  if(viewCSS!=nsnull)
	  {
	       nsCOMPtr<nsIDOMCSSStyleDeclaration> style;
	       viewCSS->GetComputedStyle(node, EmptyString(),getter_AddRefs(style));
	       if(style!=nsnull)
	       {
		    PRUint32 slen;
		    style->GetLength(&slen);
		    nsString csstext;
		    style->GetCssText(csstext);
		    for(int j=0;j<slen;j++)
		    {
			 nsString name;
			 nsString value;
			 nsString prio;
			 style->Item(j,name);
			 style->GetPropertyValue(name,value);

			 std::string strName(NS_ConvertUTF16toUTF8(name).get());

			 std::map<std::string,std::string>::iterator fit=lmap.find(strName);
			 if(fit==lmap.end())
			 {
			      lmap.insert(make_pair(strName,std::string(NS_ConvertUTF16toUTF8(value).get())));
			 }
		    }
	       }
	  }
     }
}
bool GImageMappingsExporter::Export(QSharedPointer<GImageMappings> oImageMappings, QString strFilename)
{

	std::auto_ptr<QDomDocument> oDoc(ExportImageMappings(oImageMappings));

    QFile oFile( strFilename );
    bool bRet( oFile.open(QIODevice::WriteOnly) );
    
    if(bRet)
    {
		QTextStream oTS( &oFile );
		oTS << oDoc->toString();		
		oFile.close();
		
		bRet = oTS.status() == QTextStream::Ok;
    }

    oDoc.reset();
	
	return bRet;	
}
Example #6
0
/* long GetNodeUrlDistance (in nsIDOMNode node); */
NS_IMETHODIMP nsDomAttUtil::GetNodeUrlDistance(nsIDOMNode *node, PRInt32 *_retval )
{
     nsresult rv;
     nsCOMPtr<nsIXpathUtil> xpathUtil=do_CreateInstance("@nyapc.com/XPCOM/nsXpathUtil;1",&rv);
     if (NS_FAILED(rv))
     {
	  return rv;
     }
     nsCOMPtr<nsIDOMDocument> oDoc(nsnull);
     if(node!=nsnull)
	  node->GetOwnerDocument(getter_AddRefs(oDoc));
     if(oDoc!=nsnull)
     {
	  Distance ld;
	  PRInt32 distValue=0;

	  xpathUtil->SetDocument(oDoc);

	  nsCOMPtr<nsISupportsArray> nodeArr(nsnull);
	  nsCString xpath(".//a[@href]");
	  xpathUtil->GetSubNodes(node,xpath,getter_AddRefs(nodeArr));
	  if(nodeArr!=nsnull)
	  {
	       PRUint32 arrlen=0;
	       nodeArr->Count(&arrlen);
	       std::string lastUrl;
	       bool setinit=false;
	       LOG<<"urlcount:"<<arrlen<<"\n";
	       for(PRUint32 i=0;i<arrlen;i++)
	       {
		    nsCOMPtr<nsISupports> node;
		    nodeArr->GetElementAt(i,getter_AddRefs(node));
		    nsCOMPtr<nsIDOMElement> domele=do_QueryInterface(node);
		    nsString nsName=NS_ConvertUTF8toUTF16("href");
		    nsString nsValue;
		    if(domele!=nsnull)
		    {
			 domele->GetAttribute(nsName,nsValue);


			 if(!setinit)
			 {
			      lastUrl=std::string(NS_ConvertUTF16toUTF8(nsValue).get());
			      setinit=true;
			 }
			 else
			 {
			      std::string curUrl(NS_ConvertUTF16toUTF8(nsValue).get());

			      distValue+=ld.LD(lastUrl,curUrl);
			      LOG<<"last:"<<lastUrl<<"cururl:"<<curUrl<<"dist:"<<distValue<<"\n";
			      lastUrl=curUrl;
			 }
		    }
	       }
	       *_retval=distValue;
	  }else
	  {
	       *_retval=-1;
	  }
     }else
     {
	  *_retval=-1;
     }
     return NS_OK;
}
Example #7
0
tResult cJuryModule::LoadManeuverList()
{
    // load the maneuver list
    // clear old list
    m_strManeuverList.clear();
    // use QDom for parsing
    QDomDocument oDoc("maneuver_list");
    QFile oFile(m_strManeuverFile);

    // open file
    if(!oFile.open(QIODevice::ReadOnly))
    {
        RETURN_ERROR(ERR_FILE_NOT_FOUND);
    }
    if (!oDoc.setContent(&oFile))
    {
        oFile.close();
        RETURN_ERROR(ERR_INVALID_FILE);
    }

    // get the root element
    QDomElement oRoot = oDoc.documentElement();

    // get all sectors from DOM
    QDomNodeList lstSectors = oRoot.elementsByTagName("AADC-Sector");

    // iterate over all sectors
    for (int nIdxSectors = 0; nIdxSectors < lstSectors.size(); ++nIdxSectors)
    {
        // get the ids and maneuver from sector
        QDomNode oNodeSector = lstSectors.item(nIdxSectors);
        QDomElement oElementSector = oNodeSector.toElement();
        QString strIdSector = oElementSector.attribute("id");
        tSector sSector;
        sSector.id = strIdSector.toInt();
        QDomNodeList lstManeuver = oElementSector.elementsByTagName("AADC-Maneuver");
        // iterate over all maneuver
        for (int nIdxManeuver = 0; nIdxManeuver < lstManeuver.size(); ++nIdxManeuver)
        {
            // get the id and the action
            QDomNode oNodeManeuver = lstManeuver.item(nIdxManeuver);
            QDomElement oElementManeuver = oNodeManeuver.toElement();
            QString strIdManeuver = oElementManeuver.attribute("id");
            tAADC_Maneuver sManeuver;
            sManeuver.nId = strIdManeuver.toInt();
            sManeuver.action = oElementManeuver.attribute("action").toStdString();
            // fill the internal maneuver list
            sSector.lstManeuvers.push_back(sManeuver);
        }

        // fill the internal sector list
        m_lstSections.push_back(sSector);
    }
   
    // check sector list
    if (m_lstSections.size() > 0)
    {
        SetLogText("Jury Module: Loaded Maneuver file successfully.");
    }
    else
    {
        SetLogText("Jury Module: no valid Maneuver Data found!");
    }

    // fill the combo boxes
    FillComboBoxes();
    // get the xml string for transmission
    m_strManeuverList = oDoc.toString().toStdString();
    // set the controls (enable/disable)
    SetControlState();
    
    RETURN_NOERROR;
}