--- /dev/null
+/*
+ * Copyright © FYLAB and the Conseil Régional d'Île-de-France, 2009
+ * This file is part of L'Interface Libre et Interactive de l'Enseignement (Lilie).
+ *
+ * Lilie is free software. You can redistribute it and/or modify since
+ * you respect the terms of either (at least one of the both license) :
+ * - under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ * - the CeCILL-C as published by CeCILL-C; either version 1 of the
+ * License, or any later version
+ *
+ * There are special exceptions to the terms and conditions of the
+ * licenses as they are applied to this software. View the full text of
+ * the exception in file LICENSE.txt in the directory of this software
+ * distribution.
+ *
+ * Lilie is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Licenses for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the CeCILL-C along with Lilie. If not, see :
+ * <http://www.gnu.org/licenses/> and
+ * <http://www.cecill.info/licences.fr.html>.
+ */
+
+package org.lilie.services.eliot.textes.impression.template
+
+import org.w3c.dom.Node
+import org.w3c.dom.Element
+import org.w3c.dom.NodeList
+import org.w3c.dom.Document
+import org.w3c.dom.Text
+
+/**
+ * Une fois généré ce service assure la correction du document docbook
+ * @author othe
+ */
+class CorrectionDocbookService {
+
+ private static final TAG_ORDEREDLIST = "orderedlist"
+ private static final TAG_ITEMIZEDLIST = "itemizedlist"
+ private static final TAG_LISTITEM = "listitem"
+ private static final TAG_TBODY = "tbody"
+ private static final TAG_TGROUP = "tgroup"
+ private static final TAG_INFORMAL_TABLE = "informaltable"
+ private static final TAG_THEAD = "thead"
+ private static final TAG_EMPHASIS = "emphasis"
+ private static final TAG_BOOK = "book"
+
+ /**
+ * Assure les différentes corrections à apporter au fichier docbook
+ * @param doc
+ * @return
+ */
+ public Document corrige(Document doc) {
+
+ def root = doc.documentElement
+
+ parcourtEtCorrige(root.getChildNodes())
+
+ parcourtEtCorrigeTableauxVides(root.getChildNodes())
+
+ parcourtEtCorrigeTableauxCellulesFusionnees(root.getChildNodes())
+
+ parcourtEtCorrigeTableauxImbriques(root.getChildNodes())
+
+ return doc
+
+ }
+
+ /**
+ * parcourt et corrige l'arbre du dom d'un document xml
+ */
+ private void parcourtEtCorrige(org.w3c.dom.NodeList nodeList) {
+
+ nodeList.each {Node node ->
+
+ if (log.isDebugEnabled()) {
+ log.debug nodeToString(node)
+ }
+
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+
+ switch (node.localName) {
+
+ case TAG_ORDEREDLIST:
+
+ def listeOrdonneeEnfant = node.getChildNodes().find {Node nodeRecherche ->
+ nodeRecherche.localName == TAG_ORDEREDLIST
+ }
+
+ if (listeOrdonneeEnfant) {
+ reparerListesImbriquees(node)
+ parcourtEtCorrige(node.getChildNodes())
+ }
+
+ break
+
+ case TAG_ITEMIZEDLIST:
+
+ def listeEnfant = node.getChildNodes().find {Node nodeRecherche ->
+ nodeRecherche.localName == TAG_ITEMIZEDLIST
+ }
+
+ if (listeEnfant) {
+ reparerListesImbriquees(node)
+ parcourtEtCorrige(node.getChildNodes())
+ }
+
+ break
+
+ case TAG_EMPHASIS:
+ parcourtEtCorrigeEmphasis(node)
+ break
+
+ default:
+ parcourtEtCorrige(node.getChildNodes())
+ break
+
+ }
+
+ }
+
+ }
+
+ }
+
+ /**
+ * si une balise emphasis ne contient aucun texte, elle ne sert à rien, donc on la supprime
+ * si une balise emphasis contient un <?linebreak?> cela n'a pas de sens, donc on remplace la balise emphasis par
+ * <?linebreak?>
+ * on fait l'exploration des enfants de l'emphasis, pour gérer le cas des emphasis imbriqués
+ */
+ private void parcourtEtCorrigeEmphasis(Node emphasis) {
+
+ // si une balise emphasis ne contient aucun texte
+ Node nodeProcesseur = findXmlProcesseur(emphasis)
+
+ if (isEmphasisVide(emphasis)) {
+ Node parent = emphasis.parentNode
+ if (nodeProcesseur) {
+ Node pi = emphasis.ownerDocument.createProcessingInstruction('linebreak', '')
+ parent.insertBefore(pi, emphasis)
+ }
+ if (log.isDebugEnabled()) {
+ log.debug "On enlève ce noeud : " + nodeToString(emphasis)
+ }
+ parent.removeChild(emphasis)
+ }
+
+ }
+
+ private Node findXmlProcesseur(Node emphasis) {
+
+ Node resultat = null
+ String texte = ""
+
+ org.w3c.dom.NodeList listeEnfant = emphasis.getChildNodes()
+
+ listeEnfant.each {Node nodeEmphasis ->
+
+ if (nodeEmphasis.getNodeType() == Node.TEXT_NODE) {
+ texte = texte + nodeEmphasis.nodeValue
+ }
+
+ if (nodeEmphasis.getNodeType() == Node.ELEMENT_NODE) {
+ resultat = findXmlProcesseur(nodeEmphasis)
+ }
+
+ if (nodeEmphasis.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
+ resultat = nodeEmphasis
+ }
+
+ }
+
+ if (log.isDebugEnabled()) {
+ if (resultat) {
+ log.debug("Instruction processeur xml trouvé sous emphasis.")
+ }
+ }
+
+ return resultat
+
+ }
+
+ private Boolean isEmphasisVide(Node emphasis) {
+
+ String texte = ""
+ Boolean vide = true
+
+ NodeList listeEnfant = emphasis.getChildNodes()
+
+ listeEnfant.each {Node nodeEmphasis ->
+
+ if (nodeEmphasis.getNodeType() == Node.TEXT_NODE) {
+ texte = texte + nodeEmphasis.nodeValue
+ }
+
+ if (nodeEmphasis.getNodeType() == Node.ELEMENT_NODE) {
+ vide = isEmphasisVide(nodeEmphasis)
+ }
+
+ }
+
+ boolean resultat = (texte.trim() == "") && (vide)
+
+ if (log.isDebugEnabled()) {
+ if (resultat) {
+ log.debug("Balise emphasis sans texte.")
+ }
+ }
+ return resultat
+
+ }
+
+ /**
+ * Création d'un noeud listitem pour "réparer" les listes imbriquées
+ */
+ private void reparerListesImbriquees(Node node) {
+ Element elementListe = node.getOwnerDocument().createElement(TAG_LISTITEM)
+
+ while (node.hasChildNodes()) {
+ elementListe.appendChild(node.getFirstChild())
+ }
+
+ node.appendChild(elementListe)
+ }
+
+ private String superTrim(String texte) {
+
+ String resultat = ""
+ StringTokenizer st = new StringTokenizer(texte)
+ while (st.hasMoreTokens()) {
+ resultat = resultat + st.nextToken() + " "
+ }
+ return resultat.trim()
+ }
+
+ private boolean isTableauInclu(Node informalTable) {
+
+ if (informalTable.localName != TAG_INFORMAL_TABLE) {
+ throw new IllegalStateException("Cette routine est prévue pour rechercher si la table est incluse dans une autre table")
+ }
+
+ Node noeudCourant = informalTable.parentNode
+
+ while (noeudCourant.localName != TAG_BOOK) {
+
+ if (log.isDebugEnabled()) {
+ log.debug "Recherche tableau inclu " + noeudCourant.localName
+ }
+
+ if ((noeudCourant.localName == TAG_INFORMAL_TABLE)) {
+ return true
+ }
+
+ noeudCourant = noeudCourant.parentNode
+
+ }
+
+ return false
+
+ }
+
+
+ private String toTextes(NodeList noeuds) {
+
+ String resultat = ""
+
+ for (int j = 0; j < noeuds.getLength(); j++) {
+
+ Node node = noeuds.item(j)
+
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ resultat = resultat + node.textContent.trim()
+ } else {
+ resultat = resultat + toTextes(node.childNodes)
+ }
+ }
+
+ return resultat
+
+ }
+
+ private String tableauToTextes(Node informalTable) {
+
+ NodeList noeuds = informalTable.childNodes
+ return toTextes(noeuds).trim()
+
+ }
+
+ private void parcourtEtCorrigeTableauxImbriques(NodeList nodeList) {
+
+ for (int j = 0; j < nodeList.getLength(); j++) {
+
+ Node node = nodeList.item(j)
+
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
+ continue
+ }
+
+ if (node.localName == TAG_INFORMAL_TABLE) {
+
+ if (isTableauInclu(node)) {
+
+ if (log.isDebugEnabled()) {
+ log.debug "Tableau inclu détecté"
+ }
+
+ Node parent = node.parentNode
+ parent.removeChild(node)
+
+ String texteAInclure = tableauToTextes(node)
+ if (texteAInclure) {
+ Text text = parent.ownerDocument.createTextNode(texteAInclure)
+ parent.appendChild(text)
+ }
+ println texteAInclure
+
+ }else{
+ parcourtEtCorrigeTableauxImbriques(node.getChildNodes())
+ }
+ } else {
+ parcourtEtCorrigeTableauxImbriques(node.getChildNodes())
+ }
+
+ }
+ }
+
+ private void parcourtEtCorrigeTableauxVides(NodeList nodeList) {
+
+ for (int j = 0; j < nodeList.getLength(); j++) {
+
+ Node node = nodeList.item(j)
+
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
+ continue
+ }
+
+ if (node.localName == TAG_INFORMAL_TABLE) {
+
+ Node nodeGroup = findTgroup(node.getChildNodes())
+
+ NodeList definitionTable = nodeGroup.getChildNodes()
+
+ Node tbodyVide = findEmptyTbody(definitionTable)
+ Node thead = findThead(definitionTable)
+
+ if (log.isDebugEnabled()) {
+ log.debug "Informal table"
+
+ if (tbodyVide) {
+ log.debug "La section body est vide"
+ }
+
+ if (thead) {
+ log.debug "La section head existe"
+ }
+
+ }
+
+ if ((tbodyVide) && (thead)) {
+
+ if (log.isDebugEnabled()) {
+ log.debug "On déplace l'entête vers le corps."
+ }
+
+ moveAllChildrens(thead, tbodyVide)
+
+ nodeGroup.removeChild(thead)
+
+ }
+
+ } else {
+ parcourtEtCorrigeTableauxVides(node.getChildNodes())
+ }
+
+ }
+
+ }
+
+ private Node findThead(org.w3c.dom.NodeList definitionTable) {
+ return findNode(definitionTable, TAG_THEAD)
+ }
+
+ private Node findTgroup(org.w3c.dom.NodeList definitionTable) {
+ return findNode(definitionTable, TAG_TGROUP)
+ }
+
+ private void moveAllChildrens(Node source, Node cible) {
+
+ NodeList listeHead = source.getChildNodes()
+
+ for (int i = 0; i < listeHead.getLength(); i++) {
+ Node childHead = listeHead.item(i)
+ if (childHead.getNodeType() == Node.ELEMENT_NODE) {
+ childHead = source.removeChild(childHead)
+ cible.appendChild(childHead)
+ }
+ }
+
+ }
+
+ private Node findNode(NodeList definitionTable, String nodeName) {
+
+ Node resultat = null
+
+ for (int index = 0; index < definitionTable.getLength(); index++) {
+
+ Node nodeTable = definitionTable.item(index)
+
+ if (nodeTable.localName == nodeName) {
+ resultat = nodeTable
+ }
+ }
+
+ return resultat
+ }
+
+ /**
+ * Recherche de la section tbody du tableau si celle ci est vide
+ * @param definitionTable
+ * @return
+ */
+ private Node findEmptyTbody(NodeList definitionTable) {
+
+ for (int index = 0; index < definitionTable.getLength(); index++) {
+
+ Node nodeTable = definitionTable.item(index)
+
+ if (nodeTable.localName == TAG_TBODY) {
+
+ if (isEmptyBody(nodeTable)) {
+ return nodeTable
+ }
+
+ }
+
+ }
+
+ return null
+ }
+
+ private boolean isEmptyBody(Node body) {
+
+ NodeList nodeList = body.getChildNodes()
+
+ if (nodeList.getLength() == 0) {
+ return true
+ }
+
+ Boolean estVide = true
+
+ for (int indexBody = 0; indexBody < nodeList.getLength(); indexBody++) {
+
+ Node nodeBody = nodeList.item(indexBody)
+
+ if (nodeBody.getNodeType() != Node.TEXT_NODE) {
+ estVide = false
+ break
+ }
+
+ }
+
+ return estVide
+
+ }
+
+ private void parcourtEtCorrigeTableauxCellulesFusionnees(org.w3c.dom.NodeList nodeList) {
+
+ for (int j = 0; j < nodeList.getLength(); j++) {
+
+ Node node = nodeList.item(j)
+
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
+ continue
+ }
+
+ if (node.localName == TAG_INFORMAL_TABLE) {
+
+ Node nodeGroup = findTgroup(node.getChildNodes())
+
+ corrigeCellulesFusionnees(nodeGroup)
+
+ } else {
+ parcourtEtCorrigeTableauxCellulesFusionnees(node.getChildNodes())
+ }
+
+ }
+
+ }
+
+ /**
+ * La génération automatique du fichier DocBook n'est pas correcte dans le cas
+ * de cellules fusionnées verticalement. Les lignes dont les cellules sont à
+ * fusionner sont séparées dans le thead et dans le tbody. Elles doivent être réunies
+ * dans le tbody.
+ * @param nodeGroup
+ */
+ private void corrigeCellulesFusionnees(Node nodeGroup) {
+ org.w3c.dom.NodeList definitionTable = nodeGroup.getChildNodes()
+ boolean hasCelullesFusionneesDansThead = false
+ // les cellules fusionnées posent problème quand elles sont verticales et
+ // définies à la fois dans le thead et le tbody
+ Node thead = findNode(definitionTable, TAG_THEAD)
+ Node tbody = findNode(definitionTable, TAG_TBODY)
+
+ if (thead && tbody) {
+ List<Node> theadRows = findNodes(thead.getChildNodes(), 'row')
+ List<Node> tbodyRows = findNodes(tbody.getChildNodes(), 'row')
+ if (theadRows?.size() == 1 && tbodyRows?.size() > 0) {
+ NodeList entries = theadRows[0].getChildNodes()
+ for (int index = 0; index < entries.getLength(); index++) {
+ Node node = entries.item(index)
+ if (node.localName == 'entry' && node.attributes.nodes.find {it.localName == "morerows" && it.value > 0}) {
+ hasCelullesFusionneesDansThead = true
+ }
+ }
+ if (hasCelullesFusionneesDansThead) {
+ // déplace la ligne du thead au début du tbody
+ tbody.insertBefore(theadRows[0], tbodyRows[0])
+ // supprime les balises thead
+ nodeGroup.removeChild(thead)
+ }
+ }
+ }
+ }
+
+ private List<Node> findNodes(NodeList definitionTable, String nodeName) {
+
+ List<Node> resultat = []
+
+ for (int index = 0; index < definitionTable.getLength(); index++) {
+
+ Node nodeTable = definitionTable.item(index)
+
+ if (nodeTable.localName == nodeName) {
+ resultat.add(nodeTable)
+ }
+ }
+
+ return resultat
+ }
+
+ private String nodeToString(Node node) {
+
+ String resultat = "# "
+ switch (node.getNodeType()) {
+ case Node.ELEMENT_NODE:
+ resultat = resultat + "ELEMENT_NODE "
+ break
+
+ case Node.TEXT_NODE:
+ resultat = resultat + "TEXT_NODE "
+ break
+
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ resultat = resultat + "PROCESSING_INSTRUCTION_NODE "
+ break
+
+
+ default:
+ resultat = resultat + node.getNodeType().toString() + " "
+
+ }
+
+ if (node.localName) {
+ resultat = resultat + "localName=" + node.localName + " "
+ }
+
+ if (node.nodeName) {
+ resultat = resultat + "nodeName=" + node.nodeName + " "
+ }
+
+ if (node.nodeValue) {
+ resultat = resultat + "nodeValue=" + node.nodeValue.trim() + " "
+ }
+
+ return resultat
+ }
+
+}
import org.lilie.services.eliot.textes.impression.template.htmldocbook.HtmlService
import org.lilie.services.eliot.textes.impression.template.docbook.TemplateDocbookLoader
import groovy.xml.DOMBuilder
-import org.w3c.dom.Node
-import org.w3c.dom.Element
import javax.xml.transform.TransformerFactory
import javax.xml.transform.Transformer
import javax.xml.transform.OutputKeys
import javax.xml.transform.stream.StreamResult
import org.xml.sax.SAXParseException
import org.lilie.services.eliot.textes.impression.template.htmldocbook.FeuillesDeStyle
-import org.w3c.dom.NodeList
/**
* Gestion des template permetant de générer du docbook.
*/
class DocbookTemplateService {
- private static final TAG_ORDEREDLIST = "orderedlist"
- private static final TAG_ITEMIZEDLIST = "itemizedlist"
- private static final TAG_LISTITEM = "listitem"
- private static final TAG_TBODY = "tbody"
- private static final TAG_TGROUP = "tgroup"
- private static final TAG_INFORMAL_TABLE = "informaltable"
- private static final TAG_THEAD = "thead"
- private static final TAG_EMPHASIS = "emphasis"
-
HtmlService htmlService
+ CorrectionDocbookService correctionDocbookService
/**
* Rendu docbook pour un modele et des données
org.w3c.dom.Document doc = prepareDom(xml)
- def root = doc.documentElement
-
- parcourtEtCorrige(root.getChildNodes())
-
- parcourtEtCorrigeTableauxVides(root.getChildNodes())
-
- parcourtEtCorrigeTableauxCellulesFusionnees(root.getChildNodes())
+ doc = correctionDocbookService.corrige(doc)
xmlDocumentToString(doc)
}
}
- private void parcourtEtCorrigeTableauxVides(org.w3c.dom.NodeList nodeList) {
-
- for (int j = 0; j < nodeList.getLength(); j++) {
-
- Node node = nodeList.item(j)
-
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- continue
- }
-
- if (node.localName == TAG_INFORMAL_TABLE) {
-
- Node nodeGroup = findTgroup(node.getChildNodes())
-
- org.w3c.dom.NodeList definitionTable = nodeGroup.getChildNodes()
-
- Node tbodyVide = findEmptyTbody(definitionTable)
- Node thead = findThead(definitionTable)
-
- if ((tbodyVide) && (thead)) {
-
- moveAllChildrens(thead, tbodyVide)
-
- nodeGroup.removeChild(thead)
- }
-
- } else {
- parcourtEtCorrigeTableauxVides(node.getChildNodes())
- }
-
- }
-
- }
-
- private void parcourtEtCorrigeTableauxCellulesFusionnees(org.w3c.dom.NodeList nodeList) {
-
- for (int j = 0; j < nodeList.getLength(); j++) {
-
- Node node = nodeList.item(j)
-
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- continue
- }
-
- if (node.localName == TAG_INFORMAL_TABLE) {
-
- Node nodeGroup = findTgroup(node.getChildNodes())
-
- corrigeCellulesFusionnees(nodeGroup)
-
- } else {
- parcourtEtCorrigeTableauxCellulesFusionnees(node.getChildNodes())
- }
-
- }
-
- }
-
- private void moveAllChildrens(Node source, Node cible) {
-
- NodeList listeHead = source.getChildNodes()
-
- for (int i = 0; i < listeHead.getLength(); i++) {
- Node childHead = listeHead.item(i)
- if (childHead.getNodeType() == Node.ELEMENT_NODE) {
- childHead = source.removeChild(childHead)
- cible.appendChild(childHead)
- }
- }
-
- }
-
- private Node findThead(org.w3c.dom.NodeList definitionTable) {
- return findNode(definitionTable, TAG_THEAD)
- }
-
- private Node findTgroup(org.w3c.dom.NodeList definitionTable) {
- return findNode(definitionTable, TAG_TGROUP)
- }
-
- /*
- La génération automatique du fichier DocBook n'est pas correcte dans le cas
- de cellules fusionnées verticalement. Les lignes dont les cellules sont à
- fusionner sont séparées dans le thead et dans le tbody. Elles doivent être réunies
- dans le tbody.
- */
- private void corrigeCellulesFusionnees(Node nodeGroup) {
- org.w3c.dom.NodeList definitionTable = nodeGroup.getChildNodes()
- boolean hasCelullesFusionneesDansThead = false
- // les cellules fusionnées posent problème quand elles sont verticales et
- // définies à la fois dans le thead et le tbody
- Node thead = findNode(definitionTable, TAG_THEAD)
- Node tbody = findNode(definitionTable, TAG_TBODY)
-
- if (thead && tbody){
- List<Node> theadRows = findNodes(thead.getChildNodes(),'row')
- List<Node> tbodyRows = findNodes(tbody.getChildNodes(),'row')
- if (theadRows?.size() == 1 && tbodyRows?.size() > 0){
- NodeList entries = theadRows[0].getChildNodes()
- for (int index = 0; index < entries.getLength(); index++) {
- Node node = entries.item(index)
- if (node.localName == 'entry' && node.attributes.nodes.find{it.localName=="morerows" && it.value>0}){
- hasCelullesFusionneesDansThead = true
- }
- }
- if (hasCelullesFusionneesDansThead){
- // déplace la ligne du thead au début du tbody
- tbody.insertBefore(theadRows[0], tbodyRows[0])
- // supprime les balises thead
- nodeGroup.removeChild(thead)
- }
- }
- }
- }
-
- private Node findNode(NodeList definitionTable, String nodeName) {
-
- Node resultat = null
-
- for (int index = 0; index < definitionTable.getLength(); index++) {
-
- Node nodeTable = definitionTable.item(index)
-
- if (nodeTable.localName == nodeName) {
- resultat = nodeTable
- }
- }
-
- return resultat
- }
-
- private List<Node> findNodes(NodeList definitionTable, String nodeName) {
-
- List<Node> resultat = []
-
- for (int index = 0; index < definitionTable.getLength(); index++) {
-
- Node nodeTable = definitionTable.item(index)
-
- if (nodeTable.localName == nodeName) {
- resultat.add(nodeTable)
- }
- }
-
- return resultat
- }
-
-
- private Node findEmptyTbody(NodeList definitionTable) {
-
- Node resultat = null
-
- for (int index = 0; index < definitionTable.getLength(); index++) {
-
- Node nodeTable = definitionTable.item(index)
-
- if (nodeTable.localName == TAG_TBODY) {
-
- if (nodeTable.getChildNodes().getLength() == 0) {
- resultat = nodeTable
- }
- }
-
- }
- return resultat
- }
-
- private String nodeToString(Node node) {
-
- String resultat = "# "
- switch (node.getNodeType()) {
- case Node.ELEMENT_NODE:
- resultat = resultat + "ELEMENT_NODE "
- break
-
- case Node.TEXT_NODE:
- resultat = resultat + "TEXT_NODE "
- break
-
- case Node.PROCESSING_INSTRUCTION_NODE:
- resultat = resultat + "PROCESSING_INSTRUCTION_NODE "
- break
-
-
- default:
- resultat = resultat + node.getNodeType().toString() + " "
-
- }
-
- if (node.localName) {
- resultat = resultat + "localName=" + node.localName + " "
- }
-
- if (node.nodeName) {
- resultat = resultat + "nodeName=" + node.nodeName + " "
- }
-
- if (node.nodeValue) {
- resultat = resultat + "nodeValue=" + node.nodeValue.trim() + " "
- }
-
- return resultat
- }
-
- private Boolean isEmphasisVide(Node emphasis) {
-
- String texte = ""
- Boolean vide = true
-
- org.w3c.dom.NodeList listeEnfant = emphasis.getChildNodes()
-
- listeEnfant.each {Node nodeEmphasis ->
-
- if (nodeEmphasis.getNodeType() == Node.TEXT_NODE) {
- texte = texte + nodeEmphasis.nodeValue
- }
-
- if (nodeEmphasis.getNodeType() == Node.ELEMENT_NODE) {
- vide = isEmphasisVide(nodeEmphasis)
- }
-
- }
-
- boolean resultat = (texte.trim() == "") && (vide)
-
- if (log.isDebugEnabled()) {
- if (resultat) {
- log.debug("Balise emphasis sans texte.")
- }
- }
- return resultat
-
- }
-
- private Node findXmlProcesseur(Node emphasis) {
-
- Node resultat = null
- String texte = ""
-
- org.w3c.dom.NodeList listeEnfant = emphasis.getChildNodes()
-
- listeEnfant.each {Node nodeEmphasis ->
-
- if (nodeEmphasis.getNodeType() == Node.TEXT_NODE) {
- texte = texte + nodeEmphasis.nodeValue
- }
-
- if (nodeEmphasis.getNodeType() == Node.ELEMENT_NODE) {
- resultat = findXmlProcesseur(nodeEmphasis)
- }
-
- if (nodeEmphasis.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
- resultat = nodeEmphasis
- }
-
- }
-
- if (log.isDebugEnabled()) {
- if (resultat) {
- log.debug("Instruction processeur xml trouvé sous emphasis.")
- }
- }
-
- return resultat
-
- }
-
- /**
- * si une balise emphasis ne contient aucun texte, elle ne sert à rien, donc on la supprime
- * si une balise emphasis contient un <?linebreak?> cela n'a pas de sens, donc on remplace la balise emphasis par
- * <?linebreak?>
- * on fait l'exploration des enfants de l'emphasis, pour gérer le cas des emphasis imbriqués
- */
- private void parcourtEtCorrigeEmphasis(Node emphasis) {
-
- // si une balise emphasis ne contient aucun texte
- Node nodeProcesseur = findXmlProcesseur(emphasis)
-
- if (isEmphasisVide(emphasis)) {
- Node parent = emphasis.parentNode
- if (nodeProcesseur) {
- Node pi = emphasis.ownerDocument.createProcessingInstruction('linebreak', '')
- parent.insertBefore(pi, emphasis)
- }
- if (log.isDebugEnabled()) {
- log.debug "On enlève ce noeud : " + nodeToString(emphasis)
- }
- parent.removeChild(emphasis)
- }
-
- }
-
- /**
- * parcourt et corrige l'arbre du dom d'un document xml
- */
- private void parcourtEtCorrige(org.w3c.dom.NodeList nodeList) {
-
- nodeList.each {Node node ->
-
- if (log.isDebugEnabled()) {
- log.debug nodeToString(node)
- }
-
- if (node.getNodeType() == Node.ELEMENT_NODE) {
-
- switch (node.localName) {
-
- case TAG_ORDEREDLIST:
-
- def listeOrdonneeEnfant = node.getChildNodes().find {Node nodeRecherche ->
- nodeRecherche.localName == TAG_ORDEREDLIST
- }
-
- if (listeOrdonneeEnfant) {
- reparerListesImbriquees(node)
- parcourtEtCorrige(node.getChildNodes())
- }
-
- break
-
- case TAG_ITEMIZEDLIST:
-
- def listeEnfant = node.getChildNodes().find {Node nodeRecherche ->
- nodeRecherche.localName == TAG_ITEMIZEDLIST
- }
-
- if (listeEnfant) {
- reparerListesImbriquees(node)
- parcourtEtCorrige(node.getChildNodes())
- }
-
- break
-
- case TAG_EMPHASIS:
- parcourtEtCorrigeEmphasis(node)
- break
-
- default:
- parcourtEtCorrige(node.getChildNodes())
- break
-
- }
-
- }
-
- }
-
- }
-
- /**
- * Création d'un noeud listitem pour "réparer" les listes imbriquées
- */
- private void reparerListesImbriquees(Node node) {
- Element elementListe = node.getOwnerDocument().createElement(TAG_LISTITEM)
-
- while (node.hasChildNodes()) {
- elementListe.appendChild(node.getFirstChild())
- }
-
- node.appendChild(elementListe)
- }
-
/**
* Création de la configuration du moteur de rendu des template pour
* docbook