Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 7th, 2010 | Syntax: Java | Size: 5.09 KB | Hits: 143 | Expires: Never
Copy text to clipboard
  1. package net.nova.habbo.catalog;
  2.  
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.util.Vector;
  6.  
  7. import net.nova.core.NovaEnvironment;
  8. import net.nova.habbo.message.ISerializableObject;
  9. import net.nova.habbo.message.ServerMessage;
  10. import net.verticode.hailstorm.storage.StorageQuery;
  11.  
  12. public class CatalogPage implements ISerializableObject {
  13.  
  14.         private int mID, mParent, mTree;
  15.         private boolean mVisible, mComingSoon;
  16.         private int mIconColor, mIconImage;
  17.         private String mName, mLayout;
  18.         private Vector<CatalogHeader> mHeaders;
  19.         private Vector<CatalogWidget> mWidgets;
  20.         private int mCatagorie;
  21.        
  22.         public CatalogPage(int ID, int Parent, int Tree, int Visible, int ComingSoon, String Name, int IconColor, int IconImage, String Layout, int Catagorie)
  23.         {
  24.                 if (Catagorie == 1)
  25.                         ID = -1;
  26.                
  27.                 mCatagorie = Catagorie;
  28.                
  29.                 mID = ID;
  30.                 mParent = Parent;
  31.                 mTree = Tree;
  32.                 mVisible = (Visible == 1);
  33.                 mComingSoon = (ComingSoon == 1);
  34.                 mName = Name;
  35.                 mIconColor = IconColor;
  36.                 mIconImage = IconImage;
  37.                 mLayout = Layout;
  38.                
  39.                 mHeaders = new Vector<CatalogHeader>();
  40.                
  41.                 StorageQuery Query = new StorageQuery("SELECT * FROM catalog_headers WHERE page = ? ORDER BY sort ASC;");
  42.                 Query.addParam(mID);
  43.                
  44.                 ResultSet Result = Query.getResult();
  45.                
  46.                 try
  47.                 {
  48.                         while (Result.next())
  49.                         {
  50.                                 mHeaders.add(new CatalogHeader(Result.getInt("type"), Result.getString("object")));
  51.                         }
  52.                 }
  53.                 catch (SQLException e)
  54.                 {
  55.                         NovaEnvironment.GetLog().WriteError(e.getMessage());
  56.                 }
  57.                
  58.                 mWidgets = new Vector<CatalogWidget>();
  59.                 Query = new StorageQuery("SELECT * FROM catalog_widgets WHERE page = ? ORDER BY sort ASC;");
  60.                 Query.addParam(mID);
  61.                
  62.                 Result = Query.getResult();
  63.                
  64.                 try
  65.                 {
  66.                         while (Result.next())
  67.                         {
  68.                                 mWidgets.add(new CatalogWidget(Result.getInt("type"), Result.getString("content")));
  69.                         }
  70.                 }
  71.                 catch (SQLException e)
  72.                 {
  73.                         NovaEnvironment.GetLog().WriteError(e.getMessage());
  74.                 }
  75.                
  76.         }
  77.  
  78.         @Override
  79.         public void Serialize(ServerMessage message)
  80.         {
  81.                 message.AppendInt(mID);
  82.                 message.AppendString(mLayout);
  83.                
  84.                 //message.AppendInt(mHeaders.size());
  85.                
  86.                 for (CatalogHeader Header : mHeaders)
  87.                         message.AppendObject(Header);
  88.                
  89.                 message.AppendInt(mWidgets.size());
  90.                
  91.                 for (CatalogWidget Widget : mWidgets)
  92.                         message.AppendObject(Widget);
  93.                
  94.                 message.AppendInt(0); //TODO ITEM COUNT
  95.         }
  96.        
  97.         class CatalogHeader implements ISerializableObject
  98.         {
  99.                 private String mHeader;
  100.                 private int mType;
  101.                
  102.                 public CatalogHeader(int Type, String Header)
  103.                 {
  104.                         mType = Type;
  105.                         mHeader = Header;
  106.                 }
  107.  
  108.                 @Override
  109.                 public void Serialize(ServerMessage message)
  110.                 {
  111.                         switch(mType)
  112.                         {
  113.                                 case 0:
  114.                                         message.AppendString(mHeader);
  115.                                         break;
  116.                                 case 1:
  117.                                         message.AppendInt(Integer.parseInt(mHeader));
  118.                                         break;
  119.                         }                      
  120.                 }
  121.         }
  122.        
  123.         class CatalogWidget implements ISerializableObject
  124.         {
  125.                 private int mType;
  126.                 private String mContent;
  127.                
  128.                 public CatalogWidget(int type, String content)
  129.                 {
  130.                         mType = type;
  131.                         mContent = content;
  132.                 }
  133.  
  134.                 @Override
  135.                 public void Serialize(ServerMessage message)
  136.                 {
  137.                         switch(mType)
  138.                         {
  139.                                 case 0:
  140.                                         message.AppendString(mContent);
  141.                                         break;
  142.                                 case 1:
  143.                                         message.AppendInt(Integer.parseInt(mContent));
  144.                                         break;
  145.                         }
  146.                 }
  147.         }
  148.        
  149.         /**
  150.          * @param mID the mID to set
  151.          */
  152.         public void setID(int mID) {
  153.                 this.mID = mID;
  154.         }
  155.  
  156.         /**
  157.          * @return the mID
  158.          */
  159.         public int getID() {
  160.                 return mID;
  161.         }
  162.  
  163.         /**
  164.          * @param mParent the mParent to set
  165.          */
  166.         public void setParent(int mParent) {
  167.                 this.mParent = mParent;
  168.         }
  169.  
  170.         /**
  171.          * @return the mParent
  172.          */
  173.         public int getParent() {
  174.                 return mParent;
  175.         }
  176.  
  177.         /**
  178.          * @param mTree the mTree to set
  179.          */
  180.         public void setTree(int mTree) {
  181.                 this.mTree = mTree;
  182.         }
  183.  
  184.         /**
  185.          * @return the mTree
  186.          */
  187.         public int getTree() {
  188.                 return mTree;
  189.         }
  190.  
  191.         /**
  192.          * @param mVisible the mVisible to set
  193.          */
  194.         public void setVisible(boolean mVisible) {
  195.                 this.mVisible = mVisible;
  196.         }
  197.  
  198.         /**
  199.          * @return the mVisible
  200.          */
  201.         public boolean isVisible() {
  202.                 return mVisible;
  203.         }
  204.  
  205.         /**
  206.          * @param mComingSoon the mComingSoon to set
  207.          */
  208.         public void setComingSoon(boolean mComingSoon) {
  209.                 this.mComingSoon = mComingSoon;
  210.         }
  211.  
  212.         /**
  213.          * @return the mComingSoon
  214.          */
  215.         public boolean isComingSoon() {
  216.                 return mComingSoon;
  217.         }
  218.  
  219.         /**
  220.          * @param mIconColor the mIconColor to set
  221.          */
  222.         public void setIconColor(byte mIconColor) {
  223.                 this.mIconColor = mIconColor;
  224.         }
  225.  
  226.         /**
  227.          * @return the mIconColor
  228.          */
  229.         public int getIconColor() {
  230.                 return mIconColor;
  231.         }
  232.  
  233.         /**
  234.          * @param mIconImage the mIconImage to set
  235.          */
  236.         public void setIconImage(byte mIconImage) {
  237.                 this.mIconImage = mIconImage;
  238.         }
  239.  
  240.         /**
  241.          * @return the mIconImage
  242.          */
  243.         public int getIconImage() {
  244.                 return mIconImage;
  245.         }
  246.  
  247.         /**
  248.          * @param mName the mName to set
  249.          */
  250.         public void setName(String mName) {
  251.                 this.mName = mName;
  252.         }
  253.  
  254.         /**
  255.          * @return the mName
  256.          */
  257.         public String getName() {
  258.                 return mName;
  259.         }
  260.  
  261.         public boolean isCatagorie() {
  262.                 return (mCatagorie == 1);
  263.         }
  264.        
  265. }