Răsfoiți Sursa

BETA: Changing a bit DocumentParser, now parseFile(File) calls parseDocument(Document), instead of returning the document.
* Narrowed the scope of some method from public to protected.

Zoey76 13 ani în urmă
părinte
comite
f2290df266

+ 1 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/ClassListData.java

@@ -39,11 +39,7 @@ public final class ClassListData extends DocumentParser
 	private ClassListData()
 	{
 		_classData.clear();
-		final Document doc = parseFile(new File(Config.DATAPACK_ROOT, "data/stats/chars/classList.xml"));
-		if (doc != null)
-		{
-			parseDocument(doc);
-		}
+		parseFile(new File(Config.DATAPACK_ROOT, "data/stats/chars/classList.xml"));
 		_log.info(getClass().getSimpleName() + ": Loaded " + _classData.size() + " Class data.");
 	}
 	

+ 1 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/ExperienceTable.java

@@ -39,11 +39,7 @@ public final class ExperienceTable extends DocumentParser
 	private ExperienceTable()
 	{
 		_expTable.clear();
-		final Document doc = parseFile(new File(Config.DATAPACK_ROOT, "data/stats/experience.xml"));
-		if (doc != null)
-		{
-			parseDocument(doc);
-		}
+		parseFile(new File(Config.DATAPACK_ROOT, "data/stats/experience.xml"));
 		_log.info(getClass().getSimpleName() + ": Loaded " + _expTable.size() + " levels.");
 		_log.info(getClass().getSimpleName() + ": Max Player Level is: " + (MAX_LEVEL - 1));
 		_log.info(getClass().getSimpleName() + ": Max Pet Level is: " + (MAX_PET_LEVEL - 1));

+ 1 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/HennaData.java

@@ -44,11 +44,7 @@ public final class HennaData extends DocumentParser
 	private HennaData()
 	{
 		_hennaList.clear();
-		final Document doc = parseFile(new File(Config.DATAPACK_ROOT, "data/stats/hennaList.xml"));
-		if (doc != null)
-		{
-			parseDocument(doc);
-		}
+		parseFile(new File(Config.DATAPACK_ROOT, "data/stats/hennaList.xml"));
 		_log.info(getClass().getSimpleName() + ": Loaded " + _hennaList.size() + " Henna data.");
 	}
 	

+ 1 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/HitConditionBonus.java

@@ -41,11 +41,7 @@ public final class HitConditionBonus extends DocumentParser
 	
 	private HitConditionBonus()
 	{
-		final Document doc = parseFile(new File(Config.DATAPACK_ROOT, "data/stats/hitConditionBonus.xml"));
-		if (doc != null)
-		{
-			parseDocument(doc);
-		}
+		parseFile(new File(Config.DATAPACK_ROOT, "data/stats/hitConditionBonus.xml"));
 		_log.info(getClass().getSimpleName() + ": Loaded Hit Condition bonuses.");
 		if (Config.DEBUG)
 		{

+ 1 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/InitialEquipmentData.java

@@ -44,11 +44,7 @@ public final class InitialEquipmentData extends DocumentParser
 	private InitialEquipmentData()
 	{
 		_initialEquipmentList.clear();
-		final Document doc = parseFile(new File(Config.DATAPACK_ROOT, Config.INITIAL_EQUIPMENT_EVENT ? filePathEvent : filePathNormal));
-		if (doc != null)
-		{
-			parseDocument(doc);
-		}
+		parseFile(new File(Config.DATAPACK_ROOT, Config.INITIAL_EQUIPMENT_EVENT ? filePathEvent : filePathNormal));
 		_log.info(getClass().getSimpleName() + ": Loaded " + _initialEquipmentList.size() + " Initial Equipment data.");
 	}
 	

+ 11 - 16
L2J_Server_BETA/java/com/l2jserver/gameserver/engines/DocumentParser.java

@@ -44,16 +44,16 @@ public abstract class DocumentParser
 	
 	/**
 	 * Parses a single XML file.<br>
+	 * If the file was successfully parsed, call {@link #parseDocument(Document)} for the parsed document.
 	 * Validation is enforced.
 	 * @param f the XML file to parse.
-	 * @return the document with the parsed data.
 	 */
-	public Document parseFile(File f)
+	protected void parseFile(File f)
 	{
 		if (!xmlFilter.accept(f))
 		{
 			_log.warning(getClass().getSimpleName() + ": Could not parse " + f.getName() + " is not a file or it doesn't exist!");
-			return null;
+			return;
 		}
 		
 		final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -71,9 +71,9 @@ public abstract class DocumentParser
 		catch (Exception e)
 		{
 			_log.warning(getClass().getSimpleName() + ": Could not parse " + f.getName() + " file: " + e.getMessage());
-			return null;
+			return;
 		}
-		return doc;
+		parseDocument(doc);
 	}
 	
 	/**
@@ -81,18 +81,17 @@ public abstract class DocumentParser
 	 * @param path the path to the directory where the XML files are.
 	 * @return {@code false} if it fails to find the directory, {@code true} otherwise.
 	 */
-	public boolean parseDirectory(String path)
+	protected boolean parseDirectory(String path)
 	{
 		return parseDirectory(new File(path));
 	}
 	
 	/**
-	 * Loads all XML files from {@code path} and calls {@link #parseFile(File)} for each one of them.<br>
-	 * If the file was successfully parsed, call {@link #parseDocument(Document)} for the parsed document.
+	 * Loads all XML files from {@code path} and calls {@link #parseFile(File)} for each one of them.
 	 * @param dir the directory object to scan.
 	 * @return {@code false} if it fails to find the directory, {@code true} otherwise.
 	 */
-	public boolean parseDirectory(File dir)
+	protected boolean parseDirectory(File dir)
 	{
 		if (!dir.exists())
 		{
@@ -103,18 +102,14 @@ public abstract class DocumentParser
 		final File[] listOfFiles = dir.listFiles(xmlFilter);
 		for (File f : listOfFiles)
 		{
-			final Document doc = parseFile(f);
-			if (doc != null)
-			{
-				parseDocument(doc);
-			}
+			parseFile(f);
 		}
 		return true;
 	}
 	
 	/**
 	 * Abstract method that when implemented will parse a document.<br>
-	 * Is expected to be used along with {@link #parseFile(File)}.
+	 * Is expected to be call from {@link #parseFile(File)}.
 	 * @param doc the document to parse.
 	 */
 	protected abstract void parseDocument(Document doc);
@@ -171,7 +166,7 @@ public abstract class DocumentParser
 	 * Simple XML error handler.
 	 * @author Zoey76
 	 */
-	public class XMLErrorHandler implements ErrorHandler
+	protected class XMLErrorHandler implements ErrorHandler
 	{
 		@Override
 		public void warning(SAXParseException e) throws SAXParseException