ingo@945: package de.intevation.flys.artifacts.model;
ingo@945: 
ingo@945: import org.w3c.dom.Document;
ingo@945: import org.w3c.dom.Element;
ingo@945: import org.w3c.dom.Node;
ingo@945: 
ingo@945: import de.intevation.artifacts.ArtifactNamespaceContext;
ingo@945: 
ingo@945: 
sascha@3076: /**
felix@1636:  * Use an Element (DOM) to store the information about a facet.
felix@1636:  * The intent of this facet type is to represent a facet
felix@1636:  * stored in an Collection attribute. Different facets can have different
felix@1636:  * attributes that we need to parse, but the only thing ManagedFacets need
felix@1636:  * to do, is to adjust the attributes "active" and "position". So, those
felix@1636:  * values are set directly on the Element, the other attributes aren't
felix@1636:  * touched.
felix@1636:  */
ingo@945: public class ManagedDomFacet extends ManagedFacet {
ingo@945: 
ingo@945:     protected Element facet;
ingo@945: 
ingo@945:     public ManagedDomFacet(Element facet) {
ingo@1715:         super(null, -1, null, null, -1, -1, -1);
ingo@945: 
ingo@945:         this.facet = facet;
ingo@945:     }
ingo@945: 
ingo@945: 
ingo@945:     @Override
ingo@945:     public int getIndex() {
ingo@945:         if (this.index < 0) {
ingo@945:             String index = facet.getAttributeNS(
ingo@945:                 ArtifactNamespaceContext.NAMESPACE_URI, "index");
ingo@945: 
ingo@945:             if (index != null && index.length() > 0) {
ingo@945:                 this.index = Integer.parseInt(index);
ingo@945:             }
ingo@945:         }
ingo@945: 
ingo@945:         return this.index;
ingo@945:     }
ingo@945: 
ingo@945: 
ingo@945:     @Override
ingo@945:     public String getName() {
ingo@945:         if (this.name == null || this.name.length() == 0) {
ingo@945:             String name = facet.getAttributeNS(
ingo@945:                 ArtifactNamespaceContext.NAMESPACE_URI, "facet");
ingo@945: 
ingo@945:             this.name = name;
ingo@945:         }
ingo@945: 
ingo@945:         return this.name;
ingo@945:     }
ingo@945: 
ingo@945: 
ingo@945:     @Override
ingo@945:     public String getDescription() {
ingo@945:         if (this.description == null || this.description.length() == 0) {
ingo@945:             String description = facet.getAttributeNS(
ingo@945:                 ArtifactNamespaceContext.NAMESPACE_URI, "description");
ingo@945: 
ingo@945:             this.description = description;
ingo@945:         }
ingo@945: 
ingo@945:         return this.description;
ingo@945:     }
ingo@945: 
ingo@945: 
ingo@945:     @Override
ingo@945:     public int getPosition() {
ingo@945:         if (this.position < 0) {
ingo@945:             String position = facet.getAttributeNS(
felix@1636:                 ArtifactNamespaceContext.NAMESPACE_URI,
felix@1637:                 "pos");
ingo@945: 
ingo@945:             if (position != null && position.length() > 0) {
ingo@945:                 this.position = Integer.parseInt(position);
ingo@945:             }
ingo@945:         }
ingo@945: 
ingo@945:         return this.position;
ingo@945:     }
ingo@945: 
ingo@945: 
ingo@945:     @Override
ingo@945:     public void setPosition(int position) {
ingo@945:         this.position = position;
ingo@945: 
felix@1636:         // TODO Evaluate whether other set/getAttributes also need
felix@1636:         // to use the NAMESPACE_PREFIX.
ingo@945:         facet.setAttributeNS(
ingo@945:             ArtifactNamespaceContext.NAMESPACE_URI,
felix@1636:             ArtifactNamespaceContext.NAMESPACE_PREFIX + ":" + "pos",
ingo@945:             String.valueOf(position));
ingo@945:     }
ingo@945: 
ingo@945: 
ingo@945:     @Override
ingo@945:     public int getActive() {
ingo@945:         if (this.active < 0) {
ingo@945:             String active = facet.getAttributeNS(
ingo@945:                 ArtifactNamespaceContext.NAMESPACE_URI, "active");
ingo@945: 
ingo@945:             if (active != null && active.length() > 0) {
ingo@945:                 this.active = Integer.parseInt(active);
ingo@945:             }
ingo@945:         }
ingo@945: 
ingo@945:         return this.active;
ingo@945:     }
ingo@945: 
ingo@945: 
ingo@945:     @Override
ingo@945:     public void setActive(int active) {
ingo@945:         this.active = active;
ingo@945: 
ingo@945:         facet.setAttributeNS(
ingo@945:             ArtifactNamespaceContext.NAMESPACE_URI,
felix@1813:             "art:active",
ingo@945:             String.valueOf(active));
ingo@945:     }
ingo@945: 
ingo@945: 
ingo@945:     @Override
ingo@1715:     public int getVisible() {
ingo@1715:         if (this.visible < 0) {
ingo@1715:             String visible = facet.getAttributeNS(
ingo@1715:                 ArtifactNamespaceContext.NAMESPACE_URI, "visible");
ingo@1715: 
ingo@1715:             if (visible != null && visible.length() > 0) {
ingo@1715:                 this.visible = Integer.parseInt(visible);
ingo@1715:             }
ingo@1715:         }
ingo@1715: 
ingo@1715:         return this.visible;
ingo@1715:     }
ingo@1715: 
ingo@1715: 
ingo@1715:     @Override
ingo@1715:     public void setVisible(int visible) {
ingo@1715:         this.visible = visible;
ingo@1715: 
ingo@1715:         facet.setAttributeNS(
ingo@1715:             ArtifactNamespaceContext.NAMESPACE_URI,
ingo@1715:             "visible",
ingo@1715:             String.valueOf(getVisible()));
ingo@1715:     }
ingo@1715: 
ingo@1715: 
ingo@1715:     @Override
ingo@945:     public String getArtifact() {
ingo@945:         if (this.uuid == null || this.uuid.length() == 0) {
ingo@945:             String uuid = facet.getAttributeNS(
ingo@945:                 ArtifactNamespaceContext.NAMESPACE_URI, "artifact");
ingo@945: 
ingo@945:             this.uuid = uuid;
ingo@945:         }
ingo@945: 
ingo@945:         return this.uuid;
ingo@945:     }
ingo@945: 
ingo@945: 
felix@1813:     /**
felix@1813:      * Import into document.
felix@1813:      * @param doc Document to be imported to.
felix@1813:      */
ingo@945:     @Override
ingo@945:     public Node toXML(Document doc) {
ingo@945:         return doc.importNode(facet, true);
ingo@945:     }
ingo@945: }
ingo@945: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :