Jump to content
  • 0

Convert IXMLReader code to XMLDocument


N0K3

Question

Hello friends, I'm converting a code made in IXMLReader to XMLDocument because my entire source uses XMLDocument, I'm halfway through but I'm getting error with forEach and I would like to ask for help from you friends, I'll put the code without any changes of mine and with change Anyone who can help is grateful.

No change:

package net.sf.l2j.gameserver.data.xml;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import net.sf.l2j.commons.data.xml.IXmlReader;

import net.sf.l2j.gameserver.model.event.BossEvent;
import net.sf.l2j.gameserver.templates.StatsSet;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;

/**
 * @author StinkyMadness
 */
public class BossEventData implements IXmlReader
{
   private static final List<StatsSet> data = new ArrayList<>();
  
   protected BossEventData()
   {
       load();
   }
  
   @Override
   public void load()
   {
       parseFile("./data/xml/BossEvent.xml");
   }
  
   @Override
   public void parseDocument(Document doc, Path path)
   {
      
       forEach(doc, "list", listNode -> forEach(listNode, "Boss", bossNode ->
       {
           final StatsSet set = parseAttributes(bossNode);
           forEach(bossNode, "announce", messageNode -> set.set("announceOnSpawn", parseString(messageNode.getAttributes(), "onSpawn")));
           forEach(bossNode, "spawnLoc", positionNode ->
           {
               final NamedNodeMap attrs = positionNode.getAttributes();
               set.set("posX", parseInteger(attrs, "x"));
               set.set("posY", parseInteger(attrs, "y"));
               set.set("posZ", parseInteger(attrs, "z"));
           });
           forEach(bossNode, "despawn", messageNode -> set.set("despawnTime", parseInteger(messageNode.getAttributes(), "after")));
           forEach(bossNode, "scheduleSpawnTime", spawnTimeNode -> set.set("spawnDateData", parseString(spawnTimeNode.getAttributes(), "val")));
           data.add(set);
       }));
      
       data.forEach(BossEvent::new);
   }
  
   public static BossEventData getInstance()
   {
       return SingletonHolder.INSTANCE;
   }
  
   private static class SingletonHolder
   {
       protected static final BossEventData INSTANCE = new BossEventData();
   }
}

With change:

package net.sf.l2j.gameserver.data.xml;

import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import net.sf.l2j.commons.data.xml.XMLDocument;

import net.sf.l2j.gameserver.events.BossEvent;
import net.sf.l2j.gameserver.templates.StatsSet;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;

/**
 * @author StinkyMadness
 */
public class BossEventData extends XMLDocument
{
   private static final List<StatsSet> data = new ArrayList<>();
  
   protected BossEventData()
   {
       load();
   }
  
   @Override
   public void load()
   {
	   loadDocument("./data/xml/BossEvent.xml");
   }
  
   public void parseDocument(Document doc, Path path)
   {
      
       forEach(doc, "list", listNode -> forEach(listNode, "Boss", bossNode ->
       {
           final StatsSet set = parseAttributes(bossNode);
           forEach(bossNode, "announce", messageNode -> set.set("announceOnSpawn", parseString(messageNode.getAttributes(), "onSpawn")));
           forEach(bossNode, "spawnLoc", positionNode ->
           {
               final NamedNodeMap attrs = positionNode.getAttributes();
               set.set("posX", parseInteger(attrs, "x"));
               set.set("posY", parseInteger(attrs, "y"));
               set.set("posZ", parseInteger(attrs, "z"));
           });
           forEach(bossNode, "despawn", messageNode -> set.set("despawnTime", parseInteger(messageNode.getAttributes(), "after")));
           forEach(bossNode, "scheduleSpawnTime", spawnTimeNode -> set.set("spawnDateData", parseString(spawnTimeNode.getAttributes(), "val")));
           data.add(set);
       }));
      
       data.forEach(BossEvent::new);
   }
  
   public static BossEventData getInstance()
   {
       return SingletonHolder.INSTANCE;
   }
  
   private static class SingletonHolder
   {
       protected static final BossEventData INSTANCE = new BossEventData();
   }

/* (non-Javadoc)
 * @see net.sf.l2j.commons.data.xml.XMLDocument#parseDocument(org.w3c.dom.Document, java.io.File)
 */
@Override
protected void parseDocument(Document doc, File f)
{
	// TODO Auto-generated method stub
	
}
}

Errors after change:

[javac] Compiling 1858 source files to C:\workspace\L2jMega_gameserver2\build\classes
    [javac] C:\workspace\L2jMega_gameserver2\java\net\sf\l2j\gameserver\data\xml\BossEventData.java:37: error: cannot find symbol
    [javac]        forEach(doc, "list", listNode -> forEach(listNode, "Boss", bossNode ->
    [javac]        ^
    [javac]   symbol:   method forEach(Document,String,(listNode)[...]); }))
    [javac]   location: class BossEventData
    [javac] C:\workspace\L2jMega_gameserver2\java\net\sf\l2j\gameserver\data\xml\BossEventData.java:44: error: cannot find symbol
    [javac]                set.set("posX", parseInteger(attrs, "x"));
    [javac]                                ^
    [javac]   symbol:   method parseInteger(NamedNodeMap,String)
    [javac]   location: class BossEventData
    [javac] C:\workspace\L2jMega_gameserver2\java\net\sf\l2j\gameserver\data\xml\BossEventData.java:45: error: cannot find symbol
    [javac]                set.set("posY", parseInteger(attrs, "y"));
    [javac]                                ^
    [javac]   symbol:   method parseInteger(NamedNodeMap,String)
    [javac]   location: class BossEventData
    [javac] C:\workspace\L2jMega_gameserver2\java\net\sf\l2j\gameserver\data\xml\BossEventData.java:46: error: cannot find symbol
    [javac]                set.set("posZ", parseInteger(attrs, "z"));
    [javac]                                ^
    [javac]   symbol:   method parseInteger(NamedNodeMap,String)
    [javac]   location: class BossEventData
    [javac] 4 errors

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

on acis changeset 377 XMLDocument has been replaced by the IXMLReader interface , so it means you can get it by beign a customer . dont expect ppl to help you ... pay 10E and get all the updates , it will help you since you will have access to DL all the possible changesets of the current circle ..

 

@Kara` he dont mean .forEach , he means the method forEach of the interface IXMLReader

default void forEach(..., ..., ...)

 

Edited by melron
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock