1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
\r
5 <!-- Generated by javadoc (build 1.5.0_06) on Fri Oct 17 16:04:53 EDT 2008 -->
\r
7 org.marc4j.marc (MARC4J API)
\r
10 <META NAME="keywords" CONTENT="org.marc4j.marc package">
\r
12 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
\r
14 <SCRIPT type="text/javascript">
\r
15 function windowTitle()
\r
17 parent.document.title="org.marc4j.marc (MARC4J API)";
\r
25 <BODY BGCOLOR="white" onload="windowTitle();">
\r
28 <!-- ========= START OF TOP NAVBAR ======= -->
\r
29 <A NAME="navbar_top"><!-- --></A>
\r
30 <A HREF="#skip-navbar_top" title="Skip navigation links"></A>
\r
31 <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
\r
33 <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
\r
34 <A NAME="navbar_top_firstrow"><!-- --></A>
\r
35 <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
\r
36 <TR ALIGN="center" VALIGN="top">
\r
37 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
\r
38 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT> </TD>
\r
39 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Class</FONT> </TD>
\r
40 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-use.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
\r
41 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
\r
42 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
\r
43 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
\r
44 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
\r
48 <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
\r
54 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
\r
55 <A HREF="../../../org/marc4j/converter/impl/package-summary.html"><B>PREV PACKAGE</B></A>
\r
56 <A HREF="../../../org/marc4j/marc/impl/package-summary.html"><B>NEXT PACKAGE</B></A></FONT></TD>
\r
57 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
\r
58 <A HREF="../../../index.html?org/marc4j/marc/package-summary.html" target="_top"><B>FRAMES</B></A>
\r
59 <A HREF="package-summary.html" target="_top"><B>NO FRAMES</B></A>
\r
60 <SCRIPT type="text/javascript">
\r
63 document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
\r
68 <A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
\r
75 <A NAME="skip-navbar_top"></A>
\r
76 <!-- ========= END OF TOP NAVBAR ========= -->
\r
80 Package org.marc4j.marc
\r
82 Interfaces for the record object model.
\r
86 <A HREF="#package_description"><B>Description</B></A>
\r
89 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
\r
90 <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
\r
91 <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
\r
92 <B>Interface Summary</B></FONT></TH>
\r
94 <TR BGCOLOR="white" CLASS="TableRowColor">
\r
95 <TD WIDTH="15%"><B><A HREF="../../../org/marc4j/marc/ControlField.html" title="interface in org.marc4j.marc">ControlField</A></B></TD>
\r
96 <TD>Represents a control field in a MARC record.</TD>
\r
98 <TR BGCOLOR="white" CLASS="TableRowColor">
\r
99 <TD WIDTH="15%"><B><A HREF="../../../org/marc4j/marc/DataField.html" title="interface in org.marc4j.marc">DataField</A></B></TD>
\r
100 <TD>Represents a data field in a MARC record.</TD>
\r
102 <TR BGCOLOR="white" CLASS="TableRowColor">
\r
103 <TD WIDTH="15%"><B><A HREF="../../../org/marc4j/marc/Leader.html" title="interface in org.marc4j.marc">Leader</A></B></TD>
\r
104 <TD>Represents a record label in a MARC record.</TD>
\r
106 <TR BGCOLOR="white" CLASS="TableRowColor">
\r
107 <TD WIDTH="15%"><B><A HREF="../../../org/marc4j/marc/Record.html" title="interface in org.marc4j.marc">Record</A></B></TD>
\r
108 <TD>Represents a MARC record.</TD>
\r
110 <TR BGCOLOR="white" CLASS="TableRowColor">
\r
111 <TD WIDTH="15%"><B><A HREF="../../../org/marc4j/marc/Subfield.html" title="interface in org.marc4j.marc">Subfield</A></B></TD>
\r
112 <TD>Represents a subfield in a MARC record.</TD>
\r
114 <TR BGCOLOR="white" CLASS="TableRowColor">
\r
115 <TD WIDTH="15%"><B><A HREF="../../../org/marc4j/marc/VariableField.html" title="interface in org.marc4j.marc">VariableField</A></B></TD>
\r
116 <TD>Represents a variable field in a MARC record.</TD>
\r
123 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
\r
124 <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
\r
125 <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
\r
126 <B>Class Summary</B></FONT></TH>
\r
128 <TR BGCOLOR="white" CLASS="TableRowColor">
\r
129 <TD WIDTH="15%"><B><A HREF="../../../org/marc4j/marc/MarcFactory.html" title="class in org.marc4j.marc">MarcFactory</A></B></TD>
\r
130 <TD>Factory for creating MARC record objects.</TD>
\r
137 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
\r
138 <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
\r
139 <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
\r
140 <B>Exception Summary</B></FONT></TH>
\r
142 <TR BGCOLOR="white" CLASS="TableRowColor">
\r
143 <TD WIDTH="15%"><B><A HREF="../../../org/marc4j/marc/IllegalAddException.html" title="class in org.marc4j.marc">IllegalAddException</A></B></TD>
\r
144 <TD>Thrown when the addition of the supplied object is illegal.</TD>
\r
150 <A NAME="package_description"><!-- --></A><H2>
\r
151 Package org.marc4j.marc Description
\r
155 <p>Interfaces for the record object model.</p>
\r
156 <p>The goal of the <code>org.marc4j.marc</code> package is to provide a clean and simple to use interface to
\r
157 create, store and edit MARC records or parts of records as objects.
\r
158 See the examples below to get started using the object model.</p>
\r
159 <h3>Reading records</h3>
\r
160 <p>The <A HREF="../../../org/marc4j/marc/Record.html" title="interface in org.marc4j.marc"><CODE>Record</CODE></A> interface provides access to the
\r
161 leader and variable fields for each record returned by the <A HREF="../../../org/marc4j/MarcReader.html" title="interface in org.marc4j"><CODE>MarcReader</CODE></A> implementation.</p>
\r
162 <p>The following example retrieves all control fields (tags 001 through 009):<p>
\r
164 List fields = record.getControlFields();
\r
166 <p>This method retuns the fields as a <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html" title="class or interface in java.util"><CODE>List</CODE></A>, thus enabling the use of the standard Java collections
\r
167 framework to iterate over collections of records, fields or subfields.
\r
168 The following code snippet prints the tag and data for each control field to standard output:</p>
\r
170 Iterator i = fields.iterator();
\r
171 while (i.hasNext()) {
\r
172 ControlField field = (ControlField) i.next();
\r
173 System.out.println("Tag: " + field.getTag() + " Data: " + field.getData());
\r
176 <p>The <code>getDataFields()</code> method returns all data fields (tags 010 through 999).
\r
177 An <A HREF="../../../org/marc4j/marc/DataField.html" title="interface in org.marc4j.marc"><CODE>DataField</CODE></A> provides access to the tag, the indicators and the subfields.
\r
178 For example to write all the data field information to standard output:</p>
\r
180 List fields = record.getDataFields();
\r
181 Iterator i = fields.iterator();
\r
182 while (i.hasNext()) {
\r
183 DataField field = (ControlField) i.next();
\r
184 System.out.println("Tag: " + field.getTag() + " ind1: " + field.getIndicator1() +
\r
185 " ind2: " + field.getIndicator2());
\r
186 List subfields = field.getSubfields();
\r
187 Iterator j = subfields.iterator();
\r
188 while (j.hasNext()) {
\r
189 Subfield subfield = (Subfield) j.next();
\r
190 System.out.println("Subfield code: " + subfield.getCode() +
\r
191 "Data: " + subfield.getData());
\r
195 <p>If you want to retrieve specific fields you can use one of the following methods:</p>
\r
197 // get the first field occurence for a given tag
\r
198 DataField title = (DataField)record.getVariableField("245");
\r
200 // get all occurences for a particular tag
\r
201 List subjects = record.getVariableFields("650");
\r
203 // get all occurences for a given list of tags
\r
204 String[] tags = {"010", "100", "245", "250", "260", "300"};
\r
205 List fields = record.getVariableFields(tags);
\r
207 <p>In addition you can use simple searches using the <code>find()</code> methods
\r
208 to retrieve fields that meet certain criteria. The search capabilities are very
\r
209 limited, but they can be useful when processing records. The following code snippet
\r
210 provides some examples:</p>
\r
212 // find any field containing 'Chabon'
\r
213 List fields = record.find("Chabon");
\r
215 // find 'Summerland' in a title field
\r
216 List fields = record.find("245", "Summerland");
\r
218 // find 'Graham, Paul' in main or added entries for a personal name:
\r
219 String tags = {"100", "600"};
\r
220 List fields = record.find(tags, "Graham, Paul")
\r
222 <p>The find method is also useful if you want to retrieve records that meet
\r
223 certain criteria, such as a specific control number, title words or a particular publisher
\r
224 or subject. The example below checks if the cataloging agency is DLC. The example also shows
\r
225 how you can extend the find capailities to specific subfields, a feature not directly available
\r
226 in MARC4J, since it is easy to accomplish using the record model together with the standard Java API's.</p>
\r
228 InputStream input = new FileInputStream("file.mrc");
\r
229 MarcReader reader = new MarcStreamReader(input);
\r
230 while (reader.hasNext()) {
\r
231 Record record = reader.next();
\r
233 // check if the cataloging agency is DLC
\r
234 List result = record.find("040", "DLC");
\r
235 if (result.size() > 0)
\r
236 System.out.println("Agency for this record is DLC");
\r
238 // there is no specific find for a specific subfield
\r
239 // so to check if it is the orignal cataloging agency
\r
240 DataField field = (DataField)result.get(0);
\r
241 String agency = field.getSubfield('a').getData();
\r
242 if (agency.matches("DLC"))
\r
243 System.out.println("DLC is the original agency");
\r
247 <p>By using <code>find()</code> you can also implement a kind of search and replace to batch
\r
248 update records that meet certain criteria. You can use Java regular expressions in <code>find()</code> methods.
\r
250 <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/package-summary.html">java.util.regex</a>
\r
251 package for more information and examples.</p>
\r
252 <h3>Creating or updating records</h3>
\r
253 <p>You can also create or update records using the <A HREF="../../../org/marc4j/marc/MarcFactory.html" title="class in org.marc4j.marc"><CODE>MarcFactory</CODE></A>. For example:</p>
\r
255 // create a factory instance
\r
256 MarcFactory factory = MarcFactory.newInstance();
\r
258 // create a record with leader
\r
259 Record record = factory.newRecord("00000cam a2200000 a 4500");
\r
261 // add a control field
\r
262 record.addVariableField(factory.newControlField("001", "12883376"));
\r
264 // add a data field
\r
265 DataField df = factory.newDataField("245", '1', '0');
\r
266 df.addSubfield(factory.newSubfield('a', "Summerland /"));
\r
267 df.addSubfield(factory.newSubfield('c', "Michael Chabon."));
\r
268 record.addVariableField(df);
\r
270 <p>You can use a <A HREF="../../../org/marc4j/MarcWriter.html" title="interface in org.marc4j"><CODE>MarcWriter</CODE></A> implementation to serialize your records for example to MARC or MARC XML.
\r
271 The code snippet below writes a single record in MARC format to standard output:</p>
\r
273 MarcWriter writer = new MarcStreamWriter(System.out);
\r
274 writer.write(record);
\r
277 <p>Check the Javadoc for <A HREF="../../../org/marc4j/MarcStreamWriter.html" title="class in org.marc4j"><CODE>MarcStreamWriter</CODE></A> and <A HREF="../../../org/marc4j/MarcXmlWriter.html" title="class in org.marc4j"><CODE>MarcXmlWriter</CODE></A> for more information.</p>
\r
286 <!-- ======= START OF BOTTOM NAVBAR ====== -->
\r
287 <A NAME="navbar_bottom"><!-- --></A>
\r
288 <A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
\r
289 <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
\r
291 <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
\r
292 <A NAME="navbar_bottom_firstrow"><!-- --></A>
\r
293 <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
\r
294 <TR ALIGN="center" VALIGN="top">
\r
295 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
\r
296 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT> </TD>
\r
297 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Class</FONT> </TD>
\r
298 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-use.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
\r
299 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
\r
300 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
\r
301 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
\r
302 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
\r
306 <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
\r
312 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
\r
313 <A HREF="../../../org/marc4j/converter/impl/package-summary.html"><B>PREV PACKAGE</B></A>
\r
314 <A HREF="../../../org/marc4j/marc/impl/package-summary.html"><B>NEXT PACKAGE</B></A></FONT></TD>
\r
315 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
\r
316 <A HREF="../../../index.html?org/marc4j/marc/package-summary.html" target="_top"><B>FRAMES</B></A>
\r
317 <A HREF="package-summary.html" target="_top"><B>NO FRAMES</B></A>
\r
318 <SCRIPT type="text/javascript">
\r
321 document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
\r
326 <A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
\r
333 <A NAME="skip-navbar_bottom"></A>
\r
334 <!-- ======== END OF BOTTOM NAVBAR ======= -->
\r
337 Copyright © 2002-2006 Bas Peters. All Rights Reserved.
\r