Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3 from Aldream/master

HTML DTD path fix
  • Loading branch information...
commit 5d9f6645c7ebef80c7bf94e2f4eace27d60d76a5 2 parents a4321de + b482eee
@bnjbvr bnjbvr authored
View
2  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>
View
4 xml/Document.cpp
@@ -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())
View
22 xml/Document.hpp
@@ -1,6 +1,5 @@
# ifndef __DOCUMENT_H__
# define __DOCUMENT_H__
-
# include "ProcessingInstruction.hpp"
# include "Content.hpp"
# include "Comment.hpp"
@@ -26,7 +25,9 @@ namespace xml {
private:
std::string rootName;
std::string doctype;
-
+
+ std::string filePath;
+
ProcessingInstruction *xmlProlog;
Content *root;
std::list<Comment*> comments;
@@ -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.
@@ -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.
@@ -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é.
View
4 xml/xml.y
@@ -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;
}
View
5 xsl/Test.cpp
@@ -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);
@@ -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);
View
14 xsl/XSLProcessor.cpp
@@ -1,4 +1,3 @@
-
/**
* @file XSLProcessor.cpp
* @brief Implementation - XSL processing functions
@@ -8,8 +7,6 @@
* @author Daniel BAUDRY & Benjamin Bill PLANCHE (Aldream)
*/
-#include <iostream>
-
#include "XSLProcessor.hpp"
#include "../xml/basics.h"
@@ -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);
}
View
2  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>
View
2  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"
>
View
2  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>
View
2  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>
View
2  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>
View
2  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>
View
2  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>
View
2  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>
View
2  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>
View
2  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>
View
2  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>
Please sign in to comment.
Something went wrong with that request. Please try again.