001package com.hfg.xml.msofficexml.docx.wordprocessingml; 002 003 004 005import com.hfg.xml.msofficexml.docx.Docx; 006 007//------------------------------------------------------------------------------ 008/** 009 Represents an Office Open XML bookmark. 010 011 @author J. Alex Taylor, hairyfatguy.com 012 */ 013//------------------------------------------------------------------------------ 014// com.hfg XML/HTML Coding Library 015// 016// This library is free software; you can redistribute it and/or 017// modify it under the terms of the GNU Lesser General Public 018// License as published by the Free Software Foundation; either 019// version 2.1 of the License, or (at your option) any later version. 020// 021// This library is distributed in the hope that it will be useful, 022// but WITHOUT ANY WARRANTY; without even the implied warranty of 023// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 024// Lesser General Public License for more details. 025// 026// You should have received a copy of the GNU Lesser General Public 027// License along with this library; if not, write to the Free Software 028// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 029// 030// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 031// jataylor@hairyfatguy.com 032//------------------------------------------------------------------------------ 033 034public class WmlBookmark 035{ 036 private Docx mParentDoc; 037 private int mId; 038 private String mName; 039 040 private static int sIdSrc = 0; 041 042 //--------------------------------------------------------------------------- 043 public WmlBookmark(Docx inDocx) 044 { 045 mParentDoc = inDocx; 046 mId = sIdSrc++; 047 mName = "_Ref" + mId; 048 } 049 050 //--------------------------------------------------------------------------- 051 public WmlBookmark(Docx inDocx, String inName) 052 { 053 mParentDoc = inDocx; 054 mId = sIdSrc++; 055 mName = inName; 056 057 // For convenience, keep a list of bookmarks in the document. 058 inDocx.registerBookmark(this); 059 } 060 061 //--------------------------------------------------------------------------- 062 public int getId() 063 { 064 return mId; 065 } 066 067 //--------------------------------------------------------------------------- 068 public String name() 069 { 070 return mName; 071 } 072 073 //--------------------------------------------------------------------------- 074 public WmlXMLTag generateBookmarkStart() 075 { 076 WmlXMLTag tag = new WmlXMLTag(WmlXML.BOOKMARK_START, mParentDoc); 077 tag.setAttribute(WmlXML.ID_ATT, getId()); 078 tag.setAttribute(WmlXML.NAME, name()); 079 080 return tag; 081 } 082 083 //--------------------------------------------------------------------------- 084 public WmlXMLTag generateBookmarkEnd() 085 { 086 WmlXMLTag tag = new WmlXMLTag(WmlXML.BOOKMARK_END, mParentDoc); 087 tag.setAttribute(WmlXML.ID_ATT, getId()); 088 089 return tag; 090 } 091}