--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project name="XEMELIOS-control-core" default="usage" basedir=".">
+ <import file="../../common-tasks.xml"/>
+ <description>Builds the project XEMELIOS control-core</description>
+ <property file="${user.home}/.ant.properties"/>
+
+ <target name="usage">
+ <echo>
+ Using ${ant.version}
+
+ These are targets supported by this ANT build script:
+
+ compile - compile all .java files, except
+ thoses in ./tmp folder.
+ clean - deletes all compiled and generated
+ files and resources.
+ jars - build jar files.
+
+ Do not call this script directly, use the one located
+ at root of projet (in ../..) instead.
+ </echo>
+ </target>
+
+ <target name="compile" depends="mk-output-dirs,define-compile-debug,prepare">
+ <javac srcdir="java" destdir="build/classes" debug="${compile.debug}" encoding="ISO-8859-1">
+ <classpath>
+ <pathelement path="../starter/build/classes"/>
+ <pathelement path="../xml-marshall/build/classes"/>
+ <pathelement path="../core/build/classes"/>
+ <fileset dir="../core/lib">
+ <include name="*.jar"/>
+ </fileset>
+ </classpath>
+ </javac>
+ <copy todir="build/classes">
+ <fileset dir="java">
+ <include name="**/*"/>
+ <exclude name="**/*.java"/>
+ <exclude name="**/CVS/*"/>
+ <exclude name="**/*.form"/>
+ </fileset>
+ </copy>
+ </target>
+
+ <target name="jars" depends="prepare">
+ <property file="component.properties"/>
+ <copy file="manifest/manifest.txt" tofile="build/manifest.txt">
+ <filterset>
+ <filter token="version" value="${component.release}"/>
+ <filter token="name" value="${component.name}"/>
+ </filterset>
+ </copy>
+ <jar destfile="build/jars/${component.name}.jar" basedir="build/classes" manifest="build/manifest.txt"/>
+ </target>
+
+ <target name="clean">
+ <delete dir="build"/>
+ </target>
+
+
+ <target name="mk-output-dirs">
+ <mkdir dir="build/classes"/>
+ <mkdir dir="build/jars"/>
+ </target>
+
+ <target name="config" depends="get-configuration,prepare">
+ <property name="component.dir" value="build/config/source/${component.name}/${component.release}"/>
+ <copy file="component-definition-properties.xml" tofile="build/config/source/component-definition-properties.xml"/>
+ <mkdir dir="${component.dir}"/>
+ <copy todir="${component.dir}">
+ <fileset dir="build/jars" includes="*.jar"/>
+ </copy>
+ <antcall target="generate-update"/>
+ </target>
+
+ <target name="setup">
+ <copy todir="../../build/setup/root/lib">
+ <fileset dir="build/jars" includes="*.jar"/>
+ </copy>
+ <copy todir="../../build/setup/root/lib">
+ <fileset dir="lib" includes="*.jar"/>
+ </copy>
+ </target>
+
+</project>
+
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="../../defs/technical-component-definition.xsd">
+ <name>control-core</name>
+ <description>Brique de base pour les contrôles</description>
+ <release>5.0.0.2</release>
+ <url>http://xemelios.org/updatesV5/control-core</url>
+ <type>COMPOSANT</type>
+ <destination>
+ <base>${xemelios.root}/lib</base>
+ </destination>
+ <requires>
+ <component-ref url="http://xemelios.org/updatesV5/xml-marshall" release="5.0.0.1"/>
+ <component-ref url="http://xemelios.org/updatesV5/starter" release="5.0.0.0"/>
+ </requires>
+ <release-notes>
+ <release v="5.0.0.2">
+ <note visibility="editeur">Modification de l'API de MainControl, pour supprimer le titre en paramètre du constructeur</note>
+ </release>
+ <release v="5.0.0.1">
+ <note>Standardisation des factory XML</note>
+ <note>Correction bug sur analyse XML valide</note>
+ </release>
+ </release-notes>
+</component>
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.cp.xemelios.controls;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Stack;
+import java.util.TreeSet;
+import java.util.Vector;
+
+import javax.xml.namespace.NamespaceContext;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import fr.gouv.finances.dgfip.utils.Pair;
+import fr.gouv.finances.cp.utils.ui.DlgGetPair;
+import fr.gouv.finances.dgfip.utils.xml.XmlAttributesImpl;
+import fr.gouv.finances.dgfip.xemelios.common.ToolException;
+import fr.gouv.finances.dgfip.xemelios.common.config.DocumentModel;
+import fr.gouv.finances.cp.xemelios.controls.comm.COLLBUDG;
+import fr.gouv.finances.cp.xemelios.controls.models.AddOnModel;
+import fr.gouv.finances.cp.xemelios.controls.models.ControlModel;
+import fr.gouv.finances.cp.xemelios.controls.models.DocumentControlModel;
+import fr.gouv.finances.cp.xemelios.controls.processors.Processor;
+import fr.gouv.finances.cp.xemelios.ui.MainWindow;
+import fr.gouv.finances.dgfip.utils.xml.SAXWriter;
+import fr.gouv.finances.dgfip.xemelios.auth.UnauthorizedException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * @author Jean-Philippe TESSIER
+ *
+ * Permet d'appeler les contrôles unitaires afin de
+ * traiter les anomalies rencontrées que renvoient ces controles.
+ * Ces anomalies sont envoyées à un serializer qui les ajoutent au fichier contôler
+ * par l'intermédiares de tags namespacisés en anos afin de pouvoir les traités dans XéMèLios
+ */
+public abstract class AbstractControlContentHandler extends DefaultHandler implements ContentHandler {
+
+ private static final Logger logger = Logger.getLogger(AbstractControlContentHandler.class);
+ protected Pair collectivite, budget;
+ public int MAX_ANOS = 300;
+ private ArrayList<AbstractUnitControl> controlsToCall;
+ private DocumentControlModel docControlMod;
+ private DocumentModel docModel;
+ //private DocumentModel docsModel;
+ private Hashtable<String, Object> hParams;
+ private Stack<String> stack;
+ protected MainWindow owner;
+ //private String etat;
+ private Vector<Anomalie> anos = new Vector<Anomalie>();
+ private Vector<Anomalie> vTotalAnomalies;
+ private Vector<ControlModel> controlsModel;
+ private SAXWriter saxWriter;
+ private NamespaceContext nsCtx;
+ private boolean startEtatPassed = false;
+ public boolean importInterupted = false;
+ private String fileName;
+// private DlgControl dlgControl;
+ private ControlProgressListener cpl;
+ ArrayList<AddOnModel> addOns = null;
+
+ public void setControlProgressListener(ControlProgressListener cpl) {
+ this.cpl = cpl;
+ }
+
+ public AbstractControlContentHandler(DocumentModel dm, DocumentControlModel docCtrlMod, Hashtable<String, Object> parameters, MainWindow frame, String file, ControlProgressListener cpl) {
+ super();
+ setControlProgressListener(cpl);
+ this.docModel = dm;
+ this.docControlMod = docCtrlMod;
+ this.owner = frame;
+ this.fileName = file;
+ this.nsCtx = dm.getNamespaces();
+ vTotalAnomalies = new Vector<Anomalie>();
+ stack = new Stack<String>();
+ controlsToCall = new ArrayList<AbstractUnitControl>();
+ hParams = parameters;
+ if (docCtrlMod.getEngine() != null) {
+ addOns = docCtrlMod.getEngine().getAddOns();
+ }
+ if (addOns == null) {
+ addOns = new ArrayList<AddOnModel>();
+ }
+ for (AddOnModel addOn : addOns) {
+ addOn.getProcessor().setNamespaceContext(nsCtx);
+ }
+
+ // Le premier contrôle lit le code collectivité ainsi que le code budgétaire.
+ try {
+ COLLBUDG cbc = new COLLBUDG();
+ cbc.setDocumentModel(docControlMod);
+ cbc.setCch(this);
+ cbc.setColl_path(docCtrlMod.getCollectivitePath().getCodePath().getPath());
+ cbc.setColl_lib(docCtrlMod.getCollectivitePath().getLibellePath().getPath());
+ cbc.setBudg_path(docCtrlMod.getBudgetPath().getCodePath().getPath());
+ cbc.setBudg_lib(docCtrlMod.getBudgetPath().getLibellePath().getPath());
+ controlsToCall.add(cbc);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ for (ControlModel ctrlm : docCtrlMod.getControls()) {
+ try {
+ Object o = new Object();
+ if (!ctrlm.id.startsWith("TECH")) {
+ o = Class.forName(ctrlm.getClasse()).newInstance();
+ }
+ if (o instanceof AbstractUnitControl) {
+ AbstractUnitControl auc = (AbstractUnitControl) o;
+ auc.setParameters(getParameters());
+ auc.setDocumentModel(docControlMod);
+ auc.setFileName(fileName);
+ controlsToCall.add(auc);
+ }
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void setFileName(String fileName) {
+ for (AbstractUnitControl auc : controlsToCall) {
+ auc.setFileName(fileName);
+ }
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ for (AbstractUnitControl auc : controlsToCall) {
+ try {
+ auc.startDocument();
+ } catch (SAXException saxEx) {
+ logger.debug("in startDocument cch !!!", saxEx);
+ }
+ }
+ saxWriter.startDocument();
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+ stack.push(localName);
+ String xpath = getXpathExpression();
+ XmlAttributesImpl attrs = new XmlAttributesImpl();
+ for (int i = 0; i < atts.getLength(); i++) {
+ attrs.addAttribute(atts.getURI(i), atts.getLocalName(i), atts.getQName(i), atts.getType(i), atts.getValue(i));
+ }
+ if (stack.size() == 1) {
+ // Ajout du namespace ano: au document
+ startEtatPassed = true;
+ saxWriter.startPrefixMapping(nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI), Anomalie.ANOMALY_NS_URI);
+ }
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI, "node-id",
+ (nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI) != null ? nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI) + ":" : "") + "node-id",
+ "CDATA",
+ IdGenerator.nextId());
+ for (AddOnModel addOn : addOns) {
+ if (addOn.isConcernedBy(Processor.EVENT.START_ELEMENT, uri, localName, qName)) {
+ addOn.process(Processor.EVENT.START_ELEMENT, uri, localName, qName, attrs);
+ }
+ }
+ for (AbstractUnitControl auc : controlsToCall) {
+ auc.startElement(uri, localName, qName, attrs, getXpathExpression());
+ }
+ saxWriter.startElement(uri, localName, qName, attrs);
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ Vector<Anomalie> vAno = new Vector<Anomalie>();
+ for (AbstractUnitControl auc : controlsToCall) {
+ try {
+ anos = auc.endElement(uri, localName, qName, getXpathExpression());
+ if (anos != null && !anos.isEmpty()) {
+ if (!(vTotalAnomalies.size() > MAX_ANOS)) {
+ vTotalAnomalies.addAll(anos);
+ vAno.addAll(anos);
+ }
+ }
+ } catch (SAXException saxEx) {
+ logger.debug("in endElement!!!", saxEx);
+ }
+ }
+ if (!vAno.isEmpty()) {
+ for (Anomalie ano : vAno) {
+ writeAnomalie(ano);
+ }
+ }
+ if (stack.size() == 1) {
+ saxWriter.endPrefixMapping(nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI));
+ }
+
+ saxWriter.endElement(uri, localName, qName);
+ stack.pop();
+
+ }
+
+ @Override
+ public void endDocument() throws SAXException {
+ try {
+ if (collectivite == null || collectivite.key == null || collectivite.libelle == null) {
+ try {
+ collectivite = getCollectivite(docModel, fileName);
+ if (!owner.getConnectedUser().hasCollectivite(collectivite.key, docModel)) {
+ throw new UnauthorizedException("Voux n'êtes pas autorisé à contrôler des fichier de cette collectivite" + collectivite.libelle != null ? " (" + collectivite.libelle + ")" : "");
+ }
+ } catch (ToolException e) {
+ e.printStackTrace();
+ }
+ }
+ if (budget == null || budget.key == null || budget.libelle == null || budget.libelle.equals("")) {
+ try {
+ budget = getBudget(docModel, collectivite, fileName);
+ } catch (ToolException e) {
+ e.printStackTrace();
+ }
+
+ }
+ } catch (UnauthorizedException ex) {
+ throw new SAXException(ex);
+ }
+ saxWriter.endDocument();
+ }
+
+ private Hashtable<String, Object> getParameters() {
+ return hParams;
+ }
+
+ public void setParameters(Hashtable<String, Object> ho) {
+ hParams = ho;
+ }
+
+ private String getXpathExpression() {
+ StringBuffer sb = new StringBuffer();
+ for (String s : stack) {
+ sb.append(s + "/");
+ }
+ return sb.toString();
+ }
+
+ public void setControlsModel(Vector<ControlModel> cm) {
+ this.controlsModel = cm;
+ }
+
+ public void setSaxWriter(SAXWriter sxw) {
+ saxWriter = sxw;
+ }
+
+ public Vector<Anomalie> getVTotalAnomalies() {
+ return vTotalAnomalies;
+ }
+
+ public abstract Pair getCollectivite(DocumentModel dm, String fileName) throws ToolException;
+
+ public abstract Pair getBudget(DocumentModel dm, Pair collectivite, String fileName) throws ToolException, UnauthorizedException;
+
+ protected class QueryCollectivite implements Runnable {
+
+ private Pair ret;
+ private String fileName;
+ private Pair defaultCollectivite = null;
+
+ public Pair getDefaultCollectivite() {
+ return defaultCollectivite;
+ }
+
+ public void setDefaultCollectivite(
+ Pair defaultCollectivite) {
+ this.defaultCollectivite = defaultCollectivite;
+ }
+
+ public QueryCollectivite(String fileName) {
+ super();
+ this.fileName = fileName;
+ }
+
+ public void run() {
+ DlgGetPair dlg = new DlgGetPair(owner, "Sur quelle collectivité porte ce document : " + fileName + " ?", null, null, collectivite);
+ if (dlg.run()) {
+ ret = new Pair(dlg.getCode(), dlg.getLibelle());
+ } else {
+ importInterupted = true;
+// dlgControl.notifyImportInterupted();
+// dlgControl.setVisible(false);
+ cpl.notifyImportInterrupted(true);
+ }
+ }
+
+ public Pair getRet() {
+ return ret;
+ }
+ }
+
+ protected class QueryBudget implements Runnable {
+
+ private String fileName;
+ private TreeSet<Pair> existing;
+ private Pair ret;
+ private String collectivite = null;
+
+ public QueryBudget(String fileName, TreeSet<Pair> existing, String collectivite) {
+ super();
+ this.fileName = fileName;
+ this.existing = existing;
+ this.collectivite = collectivite;
+ }
+
+ public void run() {
+ DlgGetPair dlg = null;
+ dlg = new DlgGetPair(owner, "Sur quel budget porte ce document : " + fileName + " ?", existing, collectivite, budget);
+
+ if (dlg.run()) {
+ ret = new Pair(dlg.getCode(), dlg.getLibelle());
+ } else {
+ if (!importInterupted) {
+// dlgControl.notifyImportInterupted();
+ importInterupted = true;
+ cpl.notifyImportInterrupted(false);
+ }
+ }
+ logger.debug("fin de QueryBudget.run()");
+ }
+
+ public Pair getRet() {
+ logger.debug("QueryBudget.getRet()");
+ return ret;
+ }
+ }
+
+ @Override
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+ super.startPrefixMapping(prefix, uri);
+ for (AbstractUnitControl auc : controlsToCall) {
+ auc.startPrefixMapping(prefix, uri, getXpathExpression());
+ }
+ saxWriter.startPrefixMapping(prefix, uri);
+ }
+
+ @Override
+ public void endPrefixMapping(String prefix) throws SAXException {
+ super.endPrefixMapping(prefix);
+ for (AbstractUnitControl auc : controlsToCall) {
+ auc.endPrefixMapping(prefix, getXpathExpression());
+ }
+ saxWriter.endPrefixMapping(prefix);
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ for (AbstractUnitControl auc : controlsToCall) {
+ try {
+ auc.characters(ch, start, length, getXpathExpression());
+ } catch (SAXException saxEx) {
+ logger.debug("in characters!!!", saxEx);
+ }
+ }
+ saxWriter.characters(ch, start, length);
+ }
+
+ @Override
+ public void setDocumentLocator(Locator locator) {
+ saxWriter.setDocumentLocator(locator);
+ }
+
+ @Override
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
+ saxWriter.ignorableWhitespace(ch, start, length);
+ }
+
+ @Override
+ public void processingInstruction(String target, String data) {
+ try {
+ saxWriter.processingInstruction(target, data);
+ } catch (SAXException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void skippedEntity(String name) throws SAXException {
+ saxWriter.skippedEntity(name);
+ }
+
+ public void setNamespaceContext(NamespaceContext nsCtx) {
+ this.nsCtx = nsCtx;
+ }
+
+ public Pair getBudget() {
+ return budget;
+ }
+
+ public void setBudget(Pair budget) {
+ this.budget = budget;
+ }
+
+ public Pair getCollectivite() {
+ return collectivite;
+ }
+
+ public void setCollectivite(Pair collectivite) {
+ this.collectivite = collectivite;
+ logger.debug("setting collectivite: " + collectivite);
+ }
+
+ private void writeAnomalie(Anomalie ano) {
+ AttributesImpl attrs = new AttributesImpl();
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"anoId",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":anoId","string",ano.getIdAnomalie());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"ctrlLibelle",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlLibelle","string",ano.getControleLibelle());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"ctrlId",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlId","string",ano.getControleID());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"severity",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":severity","string",ano.getSeverity());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"visibility",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":visibility","string",ano.isVisible()?"visible":"hidden");
+ try {
+ saxWriter.startElement(Anomalie.ANOMALY_NS_URI,"Anomalie",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":Anomalie",attrs);
+ } catch(Throwable t) {
+ logger.error("while calling startElement on Anomalie",t);
+ }
+ try {
+ startElement(Anomalie.ANOMALY_NS_URI,"ctrlRegleFonct",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlRegleFonct",new AttributesImpl());
+ saxWriter.addCData(SAXWriter.unescapeText(ano.getRegle()));
+ saxWriter.endElement(Anomalie.ANOMALY_NS_URI,"ctrlRegleFonct",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlRegleFonct");
+ } catch(Throwable t) {
+ logger.error("while writting ctrlRegleFonct",t);
+ }
+ try {
+ saxWriter.startElement(Anomalie.ANOMALY_NS_URI,"message",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":message",new AttributesImpl());
+ saxWriter.addCData(SAXWriter.unescapeText(ano.getMessage()));
+ saxWriter.endElement(Anomalie.ANOMALY_NS_URI,"message",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":message");
+ } catch(Throwable t) {
+ logger.error("while writting message",t);
+ }
+ for(Node node:ano.getNodes()) {
+ AttributesImpl attrs2 = new AttributesImpl();
+ attrs2.addAttribute(Anomalie.ANOMALY_NS_URI,"id",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":id","string",node.getId());
+ try {
+ saxWriter.startElement(Anomalie.ANOMALY_NS_URI,"node",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":node",attrs2);
+ saxWriter.endElement(Anomalie.ANOMALY_NS_URI,"node",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":node");
+ } catch(Throwable t) {
+ logger.error("while writting node",t);
+ }
+ }
+ try {
+ saxWriter.endElement(Anomalie.ANOMALY_NS_URI,"Anomalie",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":Anomalie");
+ } catch(Throwable t) {
+ logger.error("while calling endElement on Anomalie",t);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.cp.xemelios.controls;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.Validator;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.dgfip.utils.Pair;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import fr.gouv.finances.dgfip.xemelios.common.Constants;
+import fr.gouv.finances.dgfip.xemelios.common.config.DocumentModel;
+import fr.gouv.finances.dgfip.xemelios.common.config.DocumentsModel;
+import fr.gouv.finances.cp.xemelios.controls.models.ControlsModel;
+import fr.gouv.finances.cp.xemelios.controls.models.DocumentControlModel;
+import fr.gouv.finances.cp.xemelios.controls.models.ParamModel;
+import fr.gouv.finances.cp.xemelios.controls.models.ParamModelTech;
+import fr.gouv.finances.cp.xemelios.controls.tech.TECH01;
+import fr.gouv.finances.cp.xemelios.controls.tech.TECH02;
+import fr.gouv.finances.cp.xemelios.controls.tech.TECH03;
+import fr.gouv.finances.cp.xemelios.ui.MainWindow;
+import fr.gouv.finances.dgfip.utils.HostUtils;
+import fr.gouv.finances.dgfip.utils.xml.SAXWriter;
+import fr.gouv.finances.dgfip.xemelios.txt2xml.Txt2Xml;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import javax.xml.XMLConstants;
+import javax.xml.validation.SchemaFactory;
+
+public class MainControl implements Runnable {
+
+ public static final int STATUS_NOT_CONTROLLED = -1;
+ public static final int STATUS_NOT_XML = 1;
+ public static final int STATUS_INVALID_ENCODING = 2;
+ public static final int STATUS_NOT_SCHEMA_VALID = 3;
+ public static final int STATUS_HAS_UNIT_CONTROL_ERRORS = 4;
+ public static final int STATUS_CONTROL_NO_ERROR = 5;
+ private final static Logger logger = Logger.getLogger(MainControl.class);
+ private File fichierAController, rapport, inputXmlFile;
+ private DocumentModel documentModel;
+ private DocumentsModel docsModel;
+ private Hashtable<String, Object> hashParams = new Hashtable<String, Object>();
+ private DocumentControlModel dcm;
+ private Date datecontrole;
+ private NamespaceContext nameSpaces;
+ private SAXWriter saxWriter = null;
+ public static final String ID_DOCUMENT_RAPPORT = "DocumentRapport";
+ private ControlsModel cm;
+ private String IDrapport = "", domainesControles = "";
+ private RapportWriter rapportWriter;
+ private boolean hasTech01Error = false/*, hasTech02Error = false, hasTech03Error = false*/;
+ private AbstractControlContentHandler cch = null;
+ private File fichierEnrichi = null;
+ private String fichierEnrichiLocation = null, rapportLocation = null;
+ private ControlProgressListener cpl = null;
+ private int status = STATUS_NOT_CONTROLLED;
+ private ArrayList<Anomalie> anomaliesTechniques;
+ private SAXParserFactory factorySAX = null;
+
+ public MainControl(DocumentModel dm, DocumentsModel docsMod) {
+ super();
+ this.documentModel = dm;
+ this.docsModel = docsMod;
+ cm = getControlsModel();
+ dcm = cm.getDocumentById(dm.getId());
+ nameSpaces = documentModel.getNamespaces();
+ factorySAX = SAXParserFactory.newInstance();
+ factorySAX.setNamespaceAware(true);
+ anomaliesTechniques = new ArrayList<Anomalie>();
+ }
+
+ public DocumentControlModel getDocumentControl() {
+ return dcm;
+ }
+
+ protected boolean controlXmlSyntax(File inputFile, TECH01 tech01) {
+ FileInputStream fisTech = null;
+ try {
+ fisTech = new FileInputStream(fichierAController);
+ SAXParser parserXmlTech = factorySAX.newSAXParser();
+ tech01.setDocModel(documentModel);
+ parserXmlTech.parse(fisTech, tech01);
+ } catch (FileNotFoundException e1) {
+ e1.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ } catch (SAXException e) {
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ domainesControles = tech01.getDomaines();
+ anomaliesTechniques.addAll(tech01.getAnomalies());
+ if (anomaliesTechniques.size() > 0) {
+ status = STATUS_NOT_XML;
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public void run() {
+ if(getDocumentModel().getTextToXmlTransformer()!=null) {
+ try {
+ Class clazz = Class.forName(getDocumentModel().getTextToXmlTransformer());
+ Txt2Xml transformer = (Txt2Xml) clazz.newInstance();
+ if (transformer != null) {
+ inputXmlFile = transformer.transform(fichierAController);
+ }
+ } catch (Exception ex) {
+ logger.error("while instancying textToXmlTransformer", ex);
+ }
+ }
+ if(inputXmlFile==null) inputXmlFile = fichierAController;
+ boolean technicalValidationFailed = false;
+ TECH01 tech01 = new TECH01();
+ TECH02 tech02 = new TECH02();
+ TECH03 tech03 = new TECH03();
+ tech03.setDocumentModel(documentModel);
+
+ // on crée les éléments pour permettre l'écriture du rapport
+ File tmpDir = new File(System.getProperty("java.io.tmpdir"), Constants.NOM_APP);
+ if (!tmpDir.exists()) {
+ tmpDir.mkdirs();
+ }
+ if (rapportLocation == null) {
+ rapportLocation = new File(tmpDir, "rapport" + inputXmlFile.getName()).getAbsolutePath();
+ }
+ rapport = new File(rapportLocation);
+ logger.debug("rapport: " + rapport.getAbsolutePath());
+ datecontrole = new Date();
+
+ Charset cs = Charset.forName("ISO-8859-1");
+ OutputStreamWriter fos = null;
+ try {
+ fos = new OutputStreamWriter(new FileOutputStream(rapport), cs);
+ } catch (Exception e1) {
+ logger.error("while creating fos", e1);
+ }
+ rapportWriter = new RapportWriter(new XmlOutputter(fos, cs.name()));
+
+ // on crée l'objet qui contient les controles
+ cch = getControlContentHandler(documentModel, dcm, hashParams, MainWindow.instance, fichierAController.getName(), cpl);
+
+ // on vérifie si le document est du XML
+ hasTech01Error = !controlXmlSyntax(inputXmlFile, tech01);
+
+ if (!hasTech01Error) {
+ boolean shouldContinue = true;
+ if (dcm.getControlTechById("TECH02") != null) {
+ // on veut faire un controle d'encoding
+ boolean isEncodingValid = tech02.encodingValid(dcm.getControlTechById("TECH02"), inputXmlFile);
+ if (!isEncodingValid) {
+ Anomalie ano = new Anomalie(IdGenerator.nextId(),
+ "TECH02", "Contrôle de l'encoding du fichier.",
+ documentModel.getId(), "", "", "", "", "",
+ "Le fichier est encodé en " + tech02.getInputEncoding() + " alors qu'il devrait être encodé en " + tech02.getValidEncodings() + ".",
+ "Le fichier doit être encodé en " + tech02.getValidEncodings() + ".",
+ "BLOQUANT", "xpath namespacise",
+ new Hashtable<String, Object>());
+ anomaliesTechniques.add(ano);
+
+ // check if we should continue
+ shouldContinue = false;
+ ParamModelTech param = dcm.getControlTechById("TECH02").getParamTechById("failOnError");
+ if (param!=null && "false".equals(param.getValue())) {
+ shouldContinue = true;
+ } else {
+ technicalValidationFailed = true;
+ }
+ status = STATUS_INVALID_ENCODING;
+ tech02.getInputEncoding();
+ }
+ }
+
+ if (shouldContinue) {
+ // now, check if we need a control against schema
+ if (dcm.getControlTechById("TECH03") != null) {
+ // Contrôle de validité au schéma
+ SchemaFactory xmlsf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ File fileSchema = new File(documentModel.getBaseDirectory(), dcm.getControlTechById("TECH03").getParamTechById("schemaLocation").getValue());
+ Schema schema;
+ try {
+ schema = xmlsf.newSchema(fileSchema);
+ Validator validateur = schema.newValidator();
+ FileInputStream fis = new FileInputStream(inputXmlFile);
+ SAXSource saxSrc = new SAXSource(new InputSource(fis));
+ tech03.setDomainesControles(domainesControles);
+ validateur.setErrorHandler(tech03);
+ validateur.validate(saxSrc);
+ fis.close();
+ } catch (Exception ex) {
+ // an exception during schema loading
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw, true);
+ ex.printStackTrace(pw);
+ Anomalie ano = new Anomalie(IdGenerator.nextId(),
+ "TECH03", "Contrôle de conformité as schéma du fichier.",
+ documentModel.getId(), "", "", "", "", "",
+ "Erreur inattendue lors du chargement du schéma:\n" + sw.toString(),
+ "Le schéma ne peut pas être chargé.",
+ "BLOQUANT", "xpath namespacise",
+ new Hashtable<String, Object>());
+ anomaliesTechniques.add(ano);
+ }
+ if (tech03.getAnomalies().size() > 0) {
+ // there is some errors...
+ anomaliesTechniques.addAll(tech03.getAnomalies());
+ shouldContinue = false;
+ // should we continue ?
+ ParamModelTech param = dcm.getControlTechById("TECH03").getParamTechById("failOnError");
+ if (param != null && "false".equals(param.getValue())) {
+ shouldContinue = true;
+ } else {
+ technicalValidationFailed = true;
+ }
+ status = STATUS_NOT_SCHEMA_VALID;
+ }
+ }
+ }
+ // now, apply unit controls
+ if (shouldContinue) {
+ cch.setParameters(hashParams);
+ cch.setControlsModel(dcm.getControls());
+ try {
+ FileInputStream fis = new FileInputStream(inputXmlFile);
+ SAXParser parserXml = factorySAX.newSAXParser();
+ if (fichierEnrichiLocation == null) {
+ fichierEnrichiLocation = new File(tmpDir, inputXmlFile.getName()).getAbsolutePath();
+ }
+ fichierEnrichi = new File(fichierEnrichiLocation);
+ Charset csOutput = Charset.forName("ISO-8859-1");
+ OutputStream os = new FileOutputStream(fichierEnrichi);
+ saxWriter = new SAXWriter(os,csOutput.name());
+// saxWriter.setNamespaceContext(nameSpaces);
+// DOMResult dr = new DOMResult();
+// saxWriter.setResult(dr);
+// saxWriter.getTransformer().setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "{http://projets.admisource.gouv.fr/xemelios/namespaces#anomally}ctrlRegleFonct {http://projets.admisource.gouv.fr/xemelios/namespaces#anomally}message");
+
+ cch.setSaxWriter(saxWriter);
+ cch.setNamespaceContext(nameSpaces);
+ cch.setFileName(fichierAController.getName());
+ parserXml.parse(fis, cch);
+
+// StreamResult sr = new StreamResult(fichierEnrichi);
+// TransformerFactory tf = net.sf.saxon.TransformerFactoryImpl.newInstance();
+// Transformer t = tf.newTransformer();
+// // t.setOutputProperty(OutputKeys.ENCODING, tech02.getInputEncoding().equals("") ? FileUtils.getFileEncoding(fichierAController) : tech02.getInputEncoding());
+// t.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "{http://projets.admisource.gouv.fr/xemelios/namespaces#anomally}ctrlRegleFonct {http://projets.admisource.gouv.fr/xemelios/namespaces#anomally}message");
+// t.transform(new DOMSource(dr.getNode()), sr);
+// if (sr.getOutputStream() != null) {
+// sr.getOutputStream().flush();
+// sr.getOutputStream().close();
+// }
+ os.flush();
+ os.close();
+ // ajout CHM
+ fis.close();
+ if(cch.getVTotalAnomalies().size()>0) {
+ anomaliesTechniques.addAll(cch.getVTotalAnomalies());
+ status = STATUS_HAS_UNIT_CONTROL_ERRORS;
+ } else {
+ status = STATUS_CONTROL_NO_ERROR;
+ }
+ } catch (Exception ex) {
+ // an exception during schema loading
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw, true);
+ ex.printStackTrace(pw);
+ Anomalie ano = new Anomalie(IdGenerator.nextId(),
+ "Contrôles métier", "Application des contrôles métier.",
+ documentModel.getId(), "", "", "", "", "",
+ "Erreur inattendue lors de l'application des contrôles métiers:\n" + sw.toString(),
+ ex.getMessage(),
+ "BLOQUANT", "xpath namespacise",
+ new Hashtable<String, Object>());
+ anomaliesTechniques.add(ano);
+ }
+ }
+ }
+ Pair pColl = cch.getCollectivite();
+ if (pColl == null || pColl.key == null || pColl.libelle == null) {
+ pColl = new Pair("00000000000000", "Collectivite de Contrôle");
+ }
+ Pair pBudg = cch.getBudget();
+ if (pBudg == null || pBudg.key == null || pBudg.libelle == null) {
+ pBudg = new Pair("00", "Budget de Contrôle");
+ }
+ try {
+ writeRapport(pColl, pBudg, anomaliesTechniques, cch.MAX_ANOS);
+ } catch (IOException ioEx) {
+ // TODO
+ }
+ cpl.stopWaiting();
+ if(technicalValidationFailed) cpl.notifyTechniqueValidationFailed();
+
+ }
+
+ public Pair getCollectivite() throws IllegalStateException {
+ if (status == STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must run control before calling getCollectivite()");
+ }
+ if (cch != null) {
+ return cch.getCollectivite();
+ } else {
+ return null;
+ }
+ }
+
+ public Pair getBudget() throws IllegalStateException {
+ if (status == STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must run control before calling getBudget()");
+ }
+ if (cch != null) {
+ return cch.getBudget();
+ } else {
+ return null;
+ }
+ }
+
+ public Vector<Anomalie> getTotalAnomalies() throws IllegalStateException {
+ if (status == STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must run control before calling getTotalAnomalies()");
+ }
+ return cch != null ? cch.getVTotalAnomalies() : new Vector<Anomalie>();
+ }
+
+ private ControlsModel getControlsModel() {
+ ControlsModel ret = null;
+ try {
+ ControlParser cp = new ControlParser();
+ cp.parse(new File(documentModel.getBaseDirectory(), documentModel.getControlConfigFile()));
+ ControlsModel c = (ControlsModel) cp.getMarshallable();
+ c.validate();
+ ret = c;
+ } catch (Exception ex) {
+ logger.debug("Error in getControlsModel()!!!", ex);
+ }
+ return ret;
+ }
+
+ public void setFileToControl(File f) {
+ this.fichierAController = f;
+ }
+
+ public File getFileToControl() {
+ return fichierAController;
+ }
+
+ public void setParameters(Hashtable<String, Object> params) {
+ this.hashParams = params;
+ }
+
+ private void writeRapport(Pair collec, Pair budg, ArrayList<Anomalie> vano, int maxanos) throws IOException {
+ logger.debug("writing rapport: \n\tcollectivite = " + collec + "\n\tbuget=" + budg);
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ String msgAno = "";
+ if (vano != null && vano.size() >= maxanos && !vano.get(0).getControleID().startsWith("TECH")) {
+ msgAno = "true";
+ } else {
+ msgAno = "false";
+ }
+
+ IDrapport = datecontrole.getTime() + rapport.getName();
+ // Entete du rapport
+ Pair docid = new Pair("V", documentModel.getId());
+ rapportWriter.writeElement("DocId", docid);
+ rapportWriter.writeElement("NomFichier", new Pair("V", fichierAController.getName()), new Pair("fullPath", fichierAController.getAbsolutePath()), new Pair("host", HostUtils.getHostName()));
+ //rapportWriter.writeElement("DateControle",new Pair("V",simpleDateFormat.format(new Date())));
+ rapportWriter.writeElement("DateControle", new Pair("V", simpleDateFormat.format(datecontrole)));
+
+ rapportWriter.openElement("Collectivite");
+ rapportWriter.writeElement("Siret", new Pair("V", collec.key));
+ rapportWriter.writeElement("Libelle", new Pair("V", collec.libelle));
+ rapportWriter.closeElement("Collectivite");
+
+ rapportWriter.openElement("Budget");
+ rapportWriter.writeElement("Code", new Pair("V", budg.key));
+ rapportWriter.writeElement("Libelle", new Pair("V", budg.libelle));
+ rapportWriter.closeElement("Budget");
+
+ rapportWriter.writeElement("TropAnos", new Pair("V", msgAno));
+ rapportWriter.openElement("Domaines");
+ String domaines[] = domainesControles.split(" / ");
+ for (String domain : domaines) {
+ rapportWriter.writeElement("Domaine", new Pair("V", domain));
+ }
+ rapportWriter.closeElement("Domaines");
+ rapportWriter.openElement("Params");
+ writeParameters();
+ rapportWriter.closeElement("Params");
+
+ // Corps du rapport
+ rapportWriter.openElement("DonneesRapport");
+ rapportWriter.openElement("Rapport");
+ rapportWriter.writeElement("Id", new Pair("V", datecontrole.getTime() + rapport.getName()));
+ if (vano != null) {
+ Collections.sort(vano, Collections.reverseOrder());
+ for (Anomalie anomalie : vano) {
+ //writeAnomalie(anomalie);
+ anomalie.marshall(rapportWriter);
+ }
+ }
+ rapportWriter.closeElement("Rapport");
+ rapportWriter.closeElement("DonneesRapport");
+ if (cm.getMessage() != null) {
+ rapportWriter.openElement("Message");
+ rapportWriter.writeData(cm.getMessage().getHtmlContent());
+ rapportWriter.closeElement("Message");
+ }
+ rapportWriter.endRapport();
+ logger.debug("Le rapport se trouve dans : " + rapport.getParent());
+ }
+
+ @Deprecated
+ private void writeAnomalie(Anomalie a) {
+ rapportWriter.openElement("Anomalie");
+ rapportWriter.writeElement("Id", new Pair("V", a.getIdAnomalie()));
+ rapportWriter.writeElement("IdCtrl", new Pair("V", a.getControleID()));
+ rapportWriter.writeElement("LibelleCtrl", new Pair("V", a.getControleLibelle()));
+ rapportWriter.writeElement("EtatId", new Pair("V", a.getEtatID()));
+ rapportWriter.writeElement("ElementImportable", new Pair("V", a.getelementImportable()));
+ rapportWriter.writeElement("IdElementImportable", new Pair("V", a.getIdElementImportable()));
+ rapportWriter.writeElement("ElementEnAnomalie", new Pair("V", a.getelementEnAnomalie()));
+ rapportWriter.writeElement("LibelleLien", new Pair("V", a.getLibelleLien()));
+
+ rapportWriter.openElement("Message");
+ rapportWriter.writeData(a.getMessage().replaceAll("<", "<").replaceAll(">", ">").replaceAll("&", "&"));
+ rapportWriter.closeElement("Message");
+
+ rapportWriter.openElement("Regle");
+ rapportWriter.writeData(a.getRegle().replaceAll("<", "<").replaceAll(">", ">").replaceAll("&", "&"));
+ rapportWriter.closeElement("Regle");
+
+ rapportWriter.writeElement("Severity", new Pair("V", a.getSeverity()));
+ if (a.getXPath() != null) {
+ rapportWriter.writeElement("XPath", new Pair("V", a.getXPath()));
+ }
+ if (a.getXslParams() != null && a.getXslParams().size() > 0) {
+ for (String key : a.getXslParams().keySet()) {
+ String value = a.getXslParams().get(key).toString();
+ rapportWriter.openElement("XslParam");
+ rapportWriter.writeElement("Key", new Pair("V", key));
+ rapportWriter.writeElement("Value", new Pair("V", value));
+ rapportWriter.closeElement("XslParam");
+ }
+ }
+ rapportWriter.closeElement("Anomalie");
+ }
+
+ private String writeParameters() {
+ StringBuffer params = new StringBuffer();
+ for (ParamModel param : dcm.getParams()) {
+ String paramValue = "";
+ if (hashParams.get(param.getId()).getClass().equals(Boolean.class)) {
+ if (hashParams.get(param.getId()).equals(true)) {
+ paramValue = "Oui";
+ } else if (hashParams.get(param.getId()).equals(false)) {
+ paramValue = "Non";
+ } else {
+ paramValue = "Nc";
+ }
+ } else if (hashParams.get(param.getId()).getClass().equals(BigDecimal.class)) {
+ paramValue = hashParams.get(param.getId()).toString();
+ } else if (hashParams.get(param.getId()).getClass().equals(String.class)) {
+ paramValue = hashParams.get(param.getId()).toString();
+ } else if (hashParams.get(param.getId()).getClass().equals(Integer.class)) {
+ paramValue = hashParams.get(param.getId()).toString();
+ } else if (hashParams.get(param.getId()) instanceof String[]) {
+ if (((String[]) hashParams.get(param.getId())).length == 0) {
+ paramValue = "Non Renseigné";
+ }
+ for (int i = 0; i < ((String[]) hashParams.get(param.getId())).length; i++) {
+ paramValue += (i != 0 ? ", " : "") + ((String[]) hashParams.get(param.getId()))[i];
+ }
+ } else {
+ paramValue = hashParams.get(param.getId()).getClass().getName();
+ }
+ rapportWriter.writeElement("Param", new Pair("Name", param.getName()), new Pair("Value", paramValue));
+ }
+ return params.toString();
+ }
+
+ public void writeControlConfigFile() throws IOException {
+ File output = new File(documentModel.getBaseDirectory(), documentModel.getControlConfigFile());
+ OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(output), "ISO-8859-1");
+ XmlOutputter outputter = new XmlOutputter(os, "ISO-8859-1");
+ cm.marshall(outputter);
+ os.flush();
+ os.close();
+ }
+
+ public int getControlStatus() {
+ return status;
+ }
+
+ public DocumentModel getDocumentModel() {
+ return documentModel;
+ }
+
+ public File getFichierEnrichi() throws IllegalStateException {
+ if (status == STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must run control before calling getFichierEnrichi()");
+ }
+ return fichierEnrichi;
+ }
+
+ public File getRapport() throws IllegalStateException {
+ if (status == STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must run control before calling getRapport()");
+ }
+ return rapport;
+ }
+
+ public String getIdRapport() {
+ return IDrapport;
+ }
+
+ public void setControlProgressListener(ControlProgressListener cpl) {
+ this.cpl = cpl;
+ }
+
+ public void setFichierEnrichiLocation(String absoluteFileName) throws IllegalStateException {
+ if (status != STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must not change fichierEnrichi location after control");
+ }
+ fichierEnrichiLocation = absoluteFileName;
+ }
+
+ public void setRapportLocation(String absoluteFileName) throws IllegalStateException {
+ if (status != STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must not change rapport location after control");
+ }
+ rapportLocation = absoluteFileName;
+ }
+
+ public AbstractControlContentHandler getControlContentHandler(DocumentModel dm, DocumentControlModel docCtrlMod, Hashtable<String, Object> parameters,
+ MainWindow owner, String file, ControlProgressListener cpl) {
+ return new DefaultControlContentHandler(dm, docCtrlMod, parameters, owner, file, cpl);
+ }
+
+ /**
+ * Permet de renvoyer les informations clefs sur le rapport genere
+ */
+ public static class Triplet {
+
+ public String iDrapport;
+ public String codeCollectivite;
+ public String codeBudget;
+
+ public Triplet(String idRapport, String codColl, String codBud) {
+ super();
+ this.iDrapport = idRapport;
+ this.codeCollectivite = codColl;
+ this.codeBudget = codBud;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package fr.gouv.finances.cp.xemelios.controls;
+
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import fr.gouv.finances.dgfip.utils.Pair;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+
+
+import javax.xml.namespace.QName;
+import org.apache.log4j.Logger;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ *
+ * @author chm
+ */
+@Deprecated
+public class SaxXmlWriter extends DefaultHandler {
+ private static Logger logger = Logger.getLogger(SaxXmlWriter.class);
+ private static final String DEFAULT_ENCODING = "UTF-8";
+ private String encoding = DEFAULT_ENCODING;
+ private NamespaceContext nsCtx;
+ private XmlOutputter output;
+ private ArrayList<Pair> nsMappingToWrite;
+
+ /** Creates a new instance of SaxXmlWriter */
+ public SaxXmlWriter(OutputStreamWriter osw, String encoding) {
+// super(new Controller(new Configuration()));
+ super();
+ this.encoding = encoding;
+ output = new XmlOutputter(osw,this.encoding);
+ nsMappingToWrite = new ArrayList<Pair>();
+ }
+// public void setEncoding(String encoding) {
+// this.encoding=encoding;
+// }
+ public void setNamespaceContext(NamespaceContext nsCtx) {
+ this.nsCtx = nsCtx;
+ }
+ public void writeAnomally(Anomalie ano) {
+ AttributesImpl attrs = new AttributesImpl();
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"anoId",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":anoId","string",ano.getIdAnomalie());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"ctrlLibelle",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlLibelle","string",ano.getControleLibelle());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"ctrlId",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlId","string",ano.getControleID());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"severity",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":severity","string",ano.getSeverity());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"visibility",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":visibility","string",ano.isVisible()?"visible":"hidden");
+ try {
+ startElement(Anomalie.ANOMALY_NS_URI,"Anomalie",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":Anomalie",attrs);
+ } catch(Throwable t) {
+ logger.error("while calling startElement on Anomalie",t);
+ }
+ try {
+ startElement(Anomalie.ANOMALY_NS_URI,"ctrlRegleFonct",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlRegleFonct",new AttributesImpl());
+ addCData(ano.getRegle());
+ endElement(Anomalie.ANOMALY_NS_URI,"ctrlRegleFonct",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlRegleFonct");
+ } catch(Throwable t) {
+ logger.error("while writting ctrlRegleFonct",t);
+ }
+ try {
+ startElement(Anomalie.ANOMALY_NS_URI,"message",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":message",new AttributesImpl());
+ addCData(ano.getMessage());
+ endElement(Anomalie.ANOMALY_NS_URI,"message",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":message");
+ } catch(Throwable t) {
+ logger.error("while writting message",t);
+ }
+ for(Node node:ano.getNodes()) {
+ AttributesImpl attrs2 = new AttributesImpl();
+ attrs2.addAttribute(Anomalie.ANOMALY_NS_URI,"id",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":id","string",node.getId());
+ try {
+ startElement(Anomalie.ANOMALY_NS_URI,"node",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":node",attrs2);
+ endElement(Anomalie.ANOMALY_NS_URI,"node",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":node");
+ } catch(Throwable t) {
+ logger.error("while writting node",t);
+ }
+ }
+ try {
+ endElement(Anomalie.ANOMALY_NS_URI,"Anomalie",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":Anomalie");
+ } catch(Throwable t) {
+ logger.error("while calling endElement on Anomalie",t);
+ }
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ super.startDocument();
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+// super.startElement(uri, localName, qName, attributes);
+ output.startTag(qName);
+ for(int attCount=0;attCount<attributes.getLength();attCount++) {
+ output.addAttribute(attributes.getQName(attCount), attributes.getValue(attCount));
+ }
+ if(!nsMappingToWrite.isEmpty()) {
+ for(Pair p:nsMappingToWrite) {
+ QName att = new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,p.key,"xmlns");
+ output.addAttribute(att, p.libelle);
+ }
+ nsMappingToWrite = new ArrayList<Pair>();
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ // super.endElement(uri, localName, qName);
+ output.endTag(qName);
+ }
+
+ @Override
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+// super.startPrefixMapping(prefix, uri);
+ nsMappingToWrite.add(new Pair(prefix,uri));
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException {
+// super.characters(ch, start, length);
+ output.addCharacterData(new String(ch,0,length));
+ }
+
+ public void addCData(char[] ch, int start, int length) throws SAXException {
+ addCData(new String(ch,start,length));
+ }
+
+ public void addCData(String s) throws SAXException {
+ output.addCData(s);
+ }
+
+
+
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Stack;
+import java.util.Vector;
+
+import javax.xml.namespace.NamespaceContext;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import fr.gouv.finances.dgfip.utils.Pair;
+import fr.gouv.finances.dgfip.utils.xml.XmlAttributesImpl;
+import fr.gouv.finances.dgfip.xemelios.controls.core.comm.COLLBUDG;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.AddOnModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ControlModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.DocumentControlModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.processors.Processor;
+import fr.gouv.finances.dgfip.xemelios.auth.UnauthorizedException;
+
+/**
+ * @author Jean-Philippe TESSIER
+ *
+ * Permet d'appeler les contrôles unitaires afin de
+ * traiter les anomalies rencontrées que renvoient ces controles.
+ * Ces anomalies sont envoyées à un serializer qui les ajoutent au fichier contôler
+ * par l'intermédiares de tags namespacisés en anos afin de pouvoir les traités dans XéMèLios
+ */
+public abstract class AbstractControlContentHandler extends DefaultHandler implements ContentHandler {
+
+ private static final Logger logger = Logger.getLogger(AbstractControlContentHandler.class);
+ protected Pair collectivite, budget;
+ public int MAX_ANOS = 300;
+ private ArrayList<AbstractUnitControl> controlsToCall;
+ private DocumentControlModel docControlMod;
+ private String documentId;
+ private Hashtable<String, Object> hParams;
+ private Stack<String> stack;
+// protected MainWindow owner;
+ private Vector<Anomalie> anos = new Vector<Anomalie>();
+ private Vector<Anomalie> vTotalAnomalies;
+ private Vector<ControlModel> controlsModel;
+ private SaxXmlWriter saxXmlWriter;
+ private NamespaceContext nsCtx;
+ private boolean startEtatPassed = false;
+ public boolean importInterupted = false;
+ private String fileName;
+ private ControlProgressListener cpl;
+ ArrayList<AddOnModel> addOns = null;
+
+ public void setControlProgressListener(ControlProgressListener cpl) {
+ this.cpl = cpl;
+ }
+
+ public AbstractControlContentHandler(
+ String documentId,
+ NamespaceContext nsCtx,
+ DocumentControlModel docCtrlMod,
+ Hashtable<String, Object> parameters,
+ String file,
+ ControlProgressListener cpl) {
+ super();
+ setControlProgressListener(cpl);
+ this.documentId = documentId;
+ this.docControlMod = docCtrlMod;
+ this.fileName = file;
+ this.nsCtx = nsCtx;
+ vTotalAnomalies = new Vector<Anomalie>();
+ stack = new Stack<String>();
+ controlsToCall = new ArrayList<AbstractUnitControl>();
+ hParams = parameters;
+ if (docCtrlMod.getEngine() != null) {
+ addOns = docCtrlMod.getEngine().getAddOns();
+ }
+ if (addOns == null) {
+ addOns = new ArrayList<AddOnModel>();
+ }
+ for (AddOnModel addOn : addOns) {
+ addOn.getProcessor().setNamespaceContext(nsCtx);
+ }
+
+ // Le premier contrôle lit le code collectivité ainsi que le code budgétaire.
+ try {
+ COLLBUDG cbc = new COLLBUDG();
+ cbc.setDocumentModel(docControlMod);
+ cbc.setCch(this);
+ cbc.setColl_path(docCtrlMod.getCollectivitePath().getCodePath().getPath());
+ cbc.setColl_lib(docCtrlMod.getCollectivitePath().getLibellePath().getPath());
+ cbc.setBudg_path(docCtrlMod.getBudgetPath().getCodePath().getPath());
+ cbc.setBudg_lib(docCtrlMod.getBudgetPath().getLibellePath().getPath());
+ controlsToCall.add(cbc);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ for (ControlModel ctrlm : docCtrlMod.getControls()) {
+ try {
+ Object o = new Object();
+ if (!ctrlm.id.startsWith("TECH")) {
+ o = Class.forName(ctrlm.getClasse()).newInstance();
+ }
+ if (o instanceof AbstractUnitControl) {
+ AbstractUnitControl auc = (AbstractUnitControl) o;
+ auc.setParameters(getParameters());
+ auc.setDocumentModel(docControlMod);
+ auc.setFileName(fileName);
+ controlsToCall.add(auc);
+ }
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void setFileName(String fileName) {
+ for (AbstractUnitControl auc : controlsToCall) {
+ auc.setFileName(fileName);
+ }
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ for(AddOnModel addOn:addOns) {
+ if(addOn.isConcernedBy(Processor.EVENT.START_DOCUMENT, null, null, null))
+ addOn.process(Processor.EVENT.START_DOCUMENT);
+ }
+ for (AbstractUnitControl auc : controlsToCall) {
+ try {
+ auc.startDocument();
+ } catch (SAXException saxEx) {
+ logger.debug("in startDocument cch !!!", saxEx);
+ }
+ }
+ saxXmlWriter.startDocument();
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+ stack.push(localName);
+ String xpath = getXpathExpression();
+ XmlAttributesImpl attrs = new XmlAttributesImpl();
+ for (int i = 0; i < atts.getLength(); i++) {
+ attrs.addAttribute(atts.getURI(i), atts.getLocalName(i), atts.getQName(i), atts.getType(i), atts.getValue(i));
+ }
+ if (stack.size() == 1) {
+ // Ajout du namespace ano: au document
+ startEtatPassed = true;
+ saxXmlWriter.startPrefixMapping(nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI), Anomalie.ANOMALY_NS_URI);
+ }
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI, "node-id",
+ (nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI) != null ? nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI) + ":" : "") + "node-id",
+ "CDATA",
+ IdGenerator.nextId());
+ for (AddOnModel addOn : addOns) {
+ if (addOn.isConcernedBy(Processor.EVENT.START_ELEMENT, uri, localName, qName)) {
+ addOn.process(Processor.EVENT.START_ELEMENT, uri, localName, qName, attrs);
+ }
+ }
+ for (AbstractUnitControl auc : controlsToCall) {
+ auc.startElement(uri, localName, qName, attrs, getXpathExpression());
+ }
+ saxXmlWriter.startElement(uri, localName, qName, attrs);
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ Vector<Anomalie> vAno = new Vector<Anomalie>();
+ for (AbstractUnitControl auc : controlsToCall) {
+ try {
+ anos = auc.endElement(uri, localName, qName, getXpathExpression());
+ if (anos != null && !anos.isEmpty()) {
+ if (!(vTotalAnomalies.size() > MAX_ANOS)) {
+ vTotalAnomalies.addAll(anos);
+ vAno.addAll(anos);
+ }
+ }
+ } catch (SAXException saxEx) {
+ logger.debug("in endElement!!!", saxEx);
+ }
+ }
+ if (!vAno.isEmpty()) {
+ for (Anomalie ano : vAno) {
+ saxXmlWriter.writeAnomally(ano);
+ }
+ }
+ if (stack.size() == 1) {
+ saxXmlWriter.endPrefixMapping(nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI));
+ }
+
+ saxXmlWriter.endElement(uri, localName, qName);
+ stack.pop();
+
+ }
+
+ @Override
+ public void endDocument() throws SAXException {
+ if (collectivite == null || collectivite.key == null || collectivite.libelle == null) {
+ try {
+ collectivite = getCollectivite(documentId, fileName);
+ // on déplace ce contrôle vers le potentiel import
+// if (!owner.getConnectedUser().hasCollectivite(collectivite.key, xxx)) {
+// throw new UnauthorizedException("Voux n'êtes pas autorisé à contrôler des fichier de cette collectivite" + collectivite.libelle != null ? " (" + collectivite.libelle + ")" : "");
+// }
+ } catch (Exception e) {
+ e.printStackTrace();
+ if(e instanceof UnauthorizedException) throw new SAXException(e);
+ }
+ }
+ if (budget == null || budget.key == null || budget.libelle == null || budget.libelle.equals("")) {
+ try {
+ budget = getBudget(documentId, collectivite, fileName);
+ } catch (Exception e) {
+ e.printStackTrace();
+ if(e instanceof UnauthorizedException) throw new SAXException(e);
+ }
+
+ }
+ saxXmlWriter.endDocument();
+ }
+
+ private Hashtable<String, Object> getParameters() {
+ return hParams;
+ }
+
+ public void setParameters(Hashtable<String, Object> ho) {
+ hParams = ho;
+ }
+
+ private String getXpathExpression() {
+ StringBuffer sb = new StringBuffer();
+ for (String s : stack) {
+ sb.append(s + "/");
+ }
+ return sb.toString();
+ }
+
+ public void setControlsModel(Vector<ControlModel> cm) {
+ this.controlsModel = cm;
+ }
+
+ public void setSaxWriter(SaxXmlWriter sxw) {
+ saxXmlWriter = sxw;
+ }
+
+ public Vector<Anomalie> getVTotalAnomalies() {
+ return vTotalAnomalies;
+ }
+
+ public abstract Pair getCollectivite(String documentModelId, String fileName) throws Exception;
+
+ public abstract Pair getBudget(String documentModelId, Pair collectivite, String fileName) throws Exception, UnauthorizedException;
+
+
+ @Override
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+ super.startPrefixMapping(prefix, uri);
+ for (AbstractUnitControl auc : controlsToCall) {
+ auc.startPrefixMapping(prefix, uri, getXpathExpression());
+ }
+ saxXmlWriter.startPrefixMapping(prefix, uri);
+ }
+
+ @Override
+ public void endPrefixMapping(String prefix) throws SAXException {
+ super.endPrefixMapping(prefix);
+ for (AbstractUnitControl auc : controlsToCall) {
+ auc.endPrefixMapping(prefix, getXpathExpression());
+ }
+ saxXmlWriter.endPrefixMapping(prefix);
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ for (AbstractUnitControl auc : controlsToCall) {
+ try {
+ auc.characters(ch, start, length, getXpathExpression());
+ } catch (SAXException saxEx) {
+ logger.debug("in characters!!!", saxEx);
+ }
+ }
+ saxXmlWriter.characters(ch, start, length);
+ }
+
+ @Override
+ public void setDocumentLocator(Locator locator) {
+ saxXmlWriter.setDocumentLocator(locator);
+ }
+
+ @Override
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
+ saxXmlWriter.ignorableWhitespace(ch, start, length);
+ }
+
+ @Override
+ public void processingInstruction(String target, String data) {
+ try {
+ saxXmlWriter.processingInstruction(target, data);
+ } catch (SAXException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void skippedEntity(String name) throws SAXException {
+ saxXmlWriter.skippedEntity(name);
+ }
+
+ public void setNamespaceContext(NamespaceContext nsCtx) {
+ this.nsCtx = nsCtx;
+ }
+
+ public Pair getBudget() {
+ return budget;
+ }
+
+ public void setBudget(Pair budget) {
+ this.budget = budget;
+ }
+
+ public Pair getCollectivite() {
+ return collectivite;
+ }
+
+ public void setCollectivite(Pair collectivite) {
+ this.collectivite = collectivite;
+ logger.debug("setting collectivite: " + collectivite);
+ }
+
+ public ControlProgressListener getControlProgressListener() {
+ return cpl;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core;
+
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.DocumentControlModel;
+
+/**
+ *
+ * @author chm
+ */
+public abstract class AbstractUnitControl implements UnitControl {
+
+ private String fileName = null;
+ private DocumentControlModel docModel;
+
+ public void setDocumentModel(DocumentControlModel docModel) {
+ this.docModel = docModel;
+ }
+
+ public DocumentControlModel getDocumentModel() {
+ return docModel;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core;
+
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ControlModel;
+import fr.gouv.finances.dgfip.utils.Pair;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Hashtable;
+
+/**
+ * public Anomalie(String idAnomalie,String controleID,String controleLibelle,String docID,String etatID,String elementID,String elementLibelle,String message,String regle,String severity,XPath xPathNameSpacise,Vector<String> xslParams)
+ *
+ * @param idAnomalie
+ * @param controleID
+ * @param controleLibelle
+ * @param docID
+ * @param etatID
+ * @param elementImportable
+ * @param elementEnAnomalie
+ * @param message
+ * @param regle
+ * @param severity
+ * @param xPath
+ * @param xslParams
+ */
+public class Anomalie implements Comparable<Anomalie> {
+
+ public static final String ANOMALY_NS_URI = "http://projets.admisource.gouv.fr/xemelios/namespaces#anomally";
+ private String idAnomalie, // id auto generer avec IdGenerator
+ controleID, // id du controle
+ controleLibelle, // libelle du controle (dans le fichier de config).A recuperer par l'intermediaire du DocumentControlModel
+ documentID, // id du document importé. A recuperer par l'intermediaire du DocumentControlModel
+ etatID, // id de l'etat sur lequel porte l'anomalie.
+ elementImportable, // balise (element importable)
+ idElementImportable,// numéro de l'element importable sur lequel l'anomalie porte (obligatoire)
+ elementEnAnomalie, // le localName (nom de la balise xml au moment de la creation de l'ano) du startElement
+ libelleLien, // libelle du lien afficher pour l'anomalie dans l'affichage du rapport
+ message, // message du controle.A recuperer par l'intermediaire du DocumentControlModel
+ regle, // règle du controle.A recuperer par l'intermediaire du DocumentControlModel
+ severity, // severity du controle.A recuperer par l'intermediaire du DocumentControlModel
+ xPath; // xpath car une fois importer il faut pointer sur les éléments
+ private Hashtable<String, Object> xslParams; // Hashtable< id du paramètre , valeur du paramètre >
+ private ArrayList<Node> nodes;
+ private boolean visible = true;
+
+ public Anomalie(String idAnomalie,
+ String controleID,
+ String controleLibelle,
+ String docID,
+ String etatID,
+ String elementImportable,
+ String idElementImportable,
+ String elementEnAnomalie,
+ String libelleLien,
+ String message,
+ String regle,
+ String severity,
+ String xPath,
+ Hashtable<String, Object> xslParams) {
+ this.idAnomalie = idAnomalie;
+ this.controleID = controleID;
+ this.controleLibelle = controleLibelle;
+ this.documentID = docID;
+ this.etatID = etatID;
+ this.elementImportable = elementImportable;
+ this.idElementImportable = idElementImportable;
+ this.elementEnAnomalie = elementEnAnomalie;
+ this.libelleLien = libelleLien;
+ this.message = message;
+ this.regle = regle;
+ this.severity = severity;
+ this.xPath = xPath;
+ this.xslParams = xslParams;
+ this.nodes = new ArrayList<Node>();
+ }
+
+ /**
+ *
+ * @param idAnomalie
+ * @param ctrl
+ * @param docID
+ * @param etatID
+ * @param elementImportable
+ * @param idElementImportable
+ * @param elementEnAnomalie
+ * @param libelleLien
+ * @param message
+ * @param regle
+ * @param severity
+ * @param xPath
+ * @param xslParams
+ */
+ public Anomalie(String idAnomalie,
+ ControlModel ctrl,
+ String docID,
+ String etatID,
+ String elementImportable,
+ String idElementImportable,
+ String elementEnAnomalie,
+ String libelleLien,
+ String message,
+ String regle,
+ String severity,
+ String xPath,
+ Hashtable<String, Object> xslParams) {
+ this.idAnomalie = idAnomalie;
+ this.controleID = ctrl.getId();
+ this.controleLibelle = ctrl.getLibelle();
+ this.documentID = docID;
+ this.etatID = etatID;
+ this.elementImportable = elementImportable;
+ this.idElementImportable = idElementImportable;
+ this.elementEnAnomalie = elementEnAnomalie;
+ this.libelleLien = libelleLien;
+ this.message = message;
+ this.regle = regle;
+ this.severity = severity;
+ this.xPath = xPath;
+ this.xslParams = xslParams;
+ this.nodes = new ArrayList<Node>();
+ }
+
+ public void addNode(Node node) {
+ nodes.add(node);
+ }
+
+ public void addAll(Collection<Node> node) {
+ this.nodes.addAll(node);
+ }
+
+ public String getSeverity() {
+ return severity;
+ }
+
+ public Collection<Node> getNodes() {
+ return nodes;
+ }
+
+ public String getControleID() {
+ return controleID;
+ }
+
+ public void setControleID(String controleID) {
+ this.controleID = controleID;
+ }
+
+ public String getControleLibelle() {
+ return controleLibelle;
+ }
+
+ public void setControleLibelle(String controleLibelle) {
+ this.controleLibelle = controleLibelle;
+ }
+
+ public String getDocumentID() {
+ return documentID;
+ }
+
+ public void setDocumentID(String documentID) {
+ this.documentID = documentID;
+ }
+
+ public String getelementImportable() {
+ return elementImportable;
+ }
+
+ public void setelementImportable(String elementImportable) {
+ this.elementImportable = elementImportable;
+ }
+
+ public String getelementEnAnomalie() {
+ return elementEnAnomalie;
+ }
+
+ public void setelementEnAnomalie(String elementEnAnomalie) {
+ this.elementEnAnomalie = elementEnAnomalie;
+ }
+
+ public String getEtatID() {
+ return etatID;
+ }
+
+ public void setEtatID(String etatID) {
+ this.etatID = etatID;
+ }
+
+ public String getIdAnomalie() {
+ return idAnomalie;
+ }
+
+ public void setIdAnomalie(String idAnomalie) {
+ this.idAnomalie = idAnomalie;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getRegle() {
+ return regle;
+ }
+
+ public void setRegle(String regle) {
+ this.regle = regle;
+ }
+
+ public String getXPath() {
+ return xPath;
+ }
+
+ public void setxPath(String pathNameSpacise) {
+ xPath = pathNameSpacise;
+ }
+
+ public Hashtable<String, Object> getXslParams() {
+ return xslParams;
+ }
+
+ public void setXslParams(Hashtable<String, Object> xslParams) {
+ this.xslParams = xslParams;
+ }
+
+ public void setSeverity(String severity) {
+ this.severity = severity;
+ }
+
+ public String getElementEnAnomalie() {
+ return elementEnAnomalie;
+ }
+
+ public void setElementEnAnomalie(String elementEnAnomalie) {
+ this.elementEnAnomalie = elementEnAnomalie;
+ }
+
+ public String getElementImportable() {
+ return elementImportable;
+ }
+
+ public void setElementImportable(String elementImportable) {
+ this.elementImportable = elementImportable;
+ }
+
+ public String getIdElementImportable() {
+ return idElementImportable;
+ }
+
+ public void setIdElementImportable(String idElementImportable) {
+ this.idElementImportable = idElementImportable;
+ }
+
+ public String getLibelleLien() {
+ return libelleLien;
+ }
+
+ public void setLibelleLien(String libelleLien) {
+ this.libelleLien = libelleLien;
+ }
+
+ /**
+ * @param other other doit être de type Anomalie !
+ */
+ public int compareTo(Anomalie other) {
+ String id1 = ((Anomalie) other).getControleID();
+ String id2 = this.getControleID();
+
+ return id1.compareTo(id2);
+ }
+
+ public boolean isVisible() {
+ return visible;
+ }
+
+ public void setVisible(boolean visible) {
+ this.visible = visible;
+ }
+
+ public void marshall(RapportWriter writer) {
+ writer.openElement("Anomalie");
+ writer.writeElement("Id", new Pair("V", getIdAnomalie()));
+ writer.writeElement("Visibility", new Pair("V", isVisible() ? "visible" : "hidden"));
+ writer.writeElement("IdCtrl", new Pair("V", getControleID()));
+ writer.writeElement("LibelleCtrl", new Pair("V", getControleLibelle()));
+ writer.writeElement("EtatId", new Pair("V", getEtatID()));
+ writer.writeElement("ElementImportable", new Pair("V", getelementImportable()));
+ writer.writeElement("IdElementImportable", new Pair("V", getIdElementImportable()));
+ writer.writeElement("ElementEnAnomalie", new Pair("V", getelementEnAnomalie()));
+ writer.writeElement("LibelleLien", new Pair("V", getLibelleLien()));
+
+ writer.openElement("Message");
+ writer.writeData("<![CDATA[");
+ try {
+ writer.getWriter().getWriter().write(getMessage());
+ } catch(IOException ioEx) {
+ // ignored
+ }
+ writer.writeData("]]>");
+ writer.closeElement("Message");
+
+ writer.openElement("Regle");
+ writer.writeData("<![CDATA[");
+ try {
+ writer.getWriter().getWriter().write(getRegle());
+ } catch(IOException ioEx) {
+ // ignored
+ }
+ writer.writeData("]]>");
+ writer.closeElement("Regle");
+
+ writer.writeElement("Severity", new Pair("V", getSeverity()));
+ if (getXPath() != null) {
+ writer.writeElement("XPath", new Pair("V", getXPath()));
+ }
+ if (getXslParams() != null && getXslParams().size() > 0) {
+ for (String key : getXslParams().keySet()) {
+ String value = getXslParams().get(key).toString();
+ writer.openElement("XslParam");
+ writer.writeElement("Key", new Pair("V", key));
+ writer.writeElement("Value", new Pair("V", value));
+ writer.closeElement("XslParam");
+ }
+ }
+ writer.closeElement("Anomalie");
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2005 axYus - www.axyus.com
+ * 2005 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package fr.gouv.finances.dgfip.xemelios.controls.core;
+
+import java.util.HashMap;
+
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshalParser;
+import fr.gouv.finances.dgfip.utils.xml.FactoryProvider;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.AddOnModel;
+import fr.gouv.finances.dgfip.xemelios.common.config.BlankModel;
+import fr.gouv.finances.dgfip.xemelios.common.config.TextModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ControlModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ControlModelTech;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ControlsModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.DocumentControlModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.EngineModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.InputModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.MessageModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.MessageRapportModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.OptionModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ParamModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ParamModelTech;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.RefIdModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.RegleModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.SelectModel;
+import fr.gouv.finances.dgfip.xemelios.common.config.CollectiviteInfosModel;
+import fr.gouv.finances.dgfip.xemelios.common.config.DocumentsMapping;
+import fr.gouv.finances.dgfip.xemelios.common.config.XPathModel;
+import javax.xml.namespace.QName;
+
+/**
+ * Parser de definition de document
+ * @author chm
+ */
+public class ControlParser extends XmlMarshalParser {
+ public ControlParser() throws SAXException, ParserConfigurationException, FactoryConfigurationError {
+ super(new Mapping(),true, FactoryProvider.getSaxParserFactory());
+ }
+
+ private static class Mapping extends HashMap<QName,Class> {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 3617293411154145847L;
+
+ public Mapping() {
+ put(ControlsModel.QN,ControlsModel.class);
+ put(ControlModel.QN,ControlModel.class);
+ put(ControlModelTech.QN,ControlModelTech.class);
+ put(DocumentControlModel.QN,DocumentControlModel.class);
+// put(ElementLieModel.TAG,ElementLieModel.class);
+ put(MessageModel.QN,MessageModel.class);
+ put(MessageRapportModel.QN,MessageRapportModel.class);
+ put(RefIdModel.QN,RefIdModel.class);
+ put(ParamModel.QN,ParamModel.class);
+ put(ParamModelTech.QN,ParamModelTech.class);
+ put(RegleModel.QN,RegleModel.class);
+ put(InputModel.QN, InputModel.class);
+ put(OptionModel.QN,OptionModel.class);
+ put(SelectModel.QN,SelectModel.class);
+ put(BlankModel.QN,BlankModel.class);
+ put(DocumentsMapping.PATH,XPathModel.class);
+ put(DocumentsMapping.CODE_PATH,XPathModel.class);
+ put(DocumentsMapping.LIBELLE_PATH,XPathModel.class);
+ put(CollectiviteInfosModel.QN,CollectiviteInfosModel.class);
+ //put(NamespaceModel.TAG,NamespaceModel.class);
+ //put(NSModel.TAG,NSModel.class);
+ put(VALEUR,TextModel.class);
+ put(LIBELLE,TextModel.class);
+ put(ID,TextModel.class);
+ put(SORT,TextModel.class);
+ put(BR,TextModel.class);
+ put(UL,TextModel.class);
+ put(LI,TextModel.class);
+ put(IGNORE_REGEXP,TextModel.class);
+ put(AddOnModel.QN,AddOnModel.class);
+ put(EngineModel.QN,EngineModel.class);
+ }
+ }
+ public static final transient QName VALEUR = new QName("valeur");
+ public static final transient QName LIBELLE = new QName("libelle");
+ public static final transient QName ID = new QName("id");
+ public static final transient QName SORT = new QName("sort");
+ public static final transient QName BR = new QName("br");
+ public static final transient QName UL = new QName("ul");
+ public static final transient QName LI = new QName("li");
+ public static final transient QName IGNORE_REGEXP = new QName("ignore-regexp");
+
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package fr.gouv.finances.dgfip.xemelios.controls.core;
+
+/**
+ *
+ * @author chm
+ */
+public interface ControlProgressListener {
+
+ public void stopWaiting();
+ public void notifyImportFinished(MainControl.Triplet triplet);
+ public void notifyTechniqueValidationFailed();
+ public void notifyImportInterrupted(boolean hide);
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package fr.gouv.finances.dgfip.xemelios.controls.core;
+
+/**
+ *
+ * @author chm
+ */
+public class IdGenerator {
+ private static int count = 1;
+
+ public static synchronized String nextId() {
+ return "id" + Integer.toString(count++);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.validation.Schema;
+import javax.xml.validation.Validator;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.dgfip.utils.Pair;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.DocumentControlModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ParamModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ParamModelTech;
+import fr.gouv.finances.dgfip.xemelios.controls.core.tech.TECH01;
+import fr.gouv.finances.dgfip.xemelios.controls.core.tech.TECH02;
+import fr.gouv.finances.dgfip.xemelios.controls.core.tech.TECH03;
+import fr.gouv.finances.dgfip.utils.HostUtils;
+import fr.gouv.finances.dgfip.utils.xml.FactoryProvider;
+import fr.gouv.finances.dgfip.xemelios.common.config.DocumentModel;
+import fr.gouv.finances.dgfip.xemelios.txt2xml.Txt2Xml;
+import fr.gouv.finances.dgfip.xemelios.utils.FileUtils;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import javax.xml.XMLConstants;
+import javax.xml.validation.SchemaFactory;
+
+public abstract class MainControl implements Runnable {
+
+ public static final int STATUS_NOT_CONTROLLED = -1;
+ public static final int STATUS_NOT_XML = 1;
+ public static final int STATUS_INVALID_ENCODING = 2;
+ public static final int STATUS_NOT_SCHEMA_VALID = 3;
+ public static final int STATUS_HAS_UNIT_CONTROL_ERRORS = 4;
+ public static final int STATUS_CONTROL_NO_ERROR = 5;
+ private final static Logger logger = Logger.getLogger(MainControl.class);
+ private File fichierAController, rapport, inputXmlFile;
+ private String documentModelId;
+ private Hashtable<String, Object> hashParams = new Hashtable<String, Object>();
+ private DocumentControlModel dcm;
+ private Date datecontrole;
+ private NamespaceContext nameSpaces;
+ private SaxXmlWriter saxWriter = null;
+ public static final String ID_DOCUMENT_RAPPORT = "rapport";
+// private ControlsModel cm;
+ private String IDrapport = "", domainesControles = "";
+ private RapportWriter rapportWriter;
+ private boolean hasTech01Error = false;
+ private AbstractControlContentHandler cch = null;
+ private File fichierEnrichi = null;
+ private String fichierEnrichiLocation = null, rapportLocation = null;
+ private ControlProgressListener cpl = null;
+ private int status = STATUS_NOT_CONTROLLED;
+ private ArrayList<Anomalie> anomaliesTechniques;
+ private SAXParserFactory factorySAX = null;
+// private String documentTitre;
+ private File schemaLocation;
+ private String textToXmlTransformer = null;
+ private DocumentModel documentModel;
+
+ /**
+ * Construit une nouvelle MainControl
+ * @param documentModelId
+ * @param nsCtx
+ * @param dcm
+ * @param documentTitre
+ * @param schemaLocation
+ */
+ public MainControl(
+ DocumentModel documentModel,
+ NamespaceContext nsCtx,
+ DocumentControlModel dcm,
+// String documentTitre,
+ File schemaLocation) {
+ super();
+ this.documentModel = documentModel;
+ this.documentModelId = documentModel.getId();
+ this.dcm = dcm;
+ this.schemaLocation = schemaLocation;
+ nameSpaces = nsCtx;
+ factorySAX = FactoryProvider.getSaxParserFactory();
+ anomaliesTechniques = new ArrayList<Anomalie>();
+ saxWriter = new SaxXmlWriter();
+ }
+
+ public DocumentControlModel getDcm() {
+ return dcm;
+ }
+
+ public void setDcm(DocumentControlModel dcm) {
+ this.dcm = dcm;
+ }
+
+ public ControlProgressListener getControlProgressListener() { return cpl; }
+ public String getDocumentModelId() {
+ return documentModelId;
+ }
+
+ public void setDocumentModelId(String documentModelId) {
+ this.documentModelId = documentModelId;
+ }
+
+// public String getDocumentTitre() {
+// return documentTitre;
+// }
+//
+// public void setDocumentTitre(String documentTitre) {
+// this.documentTitre = documentTitre;
+// }
+
+ public File getSchemaLocation() {
+ return schemaLocation;
+ }
+
+ public void setSchemaLocation(File schemaLocation) {
+ this.schemaLocation = schemaLocation;
+ }
+
+ public String getTextToXmlTransformer() {
+ return textToXmlTransformer;
+ }
+
+ public void setTextToXmlTransformer(String textToXmlTransformer) {
+ this.textToXmlTransformer = textToXmlTransformer;
+ }
+
+ public DocumentControlModel getDocumentControl() {
+ return dcm;
+ }
+
+ protected boolean controlXmlSyntax(File inputFile, TECH01 tech01) {
+ FileInputStream fisTech = null;
+ try {
+ fisTech = new FileInputStream(inputFile);
+ SAXParser parserXmlTech = factorySAX.newSAXParser();
+ parserXmlTech.parse(fisTech, tech01);
+ } catch (FileNotFoundException e1) {
+ e1.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ } catch (SAXException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ anomaliesTechniques.addAll(tech01.getAnomalies());
+ if (anomaliesTechniques.size() > 0) {
+ status = STATUS_NOT_XML;
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ @Override
+ public void run() {
+ if(textToXmlTransformer!=null) {
+ try {
+ Class clazz = Class.forName(textToXmlTransformer);
+ Txt2Xml transformer = (Txt2Xml) clazz.newInstance();
+ if (transformer != null) {
+ inputXmlFile = transformer.transform(fichierAController);
+ }
+ } catch (Exception ex) {
+ logger.error("while instancying textToXmlTransformer", ex);
+ }
+ }
+ if(inputXmlFile==null) inputXmlFile = fichierAController;
+ boolean technicalValidationFailed = false;
+ TECH01 tech01 = new TECH01();
+ tech01.setDocModel(documentModel);
+ TECH02 tech02 = new TECH02();
+ TECH03 tech03 = new TECH03();
+ tech03.setDocumentTitre(documentModel.getTitre());
+ tech03.setDocumentControlModel(dcm);
+
+ // on crée les éléments pour permettre l'écriture du rapport
+ if (rapportLocation == null) {
+ rapportLocation = new File(FileUtils.getTempDir(), "rapport" + inputXmlFile.getName()).getAbsolutePath();
+ }
+ rapport = new File(rapportLocation);
+ logger.debug("rapport: " + rapport.getAbsolutePath());
+ datecontrole = new Date();
+
+ Charset cs = Charset.forName("ISO-8859-1");
+ OutputStreamWriter fos = null;
+ try {
+ fos = new OutputStreamWriter(new FileOutputStream(rapport), cs);
+ } catch (Exception e1) {
+ logger.error("while creating fos", e1);
+ }
+ rapportWriter = new RapportWriter(new XmlOutputter(fos, cs.name()));
+
+ // on crée l'objet qui contient les controles
+ cch = getControlContentHandler(documentModelId, dcm, hashParams, inputXmlFile.getName(), cpl);
+
+ // on vérifie si le document est du XML
+ hasTech01Error = !controlXmlSyntax(inputXmlFile, tech01);
+
+ if (!hasTech01Error) {
+ boolean shouldContinue = true;
+ if (dcm.getControlTechById("TECH02") != null) {
+ // on veut faire un controle d'encoding
+ boolean isEncodingValid = tech02.encodingValid(dcm.getControlTechById("TECH02"), inputXmlFile);
+ if (!isEncodingValid) {
+ Anomalie ano = new Anomalie(IdGenerator.nextId(),
+ "TECH02", "Contrôle de l'encoding du fichier.",
+ documentModelId, "", "", "", "", "",
+ "Le fichier est encodé en " + tech02.getInputEncoding() + " alors qu'il devrait être encodé en " + tech02.getValidEncodings() + ".",
+ "Le fichier doit être encodé en " + tech02.getValidEncodings() + ".",
+ dcm.getControlTechById("TECH02").getSeverity(), "xpath namespacise",
+ new Hashtable<String, Object>());
+ anomaliesTechniques.add(ano);
+
+ // check if we should continue
+ shouldContinue = false;
+ ParamModelTech param = dcm.getControlTechById("TECH02").getParamTechById("failOnError");
+ if (param!=null && "false".equals(param.getValue())) {
+ shouldContinue = true;
+ } else {
+ technicalValidationFailed = true;
+ }
+ status = STATUS_INVALID_ENCODING;
+ }
+ }
+
+ if (shouldContinue) {
+ // now, check if we need a control against schema
+ if (dcm.getControlTechById("TECH03") != null) {
+ // Contrôle de validité au schéma
+ SchemaFactory xmlsf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Schema schema;
+ try {
+ schema = xmlsf.newSchema(schemaLocation);
+ Validator validateur = schema.newValidator();
+ FileInputStream fis = new FileInputStream(inputXmlFile);
+ SAXSource saxSrc = new SAXSource(new InputSource(fis));
+ tech03.setDomainesControles(domainesControles);
+ validateur.setErrorHandler(tech03);
+ validateur.validate(saxSrc);
+ fis.close();
+ } catch (Exception ex) {
+ // an exception during schema loading
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw, true);
+ ex.printStackTrace(pw);
+ Anomalie ano = new Anomalie(IdGenerator.nextId(),
+ "TECH03", "Contrôle de conformité au schéma du fichier.",
+ documentModelId, "", "", "", "", "",
+ "Erreur inattendue lors du chargement du schéma:\n" + sw.toString(),
+ "Le schéma ne peut pas être chargé.",
+ dcm.getControlTechById("TECH03").getSeverity(), "xpath namespacise",
+ new Hashtable<String, Object>());
+ anomaliesTechniques.add(ano);
+ }
+ if (tech03.getAnomalies().size() > 0) {
+ // there is some errors...
+ anomaliesTechniques.addAll(tech03.getAnomalies());
+ shouldContinue = false;
+ // should we continue ?
+ ParamModelTech param = dcm.getControlTechById("TECH03").getParamTechById("failOnError");
+ technicalValidationFailed = true;
+ if (param != null && "false".equals(param.getValue())) {
+ shouldContinue = true;
+ }
+ status = STATUS_NOT_SCHEMA_VALID;
+ }
+ }
+ }
+ // now, apply unit controls
+ if (shouldContinue) {
+ cch.setParameters(hashParams);
+ cch.setControlsModel(dcm.getControls());
+ try {
+ FileInputStream fis = new FileInputStream(inputXmlFile);
+ SAXParser parserXml = factorySAX.newSAXParser();
+ saxWriter.setNamespaceContext(nameSpaces);
+ if (fichierEnrichiLocation == null) {
+ fichierEnrichiLocation = new File(FileUtils.getTempDir(), inputXmlFile.getName()).getAbsolutePath();
+ }
+ fichierEnrichi = new File(fichierEnrichiLocation);
+ DOMResult dr = new DOMResult();
+ saxWriter.setResult(dr);
+ cch.setSaxWriter(saxWriter);
+ cch.setNamespaceContext(nameSpaces);
+ cch.setFileName(inputXmlFile.getName());
+ parserXml.parse(fis, cch);
+
+ StreamResult sr = new StreamResult(fichierEnrichi);
+ TransformerFactory tf = FactoryProvider.getTransformerFactory();
+ Transformer t = tf.newTransformer();
+ t.transform(new DOMSource(dr.getNode()), sr);
+ if (sr.getOutputStream() != null) {
+ sr.getOutputStream().flush();
+ sr.getOutputStream().close();
+ }
+ // ajout CHM
+ fis.close();
+ if(cch.getVTotalAnomalies().size()>0 || technicalValidationFailed) {
+ anomaliesTechniques.addAll(cch.getVTotalAnomalies());
+ status = STATUS_HAS_UNIT_CONTROL_ERRORS;
+ } else {
+ status = STATUS_CONTROL_NO_ERROR;
+ }
+ } catch (Exception ex) {
+ // an exception during schema loading
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw, true);
+ ex.printStackTrace(pw);
+ Anomalie ano = new Anomalie(IdGenerator.nextId(),
+ "Contrôles métier", "Application des contrôles métier.",
+ documentModelId, "", "", "", "", "",
+ "Erreur inattendue lors de l'application des contrôles métiers:\n" + sw.toString(),
+ ex.getMessage(),
+ "BLOQUANT", "xpath namespacise",
+ new Hashtable<String, Object>());
+ anomaliesTechniques.add(ano);
+ }
+ }
+ }
+ Pair pColl = cch.getCollectivite();
+ if (pColl == null || pColl.key == null || pColl.libelle == null) {
+ pColl = new Pair("00000000000000", "Collectivite de Contrôle");
+ }
+ Pair pBudg = cch.getBudget();
+ if (pBudg == null || pBudg.key == null || pBudg.libelle == null) {
+ pBudg = new Pair("00", "Budget de Contrôle");
+ }
+ try {
+ writeRapport(pColl, pBudg, anomaliesTechniques, cch.MAX_ANOS);
+ } catch (IOException ioEx) {
+ // TODO
+ }
+ cpl.stopWaiting();
+ if(technicalValidationFailed)
+ cpl.notifyTechniqueValidationFailed();
+
+ }
+
+ public Pair getCollectivite() throws IllegalStateException {
+ if (status == STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must run control before calling getCollectivite()");
+ }
+ if (cch != null) {
+ return cch.getCollectivite();
+ } else {
+ return null;
+ }
+ }
+
+ public Pair getBudget() throws IllegalStateException {
+ if (status == STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must run control before calling getBudget()");
+ }
+ if (cch != null) {
+ return cch.getBudget();
+ } else {
+ return null;
+ }
+ }
+
+ public Vector<Anomalie> getTotalAnomalies() throws IllegalStateException {
+ if (status == STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must run control before calling getTotalAnomalies()");
+ }
+ return cch != null ? cch.getVTotalAnomalies() : new Vector<Anomalie>();
+ }
+
+ public void setFileToControl(File f) {
+ this.fichierAController = f;
+ }
+
+ public File getFileToControl() {
+ return fichierAController;
+ }
+
+ public void setParameters(Hashtable<String, Object> params) {
+ this.hashParams = params;
+ }
+
+ private void writeRapport(Pair collec, Pair budg, ArrayList<Anomalie> vano, int maxanos) throws IOException {
+ logger.debug("writing rapport: \n\tcollectivite = " + collec + "\n\tbuget=" + budg);
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ String msgAno = "";
+ if (vano != null && vano.size() >= maxanos && !vano.get(0).getControleID().startsWith("TECH")) {
+ msgAno = "true";
+ } else {
+ msgAno = "false";
+ }
+
+ IDrapport = datecontrole.getTime() + rapport.getName();
+ // Entete du rapport
+ Pair docid = new Pair("V", documentModelId);
+ rapportWriter.writeElement("DocId", docid);
+ rapportWriter.writeElement("NomFichier", new Pair("V", fichierAController.getName()), new Pair("fullPath", fichierAController.getAbsolutePath()), new Pair("host", HostUtils.getHostName()));
+ //rapportWriter.writeElement("DateControle",new Pair("V",simpleDateFormat.format(new Date())));
+ rapportWriter.writeElement("DateControle", new Pair("V", simpleDateFormat.format(datecontrole)));
+
+ rapportWriter.openElement("Collectivite");
+ rapportWriter.writeElement("Siret", new Pair("V", collec.key));
+ rapportWriter.writeElement("Libelle", new Pair("V", collec.libelle));
+ rapportWriter.closeElement("Collectivite");
+
+ rapportWriter.openElement("Budget");
+ rapportWriter.writeElement("Code", new Pair("V", budg.key));
+ rapportWriter.writeElement("Libelle", new Pair("V", budg.libelle));
+ rapportWriter.closeElement("Budget");
+
+ rapportWriter.writeElement("TropAnos", new Pair("V", msgAno));
+ rapportWriter.openElement("Domaines");
+ String domaines[] = domainesControles.split(" / ");
+ for (String domain : domaines) {
+ rapportWriter.writeElement("Domaine", new Pair("V", domain));
+ }
+ rapportWriter.closeElement("Domaines");
+ rapportWriter.openElement("Params");
+ writeParameters();
+ rapportWriter.closeElement("Params");
+
+ // Corps du rapport
+ rapportWriter.openElement("DonneesRapport");
+ rapportWriter.openElement("Rapport");
+ rapportWriter.writeElement("Id", new Pair("V", datecontrole.getTime() + rapport.getName()));
+ if (vano != null) {
+ Collections.sort(vano, Collections.reverseOrder());
+ for (Anomalie anomalie : vano) {
+ //writeAnomalie(anomalie);
+ anomalie.marshall(rapportWriter);
+ }
+ }
+ rapportWriter.closeElement("Rapport");
+ rapportWriter.closeElement("DonneesRapport");
+ if (dcm.getMessage() != null) {
+ rapportWriter.openElement("Message");
+ rapportWriter.writeData(dcm.getMessage().getHtmlContent());
+ rapportWriter.closeElement("Message");
+ }
+ rapportWriter.endRapport();
+ logger.debug("Le rapport se trouve dans : " + rapport.getParent());
+ }
+
+ private String writeParameters() {
+ StringBuffer params = new StringBuffer();
+ for (ParamModel param : dcm.getParams()) {
+ String paramValue = "";
+ if (hashParams.get(param.getId()).getClass().equals(Boolean.class)) {
+ if (hashParams.get(param.getId()).equals(true)) {
+ paramValue = "Oui";
+ } else if (hashParams.get(param.getId()).equals(false)) {
+ paramValue = "Non";
+ } else {
+ paramValue = "Nc";
+ }
+ } else if (hashParams.get(param.getId()).getClass().equals(BigDecimal.class)) {
+ paramValue = hashParams.get(param.getId()).toString();
+ } else if (hashParams.get(param.getId()).getClass().equals(String.class)) {
+ paramValue = hashParams.get(param.getId()).toString();
+ } else if (hashParams.get(param.getId()).getClass().equals(Integer.class)) {
+ paramValue = hashParams.get(param.getId()).toString();
+ } else if (hashParams.get(param.getId()) instanceof String[]) {
+ if (((String[]) hashParams.get(param.getId())).length == 0) {
+ paramValue = "Non Renseigné";
+ }
+ for (int i = 0; i < ((String[]) hashParams.get(param.getId())).length; i++) {
+ paramValue += (i != 0 ? ", " : "") + ((String[]) hashParams.get(param.getId()))[i];
+ }
+ } else {
+ paramValue = hashParams.get(param.getId()).getClass().getName();
+ }
+ rapportWriter.writeElement("Param", new Pair("Name", param.getName()), new Pair("Value", paramValue));
+ }
+ return params.toString();
+ }
+
+ public abstract void writeControlConfigFile() throws IOException;
+
+ public int getControlStatus() {
+ return status;
+ }
+
+ public File getFichierEnrichi() throws IllegalStateException {
+ if (status == STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must run control before calling getFichierEnrichi()");
+ }
+ return fichierEnrichi;
+ }
+
+ public File getRapport() throws IllegalStateException {
+ if (status == STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must run control before calling getRapport()");
+ }
+ return rapport;
+ }
+
+ public String getIdRapport() {
+ return IDrapport;
+ }
+
+ public void setControlProgressListener(ControlProgressListener cpl) {
+ this.cpl = cpl;
+ }
+
+ public void setFichierEnrichiLocation(String absoluteFileName) throws IllegalStateException {
+ if (status != STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must not change fichierEnrichi location after control");
+ }
+ fichierEnrichiLocation = absoluteFileName;
+ }
+
+ public void setRapportLocation(String absoluteFileName) throws IllegalStateException {
+ if (status != STATUS_NOT_CONTROLLED) {
+ throw new IllegalStateException("You must not change rapport location after control");
+ }
+ rapportLocation = absoluteFileName;
+ }
+
+// public AbstractControlContentHandler getControlContentHandler(DocumentModel dm, DocumentControlModel docCtrlMod, Hashtable<String, Object> parameters,
+// MainWindow owner, String file, ControlProgressListener cpl) {
+// return new DefaultControlContentHandler(dm, docCtrlMod, parameters, owner, file, cpl);
+// }
+ public abstract AbstractControlContentHandler getControlContentHandler(
+ String documentModelId,
+ DocumentControlModel docCtrlMod,
+ Hashtable<String, Object> parameters,
+ String file,
+ ControlProgressListener cpl);
+
+ /**
+ * Permet de renvoyer les informations clefs sur le rapport genere
+ */
+ public static class Triplet {
+
+ public String iDrapport;
+ public String codeCollectivite;
+ public String codeBudget;
+
+ public Triplet(String idRapport, String codColl, String codBud) {
+ super();
+ this.iDrapport = idRapport;
+ this.codeCollectivite = codColl;
+ this.codeBudget = codBud;
+ }
+ }
+}
--- /dev/null
+/*
+ * Créé le 8 févr. 2007
+ *
+ * Pour changer le modèle de ce fichier généré, allez à :
+ * Fenêtre>Préférences>Java>Génération de code>Code et commentaires
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core;
+/**
+ */
+public class Node {
+ private String id;
+ public Node(String id){
+ super();
+ this.id=id;
+ }
+ public String getId(){
+ return id;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2005 axYus - www.axyus.com
+ * 2005 JP.Tessire - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core;
+
+import java.io.IOException;
+
+import fr.gouv.finances.dgfip.utils.Pair;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+
+public class RapportWriter {
+
+ private XmlOutputter rapport;
+
+ public RapportWriter(XmlOutputter rapportxml){
+ rapport = rapportxml;
+ startRapport();
+ }
+
+ private void startRapport(){
+ rapport.startTag("ano:DocumentRapport");
+ rapport.addAttribute("xmlns:ano",Anomalie.ANOMALY_NS_URI);
+// rapport.addAttribute("xmlns:n",Anomalie.ANOMALY_NS_URI);
+ }
+
+ public void endRapport() throws IOException{
+ rapport.endTag("ano:DocumentRapport");
+ rapport.close();
+ }
+
+ public void writeElement(String name,Pair... attrs){
+ rapport.startTag("ano:"+name);
+ if(attrs.length != 0){
+ for(Pair p:attrs){
+ rapport.addAttribute("ano:"+p.key,p.libelle);
+ }
+ }
+ rapport.endTag("ano:"+name);
+ }
+
+ public void writeData(String data){
+ rapport.addCharacterData(data);
+ }
+
+ public void openElement(String name,Pair... attrs){
+ rapport.startTag("ano:"+name);
+ if(attrs.length != 0){
+ for(Pair p:attrs){
+ rapport.addAttribute(p.libelle,p.key);
+ }
+ }
+ }
+
+ public void openElement(String name){
+ rapport.startTag("ano:"+name);
+ }
+
+ public void closeElement(String name){
+ rapport.endTag("ano:"+name);
+ }
+
+ public XmlOutputter getWriter() { return rapport; }
+
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package fr.gouv.finances.dgfip.xemelios.controls.core;
+
+import javax.xml.namespace.NamespaceContext;
+
+import net.sf.saxon.Configuration;
+import net.sf.saxon.Controller;
+import net.sf.saxon.IdentityTransformerHandler;
+import org.apache.log4j.Logger;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ *
+ * @author chm
+ */
+public class SaxXmlWriter extends IdentityTransformerHandler {
+ private static Logger logger = Logger.getLogger(SaxXmlWriter.class);
+ private String encoding = "UTF-8";
+ private NamespaceContext nsCtx;
+
+ /** Creates a new instance of SaxXmlWriter */
+ public SaxXmlWriter() {
+ super(new Controller(new Configuration()));
+ }
+ public void setEncoding(String encoding) {
+ this.encoding=encoding;
+ }
+ public void setNamespaceContext(NamespaceContext nsCtx) {
+ this.nsCtx = nsCtx;
+ }
+ public void writeAnomally(Anomalie ano) {
+ AttributesImpl attrs = new AttributesImpl();
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"anoId",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":anoId","string",ano.getIdAnomalie());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"ctrlLibelle",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlLibelle","string",ano.getControleLibelle());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"ctrlId",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlId","string",ano.getControleID());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"severity",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":severity","string",ano.getSeverity());
+ attrs.addAttribute(Anomalie.ANOMALY_NS_URI,"visibility",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":visibility","string",ano.isVisible()?"visible":"hidden");
+ try {
+ startElement(Anomalie.ANOMALY_NS_URI,"Anomalie",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":Anomalie",attrs);
+ } catch(Throwable t) {
+ logger.error("while calling startElement on Anomalie",t);
+ }
+ try {
+ startElement(Anomalie.ANOMALY_NS_URI,"ctrlRegleFonct",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlRegleFonct",new AttributesImpl());
+ char[] ch = ano.getRegle().toCharArray();
+ characters(ch,0,ch.length);
+ endElement(Anomalie.ANOMALY_NS_URI,"ctrlRegleFonct",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":ctrlRegleFonct");
+ } catch(Throwable t) {
+ logger.error("while writting ctrlRegleFonct",t);
+ }
+ try {
+ startElement(Anomalie.ANOMALY_NS_URI,"message",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":message",new AttributesImpl());
+ char[] ch = ano.getMessage().toCharArray();
+ characters(ch,0,ch.length);
+ endElement(Anomalie.ANOMALY_NS_URI,"message",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":message");
+ } catch(Throwable t) {
+ logger.error("while writting message",t);
+ }
+ for(Node node:ano.getNodes()) {
+ AttributesImpl attrs2 = new AttributesImpl();
+ attrs2.addAttribute(Anomalie.ANOMALY_NS_URI,"id",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":id","string",node.getId());
+ try {
+ startElement(Anomalie.ANOMALY_NS_URI,"node",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":node",attrs2);
+ endElement(Anomalie.ANOMALY_NS_URI,"node",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":node");
+ } catch(Throwable t) {
+ logger.error("while writting node",t);
+ }
+ }
+ try {
+ endElement(Anomalie.ANOMALY_NS_URI,"Anomalie",nsCtx.getPrefix(Anomalie.ANOMALY_NS_URI)+":Anomalie");
+ } catch(Throwable t) {
+ logger.error("while calling endElement on Anomalie",t);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * <p>Receive notifications of a control ContentHandler (TODO: insert
+ * here rightclass name).</p>
+ */
+
+ interface UnitControl {
+
+ /**
+ * Receive an object for locating the origin of SAX document
+ * events.
+ *
+ * <p>SAX parsers are strongly encouraged (though not absolutely
+ * required) to supply a locator: if it does so, it must supply
+ * the locator to the application by invoking this method before
+ * invoking any of the other methods in the ContentHandler
+ * interface.</p>
+ *
+ * <p>The locator allows the application to determine the end
+ * position of any document-related event, even if the parser is
+ * not reporting an error. Typically, the application will
+ * use this information for reporting its own errors (such as
+ * character content that does not match an application's
+ * business rules). The information returned by the locator
+ * is probably not sufficient for use with a search engine.</p>
+ *
+ * <p>Note that the locator will return correct information only
+ * during the invocation SAX event callbacks after
+ * {@link #startDocument startDocument} returns and before
+ * {@link #endDocument endDocument} is called. The
+ * application should not attempt to use it at any other time.</p>
+ *
+ * @param locator an object that can return the location of
+ * any SAX document event
+ * @see org.xml.sax.Locator
+ */
+ public void setDocumentLocator (Locator locator);
+
+
+ /**
+ * Receive notification of the beginning of a document.
+ *
+ * <p>The SAX parser will invoke this method only once, before any
+ * other event callbacks (except for {@link #setDocumentLocator
+ * setDocumentLocator}).</p>
+ *
+ * @throws org.xml.sax.SAXException any SAX exception, possibly
+ * wrapping another exception
+ * @see #endDocument
+ */
+ public void startDocument () throws SAXException;
+
+
+ /**
+ * Receive notification of the end of a document.
+ *
+ * <p><strong>There is an apparent contradiction between the
+ * documentation for this method and the documentation for {@link
+ * org.xml.sax.ErrorHandler#fatalError}. Until this ambiguity is
+ * resolved in a future major release, clients should make no
+ * assumptions about whether endDocument() will or will not be
+ * invoked when the parser has reported a fatalError() or thrown
+ * an exception.</strong></p>
+ *
+ * <p>The SAX parser will invoke this method only once, and
+ * it will be the last method invoked during the parse.
+ * The parser shall not invoke this method until it has
+ * either abandoned parsing (because of an unrecoverable error)
+ * or reached the end of input.</p>
+ *
+ * @return a possibly empty set of Anomaly
+ * @throws org.xml.sax.SAXException any SAX exception, possibly
+ * wrapping another exception
+ * @see #startDocument
+ */
+ public void endDocument() throws SAXException;
+
+
+ /**
+ * Begin the scope of a prefix-URI Namespace mapping.
+ *
+ * <p>The information from this event is not necessary for
+ * normal Namespace processing: the SAX XML reader will
+ * automatically replace prefixes for element and attribute
+ * names when the <code>http://xml.org/sax/features/namespaces</code>
+ * feature is <var>true</var> (the default).</p>
+ *
+ * <p>There are cases, however, when applications need to
+ * use prefixes in character data or in attribute values,
+ * where they cannot safely be expanded automatically; the
+ * start/endPrefixMapping event supplies the information
+ * to the application to expand prefixes in those contexts
+ * itself, if necessary.</p>
+ *
+ * <p>Note that start/endPrefixMapping events are not
+ * guaranteed to be properly nested relative to each other:
+ * all startPrefixMapping events will occur immediately before the
+ * corresponding {@link #startElement startElement} event,
+ * and all {@link #endPrefixMapping endPrefixMapping}
+ * events will occur immediately after the corresponding
+ * {@link #endElement endElement} event,
+ * but their order is not otherwise
+ * guaranteed.</p>
+ *
+ * <p>There should never be start/endPrefixMapping events for the
+ * "xml" prefix, since it is predeclared and immutable.</p>
+ *
+ * @param prefix the Namespace prefix being declared.
+ * An empty string is used for the default element namespace,
+ * which has no prefix.
+ * @param uri the Namespace URI the prefix is mapped to
+ * @param xpath the xpath position in xml where this event occurs
+ * @see #endPrefixMapping
+ * @see #startElement
+ */
+ public void startPrefixMapping (String prefix, String uri, String xpath) throws SAXException;
+
+
+ /**
+ * End the scope of a prefix-URI mapping.
+ *
+ * <p>See {@link #startPrefixMapping startPrefixMapping} for
+ * details. These events will always occur immediately after the
+ * corresponding {@link #endElement endElement} event, but
+ * the order of {@link #endPrefixMapping endPrefixMapping} events
+ * is not otherwise guaranteed.</p>
+ *
+ * @param prefix the prefix that was being mapped.
+ * This is the empty string when a default mapping scope ends.
+ * @param xpath the xpath position in xml where this event occurs
+ * @see #startPrefixMapping
+ * @see #endElement
+ */
+ public void endPrefixMapping (String prefix,String xpath) throws SAXException;
+
+
+ /**
+ * Receive notification of the beginning of an element.
+ *
+ * <p>The Parser will invoke this method at the beginning of every
+ * element in the XML document; there will be a corresponding
+ * {@link #endElement endElement} event for every startElement
+ * event (even when the element is empty). All of the element's
+ * content will be reported, in order, before the corresponding
+ * endElement event.</p>
+ *
+ * <p>This event allows up to three name components for each
+ * element:</p>
+ *
+ * <ol>
+ * <li>the Namespace URI;</li>
+ * <li>the local name; and</li>
+ * <li>the qualified (prefixed) name.</li>
+ * </ol>
+ *
+ * <p>Any or all of these may be provided, depending on the
+ * values of the <var>http://xml.org/sax/features/namespaces</var>
+ * and the <var>http://xml.org/sax/features/namespace-prefixes</var>
+ * properties:</p>
+ *
+ * <ul>
+ * <li>the Namespace URI and local name are required when
+ * the namespaces property is <var>true</var> (the default), and
+ * are optional when the namespaces property is <var>false</var>
+ * (if one is specified, both must be);</li>
+ * <li>the qualified name is required when the namespace-prefixes
+ * property is <var>true</var>, and is optional when the
+ * namespace-prefixes property is <var>false</var> (the
+ * default).</li>
+ * </ul>
+ *
+ * <p>Note that the attribute list provided will contain only
+ * attributes with explicit values (specified or defaulted):
+ * #IMPLIED attributes will be omitted. The attribute list
+ * will contain attributes used for Namespace declarations
+ * (xmlns* attributes) only if the
+ * <code>http://xml.org/sax/features/namespace-prefixes</code>
+ * property is true (it is false by default, and support for a
+ * true value is optional).</p>
+ *
+ * <p>Like {@link #characters characters()}, attribute values may
+ * have characters that need more than one <code>char</code>
+ * value. </p>
+ *
+ * @param uri the Namespace URI, or the empty string if the
+ * element has no Namespace URI or if Namespace
+ * processing is not being performed
+ * @param localName the local name (without prefix), or the
+ * empty string if Namespace processing is not being
+ * performed
+ * @param qName the qualified name (with prefix), or the
+ * empty string if qualified names are not available
+ * @param atts the attributes attached to the element. If
+ * there are no attributes, it shall be an empty
+ * Attributes object. The value of this object after
+ * startElement returns is undefined
+ * @param xpath the xpath position in xml where this event occurs
+ * @see #endElement
+ * @see org.xml.sax.Attributes
+ * @see org.xml.sax.helpers.AttributesImpl
+ */
+ public void startElement (String uri, String localName,String qName, Attributes atts,String xpath) throws SAXException;
+
+
+ /**
+ * Receive notification of the end of an element.
+ *
+ * <p>The SAX parser will invoke this method at the end of every
+ * element in the XML document; there will be a corresponding
+ * {@link #startElement startElement} event for every endElement
+ * event (even when the element is empty).</p>
+ *
+ * <p>For information on the names, see startElement.</p>
+ *
+ * @param uri the Namespace URI, or the empty string if the
+ * element has no Namespace URI or if Namespace
+ * processing is not being performed
+ * @param localName the local name (without prefix), or the
+ * empty string if Namespace processing is not being
+ * performed
+ * @param qName the qualified XML name (with prefix), or the
+ * empty string if qualified names are not available
+ * @return a possibly empty set of Anomaly
+ * @param xpath the xpath position in xml where this event occurs
+ */
+ public Vector<Anomalie> endElement (String uri, String localName,String qName, String xpath) throws SAXException;
+
+
+ /**
+ * Receive notification of character data.
+ *
+ * <p>The Parser will call this method to report each chunk of
+ * character data. SAX parsers may return all contiguous
+ * character data in a single chunk, or they may split it into
+ * several chunks; however, all of the characters in any single
+ * event must come from the same external entity so that the
+ * Locator provides useful information.</p>
+ *
+ * <p>The application must not attempt to read from the array
+ * outside of the specified range.</p>
+ *
+ * <p>Individual characters may consist of more than one Java
+ * <code>char</code> value. There are two important cases where
+ * this happens, because characters can't be represented in just
+ * sixteen bits.
+ * In one case, characters are represented in a <em>Surrogate
+ * Pair</em>, using two special Unicode values. Such characters
+ * are in the so-called "Astral Planes", with a code point above
+ * U+FFFF. A second case involves composite characters, such as a
+ * base character combining with one or more accent characters.
+ * </p>
+ *
+ * <p> Your code should not assume that algorithms using
+ * <code>char</code>-at-a-time idioms will be working in character
+ * units; in some cases they will split characters. This is
+ * relevant wherever XML permits arbitrary characters, such as
+ * attribute values, processing instruction data, and comments as
+ * well as in data reported from this method. It's also
+ * generally relevant whenever Java code manipulates
+ * internationalized text; the issue isn't unique to XML.</p>
+ *
+ * <p>Note that some parsers will report whitespace in element
+ * content using the {@link #ignorableWhitespace
+ * ignorableWhitespace} method rather than this one (validating
+ * parsers <em>must</em> do so).</p>
+ *
+ * @param ch the characters from the XML document
+ * @param start the start position in the array
+ * @param length the number of characters to read from the array
+ * @param xpath the xpath position in xml where this event occurs
+ * @see #ignorableWhitespace
+ * @see org.xml.sax.Locator
+ */
+ public void characters (char ch[], int start, int length, String xpath) throws SAXException;
+
+
+ /**
+ * Receive notification of ignorable whitespace in element
+ * content.
+ *
+ * <p>Validating Parsers must use this method to report each chunk
+ * of whitespace in element content (see the W3C XML 1.0
+ * recommendation, section 2.10): non-validating parsers may also
+ * use this method if they are capable of parsing and using
+ * content models.</p>
+ *
+ * <p>SAX parsers may return all contiguous whitespace in a single
+ * chunk, or they may split it into several chunks; however, all
+ * of the characters in any single event must come from the same
+ * external entity, so that the Locator provides useful
+ * information.</p>
+ *
+ * <p>The application must not attempt to read from the array
+ * outside of the specified range.</p>
+ *
+ * @param ch the characters from the XML document
+ * @param start the start position in the array
+ * @param length the number of characters to read from the array
+ * @param xpath the xpath position in xml where this event occurs
+ * @see #characters
+ */
+ public void ignorableWhitespace (char ch[], int start, int length,String xpath) throws SAXException;
+
+
+ /**
+ * Receive notification of a processing instruction.
+ *
+ * <p>The Parser will invoke this method once for each processing
+ * instruction found: note that processing instructions may occur
+ * before or after the main document element.</p>
+ *
+ * <p>A SAX parser must never report an XML declaration (XML 1.0,
+ * section 2.8) or a text declaration (XML 1.0, section 4.3.1)
+ * using this method.</p>
+ *
+ * <p>Like {@link #characters characters()}, processing
+ * instruction data may have characters that need more than one
+ * <code>char</code> value. </p>
+ *
+ * @param target the processing instruction target
+ * @param data the processing instruction data, or null if
+ * none was supplied. The data does not include any
+ * whitespace separating it from the target
+ * @param xpath the xpath position in xml where this event occurs
+ */
+ public void processingInstruction (String target, String data,String xpath) throws SAXException;
+
+
+ /**
+ * Receive notification of a skipped entity.
+ * This is not called for entity references within markup
+ * constructs such as element start tags or markup declarations.
+ * (The XML recommendation requires reporting skipped external
+ * entities. SAX also reports internal entity expansion/non-
+ * expansion, except within markup constructs.)
+ *
+ * <p>The Parser will invoke this method each time the entity is
+ * skipped. Non-validating processors may skip entities if they
+ * have not seen the declarations (because, for example, the
+ * entity was declared in an external DTD subset). All processors
+ * may skip external entities, depending on the values of the
+ * <code>http://xml.org/sax/features/external-general-
+ * entities</code> and the <code>http://xml.org/sax/features/
+ * external-parameter-entities</code> properties.</p>
+ *
+ * @param name the name of the skipped entity. If it is a
+ * parameter entity, the name will begin with '%', and if
+ * it is the external DTD subset, it will be the string
+ * "[dtd]"
+ * @param xpath the xpath position in xml where this event occurs
+ */
+ public void skippedEntity (String name,String xpath) throws SAXException;
+
+ /**
+ * Set parameters. This method is called by controller to set
+ * environment parameters.
+ * @param params the parameters to set
+ */
+ public void setParameters(Hashtable<String,Object> params);
+}
--- /dev/null
+/*
+ * Récupère le code collectivité ainsi que le code bugdétaire du document contrôllé en question (c)JPT
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.comm;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.dgfip.utils.Pair;
+import fr.gouv.finances.dgfip.xemelios.controls.core.AbstractUnitControl;
+import fr.gouv.finances.dgfip.xemelios.controls.core.Anomalie;
+import fr.gouv.finances.dgfip.xemelios.controls.core.AbstractControlContentHandler;
+
+import fr.gouv.finances.dgfip.xemelios.utils.XmlUtils;
+import java.util.Stack;
+import javax.xml.namespace.QName;
+
+public class COLLBUDG extends AbstractUnitControl {
+
+ public static final transient String CTRL_ID = "COLLBUDG";
+ private static Logger logger = Logger.getLogger(COLLBUDG.class);
+// private DocumentControlModel docModel;
+ private String coll_path = null;
+ private String budg_path = null;
+ private String coll_lib = null;
+ private String budg_lib = null;
+ private AbstractControlContentHandler cch = null;
+ private Stack<StringBuilder> charactersStack = new Stack<StringBuilder>();
+ private Stack<QName> tagStack = new Stack<QName>();
+
+ public void startDocument() throws SAXException {
+ }
+
+ public void startElement(String uri, String localName, String qName, Attributes atts, String xpath) {
+ String tagName = XmlUtils.getShortTagName(uri, localName, qName);
+ QName _qName = XmlUtils.getQName(uri, localName, qName);
+
+ tagStack.push(_qName);
+
+ for (int i = 0; i < atts.getLength(); i++) {
+ String attUri = atts.getURI(i);
+ String prefix = null;
+ if(attUri!=null) {
+ prefix = getDocumentModel().getNamespaces().getPrefix(attUri);
+ }
+ String attQName = (prefix!=null ? prefix+":" : "") + atts.getLocalName(i);
+ String path = "/".concat(xpath).concat("@").concat(attQName);
+ String value = atts.getValue(i);
+ checkPath(path, value);
+ }
+ charactersStack.push(new StringBuilder());
+ }
+
+ public void checkPath(String path, String value) {
+ if (coll_path.equals(path)) {
+ Pair p = cch.getCollectivite();
+ if (p == null) {
+ p = new Pair();
+ }
+ p.key = value;
+ cch.setCollectivite(p);
+ }
+ if (coll_lib.equals(path)) {
+ Pair p = cch.getCollectivite();
+ if (p == null) {
+ p = new Pair();
+ }
+ p.libelle = value;
+ cch.setCollectivite(p);
+ }
+
+ if (budg_path.equals(path)) {
+ Pair p = cch.getBudget();
+ if (p == null) {
+ p = new Pair();
+ }
+ p.key = value;
+ cch.setBudget(p);
+ }
+ if (budg_lib.equals(path)) {
+ Pair p = cch.getBudget();
+ if (p == null) {
+ p = new Pair();
+ }
+ p.libelle = value;
+ cch.setBudget(p);
+ }
+
+ }
+
+ public Vector<Anomalie> endElement(String uri, String localName, String qName, String xpath) {
+
+ String path = XmlUtils.getPath(tagStack, getDocumentModel().getNamespaces()); //+"/text()";
+ String innerData = charactersStack.pop().toString();
+
+ checkPath(path, innerData);
+
+ tagStack.pop();
+
+ return null;
+ }
+
+ public void endDocument() throws SAXException {
+ }
+
+ public void characters(char[] ch, int start, int length, String xpath) {
+
+ String s = new String(ch, start, length).trim();
+ if (s.length() > 0) {
+
+ charactersStack.peek().append(new String(ch, start, length));
+ }
+
+ checkPath(xpath.concat("/text()"), new String(ch, start, length));
+
+ }
+
+ public void ignorableWhitespace(char[] ch, int start, int length, String xpath) {
+ }
+
+ public void startPrefixMapping(String prefix, String uri, String xpath) {
+ }
+
+ public void endPrefixMapping(String prefix, String xpath) {
+ }
+
+ public void processingInstruction(String target, String data, String xpath) {
+ }
+
+ public void skippedEntity(String name, String xpath) {
+ }
+
+ public void setParameters(Hashtable<String, Object> params) {
+ }
+
+ public void setDocumentLocator(Locator locator) {
+ }
+
+ public String getColl_path() {
+ return coll_path;
+ }
+
+ public void setColl_path(String coll_path) {
+ this.coll_path = coll_path;
+ }
+
+ public AbstractControlContentHandler getCch() {
+ return cch;
+ }
+
+ public void setCch(
+ AbstractControlContentHandler cch) {
+ this.cch = cch;
+ }
+
+ public String getBudg_path() {
+ return budg_path;
+ }
+
+ public void setBudg_path(String budg_path) {
+ this.budg_path = budg_path;
+ }
+
+ public String getBudg_lib() {
+ return budg_lib;
+ }
+
+ public void setBudg_lib(
+ String budg_lib) {
+ this.budg_lib = budg_lib;
+ }
+
+ public String getColl_lib() {
+ return coll_lib;
+ }
+
+ public void setColl_lib(
+ String coll_lib) {
+ this.coll_lib = coll_lib;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2010 axYus - www.axyus.com
+ * 2010 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import java.util.Hashtable;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import fr.gouv.finances.dgfip.xemelios.controls.core.processors.Processor;
+import fr.gouv.finances.dgfip.xemelios.controls.core.processors.Processor.EVENT;
+import fr.gouv.finances.dgfip.utils.xml.XmlAttributesImpl;
+import java.util.ArrayList;
+import javax.xml.namespace.QName;
+import org.apache.log4j.Logger;
+
+public class AddOnModel implements XmlMarshallable {
+ private static final Logger logger = Logger.getLogger(AddOnModel.class);
+ public static final transient String TAG = "add-on";
+ public static final transient QName QN = new QName(TAG);
+
+ private Hashtable<String,ParamModel> parameters;
+ private String name;
+
+ private Processor processor;
+
+ public AddOnModel(QName qn) {
+ super();
+ parameters = new Hashtable<String, ParamModel>();
+ }
+
+ public void addCharacterData(String cData) throws SAXException { }
+
+ public void addChild(XmlMarshallable child, QName tag) throws SAXException {
+ if(tag.equals(ParamModel.QN)) {
+ ParamModel p = (ParamModel)child;
+ parameters.put(p.getId(),p);
+ }
+ }
+
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ name = attributes.getValue("name");
+ return this;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ if(atts.getValue("name")!=null) {
+ return parameters.get(atts.getValue("name"));
+ }
+ return null;
+ }
+
+ public void marshall(XmlOutputter output) {
+ output.startTag(QN);
+ output.addAttribute("name", name);
+ for(ParamModel p:parameters.values()) {
+ p.marshall(output);
+ }
+ output.endTag(QN);
+ }
+
+ public void validate() throws InvalidXmlDefinition {}
+
+ public QName getQName() {
+ return QN;
+ }
+
+ @Override
+ public AddOnModel clone() {
+ AddOnModel other = new AddOnModel(QN);
+ other.name=name;
+ for(ParamModel p:parameters.values()) {
+ try {
+ other.addChild(p, ParamModel.QN);
+ } catch(Throwable t) {}
+ }
+ return other;
+ }
+
+ public boolean isConcernedBy(EVENT evt, String uri, String localName, String qName) {
+ boolean ret = true;
+ String targetEvent = (String)parameters.get("event").getValue();
+ if(!"*".equals(targetEvent)) {
+ switch(evt) {
+ case START_DOCUMENT: ret = targetEvent.contains("start.document"); break;
+ case START_ELEMENT: ret = targetEvent.contains("start.element"); break;
+ case END_ELEMENT: ret = targetEvent.contains("end.element"); break;
+ case END_DOCUMENT: ret = targetEvent.contains("end.document"); break;
+ default: ret = false;
+ }
+ if(!ret) logger.debug(name+" is not concerned by "+qName);
+ }
+ if(ret) {
+ // event is OK, try to match element name
+ // only if start.element or end.elment
+ if(evt == EVENT.START_ELEMENT || evt == EVENT.END_ELEMENT) {
+ ret = parameters.get("element.name").getValue().equals(localName);
+ }
+ }
+ return ret;
+ }
+ public Processor getProcessor() {
+ if(processor==null) {
+ try {
+ Class clazz = Class.forName((String)parameters.get("processor").getValue());
+ processor = (Processor)clazz.newInstance();
+ ArrayList<ParamModel> params = new ArrayList<ParamModel>();
+ for(ParamModel p:parameters.values()) params.add(p);
+ processor.setParameters(params);
+ } catch(Throwable t) {
+ logger.error("getProcessor()",t);
+ }
+ }
+ return processor;
+ }
+ public void process(EVENT evt, String uri, String localName, String qName, XmlAttributesImpl atts) {
+ getProcessor().process(evt, uri, localName, qName, atts);
+ }
+ public void process(EVENT evt, String uri, String localName, String qName) {
+ getProcessor().process(evt, uri, localName, qName);
+ }
+ public void process(EVENT evt) {
+ getProcessor().process(evt);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import java.util.Vector;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import javax.xml.namespace.QName;
+
+
+public class ControlModel implements XmlMarshallable{
+ public static final transient String TAG = "control";
+ public static final transient QName QN = new QName(TAG);
+ public String id, libelle, severity, classe;
+ public RegleModel regle;
+ public Vector<RefIdModel> params;
+ public MessageModel message;
+ //public Vector<ElementLieModel> elementsLies;
+
+
+ public ControlModel(QName tagName) {
+ super();
+ //regles=new Vector<RegleModel>();
+ params=new Vector<RefIdModel>();
+ //messages=new Vector<MessageModel>();
+ //elementsLies=new Vector<ElementLieModel>();
+ }
+
+ public void addCharacterData(String cData) throws SAXException { }
+ public void addChild(XmlMarshallable child, QName tagName) throws SAXException {
+ if(RegleModel.QN.equals(tagName)) {
+ regle = (RegleModel)child;
+ } else if(RefIdModel.QN.equals(tagName)) {
+ params.add((RefIdModel)child);
+ } else if(MessageModel.QN.equals(tagName)) {
+ message=(MessageModel)child;
+// } else if(ElementLieModel.TAG.equals(tagName)) {
+// elementsLies.add((ElementLieModel)child);
+ }
+ }
+
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ id=attributes.getValue("id");
+ libelle=attributes.getValue("libelle");
+ severity=attributes.getValue("severity");
+ classe=attributes.getValue("class");
+ return this;
+ }
+ public void validate() throws InvalidXmlDefinition {
+ if(regle==null) throw new InvalidXmlDefinition("<regle/> element is required in <control/>");
+ regle.validate();
+ for(RefIdModel pcm:params) pcm.validate();
+ if(message==null) throw new InvalidXmlDefinition("<message/> element is required in <control/>");
+ message.validate();
+ //for(ElementLieModel elm:elementsLies) elm.validate();
+ }
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ output.addAttribute("id",id);
+ output.addAttribute("libelle",libelle);
+ output.addAttribute("severity",severity);
+ output.addAttribute("class",classe);
+ if(regle!=null) regle.marshall(output);
+ for(RefIdModel pcm:params) pcm.marshall(output);
+ message.marshall(output);
+ output.endTag(TAG);
+ }
+
+ public String getId() {return id;}
+ public String getLibelle() {return libelle;}
+ public String getSeverity() {return severity;}
+ public String getClasse() {return classe;}
+ public RegleModel getRegle() {return regle;}
+ public RefIdModel getRefIdModel() {return params.firstElement();}
+ public MessageModel getMessage() {return message;}
+
+ public RegleModel getRegleFonctionnelle(String etatId) { return regle;}
+
+ public ControlModel clone() {
+ ControlModel cm = new ControlModel(QN);
+
+ cm.id = this.id;
+ cm.libelle = this.libelle;
+ cm.severity = this.severity;
+ cm.classe = this.classe;
+ cm.regle=regle.clone();
+ for(RefIdModel pcm:params) {
+ try {
+ cm.addChild(pcm.clone(),RefIdModel.QN);
+ }catch(Throwable t) {}
+ }
+ return cm;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ QName tagName = new QName(uri,localName);
+ if(RegleModel.QN.equals(tagName)) {
+ return regle;
+ } else if(RefIdModel.QN.equals(tagName)) {
+ return null;
+ } else if(MessageModel.TAG.equals(tagName)) {
+ return message;
+ }
+ return null;
+ }
+
+ public QName getQName() {
+ return QN;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import fr.gouv.finances.dgfip.xemelios.controls.core.ControlParser;
+import fr.gouv.finances.dgfip.xemelios.common.config.TextModel;
+import java.util.ArrayList;
+import javax.xml.namespace.QName;
+
+
+public class ControlModelTech implements XmlMarshallable{
+ public static final transient String TAG = "controlTech";
+ public static final transient QName QN = new QName(TAG);
+ public String id, libelle, severity;
+ public Vector<ParamModelTech> params;
+ private Hashtable<String,ParamModelTech> indexedParamsTech;
+ private ArrayList<TextModel> ignoreRegexp;
+
+ public ControlModelTech(QName tagName) {
+ super();
+ params=new Vector<ParamModelTech>();
+ indexedParamsTech=new Hashtable<String,ParamModelTech>();
+ ignoreRegexp = new ArrayList<TextModel>();
+ }
+
+ public void addCharacterData(String cData) throws SAXException { }
+
+ public void addChild(XmlMarshallable child, QName tagName) throws SAXException {
+ if(ParamModelTech.QN.equals(tagName)) {
+ ParamModelTech cm = (ParamModelTech)child;
+ if(indexedParamsTech.containsKey(cm.getId())) {
+ ParamModelTech old = indexedParamsTech.get(cm.getId());
+ params.remove(old);
+ indexedParamsTech.remove(old.getId());
+ }
+ params.add(cm);
+ indexedParamsTech.put(cm.getId(),cm);
+ } else if(ControlParser.IGNORE_REGEXP.equals(tagName)) {
+ ignoreRegexp.add((TextModel)child);
+ }
+ }
+
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ id=attributes.getValue("id");
+ libelle=attributes.getValue("libelle");
+ severity=attributes.getValue("severity");
+ return this;
+ }
+ public void validate() throws InvalidXmlDefinition {
+ for(ParamModelTech pcm:params) pcm.validate();
+ }
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ output.addAttribute("id",id);
+ output.addAttribute("libelle",libelle);
+ output.addAttribute("severity",severity);
+ for(ParamModelTech pcm:params) pcm.marshall(output);
+ for(TextModel ir:ignoreRegexp) {
+ ir.marshall(output);
+ }
+ output.endTag(TAG);
+ }
+
+ public String getId() {return id;}
+ public String getLibelle() {return libelle;}
+ public String getSeverity() {return severity;}
+ public Vector<ParamModelTech> getParams() {return params;}
+
+ public ParamModelTech getParamTechById(String ctrlId) {
+ return indexedParamsTech.get(ctrlId);
+ }
+
+ @Override
+ public ControlModelTech clone() {
+ ControlModelTech cm = new ControlModelTech(QN);
+ cm.id = this.id;
+ cm.libelle = this.libelle;
+ cm.severity = this.severity;
+ for(ParamModelTech pmt:getParams()) {
+ try {
+ addChild(pmt.clone(), ParamModelTech.QN);
+ } catch(SAXException ignore) {}
+ }
+ return cm;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ if(ParamModelTech.QN.equals(new QName(uri,localName))) {
+ return indexedParamsTech.get(atts.getValue("id"));
+ }
+ return null;
+ }
+
+ public QName getQName() {
+ return QN;
+ }
+ public ArrayList<TextModel> getIgnoreRegexp() {
+ return ignoreRegexp;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import java.util.Vector;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import java.util.Hashtable;
+import javax.xml.namespace.QName;
+
+/**
+ * Modelise un ensemble de documents
+ *
+ * @author chm
+ */
+public class ControlsModel implements XmlMarshallable {
+ public static final transient String TAG = "controls";
+ public static final transient QName QN = new QName(TAG);
+ private Vector<DocumentControlModel> documents;
+ private Hashtable<String, DocumentControlModel> hDocuments;
+
+ public ControlsModel(QName tag) {
+ super();
+ documents = new Vector<DocumentControlModel>();
+ hDocuments = new Hashtable<String, DocumentControlModel>();
+ }
+
+ @Override
+ public void addCharacterData(String cData) throws SAXException {
+ throw new SAXException("pas de CDATA attendu");
+ }
+ @Override
+ public void addChild(XmlMarshallable child, QName tagName)
+ throws SAXException {
+ if (DocumentControlModel.QN.equals(tagName)) {
+ DocumentControlModel dcm = (DocumentControlModel) child;
+ if (hDocuments.containsKey(dcm.getDocumentId())) {
+ DocumentControlModel old = hDocuments.get(dcm.getDocumentId());
+ documents.remove(old);
+ hDocuments.remove(old.getDocumentId());
+ }
+ documents.add(dcm);
+ hDocuments.put(dcm.getDocumentId(), dcm);
+ } else
+ throw new SAXException(tagName + ": tag non attendu");
+ }
+ @Override
+ public XmlMarshallable getAttributes(XmlAttributes attributes)
+ throws SAXException {
+ return this;
+ }
+ @Override
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ for (DocumentControlModel dm : documents)
+ dm.marshall(output);
+ output.endTag(TAG);
+ }
+ @Override
+ public void validate() throws InvalidXmlDefinition {
+ for (DocumentControlModel dm : documents)
+ dm.validate();
+ }
+ public Vector<DocumentControlModel> getDocuments() {
+ return documents;
+ }
+ public DocumentControlModel getDocumentById(String docId) {
+ // for(Enumeration<DocumentControlModel>
+ // enumer=documents.elements();enumer.hasMoreElements();) {
+ // DocumentControlModel doc = enumer.nextElement();
+ // if(doc.getDocumentById().equals(docId)) return doc;
+ // }
+ return hDocuments.get(docId);
+ }
+ @Override
+ public ControlsModel clone() {
+ ControlsModel dom = new ControlsModel(QN);
+ for (DocumentControlModel dm : this.documents)
+ try {
+ dom.addChild(dm, DocumentControlModel.QN);
+ } catch (Exception ex) {
+ }
+ return dom;
+ }
+
+ @Override
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ if (DocumentControlModel.QN.equals(qName)) {
+ return hDocuments.get(atts.getValue("id"));
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public QName getQName() {
+ return QN;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import fr.gouv.finances.dgfip.xemelios.common.config.CollectiviteInfosModel;
+import fr.gouv.finances.dgfip.xemelios.common.config.DocumentModel;
+import fr.gouv.finances.dgfip.xemelios.common.config.DocumentsMapping;
+import fr.gouv.finances.dgfip.xemelios.common.config.Loader;
+import fr.gouv.finances.dgfip.xemelios.common.config.NamespaceModel;
+import fr.gouv.finances.dgfip.xemelios.common.config.RecherchePaireModel;
+import javax.xml.namespace.QName;
+
+public class DocumentControlModel implements XmlMarshallable {
+
+ public static final transient String TAG = "document";
+ public static final transient QName QN = new QName(TAG);
+ private String id;
+ private Vector<ParamModel> params;
+ private Vector<ControlModelTech> controlsTech;
+ private Vector<ControlModel> controls;
+ private Hashtable<String,ControlModel> indexedControls;
+ private Hashtable<String,ControlModelTech> indexedControlsTech;
+ private CollectiviteInfosModel collectivitePath;
+ private RecherchePaireModel budgetPath;
+ private DocumentModel parentDocumentModel;
+ private EngineModel engine;
+ private MessageRapportModel message;
+
+ public DocumentControlModel(QName tagName) {
+ super();
+ params=new Vector<ParamModel>();
+ controls=new Vector<ControlModel>();
+ controlsTech=new Vector<ControlModelTech>();
+ indexedControls = new Hashtable<String,ControlModel>();
+ indexedControlsTech = new Hashtable<String,ControlModelTech>();
+ }
+
+ @Override
+ public void addCharacterData(String cData) throws SAXException { }
+ @Override
+ public void addChild(XmlMarshallable child, QName tagName) throws SAXException {
+ if(ParamModel.QN.equals(tagName)) {
+ params.add((ParamModel)child);
+ } else if(ControlModel.QN.equals(tagName)) {
+ ControlModel cm = (ControlModel)child;
+ if(indexedControls.containsKey(cm.getId())) {
+ ControlModel old = indexedControls.get(cm.getId());
+ controls.remove(old);
+ indexedControls.remove(old.getId());
+ }
+ controls.add(cm);
+ indexedControls.put(cm.getId(),cm);
+ } else if(ControlModelTech.QN.equals(tagName)) {
+ ControlModelTech cm = (ControlModelTech)child;
+ if(indexedControlsTech.contains(cm.getId())) {
+ ControlModelTech old = indexedControlsTech.get(cm.getId());
+ controlsTech.remove(old);
+ indexedControlsTech.remove(old.getId());
+ }
+ controlsTech.add(cm);
+ indexedControlsTech.put(cm.getId(),cm);
+ } else if(CollectiviteInfosModel.QN.equals(tagName)) {
+ collectivitePath = (CollectiviteInfosModel)child;
+ } else if (DocumentsMapping.BUDGET_PATH.equals(tagName)) {
+ budgetPath = (RecherchePaireModel) child;
+ } else if(EngineModel.QN.equals(tagName)) {
+ engine = (EngineModel)child;
+ } else if (MessageRapportModel.QN.equals(tagName)) {
+ message = (MessageRapportModel)child;
+ }
+ }
+ @Override
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ id=attributes.getValue("id");
+ return this;
+ }
+ @Override
+ public void validate() throws InvalidXmlDefinition {
+ for(ParamModel pcm:params) pcm.validate();
+ for(ControlModel cm:controls) cm.validate();
+ for(ControlModelTech cm:controlsTech) cm.validate();
+ }
+ @Override
+ public void marshall(XmlOutputter output) {
+ output.startTag (TAG);
+ output.addAttribute("id",id);
+ if (message!=null) message.marshall(output);
+ if(collectivitePath!=null) collectivitePath.marshall(output);
+ if(budgetPath!=null) budgetPath.marshall(output);
+ for(ParamModel pm:params) pm.marshall(output);
+ if(engine!=null) engine.marshall(output);
+ for(ControlModelTech cm:controlsTech) cm.marshall(output);
+ for(ControlModel cm:controls) cm.marshall(output);
+ output.endTag(TAG);
+ }
+
+ public String getDocumentId() {return id;}
+
+ public ParamModel getParamById(String etatId) {
+ for(ParamModel param:params) {
+ if(param.getId().equals(etatId)) return param;
+ }
+ return null;
+ }
+
+ public ControlModel getControlById(String ctrlId) {
+ return indexedControls.get(ctrlId);
+ }
+
+ public ControlModelTech getControlTechById(String ctrlId) {
+ return indexedControlsTech.get(ctrlId);
+ }
+
+ public Vector<ControlModelTech> getControlsTech(){
+ return controlsTech;
+ }
+
+ public Vector<ControlModel> getControls(){
+ return controls;
+ }
+ public Vector<ParamModel> getParams(){
+ return params;
+ }
+
+ @Override
+ public DocumentControlModel clone() {
+ DocumentControlModel dcm = new DocumentControlModel(QN);
+ dcm.id = this.id;
+ try {
+ if (this.message!=null) dcm.addChild(this.message, MessageRapportModel.QN);
+ } catch (Throwable t) {}
+ if(collectivitePath!=null)
+ dcm.collectivitePath = collectivitePath.clone();
+ if(budgetPath!=null)
+ dcm.budgetPath=budgetPath.clone();
+ if(engine!=null)
+ dcm.engine = engine.clone();
+ for(ControlModel cm:getControls()){
+ try{
+ addChild(cm.clone(),ControlModel.QN);
+ } catch(SAXException ignore){}
+ }
+ for(ControlModelTech cmt:getControlsTech()) {
+ try {
+ addChild(cmt.clone(), ControlModelTech.QN);
+ } catch(SAXException ignore) {}
+ }
+ for(ParamModel pm:getParams()) {
+ try {
+ addChild(pm.clone(), ParamModel.QN);
+ } catch(SAXException ignore) {}
+ }
+ return dcm;
+ }
+
+ @Override
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ QName tagName = new QName(uri,localName);
+ if(ControlModel.QN.equals(tagName)) {
+ return indexedControls.get(atts.getValue("id"));
+ } else if(ControlModelTech.QN.equals(tagName)) {
+ return indexedControlsTech.get(atts.getValue("id"));
+ } else if (MessageRapportModel.QN.equals(tagName)) {
+ return message;
+ }
+ return null;
+ }
+
+ @Override
+ public QName getQName() {
+ return QN;
+ }
+ public CollectiviteInfosModel getCollectivitePath() {
+ if(collectivitePath==null) {
+ return getParentDocumentModel().getCollectivitePath();
+ } else {
+ return collectivitePath;
+ }
+ }
+ protected DocumentModel getParentDocumentModel() {
+ if(parentDocumentModel==null) {
+ try {
+ parentDocumentModel = Loader.getDocumentsInfos(null).getDocumentById(id);
+ } catch(Exception ex) {}
+ }
+ return parentDocumentModel;
+ }
+ public NamespaceModel getNamespaces() {
+ return getParentDocumentModel().getNamespaces();
+ }
+
+ public RecherchePaireModel getBudgetPath() {
+ if(budgetPath==null) {
+ return getParentDocumentModel().getBudgetPath();
+ } else {
+ return budgetPath;
+ }
+ }
+ public EngineModel getEngine() { return engine; }
+ public void setEngine(EngineModel engine) { this.engine=engine; }
+ public MessageRapportModel getMessage() {
+ return message;
+ }
+
+ public void setMessage(MessageRapportModel message) {
+ this.message = message;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import javax.xml.namespace.QName;
+
+/**
+ *
+ * @author chm
+ * @deprecated
+ */
+public class ElementLieModel implements XmlMarshallable {
+ public static final transient String TAG = "element-lie";
+ public static final transient QName QN = new QName(TAG);
+ private StringBuffer balise;
+ private String data;
+
+ public ElementLieModel(QName tagName) {
+ super();
+ balise = new StringBuffer();
+ throw new UnsupportedOperationException("Cette classe est dépréciée, elle ne doit plus être utilisée.");
+ }
+ public void addCharacterData(String cData) throws SAXException {
+ balise.append(cData);
+ }
+ public void addChild(XmlMarshallable child, QName tagName)throws SAXException {}
+ public XmlMarshallable getAttributes(XmlAttributes attributes)throws SAXException {
+ return this;
+ }
+ public void marshall(XmlOutputter output) {throw new Error("Not yet implemented"); }
+ public void validate() throws InvalidXmlDefinition {}
+ public String getBalise() { return balise.toString(); }
+ public String getData() {
+ return data;
+ }
+ public void setData(String data) {
+ this.data = data;
+ }
+ @Override
+ public ElementLieModel clone() {
+ ElementLieModel elm = new ElementLieModel(QN);
+ elm.balise = this.balise;
+ elm.data = this.data;
+ return elm;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ return null;
+ }
+
+ public QName getQName() {
+ return QN;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2010 axYus - www.axyus.com
+ * 2010 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import java.util.ArrayList;
+import javax.xml.namespace.QName;
+
+public class EngineModel implements XmlMarshallable {
+ public static final transient String TAG = "engine";
+ public static final transient QName QN = new QName(TAG);
+
+ private ArrayList<AddOnModel> addOns;
+
+ public EngineModel(QName qn) {
+ super();
+ addOns = new ArrayList<AddOnModel>();
+ }
+
+ public void addCharacterData(String cData) throws SAXException { }
+
+ public void addChild(XmlMarshallable child, QName tag) throws SAXException {
+System.err.println("adding "+tag);
+ if(AddOnModel.QN.equals(tag)) {
+ addOns.add((AddOnModel)child);
+ }
+ }
+
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ return this;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ return null;
+ }
+
+ public void marshall(XmlOutputter output) {
+ output.startTag(QN);
+ for(AddOnModel addOn:addOns) {
+ addOn.marshall(output);
+ }
+ output.endTag(QN);
+ }
+
+ public void validate() throws InvalidXmlDefinition {}
+
+ public QName getQName() {
+ return QN;
+ }
+
+ @Override
+ public EngineModel clone() {
+ EngineModel other = new EngineModel(QN);
+ for(AddOnModel addOn:addOns) {
+ try {
+ other.addChild(addOn, AddOnModel.QN);
+ } catch(Throwable t) {}
+ }
+ return other;
+ }
+
+ public ArrayList<AddOnModel> getAddOns() { return addOns; }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2005 axYus - www.axyus.com
+ * 2005 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import javax.xml.namespace.QName;
+
+/**
+ * Modelise un champ de saisie
+ * @author chm
+ */
+public class InputModel implements XmlMarshallable {
+
+ public static final transient String TAG = "input";
+ public static final transient QName QN = new QName(TAG);
+ private String id, libelle, datatype, xmlFormat;
+
+ public InputModel(QName tagName) {
+ super();
+ }
+
+ public void addCharacterData(String cData) throws SAXException {
+ }
+
+ public void addChild(XmlMarshallable child, QName tagName) throws SAXException {
+ }
+
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ id = attributes.getValue("id");
+ libelle = attributes.getValue("libelle");
+ datatype = attributes.getValue("datatype");
+ xmlFormat = attributes.getValue("xml-format");
+ return this;
+ }
+
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ output.addAttribute("id", id);
+ if (libelle != null) {
+ output.addAttribute("libelle", StringEscapeUtils.escapeXml(libelle));
+ }
+ output.addAttribute("datatype", datatype);
+ if ("date".equals(datatype)) {
+ output.addAttribute("xml-format", xmlFormat);
+ }
+ output.endTag(TAG);
+ }
+
+ public void validate() throws InvalidXmlDefinition {
+ }
+
+ public String getDatatype() {
+ return datatype;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getLibelle() {
+ return libelle;
+ }
+
+ public String getXmlDateFormat() {
+ return xmlFormat;
+ }
+
+ @Override
+ public InputModel clone() {
+ InputModel im = new InputModel(QN);
+ im.id = this.id;
+ im.libelle = this.libelle;
+ im.datatype = this.datatype;
+ im.xmlFormat = this.xmlFormat;
+ return im;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ return null;
+ }
+
+ public QName getQName() {
+ return QN;
+
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import javax.xml.namespace.QName;
+
+public class MessageModel implements XmlMarshallable {
+ public static final transient String TAG = "message-echec";
+ public static final transient QName QN = new QName(TAG);
+ private StringBuffer content;
+
+ public MessageModel(QName tagName) {
+ super();
+ content = new StringBuffer();
+ }
+ public void addCharacterData(String cData) throws SAXException {
+ content.append(cData);
+ }
+ public void addChild(XmlMarshallable child, QName tagName)throws SAXException {}
+ public XmlMarshallable getAttributes(XmlAttributes attributes)throws SAXException {
+ return this;
+ }
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ String sContent = content.toString();
+ boolean isCData = (sContent.indexOf('<')>=0 || sContent.indexOf('>')>=0);
+ output.addCharacterData("");
+ if(isCData) {
+ try {
+ output.getWriter().write("<![CDATA[");
+ output.getWriter().write(content.toString());
+ output.getWriter().write("]]>");
+ } catch(Exception ex) {}
+ } else {
+ output.addCharacterData(content.toString());
+ }
+ output.endTag(TAG);
+ }
+ public void validate() throws InvalidXmlDefinition {}
+ public String getContent() { return content.toString(); }
+ public String getHtmlContent() { return content.toString().replaceAll("<","<").replaceAll(">",">"); }
+ @Override
+ public MessageModel clone() {
+ MessageModel mm = new MessageModel(QN);
+ mm.content = new StringBuffer(content.toString());
+ return mm;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ return null;
+ }
+
+ public QName getQName() {
+ return QN;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import javax.xml.namespace.QName;
+
+public class MessageRapportModel implements XmlMarshallable {
+ public static final transient String TAG = "Message";
+ public static final transient QName QN = new QName(TAG);
+ private StringBuffer content;
+
+ public MessageRapportModel(QName tagName) {
+ super();
+ content = new StringBuffer();
+ }
+ public void addCharacterData(String cData) throws SAXException {
+ content.append(cData);
+ }
+ public void addChild(XmlMarshallable child, QName tagName)throws SAXException {}
+ public XmlMarshallable getAttributes(XmlAttributes attributes)throws SAXException {
+ return this;
+ }
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ String sContent = content.toString();
+ boolean isCData = (sContent.indexOf('<')>=0 || sContent.indexOf('>')>=0);
+ output.addCharacterData("");
+ if(isCData) {
+ try {
+ output.getWriter().write("<![CDATA[");
+ } catch(Exception ex) {}
+ }
+ output.addCharacterData(content.toString());
+ if(isCData) {
+ try {
+ output.getWriter().write("]]>");
+ } catch(Exception ex) {}
+ }
+ output.endTag(TAG);
+ }
+ public void validate() throws InvalidXmlDefinition {}
+ public String getContent() { return content.toString(); }
+ public String getHtmlContent() { return content.toString().replaceAll("<","<").replaceAll(">",">"); }
+ @Override
+ public MessageRapportModel clone() {
+ MessageRapportModel mm = new MessageRapportModel(QN);
+ mm.content = new StringBuffer(content.toString());
+ return mm;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ return null;
+ }
+
+ public QName getQName() {
+ return QN;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2005 axYus - www.axyus.com
+ * 2005 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import javax.xml.namespace.QName;
+
+/**
+ * Modelise une entree de liste de selection
+ * @author chm
+ */
+public class OptionModel implements XmlMarshallable {
+ public static final transient String TAG = "option";
+ public static final transient QName QN = new QName(TAG);
+ private String value;
+ private StringBuffer libelle;
+
+ public OptionModel(QName tagName) {
+ super();
+ libelle = new StringBuffer();
+ }
+ public OptionModel(String value, String libelle) {
+ this(QN);
+ this.value=value;
+ this.libelle.append(libelle);
+ }
+ public void addCharacterData(String cData) throws SAXException {
+ libelle.append(cData);
+ }
+ public void addChild(XmlMarshallable child, QName tagName)throws SAXException {}
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ value = attributes.getValue("value");
+ return this;
+ }
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ output.addAttribute("value",StringEscapeUtils.escapeXml(value));
+ output.addCharacterData(StringEscapeUtils.escapeXml(libelle.toString()));
+ output.endTag(TAG);
+ }
+ public void validate() throws InvalidXmlDefinition {}
+ public String getLibelle() {return libelle.toString();}
+ public String getValue() {return value;}
+ @Override
+ public OptionModel clone() {
+ OptionModel om = new OptionModel(QN);
+ om.value=this.value;
+ om.libelle = this.libelle;
+ return om;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ return null;
+ }
+
+ public QName getQName() {
+ return QN;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import fr.gouv.finances.dgfip.xemelios.common.Constants;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.dgfip.utils.Pair;
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import javax.xml.namespace.QName;
+
+
+/**
+ * Le datatype est "string" par défaut
+ * @author cmarchand
+ */
+public class ParamModel implements XmlMarshallable {
+ private static Logger logger = Logger.getLogger(ParamModel.class);
+ public static final transient String TAG = "param";
+ public static final transient QName QN = new QName(TAG);
+ public String id, name, datatype;
+ public SelectModel select;
+ public InputModel input;
+ private Object value;
+ private boolean optional = true;
+
+ public ParamModel(QName tagName) {
+ super();
+ datatype = "string";
+ }
+
+ public void addCharacterData(String cData) throws SAXException { }
+ public void addChild(XmlMarshallable child, QName tagName) throws SAXException {
+ if(SelectModel.QN.equals(tagName)) {
+ select=(SelectModel)child;
+ } else if(InputModel.QN.equals(tagName)) {
+ input=(InputModel)child;
+ }
+ }
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ id=attributes.getValue("id");
+ name=attributes.getValue("name");
+ datatype=attributes.getValue("datatype")!=null ? attributes.getValue("datatype") : datatype;
+ if(attributes.getValue("use")!=null) {
+ String sTmp = attributes.getValue("use");
+ optional = !"required".equals(sTmp);
+ }
+ value=attributes.getValue("value");
+ if(value!=null) checkValueDatatype();
+ return this;
+ }
+ public void validate() throws InvalidXmlDefinition {
+ if(select!=null&&input!=null) throw new InvalidXmlDefinition("A param must not own an input and a select");
+ if(select==null&&input==null) throw new InvalidXmlDefinition("A param must own either a select or either an input");
+ }
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ output.addAttribute("id",id);
+ output.addAttribute("name",name);
+ output.addAttribute("datatype",datatype);
+ if(!isOptional()) output.addAttribute("use","required");
+ if(value!=null) output.addAttribute("value",value.toString());
+ else output.addComment("no value specified");
+ if(select!=null) select.marshall(output);
+ if(input!=null) input.marshall(output);
+ output.endTag(TAG);
+ }
+
+ public String getId() {return id;}
+ public String getName() {return name;}
+ public String getDatatype() {return datatype;}
+
+ public InputModel getInput() { return input; }
+ public SelectModel getSelect() { return select;}
+
+ @Override
+ public ParamModel clone() {
+ ParamModel pcm = new ParamModel(QN);
+ pcm.id = this.id;
+ pcm.name = this.name;
+ pcm.datatype = this.datatype;
+ pcm.select=select.clone();
+ pcm.input=input.clone();
+ pcm.value=value;
+ return pcm;
+ }
+ public void setValue(Object o, String dateForamt) {
+// logger.debug("setting value to "+o);
+ if(o==null) this.value=o;
+ else {
+ String sValue;
+ if(o instanceof Pair) sValue = ((Pair)o).key;
+ else if(o instanceof Boolean) sValue = ((Boolean)o).toString();
+ else sValue = o.toString();
+ if("string".equals(datatype)) this.value=sValue;
+ else if("integer".equals(datatype)) {
+ try {
+ String s = o.toString();
+ if(s.length()>0) {
+ int i = Integer.parseInt(s);
+ this.value=new Integer(i);
+ } else {
+ this.value = new Integer(0);
+ }
+ } catch(Throwable t) {
+ logger.debug("parsing int",t);
+ }
+ } else if("decimal".equals(datatype)) {
+ try {
+ String s = o.toString();
+ if(s.length()>0) {
+ BigDecimal bd = new BigDecimal(s);
+ this.value=bd;
+ } else {
+ this.value = new BigDecimal(0.0);
+ }
+ } catch(Throwable t) {
+ logger.debug("parsing BigDecimal",t);
+ }
+ } else if("boolean".equals(datatype)) {
+ boolean b = Boolean.valueOf(o.toString());
+ this.value = new Boolean(b);
+ } else if("date".equals(datatype)) {
+ SimpleDateFormat sdf = new SimpleDateFormat(dateForamt);
+ try {
+ Date d = sdf.parse(o.toString());
+ this.value = d;
+ } catch(Throwable t) {
+ logger.debug("parsing date",t);
+ }
+ }
+// logger.debug("value set to "+this.value);
+ }
+ }
+ public Object getValue() { return value; }
+ public boolean isOptional() { return optional; }
+ private void checkValueDatatype() {
+ setValue(value, "yyyy-MM-dd");
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ QName tagName = new QName(uri,localName);
+ if(SelectModel.QN.equals(tagName)) {
+ return select;
+ } else if(InputModel.QN.equals(tagName)) {
+ return input;
+ }
+ return null;
+ }
+
+ public QName getQName() {
+ return QN;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import javax.xml.namespace.QName;
+
+
+
+public class ParamModelTech implements XmlMarshallable {
+ public static final transient String TAG = "paramTech";
+ public static final transient QName QN = new QName(TAG);
+ public String id, name, value;
+
+ public ParamModelTech(QName tagName) {
+ super();
+ }
+
+ public void addCharacterData(String cData) throws SAXException { }
+
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ id=attributes.getValue("id");
+ name=attributes.getValue("name");
+ value=attributes.getValue("value");
+ return this;
+ }
+
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ output.addAttribute("id",id);
+ output.addAttribute("name",name);
+ if(value!=null) output.addAttribute("value",value.toString());
+ else output.addComment("no value specified");
+ output.endTag(TAG);
+ }
+
+ public String getId() {return id;}
+ public String getName() {return name;}
+ public String getValue() { return value; }
+
+ public void validate() throws InvalidXmlDefinition {}
+
+ public ParamModelTech clone() {
+ ParamModelTech pcm = new ParamModelTech(QN);
+ pcm.id = this.id;
+ pcm.name = this.name;
+ pcm.value=value;
+ return pcm;
+ }
+
+ public void addChild(XmlMarshallable child, QName tagName) throws SAXException {}
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ return null;
+ }
+
+ public QName getQName() {
+ return QN;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import javax.xml.namespace.QName;
+
+public class RefIdModel implements XmlMarshallable {
+
+ public static final transient String TAG = "refId";
+ public static final transient QName QN = new QName(TAG);
+ public String param;
+
+ public RefIdModel(QName tagName) {
+ super();
+ }
+
+ public void addCharacterData(String cData) throws SAXException {
+ }
+
+ public void addChild(XmlMarshallable child, QName tagName) throws SAXException {
+ }
+
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ param = attributes.getValue("param");
+ return this;
+ }
+
+ public void validate() throws InvalidXmlDefinition {
+ }
+
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ output.addAttribute("param", param);
+ output.endTag(TAG);
+ }
+
+ public String getParam() {
+ return param;
+ }
+
+ public RefIdModel clone() {
+ RefIdModel pcm = new RefIdModel(QN);
+
+ pcm.param = this.param;
+ return pcm;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ return null;
+ }
+
+ public QName getQName() {
+ return QN;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import javax.xml.namespace.QName;
+
+public class RegleModel implements XmlMarshallable {
+ public static final transient String TAG = "regle-fonctionnelle";
+ public static final transient QName QN = new QName(TAG);
+ private StringBuffer content;
+
+ public RegleModel(QName tagName) {
+ super();
+ content = new StringBuffer();
+ }
+ public void addCharacterData(String cData) throws SAXException {
+ content.append(cData);
+ }
+ public void addChild(XmlMarshallable child, QName tagName)throws SAXException {}
+ public XmlMarshallable getAttributes(XmlAttributes attributes)throws SAXException {
+ return this;
+ }
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ String sContent = content.toString();
+ boolean isCData = (sContent.indexOf('<')>=0 || sContent.indexOf('>')>=0);
+ output.addCharacterData("");
+ if(isCData) {
+ try {
+ output.getWriter().write("<![CDATA[");
+ output.getWriter().write(content.toString());
+ output.getWriter().write("]]>");
+ } catch(Exception ex) {}
+ } else {
+ output.addCharacterData(content.toString());
+ }
+
+ output.endTag(TAG);
+ }
+ public void validate() throws InvalidXmlDefinition {}
+ public String getContent() { return content.toString(); }
+ public String getHtmlContent() { return content.toString().replaceAll("<","<").replaceAll(">",">"); }
+ @Override
+ public RegleModel clone() {
+ RegleModel rm = new RegleModel(QN);
+ rm.content = new StringBuffer(content.toString());
+ return rm;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ return null;
+ }
+
+ public QName getQName() {
+ return QN;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2005 axYus - www.axyus.com
+ * 2005 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package fr.gouv.finances.dgfip.xemelios.controls.core.models;
+
+import java.util.Vector;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
+import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
+import java.util.Hashtable;
+import javax.xml.namespace.QName;
+
+/**
+ * Modelise une liste de selection
+ * @author chm
+ */
+public class SelectModel implements XmlMarshallable {
+ public static final transient String TAG = "select";
+ public static final transient QName QN = new QName(TAG);
+
+ private Vector<OptionModel> options;
+ private Hashtable<String,OptionModel> hOptions;
+ private String id;
+ private boolean multiValued = false;
+ private boolean editable = false;
+
+
+ public SelectModel(QName tagName) {
+ super();
+ options = new Vector<OptionModel>();
+ hOptions = new Hashtable<String,OptionModel>();
+ }
+ public void addCharacterData(String cData) throws SAXException {}
+ public void addChild(XmlMarshallable child, QName tagName) throws SAXException {
+ if(OptionModel.QN.equals(tagName)){
+ OptionModel om = (OptionModel)child;
+ if(hOptions.containsKey(om.getValue())) {
+ OptionModel old = hOptions.get(om.getValue());
+ options.remove(old);
+ hOptions.remove(old.getValue());
+ }
+ options.add(om);
+ hOptions.put(om.getValue(), om);
+ }
+ }
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ setId(attributes.getValue("id"));
+ if(attributes.getValue("multivalued")!=null)
+ multiValued = attributes.getBooleanValue("multivalued");
+ if(attributes.getValue("editable")!=null)
+ editable=attributes.getBooleanValue("editable");
+ return this;
+ }
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ output.addAttribute("id", getId());
+ if(multiValued) output.addAttribute("multivalued",true);
+ if(editable) output.addAttribute("editable",true);
+ for(OptionModel om:options) om.marshall(output);
+ output.endTag(TAG);
+ }
+ public void validate() throws InvalidXmlDefinition {
+ for(OptionModel om:options) om.validate();
+ }
+ public String getId() {return id;}
+ public Vector<OptionModel> getOptions() {return options;}
+
+ @Override
+ public SelectModel clone() {
+ SelectModel sm = new SelectModel(QN);
+ sm.setId(this.getId());
+ for(OptionModel om:options) sm.getOptions().add(om.clone());
+ return sm;
+ }
+
+ public void setOptions(Vector<OptionModel> options) {
+ this.options = options;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public boolean isMultiValued() {
+ return multiValued;
+ }
+
+ public void setMultiValued(boolean multiValued) {
+ this.multiValued = multiValued;
+ }
+
+ public boolean isEditable() {
+ return editable;
+ }
+
+ public void setEditable(boolean editable) {
+ this.editable = editable;
+ }
+
+ public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
+ return hOptions.get(atts.getValue("value"));
+ }
+
+ public QName getQName() {
+ return QN;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2010 axYus - www.axyus.com
+ * 2010 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.processors;
+
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ParamModel;
+import fr.gouv.finances.dgfip.utils.xml.XmlAttributesImpl;
+
+import java.util.Hashtable;
+import java.util.List;
+import javax.xml.namespace.NamespaceContext;
+import org.xml.sax.Attributes;
+
+
+/**
+ * A processor, used by control engines
+ * @author cmarchand
+ */
+public abstract class AbstractProcessor implements Processor {
+ private Hashtable<String,ParamModel> parameters;
+ private NamespaceContext nsCtx;
+
+ public void setParameters(List<ParamModel> params) {
+ parameters = new Hashtable<String, ParamModel>();
+ for(ParamModel p:params) {
+ parameters.put(p.getName(), p);
+ }
+ }
+ public ParamModel getParamByName(String name) {
+ if(parameters==null) return null;
+ return parameters.get(name);
+ }
+
+ public void setNamespaceContext(NamespaceContext nsCtx) {
+ this.nsCtx = nsCtx;
+ }
+ public NamespaceContext getNamespaceContext() { return nsCtx; }
+
+
+ /**
+ * By default, does nothing
+ * @param evt
+ */
+ public void process(EVENT evt) {
+ //throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ /**
+ * By default, does nothing
+ * @param evt
+ * @param uri
+ * @param localName
+ * @param qName
+ */
+ public void process(EVENT evt, String uri, String localName, String qName) {
+ //throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ /**
+ * By default does nothing
+ * @param evt
+ * @param uri
+ * @param localName
+ * @param qName
+ * @param atts
+ */
+ public void process(EVENT evt, String uri, String localName, String qName, Attributes atts) {
+ //throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ /**
+ * By default does nothing
+ * @param evt
+ * @param uri
+ * @param localName
+ * @param qName
+ * @param atts
+ */
+ public void process(EVENT evt, String uri, String localName, String qName, XmlAttributesImpl atts) {
+ //throw new UnsupportedOperationException("Not supported yet.");
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2010 axYus - www.axyus.com
+ * 2010 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.processors;
+
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ParamModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.processors.Processor.EVENT;
+import fr.gouv.finances.dgfip.xemelios.controls.core.processors.impl.IdGenerator;
+import fr.gouv.finances.dgfip.utils.xml.XmlAttributesImpl;
+import java.util.List;
+import org.apache.log4j.Logger;
+
+
+/**
+ * A processor, used by control engines
+ * @author cmarchand
+ */
+public class IdGeneratorProcessor extends AbstractProcessor {
+ private static final Logger logger = Logger.getLogger(IdGeneratorProcessor.class);
+ private IdGenerator idGenerator = null;
+
+ public IdGeneratorProcessor() {
+ super();
+ }
+
+ @Override
+ public void setParameters(List<ParamModel> params) {
+ super.setParameters(params);
+ try {
+ Class clazz = Class.forName((String)getParamByName("generator").getValue());
+ idGenerator = (IdGenerator)(clazz.newInstance());
+ } catch(Throwable t) {
+ logger.fatal("instanciating IdGenerator",t);
+ }
+ }
+
+ public void process(EVENT evt, String uri, String localName, String qName, XmlAttributesImpl atts) {
+ String attributeName = getParamByName("generated.attribute").getValue().toString();
+ String targetUri = null;
+ String targetLocalName = null;
+ String targetQName = null;
+ int pos = -1;
+ if((pos=attributeName.indexOf(":")) >= 0) {
+ String prefix = attributeName.substring(0,pos);
+ targetLocalName = attributeName.substring(pos+1);
+ targetUri = getNamespaceContext().getNamespaceURI(prefix);
+ targetQName = getNamespaceContext().getPrefix(targetUri)+":"+targetLocalName;
+ } else {
+ targetLocalName = targetLocalName = attributeName;
+ }
+ atts.addAttribute(targetUri, targetLocalName, targetQName, "CDATA", idGenerator.generateId());
+ }
+
+
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright
+ * 2010 axYus - www.axyus.com
+ * 2010 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.processors;
+
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ParamModel;
+import fr.gouv.finances.dgfip.utils.xml.XmlAttributesImpl;
+import java.util.List;
+import javax.xml.namespace.NamespaceContext;
+
+/**
+ * A processor, used by control engines
+ * @author cmarchand
+ */
+public interface Processor {
+ public enum EVENT {
+ START_DOCUMENT,
+ START_ELEMENT,
+ END_ELEMENT,
+ END_DOCUMENT
+ }
+ public void process(EVENT evt, String uri, String localName, String qName, XmlAttributesImpl atts);
+ public void process(EVENT evt, String uri, String localName, String qName);
+ public void process(EVENT evt);
+ public void setParameters(List<ParamModel> params);
+ public void setNamespaceContext(NamespaceContext nsCtx);
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright
+ * 2010 axYus - www.axyus.com
+ * 2010 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.processors.impl;
+
+public interface IdGenerator {
+ /**
+ * generates a unique id
+ * @return
+ */
+ public String generateId();
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright
+ * 2010 axYus - www.axyus.com
+ * 2010 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.processors.impl;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * Generates ID such as iii.iii.iii.iii-tttttttttt-c
+ * @author cmarchand
+ */
+public class TstampIPUniqueId implements IdGenerator {
+ private static long lastTime = System.currentTimeMillis();
+ private static int count = 0;
+ private String ip;
+ public TstampIPUniqueId() {
+ super();
+ if(ip==null) {
+ try {
+ InetAddress addr = InetAddress.getLocalHost();
+ // Get IP Address
+ byte[] ipAddr = addr.getAddress();
+ // Get hostname
+ StringBuffer sb = new StringBuffer();
+ for(byte i:ipAddr) {
+ sb.append(Byte.toString(i)).append(".");
+ }
+ ip = sb.toString();
+ ip = ip.substring(0, ip.length()-1);
+ } catch (UnknownHostException e) {
+ ip = "127.0.0.1";
+ }
+ }
+ }
+
+ public String generateId() {
+ long now = System.currentTimeMillis();
+ if(now==lastTime) {
+ count++;
+ } else {
+ lastTime = now;
+ count = 0;
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append(ip).append("-").append(Long.toString(now)).append("-").append(Integer.toBinaryString(count));
+ return sb.toString();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.tech;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import fr.gouv.finances.dgfip.xemelios.common.config.DocumentModel;
+import fr.gouv.finances.dgfip.xemelios.common.config.EtatModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.Anomalie;
+import fr.gouv.finances.dgfip.xemelios.controls.core.IdGenerator;
+import fr.gouv.finances.dgfip.xemelios.controls.core.Node;
+
+public class TECH01 extends DefaultHandler {
+
+ /**
+ * @author jp.tessier
+ * AXYUS
+ */
+ private final static Logger logger = Logger.getLogger(TECH01.class);
+ public static final transient String CTRL_ID = "TECH01";
+ private Vector<Anomalie> anos = new Vector<Anomalie>();
+ public String baliseCourante = "";
+ public StringBuffer message = new StringBuffer(), domaines = new StringBuffer();
+ private DocumentModel docModel;
+
+ protected void createAnomalie(SAXParseException e) {
+ if (isValidError(e)) {
+ Anomalie ano = new Anomalie(IdGenerator.nextId(),
+ CTRL_ID,
+ "Contrôle de la validité du XML.",
+ CTRL_ID,
+ "",
+ "",
+ "",
+ "",
+ "",
+ addMessage(e),
+ "Le fichier doit être un fichier xml valide.",
+ "BLOQUANT",
+ "xpath namespacise",
+ new Hashtable<String, Object>());
+ ano.addNode(new Node(null));
+ anos.add(ano);
+ }
+
+ }
+ @Override
+ public void error(SAXParseException e) throws SAXException {
+ createAnomalie(e);
+ }
+
+ @Override
+ public void fatalError(SAXParseException e) throws SAXException {
+ createAnomalie(e);
+ }
+
+ @Override
+ public void warning(SAXParseException e) throws SAXException {
+ createAnomalie(e);
+ }
+
+ private String addMessage(SAXParseException e) {
+ return "<b>Line n°" + e.getLineNumber() + " : </b>" + e.getMessage().replaceAll("<", "").replaceAll(">", "").replaceAll("/", "");
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ logger.info("In " + CTRL_ID);
+ }
+
+ public void setDocModel(DocumentModel dm) {
+ docModel = dm;
+ }
+
+ @Override
+ public void startElement(String URI, String localName, String rawName, Attributes attributs) throws SAXException {
+ baliseCourante = localName;
+ for (EtatModel etat : docModel.getEtats()) {
+ if (etat.getBalise().equals(localName)) {
+ domaines.append((domaines.length() > 0 ? "," : "") + localName);
+ }
+ }
+ }
+
+ public Vector<Anomalie> getAnomalies() {
+ return anos;
+ }
+
+ public String getDomaines() {
+ return domaines.toString();
+ }
+
+ public boolean isValidError(SAXParseException ex) {
+ return !ex.getMessage().contains("processing instruction");
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.tech;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ControlModelTech;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.ParamModelTech;
+import fr.gouv.finances.dgfip.xemelios.utils.FileUtils;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+
+/**
+ * Controls if input file has an acceptable encoding.
+ * Valid encodings must be listed as parameters with name="encoding".
+ * @author cmarchand
+ */
+public class TECH02 {
+ public static final transient String ENCODING_PARAM_NAME = "encoding";
+ private String inputFileEncoding="";
+ private final static Logger logger = Logger.getLogger(TECH02.class);
+ private ArrayList<String> acceptableEncodings;
+ private String validEncodings;
+
+ public TECH02() {
+ super();
+ acceptableEncodings = new ArrayList<String>();
+ }
+
+ public boolean encodingValid(ControlModelTech cmt,File fichierAController){
+ // build the acceptable encodings list
+ StringBuilder sb = new StringBuilder();
+ for(ParamModelTech pmt:cmt.getParams()){
+ if(ENCODING_PARAM_NAME.equals(pmt.getName())) {
+ try {
+ Charset cs = Charset.forName(pmt.getValue());
+ String encodingName = cs.name();
+ acceptableEncodings.add(encodingName);
+ sb.append(encodingName).append(',');
+ } catch(Exception ex) {
+ logger.error("while initializing charset: "+pmt.getValue(),ex);
+ }
+ }
+ }
+ if(sb.length()>0) sb.deleteCharAt(sb.length()-1);
+ validEncodings = sb.toString().replaceAll(",", ", ");
+
+ boolean encodingValid=false;
+ try {
+ inputFileEncoding = FileUtils.getFileEncoding(fichierAController);
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ try {
+ Charset cs = Charset.forName(inputFileEncoding);
+ inputFileEncoding = cs.name();
+ encodingValid = acceptableEncodings.contains(inputFileEncoding);
+ } catch(Exception ex) {
+ // unknown or illega encoding => invalid
+ encodingValid = false;
+ }
+ return encodingValid;
+ }
+
+ public String getInputEncoding(){
+ return inputFileEncoding;
+ }
+
+ public String getValidEncodings() {
+ return validEncodings;
+ }
+}
--- /dev/null
+/*
+ * Copyright
+ * 2007 axYus - www.axyus.com
+ * 2007 JP.Tessier - jean-philippe.tessier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package fr.gouv.finances.dgfip.xemelios.controls.core.tech;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+
+import fr.gouv.finances.dgfip.xemelios.common.config.TextModel;
+import fr.gouv.finances.dgfip.xemelios.controls.core.Anomalie;
+import fr.gouv.finances.dgfip.xemelios.controls.core.IdGenerator;
+import fr.gouv.finances.dgfip.xemelios.controls.core.Node;
+import fr.gouv.finances.dgfip.xemelios.controls.core.models.DocumentControlModel;
+
+public class TECH03 extends DefaultHandler {
+
+ /**
+ * @author jp.tessier
+ * AXYUS
+ */
+ private final static Logger logger = Logger.getLogger(TECH03.class);
+ public static final transient String CTRL_ID = "TECH03";
+ private Vector<Anomalie> anos = new Vector<Anomalie>();
+// private DocumentModel docModel;
+ private String documentTitre;
+ private DocumentControlModel docControlModel;
+ private String domainesControles;
+ public int MAX_ANOS = 300;
+ private String severity = "BLOQUANT";
+
+ @Override
+ public void error(SAXParseException e) throws SAXException {
+ createAnomalie(e);
+ }
+
+ @Override
+ public void fatalError(SAXParseException e) throws SAXException {
+ createAnomalie(e);
+ }
+
+ @Override
+ public void warning(SAXParseException e) throws SAXException {
+ createAnomalie(e);
+ }
+
+ private void createAnomalie(SAXParseException e) {
+ if (isValidError(e)) {
+ if (isAnomalieToReturn(e)) {
+ Anomalie ano = new Anomalie(IdGenerator.nextId(),
+ CTRL_ID,
+ "Contrôle de la conformance au schéma de : " + documentTitre + ".",
+ CTRL_ID,
+ domainesControles,
+ "",
+ "",
+ "",
+ "",
+ "<b>Line n°" + e.getLineNumber() + " : </b>" + e.getMessage().substring(e.getMessage().indexOf(":") + 2, e.getMessage().length()).replaceAll("<", "").replaceAll(">", "").replaceAll("/", ""),
+ // "<b>Line n°"+e.getLineNumber()+" : </b>"+e.getMessage().substring(e.getMessage().indexOf(":")+2,e.getMessage().length()).replaceAll("<","").replaceAll(">","").replaceAll("/",""),
+ "Le fichier doit être conforme au schéma : " + documentTitre + ".",
+ severity,
+ "xpath namespacise",
+ new Hashtable<String, Object>());
+ ano.addNode(new Node(null));
+ if (!(anos.size() > MAX_ANOS)) {
+ anos.add(ano);
+ }
+ }
+ }
+ }
+
+ public Vector<Anomalie> getAnomalies() {
+ return anos;
+ }
+
+ public void setDocumentTitre(String documentTitre) {
+ this.documentTitre = documentTitre;
+ }
+
+ public void setDocumentControlModel(DocumentControlModel dcm) {
+ docControlModel = dcm;
+ severity = docControlModel.getControlTechById(CTRL_ID).getSeverity();
+ }
+
+ public void setDomainesControles(String dc) {
+ domainesControles = dc;
+ }
+
+ public boolean isValidError(SAXParseException ex) {
+ return !ex.getMessage().contains("processing instruction");
+ }
+
+ private boolean isAnomalieToReturn(SAXParseException ex) {
+ boolean ret = true;
+ if (docControlModel.getControlTechById(CTRL_ID).getIgnoreRegexp().size() > 0) {
+ for (TextModel textModel : docControlModel.getControlTechById(CTRL_ID).getIgnoreRegexp()) {
+ if (ex.getMessage().matches(textModel.getData())) {
+ ret = false;
+ break;
+ }
+ }
+ }
+ return ret;
+ }
+}
--- /dev/null
+Manifest-version: 1.0
+Jar-Version: @version@
+Jar-Content: @name@
+