// Copyright (C) 1999-2006 InetSoft Technology Corp

/**
 * RepositoryEntry is the super class for all the entries.
 *
 * @version 8.5
 * @author InetSoft Technology Corp
 * @depend util.js
 */
RepositoryEntry = function(path, type, owner) {
   this._class = "inetsoft.sree.RepositoryEntry";
   this._extend("isii_Object");
   var _this = this._this;
   _this.path = path;
   _this.type = type;
   _this.owner = owner;
   _this.label = null;

   this.isRoot = isRootFunction;
   this.isRoot._class = this._class;

   function isRootFunction() {
      return _this.path == "/";
   }

   this.supportsOperation = supportsOperationFunction;
   this.supportsOperation._class = this._class;

   function supportsOperationFunction(operation) {
      return false;
   }

   this.getName = getNameFunction;
   this.getName._class = this._class;

   function getNameFunction() {
      if(_this.isRoot()) {
         return "";
      }

      var index = _this.path.lastIndexOf("/");
      return index >= 0 ? _this.path.substring(index + 1) : _this.path;
   }

   this.getLabel = getLabelFunction;
   this.getLabel._class = this._class;

   function getLabelFunction() {
      return _this.label;
   }

   this.getParent = getParentFunction;
   this.getParent._class = this._class;

   function getParentFunction() {
      var ppath = _this.getParentPath();
      return ppath == null ? null : new DefaultFolderEntry(ppath, owner);
   }

   this.getParentPath = getParentPathFunction;
   this.getParentPath._class = this._class;

   function getParentPathFunction() {
      if(_this.isRoot()) {
         return null;
      }

      var index = _this.path.lastIndexOf("/");
      return index >= 0 ? _this.path.substring(0, index) : "/";
   }

   this.getType = getTypeFunction;
   this.getType._class = this._class;

   function getTypeFunction() {
      return _this.type;
   }

   this.isFolder = isFolderFunction;
   this.isFolder._class = this._class;

   function isFolderFunction() {
      return (_this.type & RepositoryEntry.FOLDER) == RepositoryEntry.FOLDER;
   }

   this.getPath = getPathFunction;
   this.getPath._class = this._class;

   function getPathFunction() {
      return _this.path;
   }

   this.getOwner = getOwnerFunction;
   this.getOwner._class = this._class;

   function getOwnerFunction() {
      return _this.owner;
   }

   this.isMyReport = isMyReportFunction;
   this.isMyReport._class = this._class;

   function isMyReportFunction() {
      return _this.getOwner() != null || _this.getPath() == "My Reports";
   }

   this.isReplet = isRepletFunction;
   this.isReplet._class = this._class;

   function isRepletFunction() {
      return (_this.type & RepositoryEntry.REPLET) == RepositoryEntry.REPLET;
   }

   this.isArchive = isArchiveFunction;
   this.isArchive._class = this._class;

   function isArchiveFunction() {
      return (_this.type & RepositoryEntry.ARCHIVE) == RepositoryEntry.ARCHIVE;
   }

   this.isViewsheet = isViewsheetFunction;
   this.isViewsheet._class = this._class;

   function isViewsheetFunction() {
      return (_this.type & RepositoryEntry.VIEWSHEET) ==
         RepositoryEntry.VIEWSHEET;
   }

   this.toString = toStringFunction;
   this.toString._class = this._class;

   function toStringFunction() {
      return _this.getPath();
   }

   /**
    * Write the xml segment.
    * @public
    */
   this.writeXML = writeXMLFunction;
   this.writeXML._class = this._class;

   function writeXMLFunction() {
      var str = "<entry" + _this.writeAttributes() + ">";
      str += _this.writeContents();
      str += "</entry>";

      return str;
   }

   /**
    * Method to parse an xml segment.
    * @public
    */
   this.parseXML = parseXMLFunction;
   this.parseXML._class = this._class;

   function parseXMLFunction(elem) {
      _this.parseAttributes(elem);
      _this.parseContents(elem);
   }

   /**
    * Write attributes.
    * @public
    */
   this.writeAttributes = writeAttributesFunction;
   this.writeAttributes._class = this._class;

   function writeAttributesFunction() {
      var str = "";
      str += " class=\"" + _this._class + "\"";

      if(_this.type) {
         str += " type=\"" + _this.type + "\"";
      }

      return str;
   }

   /**
    * Method to parse attributes.
    * @public
    */
   this.parseAttributes = parseAttributesFunction;
   this.parseAttributes._class = this._class;

   function parseAttributesFunction(elem) {
      try {
         if(elem.getAttribute("type")) {
            _this.type = parseInt(elem.getAttribute("type"));
         }
      }
      catch(e) {
      }
   }

   /**
    * Write contents.
    * @public
    */
   this.writeContents = writeContentsFunction;
   this.writeContents._class = this._class;

   function writeContentsFunction() {
      var str = "";

      if(_this.path) {
         str += _this.writeCDATA("path", byteEncode(_this.path));
      }

      if(_this.owner) {
         str += _this.writeCDATA("owner", byteEncode(_this.owner));
      }

      return str;
   }

   /**
    * Method to parse contents.
    * @public
    */
   this.parseContents = parseContentsFunction;
   this.parseContents._class = this._class;

   function parseContentsFunction(elem) {
      var vnode = Tool.getChildNodeByTagName(elem, "path");

      if(vnode) {
         _this.path = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }

      vnode = Tool.getChildNodeByTagName(elem, "owner");

      if(vnode) {
         _this.owner = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }

      vnode = Tool.getChildNodeByTagName(elem, "label");

      if(vnode) {
         _this.label = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }
   }

   this.equals = equalsFunction;
   this.equals._class = this._class;

   function equalsFunction(entry) {
      var result = entry.path == _this.path;

      if(result && entry.type != null && _this.type != null)  {
         result = (entry.type == _this.type);
      }

      if(result && entry.version && entry.version != null &&
         _this.version && _this.version != null)
      {
         result = entry.version == _this.version;
      }

      if(entry.getOwner() && _this.getOwner()) {
         result = result && entry.getOwner() == _this.getOwner();
      }

      return result;
   }

   this.writeCDATA = writeCDATAFunction;
   this.writeCDATA._class = this._class;

   function writeCDATAFunction(name, value) {
      return "<" + name + "><![CDATA[" + value + "]]></" + name + ">";
   }
}

RepositoryEntry.FOLDER = 0x01;
RepositoryEntry.REPLET = 0x02;
RepositoryEntry.ARCHIVE = 0x04;
RepositoryEntry.COMPOSITE_ARCHIVE = 0x0C;
RepositoryEntry.TRASHCAN = 0x10;
RepositoryEntry.FILE = 0x20;
RepositoryEntry.VIEWSHEET = 0x40;
RepositoryEntry.ALL = RepositoryEntry.FOLDER | RepositoryEntry.REPLET |
                      RepositoryEntry.ARCHIVE |
                      RepositoryEntry.COMPOSITE_ARCHIVE |
                      RepositoryEntry.TRASHCAN | RepositoryEntry.FILE |
                      RepositoryEntry.VIEWSHEET;
RepositoryEntry.RENAME_OPERATION = 1;
RepositoryEntry.CHANGE_FOLDER_OPERATION = 2;
RepositoryEntry.REMOVE_OPERATION = 3;
RepositoryEntry.CREATE_FOLDER_OPERATION = 4;
RepositoryEntry.REPOSITORY_FOLDER = "Repository";
RepositoryEntry.PROTOTYPE_FOLDER = "Prototype";
RepositoryEntry.TRASHCAN_FOLDER = "Trashcan";
RepositoryEntry.USER_REPORT_FOLDER = "'s Reports";
RepositoryEntry.USERS_FOLDER = "Users' Reports";

RepositoryEntry.createEntry = function(elem) {
   var cls = elem.getAttribute("class");
   var object = null;

   if(cls == "inetsoft.sree.DefaultFolderEntry") {
      object = new DefaultFolderEntry();
   }
   else if(cls == "inetsoft.sree.CompositeArchiveEntry") {
      object = new CompositeArchiveEntry();
   }
   else if(cls == "inetsoft.sree.TrashcanEntry") {
      object = new TrashcanEntry();
   }
   else if(cls == "inetsoft.sree.ArchiveEntry") {
      object = new ArchiveEntry();
   }
   else if(cls == "inetsoft.sree.RepletEntry") {
      object = new RepletEntry();
   }
   else if(cls == "inetsoft.sree.ViewsheetEntry") {
      object = new ViewsheetEntry();
   }
   else if(cls == "inetsoft.sree.RepletFolderEntry") {
      object = new RepletFolderEntry();
   }

   if(object != null) {
   	/*
   	  try {
	      object.parseXML(elem);
	    }
	    catch(ex) {
	    	//alert("s" + ex + elem + "|" + cls);
	    }
	  */
	  object.parseXML(elem);
   }
   else {
      alert("Invalid entry type found.");
   }

   return object;
}

DefaultFolderEntry = function(path, owner) {
   this._class = "inetsoft.sree.DefaultFolderEntry";
   this._extend("RepositoryEntry", path, RepositoryEntry.FOLDER, owner);

   this.desc = null;
   this.alias = null;
   this.alabel = null;
   var _this = this._this;

   this.setDescription = setDescriptionFunction;
   this.setDescription._class = this._classl

   function setDescriptionFunction(desc) {
      _this.desc = desc;
   }

   this.getDescription = getDescriptionFunction;
   this.getDescription._class = this._class;

   function getDescriptionFunction() {
      return _this.desc;
   }

   this.setAlias = setAliasFunction;
   this.setAlias._class = this._classl

   function setAliasFunction(alias) {
      _this.alias = alias;
   }

   this.getAlias = getAliasFunction;
   this.getAlias._class = this._class;

   function getAliasFunction() {
      return _this.alias;
   }

   this.getAlabel = getAlabelFunction;
   this.getAlabel._class = this._class;

   function getAlabelFunction() {
      return _this.alabel;
   }

   /**
    * Write contents.
    * @public
    */
   this.writeContents = writeContentsFunction;
   this.writeContents._class = this._class;

   function writeContentsFunction() {
      var str = this._super.writeContents();

      if(_this.desc) {
         str += this._super.writeCDATA("desc", byteEncode(_this.desc));
      }

      if(_this.alias) {
         str += this._super.writeCDATA("alias", byteEncode(_this.alias));
      }

      return str;
   }

   /**
    * Method to parse contents.
    * @public
    */
   this.parseContents = parseContentsFunction;
   this.parseContents._class = this._class;

   function parseContentsFunction(elem) {
      this._super.parseContents(elem);

      var vnode = Tool.getChildNodeByTagName(elem, "desc");

      if(vnode) {
         _this.desc = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }

      vnode = Tool.getChildNodeByTagName(elem, "alias");

      if(vnode) {
         _this.alias = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }

      vnode = Tool.getChildNodeByTagName(elem, "alabel");

      if(vnode) {
         _this.alabel = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }
   }
}

CompositeArchiveEntry = function(path, owner) {
   this._class = "inetsoft.sree.CompositeArchiveEntry";
   this._extend("ArchiveEntry", path, RepositoryEntry.COMPOSITE_ARCHIVE, owner);
   this.entries = new Array(0);

   var _this = this._this;

   this.supportsOperation = supportsOperationFunction;
   this.supportsOperation._class = this._class;

   function supportsOperationFunction(operation) {
      if(operation == RepositoryEntry.RENAME_OPERATION) {
         return true;
      }
      else if(operation == RepositoryEntry.CHANGE_FOLDER_OPERATION) {
         return true;
      }
      else if(operation == RepositoryEntry.REMOVE_OPERATION) {
         return true;
      }
      else {
         return false;
      }
   }

   this.setVersionedArchive = setVersionedArchiveFunction;
   this.setVersionedArchive._class = this._class;

   function setVersionedArchiveFunction(versioned) {
      alert(_this._class + " Unsupported method is called!");
      return;
   }

   this.isVersionedArchive = isVersionedArchiveFunction;
   this.isVersionedArchive._class = this._class;

   function isVersionedArchiveFunction() {
      return true;
   }

   this.setArchiveEntries = setArchiveEntriesFunction;
   this.setArchiveEntries._class = this._class;

   function setArchiveEntriesFunction(entries) {
      if(entries == null || entries.length == 0) {
         alert("Invalid entry array found!");
         return;
      }

      for(var i = 0; i < entries.length; i++) {
         if(_this.getPath() != entries[i].getPath()) {
            alert("Path should be the same!");
            return;
         }

         if(!entries[i].isVersionedArchive()) {
            alert("Sub entry should be versioned!");
            return;
         }
      }

      _this.entries = entries;
   }

   this.getArchiveEntries = getArchiveEntriesFunction;
   this.getArchiveEntries._class = this._class;

   function getArchiveEntriesFunction() {
      return _this.entries;
   }

   this.isCompositeArchive = isCompositeArchiveFunction;
   this.isCompositeArchive._class = this._class;

   function isCompositeArchiveFunction() {
      return true;
   }

   this.getFileType = getFileTypeFunction;
   this.getFileType._class = this._class;

   function getFileTypeFunction() {
      if(_this.entries == null || _this.entries.length == 0) {
         return null;
      }

      return _this.entries[0].getFileType();
   }

   this.isFolder = isFolderFunction;
   this.isFolder._class = this._class;

   function isFolderFunction() {
      return true;
   }

   /**
    * Write attributes.
    * @public
    */
   this.writeAttributes = writeAttributesFunction;
   this.writeAttributes._class = this._class;

   function writeAttributesFunction() {
      return this._super.writeAttributes();
   }

   /**
    * Method to parse attributes.
    * @public
    */
   this.parseAttributes = parseAttributesFunction;
   this.parseAttributes._class = this._class;

   function parseAttributesFunction(elem) {
      try {
         this._super.parseAttributes(elem);
      }
      catch(e) {
      }
   }

   /**
    * Write contents.
    * @public
    */
   this.writeContents = writeContentsFunction;
   this.writeContents._class = this._class;

   function writeContentsFunction() {
      var str = this._super.writeContents();

      if(_this.entries && _this.entries.length > 0) {
         str += "<entries>";

         for(var i = 0; i < _this.entries.length; i++) {
            str += _this.entries[i].writeXML();
         }

         str += "</entries>";
      }

      return str;
   }

   /**
    * Method to parse contents.
    * @public
    */
   this.parseContents = parseContentsFunction;
   this.parseContents._class = this._class;

   function parseContentsFunction(elem) {
      this._super.parseContents(elem);

      var node = Tool.getChildNodeByTagName(elem, "entries");

      if(!node) {
         return;
      }

      var nodes = Tool.getChildNodesByTagName(node, "entry");
      _this.entries = new Array(nodes.length);

      for(var i = 0; i < _this.entries.length; i++) {
         _this.entries[i] = new ArchiveEntry(
            _this.getPath(), _this.getOwner());
         _this.entries[i].parseXML(nodes[i]);
      }
   }
}

TrashcanEntry = function(path, owner) {
   this._class = "inetsoft.sree.TrashcanEntry";
   this._extend("RepositoryEntry", path, RepositoryEntry.TRASHCAN, owner);
   this.folder = false;
   this.archiveEntry = null;
   var _this = this._this;

   this.getName = getNameFunction;
   this.getName._class = this._class;

   function getNameFunction() {
      var path = this._this.path;
      var index = path.indexOf(RepositoryEntry.TRASHCAN_FOLDER);
      return index == 0 ?
         path.substring(RepositoryEntry.TRASHCAN_FOLDER.length + 1) : path;
   }

   this.supportsOperation = supportsOperationFunction;
   this.supportsOperation._class = this._class;

   function supportsOperationFunction(operation) {
      if(operation == RepositoryEntry.REMOVE_OPERATION) {
         return true;
      }

      return false;
   }

   this.getParent = getParentFunction;
   this.getParent._class = this._class;

   function getParentFunction() {
      return new DefaultFolderEntry(RepositoryEntry.TRASHCAN_FOLDER,
         _this.getOwner());
   }

   this.getParentPath = getParentPathFunction;
   this.getParentPath._class = this._class;

   function getParentPathFunction() {
      return RepositoryEntry.TRASHCAN_FOLDER;
   }

   this.getArchiveEntry = getArchiveEntryFunction;
   this.getArchiveEntry._class = this._class;

   function getArchiveEntryFunction() {
      return _this.archiveEntry;
   }

   this.setArchiveEntry = setArchiveEntryFunction;
   this.setArchiveEntry._class = this._class;

   function setArchiveEntryFunction(archiveEntry) {
      _this.archiveEntry = archiveEntry;
   }

   this.isFolder = isFolderFunction;
   this.isFolder._class = this._class;

   function isFolderFunction() {
      return _this.folder;
   }

   this.setFolder = setFolderFunction;
   this.setFolder._class = this._class;

   function setFolderFunction(folder) {
      _this.folder = folder;
   }

   /**
    * Write attributes.
    * @public
    */
   this.writeAttributes = writeAttributesFunction;
   this.writeAttributes._class = this._class;

   function writeAttributesFunction() {
      var str = this._super.writeAttributes();
      str += " isFolder=\"" + _this.folder + "\"";

      return str;
   }

   /**
    * Method to parse attributes.
    * @public
    */
   this.parseAttributes = parseAttributesFunction;
   this.parseAttributes._class = this._class;

   function parseAttributesFunction(elem) {
      try {
         this._super.parseAttributes(elem);
         _this.folder = ("true" == elem.getAttribute("isFolder"));
      }
      catch(e) {
      }
   }

   this.writeContents = writeContentsFunction;
   this.writeContents._class = this._class;

   function writeContentsFunction() {
      var str = this._super.writeContents();

      if(_this.archiveEntry) {
         str += "<archiveEntry>" + _this.archiveEntry.writeXML() +
            "</archiveEntry>";
      }

      return str;
   }

   this.parseContents = parseContentsFunction;
   this.parseContents._class = this._class;

   function parseContentsFunction(elem) {
      this._super.parseContents(elem);
      var node = Tool.getChildNodeByTagName(elem, "archiveEntry");
      node = Tool.getChildNodeByTagName(node, "entry");

      if(!_this.archiveEntry) {
         _this.archiveEntry = new ArchiveEntry();
      }

      if(node) {
         _this.archiveEntry.parseXML(node);
      }
   }
}

ArchiveEntry = function(path, type, owner) {
   this._class = "inetsoft.sree.ArchiveEntry";
   var clsType = type ? type : RepositoryEntry.ARCHIVE;
   this._extend("RepositoryEntry", path, clsType, owner);
   this.version = null;
   this.versioned = false;
   this.date = null;
   this.comment = null;
   this.ftype = null;
   this.dateTimeFormat = null;
   var _this = this._this;

   this.getDateTimeFormat = getdateTimeFormatFunction;
   this.getDateTimeFormat._class = this._class;

   function getdateTimeFormatFunction() {
      return _this.dateTimeFormat;
   }
   
   this.setDateTimeFormat = setDateTimeFormatFunction;
   this.setDateTimeFormat._class = this._class;
   
   function setDateTimeFormatFunction(dateTimeFormat) {
      _this.dateTimeFormat = dateTimeFormat;
   }

   this.supportsOperation = supportsOperationFunction;
   this.supportsOperation._class = this._class;

   function supportsOperationFunction(operation) {
      if(operation == RepositoryEntry.RENAME_OPERATION) {
         return !_this.versioned;
      }
      else if(operation == RepositoryEntry.CHANGE_FOLDER_OPERATION) {
         return !_this.versioned;
      }
      else if(operation == RepositoryEntry.REMOVE_OPERATION) {
         return true;
      }
      else {
         return false;
      }
   }

   this.setVersionedArchive = setVersionedArchiveFunction;
   this.setVersionedArchive._class = this._class;

   function setVersionedArchiveFunction(versioned) {
      _this.versioned = versioned;
   }

   this.isVersionedArchive = isVersionedArchiveFunction;
   this.isVersionedArchive._class = this._class;

   function isVersionedArchiveFunction() {
      return _this.versioned;
   }

   this.getVersion = getVersionFunction;
   this.getVersion._class = this._class;

   function getVersionFunction() {
      return _this.version;
   }

   this.setVersion = setVersionFunction;
   this.setVersion._class = this._class;

   function setVersionFunction(version) {
      _this.version = version;
   }

   this.setDate = setDateFunction;
   this.setDate._class = this._class;

   function setDateFunction(date) {
      _this.date = date;
   }

   this.getDate = getDateFunction;
   this.getDate._class = this._class;

   function getDateFunction() {
      return _this.date;
   }

   this.setComment = setCommentFunction;
   this.setComment._class = this._class;

   function setCommentFunction(comment) {
      _this.comment = comment;
   }

   this.getComment = getCommentFunction;
   this.getComment._class = this._class;

   function getCommentFunction() {
      return _this.comment;
   }

   this.setFileType = setFileTypeFunction;
   this.setFileType._class = this._class;

   function setFileTypeFunction(ftype) {
      _this.ftype = ftype;
   }

   this.getFileType = getFileTypeFunction;
   this.getFileType._class = this._class;

   function getFileTypeFunction() {
      return _this.ftype != null ? _this.ftype : _this.getSuffix();
   }

   this.getSuffix = getSuffixFunction;
   this.getSuffix._class = this._class;

   function getSuffixFunction() {
      var name = _this.getName();
      var idx = name.lastIndexOf(".");
      return idx < 0 ? name : name.substring(idx + 1);
   }

   this.getPrefix = getPrefixFunction;
   this.getPrefix._class = this._class;

   function getPrefixFunction() {
      var name = _this.getName();
      var idx = name.lastIndexOf(".");
      return idx < 0 ? name : name.substring(0, idx);
   }

   this.isCompositeArchive = isCompositeArchiveFunction;
   this.isCompositeArchive._class = this._class;

   function isCompositeArchiveFunction() {
      return false;
   }

   this.getParent = getParentFunction;
   this.getParent._class = this._class;

   function getParentFunction() {
      if(_this.versioned && !_this.isCompositeArchive()) {
         var centry = new CompositeArchiveEntry(_this.getPath());
         var entries = new Array(_this);
         centry.setArchiveEntries(entries);
         return centry;
      }

      return this._super.getParent();
   }

   this.writeAttributes = writeAttributesFunction;
   this.writeAttributes._class = this._class;

   function writeAttributesFunction() {
      var str = this._super.writeAttributes();

      str += " isVersioned=\"" + _this.versioned + "\"";

      if(_this.date) {
         str += " date=\"" + _this.date.getTime() + "\"";
      }

      if(_this.ftype) {
         str += " ftype=\"" + _this.ftype + "\"";
      }

      return str;
   }

   this.parseAttributes = parseAttributesFunction;
   this.parseAttributes._class = this._class;

   function parseAttributesFunction(elem) {
      this._super.parseAttributes(elem);
      _this.versioned = elem.getAttribute("isVersioned") == "true";

      try {
         if(elem.getAttribute("date")) {
            _this.date = new Date();
            _this.date.setTime(parseInt(elem.getAttribute("date")));
         }
      }
      catch(e) {
      }
      if(elem.getAttribute("ftype")) {
         _this.ftype = elem.getAttribute("ftype");
      }
   }

   /**
    * Write contents.
    * @public
    */
   this.writeContents = writeContentsFunction;
   this.writeContents._class = this._class;

   function writeContentsFunction() {
      var str = this._super.writeContents();

      if(_this.version) {
         str += this._super.writeCDATA("version", byteEncode(_this.version));
      }

      if(_this.comment) {
         str += this._super.writeCDATA("comment", byteEncode(_this.comment));
      }

      return str;
   }

   /**
    * Method to parse contents.
    * @public
    */
   this.parseContents = parseContentsFunction;
   this.parseContents._class = this._class;

   function parseContentsFunction(elem) {
      this._super.parseContents(elem);

      var vnode = Tool.getChildNodeByTagName(elem, "version");
      if(vnode) {
         _this.version = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }
      vnode = Tool.getChildNodeByTagName(elem, "comment");
      if(vnode) {
         _this.comment = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }
      vnode = Tool.getChildNodeByTagName(elem, "localDateTimeFormat");
      if(vnode) {
         _this.dateTimeFormat = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }
   }
}

RepletEntry = function(path, owner) {
   this._class = "inetsoft.sree.RepletEntry";
   this._extend("RepositoryEntry", path, RepositoryEntry.REPLET, owner);
   this.visible = false;
   this.alias = null;
   this.fileReplet = false;
   this.pregen = false;
   this.portlet = false;
   this.burst = false;
   this.paramOnly = false;
   this.desc = null;
   this.alabel = null;

   var _this = this._this;

   this.supportsOperation = supportsOperationFunction;
   this.supportsOperation._class = this._class;

   function supportsOperationFunction(operation) {
      // is a file replet? any change is forbidden
      if(_this.fileReplet) {
         return false;
      }

      if(operation == RepositoryEntry.RENAME_OPERATION) {
         return true;
      }
      else if(operation == RepositoryEntry.CHANGE_FOLDER_OPERATION) {
         return true;
      }
      else if(operation == RepositoryEntry.REMOVE_OPERATION) {
         return true;
      }
      else {
         return false;
      }
   }

   this.setVisible = setVisibleFunction;
   this.setVisible._class = this._class;

   function setVisibleFunction(visible) {
      _this.visible = visible;
   }

   this.isVisible = isVisibleFunction;
   this.isVisible._class = this._class;

   function isVisibleFunction() {
      return _this.visible;
   }

   this.setPregenerated = setPregeneratedFunction;
   this.setPregenerated._class = this._class;

   function setPregeneratedFunction(pregen) {
      _this.pregen = pregen;
   }

   this.isPregenerated = isPregeneratedFunction;
   this.isPregenerated._class = this._class;

   function isPregeneratedFunction() {
      return _this.pregen;
   }

   this.setPortlet = setPortletFunction;
   this.setPortlet._class = this._class;

   function setPortletFunction(portlet) {
      _this.portlet = portlet;
   }

   this.isPortlet = isPortletFunction;
   this.isPortlet._class = this._class;

   function isPortletFunction() {
      return _this.portlet;
   }

   this.setBursting = setBurstingFunction;
   this.setBursting._class = this._class;

   function setBurstingFunction(burst) {
      _this.burst = burst;
   }

   this.isBursting = isBurstingFunction;
   this.isBursting._class = this._class;

   function isBurstingFunction() {
      return _this.burst;
   }

   this.setParamOnly = setParamOnlyFunction;
   this.setParamOnly._class = this._class;

   function setParamOnlyFunction(burst) {
      _this.paramOnly = paramOnly;
   }

   this.isParamOnly = isParamOnlyFunction;
   this.isParamOnly._class = this._class;

   function isParamOnlyFunction() {
      return _this.paramOnly;
   }

   this.setDescription = setDescriptionFunction;
   this.setDescription._class = this._classl

   function setDescriptionFunction(desc) {
      _this.desc = desc;
   }

   this.getDescription = getDescriptionFunction;
   this.getDescription._class = this._class;

   function getDescriptionFunction() {
      return _this.desc;
   }

   this.setFileReplet = setFileRepletFunction;
   this.setFileReplet._class = this._class;

   function setFileRepletFunction(fileReplet) {
      _this.fileReplet = fileReplet;
   }

   this.isFileReplet = isFileRepletFunction;
   this.isFileReplet._class = this._class;

   function isFileRepletFunction() {
      return _this.fileReplet;
   }

   this.setAlias = setAliasFunction;
   this.setAlias._class = this._class;

   function setAliasFunction(alias) {
      _this.alias = alias;
   }

   this.getAlias = getAliasFunction;
   this.getAlias._class = this._class;

   function getAliasFunction() {
      return _this.alias;
   }

   this.getAlabel = getAlabelFunction;
   this.getAlabel._class = this._class;

   function getAlabelFunction() {
      return _this.alabel;
   }

   this.writeAttributes = writeAttributesFunction;
   this.writeAttributes._class = this._class;

   function writeAttributesFunction() {
      var str = this._super.writeAttributes();

      str += " visible=\"" + _this.visible + "\"";
      str += " fileReplet=\"" + _this.fileReplet + "\"";
      str += " pregen=\"" + _this.pregen + "\"";
      str += " portlet=\"" + _this.portlet + "\"";
      str += " burst=\"" + _this.burst + "\"";
      str += " paramOnly=\"" + _this.paramOnly + "\"";

      return str;
   }

   this.parseAttributes = parseAttributesFunction;
   this.parseAttributes._class = this._class;

   function parseAttributesFunction(elem) {
      this._super.parseAttributes(elem);

      _this.visible = elem.getAttribute("visible") == "true";
      _this.fileReplet = elem.getAttribute("fileReplet") == "true";
      _this.pregen = elem.getAttribute("pregen") == "true";
      _this.portlet = elem.getAttribute("portlet") == "true";
      _this.burst = elem.getAttribute("burst") == "true";
      _this.paramOnly = elem.getAttribute("paramOnly") == "true";
   }

   /**
    * Write contents.
    * @public
    */
   this.writeContents = writeContentsFunction;
   this.writeContents._class = this._class;

   function writeContentsFunction() {
      var str = this._super.writeContents();

      if(_this.alias) {
         str += this._super.writeCDATA("alias", byteEncode(_this.alias));
      }

      if(_this.desc) {
         str += this._super.writeCDATA("desc", byteEncode(_this.desc));
      }

      return str;
   }

   /**
    * Method to parse contents.
    * @public
    */
   this.parseContents = parseContentsFunction;
   this.parseContents._class = this._class;

   function parseContentsFunction(elem) {
      this._super.parseContents(elem);

      var vnode = Tool.getChildNodeByTagName(elem, "alias");

      if(vnode) {
         _this.alias = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }

      vnode = Tool.getChildNodeByTagName(elem, "desc");

      if(vnode) {
         _this.desc = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }

      vnode = Tool.getChildNodeByTagName(elem, "alabel");

      if(vnode) {
         _this.alabel = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }
   }

   this.getIconPath = getIconPathFunction;
   this.getIconPath._class = this._class;

   function getIconPathFunction() {
      if(_this.isPregenerated()) {
         return "/inetsoft/sree/web/images/preplet.gif";
      }
      else if(_this.isParamOnly()) {
         return "/inetsoft/sree/web/images/param_only_replet.gif";
      }
      else if(_this.isFileReplet()) {
         return "/inetsoft/sree/web/images/reportfile.gif";
      }
      else {
         return "/inetsoft/sree/web/images/replet.gif";
      }
   }
}

ViewsheetEntry = function(path, owner) {
   this._class = "inetsoft.sree.ViewsheetEntry";
   this._extend("RepositoryEntry", path, RepositoryEntry.VIEWSHEET, owner);
   var _this = this._this;

   this.dtype = null;
   this.onReport = true;
   this.snapshot = false;
   this.identifier = null;
   this.desc = null;
   this.alias = null;
   this.alable = null;

   this.supportsOperation = supportsOperationFunction;
   this.supportsOperation._class = this._class;

   function supportsOperationFunction(operation) {
      if(operation == RepositoryEntry.RENAME_OPERATION) {
         return true;
      }
      else if(operation == RepositoryEntry.CHANGE_FOLDER_OPERATION) {
         return true;
      }
      else if(operation == RepositoryEntry.REMOVE_OPERATION) {
         return true;
      }
      else {
         return false;
      }
   }

   this.isOnReport = isOnReportFunction;
   this.isOnReport._class = this._class;

   function isOnReportFunction() {
      return _this.onReport;
   }

   this.setOnReport = setOnReportFunction;
   this.setOnReport._class = this._class;

   function setOnReportFunction(onReport) {
      _this.onReport = onReport;
   }

   this.isSnapshot = isSnapshotFunction;
   this.isSnapshot._class = this._class;

   function isSnapshotFunction() {
      return _this.snapshot;
   }

   this.setSnapshot = setSnapshotFunction;
   this.setSnapshot._class = this._class;

   function setSnapshotFunction(snapshot) {
      _this.snapshot = snapshot;
   }

   this.setDeploymentType = setDeploymentTypeFunction;
   this.setDeploymentType._class = this._class;

   function setDeploymentTypeFunction(dtype) {
      _this.dtype = dtype;
   }

   this.getDeploymentType = getDeploymentTypeFunction;
   this.getDeploymentType._class = this._class;

   function getDeploymentTypeFunction() {
      return _this.dtype;
   }

   this.setIdentifier = setIdentifierFunction;
   this.setIdentifier._class = this._class;

   function setIdentifierFunction(identifier) {
      _this.identifier = identifier;
   }

   this.getIdentifier = getIdentifierFunction;
   this.getIdentifier._class = this._class;

   function getIdentifierFunction() {
      return _this.identifier;
   }

   this.setDescription = setDescriptionFunction;
   this.setDescription._class = this._classl

   function setDescriptionFunction(desc) {
      _this.desc = desc;
   }

   this.getDescription = getDescriptionFunction;
   this.getDescription._class = this._class;

   function getDescriptionFunction() {
      return _this.desc;
   }

   this.setAlias = setAliasFunction;
   this.setAlias._class = this._classl

   function setAliasFunction(alias) {
      _this.alias = alias;
   }

   this.getAlias = getAliasFunction;
   this.getAlias._class = this._class;

   function getAliasFunction() {
      return _this.alias;
   }

   this.getAlabel = getAlabelFunction;
   this.getAlabel._class = this._class;

   function getAlabelFunction() {
      return _this.alabel;
   }

   this.writeAttributes = writeAttributesFunction;
   this.writeAttributes._class = this._class;

   function writeAttributesFunction() {
      var str = this._super.writeAttributes();
      str += " onReport=\"" + _this.onReport + "\"";
      str += " snapshot=\"" + _this.snapshot + "\"";

      if(_this.dtype) {
         str += " dtype=\"" + _this.dtype + "\"";
      }

      if(_this.identifier) {
         str += " identifier=\"" + byteEncode(_this.identifier) + "\"";
      }

      return str;
   }

   this.parseAttributes = parseAttributesFunction;
   this.parseAttributes._class = this._class;

   function parseAttributesFunction(elem) {
      this._super.parseAttributes(elem);

      _this.onReport = elem.getAttribute("onReport") == "true";
      _this.snapshot = elem.getAttribute("snapshot") == "true";

      try {
         if(elem.getAttribute("dtype")) {
            _this.dtype = parseInt(elem.getAttribute("dtype"));
         }

         if(elem.getAttribute("identifier")) {
            _this.identifier = byteDecode(elem.getAttribute("identifier"));
         }
      }
      catch(e) {
      }
   }

   /**
    * Write contents.
    * @public
    */
   this.writeContents = writeContentsFunction;
   this.writeContents._class = this._class;

   function writeContentsFunction() {
      var str = this._super.writeContents();

      if(_this.desc) {
         str += this._super.writeCDATA("desc", byteEncode(_this.desc));
      }

      if(_this.alias) {
         str += this._super.writeCDATA("alias", byteEncode(_this.alias));
      }

      return str;
   }

   /**
    * Method to parse contents.
    * @public
    */
   this.parseContents = parseContentsFunction;
   this.parseContents._class = this._class;

   function parseContentsFunction(elem) {
      this._super.parseContents(elem);

      vnode = Tool.getChildNodeByTagName(elem, "desc");

      if(vnode) {
         _this.desc = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }

      vnode = Tool.getChildNodeByTagName(elem, "alias");

      if(vnode) {
         _this.alias = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }

      vnode = Tool.getChildNodeByTagName(elem, "alabel");

      if(vnode) {
         _this.alabel = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }
   }

   this.getIconPath = getIconPathFunction;
   this.getIconPath._class = this._class;

   function getIconPathFunction() {
      if(_this.isSnapshot()) {
         return "/inetsoft/sree/web/images/snapshot.gif";
      }
      else {
         return "/inetsoft/sree/web/images/viewsheet.gif";
      }
   }
}

RepletFolderEntry = function(path, owner) {
   this._class = "inetsoft.sree.RepletFolderEntry";
   this._extend("DefaultFolderEntry", path, owner);
   this.fileFolder = false;
   this.desc = null;

   var _this = this._this;


   this.supportsOperation = supportsOperationFunction;
   this.supportsOperation._class = this._class;

   function supportsOperationFunction(operation) {
      // is a file folder? any change is forbidden
      if(_this.fileFolder) {
         return false;
      }

      if(operation == RepositoryEntry.RENAME_OPERATION) {
         return !_this.isRoot() && _this.getPath() != "My Reports";
      }
      else if(operation == RepositoryEntry.CHANGE_FOLDER_OPERATION) {
         return !_this.isRoot() && _this.getPath() != "My Reports";
      }
      else if(operation == RepositoryEntry.REMOVE_OPERATION) {
         return !_this.isRoot() && _this.getPath() != "My Reports";
      }
      else if(operation == RepositoryEntry.CREATE_FOLDER_OPERATION) {
         return this.getType() == RepositoryEntry.FOLDER;
      }
      else {
         return false;
      }
   }

   this.setFileFolder = setFileFolderFunction;
   this.setFileFolder._class = this._class;

   function setFileFolderFunction(fileFolder) {
      _this.fileFolder = fileFolder;
   }

   this.isFileFolder = isFileFolderFunction;
   this.isFileFolder._class = this._class;

   function isFileFolderFunction() {
      return _this.fileFolder;
   }

   this.writeAttributes = writeAttributesFunction;
   this.writeAttributes._class = this._class;

   function writeAttributesFunction() {
      var str = this._super.writeAttributes();
      str += " fileFolder=\"" + _this.fileFolder + "\"";
      return str;
   }

   this.parseAttributes = parseAttributesFunction;
   this.parseAttributes._class = this._class;

   function parseAttributesFunction(elem) {
      this._super.parseAttributes(elem);

      _this.fileFolder = elem.getAttribute("fileFolder") == "true";
   }
}

ReportData = function() {
   this._class = "inetsoft.sree.store.ReportData";
}

ReportData.REPLET = "xgm";
ReportData.BURST = "srb";
ReportData.TEXT = "txt";
ReportData.PDF = "pdf";
ReportData.XLS = "xls";
ReportData.PPT = "ppt";
ReportData.RTF = "rtf";
ReportData.HTML_BUNDLE = "html_bundle";
ReportData.HTML_BUNDLE_NO_PAGINATION = "html_bundle_no_pagination";
ReportData.CSV = "csv";
ReportData.SVG = "svg";
ReportData.REPORT = "xsr";

ViewsheetEntry.DEPLOY_PORTLET = 1;
ViewsheetEntry.DEPLOY_DASHBOARD = 2;

/**
 * Represents an entry in the style report library. An entry can be a bean,
 * meta-report, parameter sheet, script, or table style.
 *
 * @version 9.6
 * @author InetSoft Technology Corp
 * @depend util.js
 */
StyleReportEntry = function(path, type, isFolder, description, fullPath) {
   this._class = "inetsoft.sree.internal.StyleReportEntry";
   this._extend("isii_Object");
   var _this = this._this;
   _this.path = path;
   _this.type = type;
   _this.isFolder = isFolder;
   _this.descirption = description;
   _this.fullPath = fullPath;
   _this.label = null;

   this.getIconPath = getIconPathFunction;
   this.getIconPath._class = this._class;

   function getIconPathFunction() {
      if(_this.isFolder) {
         return;
      }

      if(_this.isBean()) {
         return "/inetsoft/sree/adm/markup/images/bean.gif";
      }
      else if(_this.isMetaReport()) {
         return "/inetsoft/sree/adm/markup/images/meta_report.gif";
      }
      else if(_this.isParameterSheet()) {
         return "/inetsoft/sree/adm/markup/images/parameter_sheet.gif";
      }
      else if(_this.isScript()) {
         return "/inetsoft/sree/adm/markup/images/script.gif";
      }
      else if(_this.isTableStyle()) {
         return "/inetsoft/sree/adm/markup/images/table_style.gif";
      }
   }

   this.getLabel = getLabelFunction;
   this.getLabel._class = this._class;

   function getLabelFunction() {
      var label = _this.getPath();

      if(_this.isRoot()) {
         label = StyleReportEntry.LIBRARY_FOLDER;
      }
      else if(_this.isFolder) {
         if(_this.isBean()) {
            label = StyleReportEntry.BEAN_FOLDER;
         }
         else if(_this.isMetaReport()) {
            label = StyleReportEntry.METAREPORT_FOLDER;
         }
         else if(_this.isParameterSheet()) {
            label = StyleReportEntry.PARAMETERSHEET_FOLDER;
         }
         else if(_this.isScript()) {
            label = StyleReportEntry.SCRIPT_FOLDER;
         }
         else if(_this.isTableStyle()) {
            label = StyleReportEntry.TABLESTYLE_FOLDER;
         }
         else if(_this.isSubFolder()) {
            var strs = _this.path.split('~');
            label = strs[strs.length - 1];
         }
      }

      return label;
   }

   this.toString = toStringFunction;
   this.toString._class = this._class;

   function toStringFunction() {
      return _this.getLabel();
   }

   this.isRoot = isRootFunction;
   this.isRoot._class = this._class;

   function isRootFunction() {
      return _this.path == "/";
   }

   this.isBean = isBeanFunction;
   this.isBean._class = this._class;

   function isBeanFunction() {
      return (_this.type & StyleReportEntry.BEAN) != 0;
   }

   this.isMetaReport = isMetaReportFunction;
   this.isMetaReport._class = this._class;

   function isMetaReportFunction() {
      return (_this.type & StyleReportEntry.METAREPORT) != 0;
   }

   this.isParameterSheet = isParameterSheetFunction;
   this.isParameterSheet._class = this._class;

   function isParameterSheetFunction() {
      return (_this.type & StyleReportEntry.PARAMETERSHEET) != 0;
   }

   this.isScript = isScriptFunction;
   this.isScript._class = this._class;

   function isScriptFunction() {
      return (_this.type & StyleReportEntry.SCRIPT) != 0;
   }

   this.isTableStyle = isTableStyleFunction;
   this.isTableStyle._class = this._class;

   function isTableStyleFunction() {
      return (_this.type & StyleReportEntry.TABLESTYLE) != 0;
   }

   this.isSubFolder = isSubFolderFunction;
   this.isSubFolder._class = this._class;

   function isSubFolderFunction() {
      return (_this.type & StyleReportEntry.SUB_FOLDER) != 0;
   }

   this.getType = getTypeFunction;
   this.getType._class = this._class;

   function getTypeFunction() {
      return _this.type;
   }

   this.getPath = getPathFunction;
   this.getPath._class = this._class;

   function getPathFunction() {
      return _this.path;
   }

   this.getFullPath = getFullPathFunction;
   this.getFullPath._class = this._class;

   function getFullPathFunction() {
      return _this.fullPath;
   }

   this.equals = equalsFunction;
   this.equals._class = this._class;

   function equalsFunction(entry) {
      if(entry._class != _this._class) {
         return false;
      }

      return entry.path == _this.path && entry.type == _this.type &&
         entry.isFolder == _this.isFolder;
   }

   this.writeCDATA = writeCDATAFunction;
   this.writeCDATA._class = this._class;

   function writeCDATAFunction(name, value) {
      return "<" + name + "><![CDATA[" + value + "]]></" + name + ">";
   }

   /**
    * Write the xml segment.
    * @public
    */
   this.writeXML = writeXMLFunction;
   this.writeXML._class = this._class;

   function writeXMLFunction() {
      var str = "<StyleReportEntry path=\"" + byteEncode(_this.path) +
         "\" type=\"" + _this.type + "\" isFolder = \"" + _this.isFolder +
         "\" fullPath = \"" + fullPath + "\" >";

      if(_this.description) {
         str += _this.writeCDATA("description", byteEncode(_this.description));
      }

      str += "</StyleReportEntry>";

      return str;
   }

   /**
    * Method to parse an xml segment.
    * @public
    */
   this.parseXML = parseXMLFunction;
   this.parseXML._class = this._class;

   function parseXMLFunction(elem) {
      _this.path = byteDecode(elem.getAttribute("path"));
      _this.type = parseInt(elem.getAttribute("type"));
      _this.isFolder = elem.getAttribute("isFolder") == "true";
      _this.fullPath = byteDecode(elem.getAttribute("fullPath"));
      _this.label = _this.getLabel();

      var vnode = Tool.getChildNodeByTagName(elem, "description");

      if(vnode) {
         _this.description = byteDecode(Tool.getFirstChildNodeValue(vnode));
      }
   }

   this.getDescription = getDescriptionFunction;
   this.getDescription._class = this._class;

   function getDescriptionFunction() {
      return _this.description;
   }
}

StyleReportEntry.BEAN = 0x01;
StyleReportEntry.METAREPORT = 0x02;
StyleReportEntry.PARAMETERSHEET = 0x04;
StyleReportEntry.SCRIPT = 0x08;
StyleReportEntry.TABLESTYLE = 0x10;
StyleReportEntry.SUB_FOLDER = 0x20;

StyleReportEntry.BEAN_FOLDER = "Bean";
StyleReportEntry.METAREPORT_FOLDER = "Meta Report";
StyleReportEntry.PARAMETERSHEET_FOLDER = "Parameter Sheet";
StyleReportEntry.SCRIPT_FOLDER = "Script";
StyleReportEntry.TABLESTYLE_FOLDER = "Table Style";
StyleReportEntry.LIBRARY_FOLDER = "Library";
