Skip to content

Commit

Permalink
Merge pull request #3 from Aldream/master
Browse files Browse the repository at this point in the history
HTML DTD path fix
  • Loading branch information
Benjamin BOUVIER committed May 1, 2012
2 parents a4321de + b482eee commit 5d9f664
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tests/rapport.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="/home/bill/git/mesForks/Projet-Grammaire-Langages/tests/html.dtd">

<xsl:template match="rapport">
<html>
Expand Down
4 changes: 4 additions & 0 deletions xml/Document.cpp
Expand Up @@ -40,6 +40,10 @@ xml::Content* xml::Document::getRoot()
return root;
}

string xml::Document::getFilePath() {
return filePath;
}

ostream& xml::Document::toString(ostream& stream)
{
if (!doctype.empty())
Expand Down
22 changes: 19 additions & 3 deletions xml/Document.hpp
@@ -1,6 +1,5 @@
# ifndef __DOCUMENT_H__
# define __DOCUMENT_H__

# include "ProcessingInstruction.hpp"
# include "Content.hpp"
# include "Comment.hpp"
Expand All @@ -26,7 +25,9 @@ namespace xml {
private:
std::string rootName;
std::string doctype;


std::string filePath;

ProcessingInstruction *xmlProlog;
Content *root;
std::list<Comment*> comments;
Expand All @@ -48,6 +49,15 @@ namespace xml {
rootName = _d.first;
doctype = _d.second;
}

/**
* Mutateur : Définit le chemin vers le fichier à l'origine de ce document.
* @param _d Chemin vers le fichier utilisé.
*/
void setFilePath(const char* _d)
{
filePath = std::string(_d);
}

/**
* Mutateur : Définit le prologue xml.
Expand All @@ -72,6 +82,12 @@ namespace xml {
* @returns L'élément racine.
*/
Content* getRoot();

/**
* Accesseur : renvoie le chemin vers le fichier à l'origine de ce document.
* @returns L'élément racine.
*/
std::string getFilePath();

/**
* Destructeur de l'objet.
Expand All @@ -81,7 +97,7 @@ namespace xml {
/**
* Constructeur par défaut de l'objet, initialise les variables aux valeurs par défaut.
*/
Document() : doctype(""), xmlProlog(0), root(0) { /* empty */ }
Document() : doctype(""), xmlProlog(0), root(0), filePath() { /* empty */ }

/**
* Affiche le contenu du document (ie l'ensemble de son arboresence) dans le flux passé.
Expand Down
4 changes: 4 additions & 0 deletions xml/xml.y
Expand Up @@ -266,9 +266,13 @@ xml::Document* parseXML(const char* file)
fprintf(stderr, "Parse ended with %d error(s)\n", err);
document = NULL;
}

fclose(xmlin);
xmllex_destroy();
}
if (document != NULL) {
document->setFilePath(file);
}

return document;
}
Expand Down
5 changes: 2 additions & 3 deletions xsl/Test.cpp
Expand Up @@ -71,8 +71,8 @@ struct XSLProcessTest_NoHTMLDTD : public TestCase
xml::Document* document = NULL;
dtd::Document* docDtd;

docDtd = parseDTD("tests/html.dtd");
document = parseXML("tests/testNoHTMLDTD.xsl");
docDtd = parseDTD("./tests/html.dtd");
document = parseXML("./tests/testNoHTMLDTD.xsl");
XSLProcessor xslProcessor = XSLProcessor();
try{
xslProcessor.setXslDTD(docDtd);
Expand Down Expand Up @@ -101,7 +101,6 @@ struct XSLProcessTest_InvalidHTMLDTD : public TestCase

docXml = parseXML("./tests/testHtmlDtdInvalid.xsl");
docDtd = parseDTD("./tests/xsl.dtd");

try {
proc.setXslDTD(docDtd);
proc.processXslFile(docXml);
Expand Down
14 changes: 9 additions & 5 deletions xsl/XSLProcessor.cpp
@@ -1,4 +1,3 @@

/**
* @file XSLProcessor.cpp
* @brief Implementation - XSL processing functions
Expand All @@ -8,8 +7,6 @@
* @author Daniel BAUDRY & Benjamin Bill PLANCHE (Aldream)
*/

#include <iostream>

#include "XSLProcessor.hpp"

#include "../xml/basics.h"
Expand Down Expand Up @@ -75,10 +72,17 @@ void xsl::XSLProcessor::processXslFile(xml::Document* newXslDoc) throw (string)
string attrXMLNS = rootXSL->getAttributeValue("xmlns:xsl");
if (attrXMLNS.empty()) {
throw(ERROR_NO_XMLNS);
}
}

// --------- Building a full path, by prepending the path to the folder of the XSL file to the path to the HTML DTD file (without this, if the program is running in a different folder than the XSL file, it won't be able to find the HTML DTD with the relative path of the XSL)
string xslPath = newXslDoc->getFilePath();
string fullHtmlDtdPath = attrXMLNS;
if (attrXMLNS[0] != '/') {
string xslFolder = xslPath.substr(0, xslPath.find_last_of("/\\"));
fullHtmlDtdPath = xslFolder + "/" + attrXMLNS;
}
// --------- Opening, validating ant getting the structure of the HTML DTD file :
dtd::Document * htmlDTDdoc = parseDTD(attrXMLNS.c_str());
dtd::Document * htmlDTDdoc = parseDTD(fullHtmlDtdPath.c_str());
if (htmlDTDdoc == NULL) {
throw(ERROR_INVALID_HTML_DTD);
}
Expand Down
2 changes: 1 addition & 1 deletion xsl/tests/rapport.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="./html.dtd">

<xsl:template match="rapport">
<html>
Expand Down
2 changes: 1 addition & 1 deletion xsl/tests/rapportInvalidXSL.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="./html.dtd">

<xsl:template match="rapport"
>
Expand Down
2 changes: 1 addition & 1 deletion xsl/tests/rapportSemanticHTML.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="./html.dtd">

<xsl:template match="rapport">
<html>
Expand Down
2 changes: 1 addition & 1 deletion xsl/tests/rapportSemanticXSL.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="./html.dtd">

<xsl:template match="rapport">
<html>
Expand Down
2 changes: 1 addition & 1 deletion xsl/tests/testApplyTemplates.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="./html.dtd">

<xsl:template match="rapport">
<html>
Expand Down
2 changes: 1 addition & 1 deletion xsl/tests/testAttribute.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="./html.dtd">

<xsl:template match="rapport">
<html>
Expand Down
2 changes: 1 addition & 1 deletion xsl/tests/testComplex.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="./html.dtd">

<xsl:template match="rapport">
<html>
Expand Down
2 changes: 1 addition & 1 deletion xsl/tests/testHtmlDtdInvalid.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html_invalid.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="./html_invalid.dtd">

<xsl:template match="rapport">
<html>
Expand Down
2 changes: 1 addition & 1 deletion xsl/tests/testNoRoot.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="./html.dtd">

<xsl:template match="titre"></xsl:template>

Expand Down
2 changes: 1 addition & 1 deletion xsl/tests/testSimple.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="./html.dtd">

<xsl:template match="rapport">
<html>
Expand Down
2 changes: 1 addition & 1 deletion xsl/tests/testValueOf.xsl
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="./tests/html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="./html.dtd">

<xsl:template match="rapport">
<html>
Expand Down

0 comments on commit 5d9f664

Please sign in to comment.