package com.dbxml.db.enterprise.sync;
/*
* dbXML - Native XML Database
* Copyright (c) 1999-2006 The dbXML Group, L.L.C.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* $Id: Content.java,v 1.3 2006/02/02 19:04:15 bradford Exp $
*/
import com.dbxml.labrador.types.Variant;
import com.dbxml.xml.XMLSerializable;
import com.dbxml.xml.dom.DOMUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.Set;
import java.util.TreeSet;
/**
* Content represents metadata about a piece of dbXML content,
* such as a Document or a binary image.
*/
public final class Content implements XMLSerializable {
private Set groups = Collections.synchronizedSet(new TreeSet());
private Set tags = Collections.synchronizedSet(new TreeSet());
private List notes = Collections.synchronizedList(new ArrayList());
private int status = Constants.STATUS_ACTIVE;
private String path = "";
private String owner = "";
private Date modified = new Date();
private Date created = new Date();
private long size = 0;
private double version = 1.0;
public Content() {
}
public Content(String path) {
this.path = path;
}
public Element streamToXML(Document doc) throws DOMException {
Element contentElem = doc.createElement(Constants.CONTENT);
contentElem.setAttribute(Constants.STATUS, Constants.getStatusString(status));
Element pathElem = DOMUtils.addElement(contentElem, Constants.PATH);
Element ownerElem = DOMUtils.addElement(contentElem, Constants.OWNER);
Element modifiedElem = DOMUtils.addElement(contentElem, Constants.MODIFIED);
Element createdElem = DOMUtils.addElement(contentElem, Constants.CREATED);
Element sizeElem = DOMUtils.addElement(contentElem, Constants.SIZE);
Element versionElem = DOMUtils.addElement(contentElem, Constants.VERSION);
Element groupsElem = DOMUtils.addElement(contentElem, Constants.GROUPS);
Element tagsElem = DOMUtils.addElement(contentElem, Constants.TAGS);
Element notesElem = DOMUtils.addElement(contentElem, Constants.NOTES);
DOMUtils.setText(pathElem, path);
DOMUtils.setText(ownerElem, owner);
DOMUtils.setText(modifiedElem, new Variant(modified).toString());
DOMUtils.setText(createdElem, new Variant(created).toString());
DOMUtils.setText(sizeElem, Long.toString(size));
DOMUtils.setText(versionElem, Double.toString(version));
DOMUtils.setToElements(groupsElem, Constants.GROUP, groups);
DOMUtils.setToElements(tagsElem, Constants.TAG, tags);
DOMUtils.listToElements(notesElem, Constants.NOTE, notes);
return contentElem;
}
public void streamFromXML(Element element) throws DOMException {
status = Constants.getStatusValue(element.getAttribute(Constants.STATUS));
path = DOMUtils.getElementText(element, Constants.PATH);
owner = DOMUtils.getElementText(element, owner);
modified = new Variant(DOMUtils.getElementText(element, Constants.MODIFIED)).getDate();
created = new Variant(DOMUtils.getElementText(element, Constants.CREATED)).getDate();
size = Long.parseLong(DOMUtils.getElementText(element, Constants.SIZE));
version = Double.parseDouble(DOMUtils.getElementText(element, Constants.VERSION));
DOMUtils.elementsToSet(element, Constants.GROUP, groups);
DOMUtils.elementsToSet(element, Constants.TAG, tags);
DOMUtils.elementsToList(element, Constants.NOTE, notes);
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public double getVersion() {
return version;
}
public void setVersion(double version) {
this.version = version;
}
public Set getGroups() {
return groups;
}
public Set getTags() {
return tags;
}
public List getNotes() {
return notes;
}
}