Commit a4dc4095 authored by Vincent Calame's avatar Vincent Calame

Renommage en ElementHandler

parent 53e109b7
......@@ -9,7 +9,6 @@
package net.scrutari.xml;
import net.scrutari.xml.SctXmlUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -19,14 +18,14 @@ import net.mapeadores.util.text.CleanedString;
import net.mapeadores.util.text.StringChecker;
import net.mapeadores.util.xml.xmlpull.DefaultElementHandler;
import net.mapeadores.util.xml.xmlpull.SimpleElementHandler;
import net.mapeadores.util.xml.xmlpull.XmlPullElementHandler;
import net.mapeadores.util.xml.xmlpull.ElementHandler;
/**
*
* @author Vincent Calame
*/
public class AttrHandler extends DefaultElementHandler {
class AttrHandler extends DefaultElementHandler {
private static final int VALUE = 1;
private final AttributeKey attributeKey;
......@@ -36,23 +35,15 @@ public class AttrHandler extends DefaultElementHandler {
private final StringChecker stringChecker;
public AttrHandler(AttributeKey attributeKey, MessageHandler messageHandler, String xpath, StringChecker stringChecker) {
AttrHandler(AttributeKey attributeKey, MessageHandler messageHandler, String xpath, StringChecker stringChecker) {
this.attributeKey = attributeKey;
this.messageHandler = messageHandler;
this.xpath = xpath;
this.stringChecker = stringChecker;
}
public AttributeKey getAttributeKey() {
return attributeKey;
}
public List<CleanedString> getValueList() {
return valueList;
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
switch (tagname) {
case "val":
return new SimpleElementHandler(VALUE);
......@@ -74,6 +65,14 @@ public class AttrHandler extends DefaultElementHandler {
}
}
AttributeKey getAttributeKey() {
return attributeKey;
}
List<CleanedString> getValueList() {
return valueList;
}
private CleanedString check(CleanedString cs) {
if ((stringChecker == null) || (cs == null)) {
return cs;
......
......@@ -17,11 +17,11 @@ import net.mapeadores.util.logging.MessageHandler;
import net.mapeadores.util.xml.DomMessages;
import net.mapeadores.util.xml.xmlpull.DefaultElementHandler;
import net.mapeadores.util.xml.xmlpull.SimpleElementHandler;
import net.mapeadores.util.xml.xmlpull.XmlPullElementHandler;
import net.scrutari.datauri.BaseURI;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import net.mapeadores.util.xml.xmlpull.ElementHandler;
/**
......@@ -110,7 +110,7 @@ public class BaseURIXmlEngine {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map attributeMap) {
public ElementHandler startSubElement(String tagname, Map attributeMap) {
if ((tagname.equals("authority")) || (tagname.equals("authority-uuid"))) {
return new SimpleElementHandler(AUTHORITY);
}
......
......@@ -25,7 +25,6 @@ import net.mapeadores.util.xml.DomMessages;
import net.mapeadores.util.xml.xmlpull.DefaultElementHandler;
import net.mapeadores.util.xml.xmlpull.LabelElementHandler;
import net.mapeadores.util.xml.xmlpull.SimpleElementHandler;
import net.mapeadores.util.xml.xmlpull.XmlPullElementHandler;
import net.scrutari.data.BaseData;
import net.scrutari.data.CorpusData;
import net.scrutari.data.DataConstants;
......@@ -36,6 +35,7 @@ import net.scrutari.datauri.ThesaurusURI;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import net.mapeadores.util.xml.xmlpull.ElementHandler;
/**
......@@ -154,7 +154,7 @@ public class BaseXmlEngine {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
switch (tagname) {
case "base-metadata":
if (buildBaseMetadata) {
......@@ -200,7 +200,7 @@ public class BaseXmlEngine {
}
@Override
public void endSubElement(XmlPullElementHandler elementHandler) {
public void endSubElement(ElementHandler elementHandler) {
if (elementHandler instanceof CorpusHandler) {
CorpusData corpusData = ((CorpusHandler) elementHandler).flushCorpusData();
if (corpusData != null) {
......@@ -233,7 +233,7 @@ public class BaseXmlEngine {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
String tagXpath = xpath + "/" + tagname;
switch (tagname) {
case "base-icon":
......@@ -273,7 +273,7 @@ public class BaseXmlEngine {
}
@Override
public void endSubElement(XmlPullElementHandler elementHandler) {
public void endSubElement(ElementHandler elementHandler) {
if (elementHandler instanceof AttrHandler) {
AttrHandler attrHandler = (AttrHandler) elementHandler;
baseDataBuilder.addAttribute(attrHandler.getAttributeKey(), attrHandler.getValueList());
......@@ -298,7 +298,7 @@ public class BaseXmlEngine {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
if (tagname.equals("lib")) {
try {
return new LabelElementHandler(attributeMap, xpath + "/" + tagname);
......@@ -311,7 +311,7 @@ public class BaseXmlEngine {
}
@Override
public void endSubElement(XmlPullElementHandler elementHandler) {
public void endSubElement(ElementHandler elementHandler) {
baseDataBuilder.addLabel(name, SctXmlUtils.testLabel(elementHandler));
}
......@@ -331,7 +331,7 @@ public class BaseXmlEngine {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map attributeMap) {
public ElementHandler startSubElement(String tagname, Map attributeMap) {
if (tagname.equals("lang")) {
return new SimpleElementHandler(LANG);
}
......
......@@ -9,7 +9,6 @@
package net.scrutari.xml;
import net.scrutari.xml.SctXmlUtils;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.text.ParseException;
......@@ -22,7 +21,6 @@ import net.mapeadores.util.primitives.FuzzyDate;
import net.mapeadores.util.xml.xmlpull.DefaultElementHandler;
import net.mapeadores.util.xml.xmlpull.LabelElementHandler;
import net.mapeadores.util.xml.xmlpull.SimpleElementHandler;
import net.mapeadores.util.xml.xmlpull.XmlPullElementHandler;
import net.scrutari.data.CorpusData;
import net.scrutari.data.DataConstants;
import net.scrutari.data.DataValidationException;
......@@ -32,14 +30,14 @@ import net.scrutari.datauri.CorpusURI;
import net.scrutari.datauri.FicheURI;
import net.scrutari.db.api.DataCoder;
import net.scrutari.db.api.caches.DataCacheWriter;
import net.scrutari.xml.Parameters;
import net.mapeadores.util.xml.xmlpull.ElementHandler;
/**
*
* @author Vincent Calame
*/
public class CorpusHandler extends DefaultElementHandler {
class CorpusHandler extends DefaultElementHandler {
private static final int HREF_PARENT = 1;
private static final int TITRE = 3;
......@@ -63,7 +61,7 @@ public class CorpusHandler extends DefaultElementHandler {
private final String corpusxpath;
private boolean metadataDone = false;
public CorpusHandler(CorpusURI corpusURI, Parameters parameters) {
CorpusHandler(CorpusURI corpusURI, Parameters parameters) {
this.corpusURI = corpusURI;
String corpusName = corpusURI.getCorpusName();
this.messageHandler = parameters.getMessageHandler();
......@@ -81,7 +79,7 @@ public class CorpusHandler extends DefaultElementHandler {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
if (!metadataDone) {
if (tagname.equals("corpus-metadata")) {
metadataDone = true;
......@@ -116,7 +114,7 @@ public class CorpusHandler extends DefaultElementHandler {
}
@Override
public void endSubElement(XmlPullElementHandler elementHandler) {
public void endSubElement(ElementHandler elementHandler) {
if (elementHandler instanceof FicheHandler) {
FicheHandler fh = (FicheHandler) elementHandler;
FicheData.Builder ficheDataBuilder = fh.getFicheDataBuilder();
......@@ -132,7 +130,7 @@ public class CorpusHandler extends DefaultElementHandler {
}
}
public CorpusData flushCorpusData() {
CorpusData flushCorpusData() {
if (!metadataDone) {
return null;
}
......@@ -149,7 +147,7 @@ public class CorpusHandler extends DefaultElementHandler {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
String xpath = corpusxpath + "/corpus-metadata/" + tagname;
switch (tagname) {
case "intitule-corpus":
......@@ -193,7 +191,7 @@ public class CorpusHandler extends DefaultElementHandler {
}
@Override
public void endSubElement(XmlPullElementHandler elementHandler) {
public void endSubElement(ElementHandler elementHandler) {
if (elementHandler instanceof AttrHandler) {
AttrHandler attrHandler = (AttrHandler) elementHandler;
corpusDataBuilder.addAttribute(attrHandler.getAttributeKey(), attrHandler.getValueList());
......@@ -227,7 +225,7 @@ public class CorpusHandler extends DefaultElementHandler {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
switch (tagname) {
case "titre":
return new SimpleElementHandler(TITRE);
......@@ -316,7 +314,7 @@ public class CorpusHandler extends DefaultElementHandler {
}
@Override
public void endSubElement(XmlPullElementHandler elementHandler) {
public void endSubElement(ElementHandler elementHandler) {
if (elementHandler instanceof GeolocHandler) {
GeolocHandler geolocHandler = (GeolocHandler) elementHandler;
String latitude = geolocHandler.latitude;
......@@ -356,7 +354,7 @@ public class CorpusHandler extends DefaultElementHandler {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
if (tagname.equals("lib")) {
try {
return new LabelElementHandler(attributeMap, xpath + "/lib");
......@@ -369,7 +367,7 @@ public class CorpusHandler extends DefaultElementHandler {
}
@Override
public void endSubElement(XmlPullElementHandler elementHandler) {
public void endSubElement(ElementHandler elementHandler) {
corpusDataBuilder.addLabel(name, SctXmlUtils.testLabel(elementHandler));
}
......@@ -385,7 +383,7 @@ public class CorpusHandler extends DefaultElementHandler {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
switch (tagname) {
case "lat":
return new SimpleElementHandler(LATITUDE);
......
......@@ -22,8 +22,8 @@ import net.mapeadores.util.logging.MessageHandler;
import net.mapeadores.util.text.Label;
import net.mapeadores.util.xml.DomMessages;
import net.mapeadores.util.xml.xmlpull.LabelElementHandler;
import net.mapeadores.util.xml.xmlpull.XmlPullElementHandler;
import net.scrutari.data.SctSpace;
import net.mapeadores.util.xml.xmlpull.ElementHandler;
/**
......@@ -35,7 +35,7 @@ public final class SctXmlUtils {
private SctXmlUtils() {
}
public static Label testLabel(XmlPullElementHandler elementHandler) {
public static Label testLabel(ElementHandler elementHandler) {
if (elementHandler instanceof LabelElementHandler) {
return ((LabelElementHandler) elementHandler).toLabel();
} else {
......
......@@ -9,14 +9,12 @@
package net.scrutari.xml;
import net.scrutari.xml.SctXmlUtils;
import java.util.Map;
import net.mapeadores.util.attr.AttributeKey;
import net.mapeadores.util.logging.ErrorMessageException;
import net.mapeadores.util.logging.MessageHandler;
import net.mapeadores.util.xml.xmlpull.DefaultElementHandler;
import net.mapeadores.util.xml.xmlpull.LabelElementHandler;
import net.mapeadores.util.xml.xmlpull.XmlPullElementHandler;
import net.scrutari.data.DataConstants;
import net.scrutari.data.DataValidator;
import net.scrutari.data.MotcleData;
......@@ -25,14 +23,14 @@ import net.scrutari.datauri.MotcleURI;
import net.scrutari.datauri.ThesaurusURI;
import net.scrutari.db.api.DataCoder;
import net.scrutari.db.api.caches.DataCacheWriter;
import net.scrutari.xml.Parameters;
import net.mapeadores.util.xml.xmlpull.ElementHandler;
/**
*
* @author Vincent Calame
*/
public class ThesaurusHandler extends DefaultElementHandler {
class ThesaurusHandler extends DefaultElementHandler {
private final DataCacheWriter dataCacheWriter;
private final DataCoder dataCoder;
......@@ -46,7 +44,7 @@ public class ThesaurusHandler extends DefaultElementHandler {
private final String thesaurusxpath;
private boolean metadataDone = false;
public ThesaurusHandler(ThesaurusURI thesaurusURI, Parameters parameters) {
ThesaurusHandler(ThesaurusURI thesaurusURI, Parameters parameters) {
this.thesaurusURI = thesaurusURI;
String thesaurusName = thesaurusURI.getThesaurusName();
this.messageHandler = parameters.getMessageHandler();
......@@ -63,17 +61,8 @@ public class ThesaurusHandler extends DefaultElementHandler {
thesaurusDataBuilder = new ThesaurusData.Builder(thesaurusURI);
}
public ThesaurusData flushThesaurusData() {
if (!metadataDone) {
return null;
}
ThesaurusData thesaurusData = thesaurusDataBuilder.toThesaurusData(codethesaurus, codebase);
dataCacheWriter.cacheThesaurusData(thesaurusData);
return thesaurusData;
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
if (!metadataDone) {
if (tagname.equals("thesaurus-metadata")) {
metadataDone = true;
......@@ -108,7 +97,7 @@ public class ThesaurusHandler extends DefaultElementHandler {
}
@Override
public void endSubElement(XmlPullElementHandler elementHandler) {
public void endSubElement(ElementHandler elementHandler) {
if (elementHandler instanceof MotcleHandler) {
MotcleHandler mh = (MotcleHandler) elementHandler;
MotcleData.Builder motcleDataBuilder = mh.getMotcleDataBuilder();
......@@ -119,6 +108,15 @@ public class ThesaurusHandler extends DefaultElementHandler {
}
}
ThesaurusData flushThesaurusData() {
if (!metadataDone) {
return null;
}
ThesaurusData thesaurusData = thesaurusDataBuilder.toThesaurusData(codethesaurus, codebase);
dataCacheWriter.cacheThesaurusData(thesaurusData);
return thesaurusData;
}
private class MetadataHandler extends DefaultElementHandler {
......@@ -127,7 +125,7 @@ public class ThesaurusHandler extends DefaultElementHandler {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
String xpath = thesaurusxpath + "/thesaurus-metadata/" + tagname;
switch (tagname) {
case "intitule-thesaurus":
......@@ -145,7 +143,7 @@ public class ThesaurusHandler extends DefaultElementHandler {
}
@Override
public void endSubElement(XmlPullElementHandler elementHandler) {
public void endSubElement(ElementHandler elementHandler) {
if (elementHandler instanceof AttrHandler) {
AttrHandler attrHandler = (AttrHandler) elementHandler;
thesaurusDataBuilder.addAttribute(attrHandler.getAttributeKey(), attrHandler.getValueList());
......@@ -166,7 +164,7 @@ public class ThesaurusHandler extends DefaultElementHandler {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
if (tagname.equals("lib")) {
try {
return new LabelElementHandler(attributeMap, xpath + "/lib");
......@@ -179,7 +177,7 @@ public class ThesaurusHandler extends DefaultElementHandler {
}
@Override
public void endSubElement(XmlPullElementHandler elementHandler) {
public void endSubElement(ElementHandler elementHandler) {
thesaurusDataBuilder.addLabel(name, SctXmlUtils.testLabel(elementHandler));
}
......@@ -210,7 +208,7 @@ public class ThesaurusHandler extends DefaultElementHandler {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
String xpath = thesaurusxpath + "/motcle[motcle-id='" + motcleURI.getMotcleId() + "']/" + tagname;
switch (tagname) {
case "lib":
......@@ -232,7 +230,7 @@ public class ThesaurusHandler extends DefaultElementHandler {
}
@Override
public void endSubElement(XmlPullElementHandler elementHandler) {
public void endSubElement(ElementHandler elementHandler) {
if (elementHandler instanceof LabelElementHandler) {
motcleDataBuilder.addLabel(SctXmlUtils.testLabel(elementHandler));
} else if (elementHandler instanceof AttrHandler) {
......
......@@ -16,9 +16,9 @@ import java.util.Map;
*
* @author Vincent Calame
*/
public abstract class AbstractElementHandler implements XmlPullElementHandler {
public abstract class AbstractElementHandler implements ElementHandler {
private XmlPullElementHandler subElementHandler;
private ElementHandler subElementHandler;
public AbstractElementHandler() {
}
......@@ -63,9 +63,9 @@ public abstract class AbstractElementHandler implements XmlPullElementHandler {
}
}
public abstract XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap);
public abstract ElementHandler startSubElement(String tagname, Map<String, String> attributeMap);
public abstract void endSubElement(XmlPullElementHandler subElementHandler);
public abstract void endSubElement(ElementHandler subElementHandler);
public abstract void endSimpleSubElement(int type, String text);
......
......@@ -22,12 +22,12 @@ public class DefaultElementHandler extends AbstractElementHandler {
}
@Override
public XmlPullElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
public ElementHandler startSubElement(String tagname, Map<String, String> attributeMap) {
return null;
}
@Override
public void endSubElement(XmlPullElementHandler subElementHandler) {
public void endSubElement(ElementHandler subElementHandler) {
}
@Override
......
/* UtilLib - Copyright (c) 2008 Vincent Calame - Exemole
/* UtilLib - Copyright (c) 2008-2018 Vincent Calame - Exemole
* Logiciel libre donné sous triple licence :
* 1) selon les termes de la CeCILL V2
* 2) selon les termes de l’EUPL V.1.1
......@@ -16,7 +16,7 @@ import java.util.Map;
*
* @author Vincent Calame
*/
public interface XmlPullElementHandler {
public interface ElementHandler {
public void processStartElement(String tagname, Map<String, String> attributeMap);
......
......@@ -22,7 +22,7 @@ import net.mapeadores.util.text.LabelUtils;
*
* @author Vincent Calame
*/
public class LabelElementHandler implements XmlPullElementHandler {
public class LabelElementHandler implements ElementHandler {
private final static Lang UNDETERMINED_LANG = Lang.build("und");
private Lang lang;
......@@ -70,11 +70,11 @@ public class LabelElementHandler implements XmlPullElementHandler {
buf.append(text);
}
public XmlPullElementHandler initSubElementHandler(String tagname, Map attributeMap) {
public ElementHandler initSubElementHandler(String tagname, Map attributeMap) {
return null;
}
public void flushSubElementHandler(String tagname, XmlPullElementHandler elementHandler) {
public void flushSubElementHandler(String tagname, ElementHandler elementHandler) {
}
/**
......
......@@ -16,7 +16,7 @@ import java.util.Map;
*
* @author Vincent Calame
*/
public class NullHandler implements XmlPullElementHandler {
public class NullHandler implements ElementHandler {
private int subCount = 0;
......
......@@ -16,7 +16,7 @@ import java.util.Map;
*
* @author Vincent Calame
*/
public class SimpleElementHandler implements XmlPullElementHandler {
public class SimpleElementHandler implements ElementHandler {
private final StringBuilder buf = new StringBuilder();
private final int type;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment