package smart_gs.logical;


import org.w3c.dom.Element;

import smart_gs.logical.region.AnchorRegion;

public class AnchorTextSegment extends TextSegment {
	
	private AnchorRegion anchorRegion;
	
	public AnchorTextSegment(int id, String uri, String originalURI,
			String version) {
		super("anchor", id, uri, originalURI, version);
	}
	public AnchorTextSegment(SmartDocument document, int id) {
		super("anchor",document,id);
		this.document = document;
		this.setId(id);
		this.setURIs();
	}
	
	public static AnchorTextSegment restore(Element element,Spread spread){
		String id = element.getAttribute("id");
		String uri = element.getAttribute("uri");
		String originalURI = element.getAttribute("originalURI");
		String version = element.getAttribute(GSResource.VERSION);
		AnchorTextSegment segment = new AnchorTextSegment(new Integer(id),uri,originalURI,version);
		String anchorURI = URIObject.HEADER + uri.substring(uri.indexOf(URIObject.SEP4 + URIObject.ANCHOR) +1);
		Region region = spread.getRegionByURI(anchorURI);
		segment.setAnchorRegion((AnchorRegion) region);
		return segment;
	}

	
	public AnchorRegion getAnchorRegion() {
		return this.anchorRegion;
	}
	public void setAnchorRegion(AnchorRegion anchorRegion) {
		this.anchorRegion = anchorRegion;
	}
}
