1 // $Id: NonSortExample.java,v 1.1 2006/08/04 12:39:58 bpeters Exp $
\r
3 * Copyright (C) 2002-2006 Bas Peters
\r
5 * This file is part of MARC4J
\r
7 * MARC4J is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU Lesser General Public
\r
9 * License as published by the Free Software Foundation; either
\r
10 * version 2.1 of the License, or (at your option) any later version.
\r
12 * MARC4J is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
15 * Lesser General Public License for more details.
\r
17 * You should have received a copy of the GNU Lesser General Public
\r
18 * License along with MARC4J; if not, write to the Free Software
\r
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
21 package org.marc4j.samples;
\r
23 import java.io.InputStream;
\r
25 import org.marc4j.MarcReader;
\r
26 import org.marc4j.MarcStreamReader;
\r
27 import org.marc4j.marc.DataField;
\r
28 import org.marc4j.marc.Record;
\r
29 import org.marc4j.marc.Subfield;
\r
32 * Demonstrates getting the title without non-sorting characters.
\r
34 * @author Bas Peters
\r
35 * @version $Revision: 1.1 $
\r
37 public class NonSortExample {
\r
39 public static void main(String args[]) throws Exception {
\r
41 InputStream input = DataFieldExample.class
\r
42 .getResourceAsStream("resources/chabon.mrc");
\r
44 MarcReader reader = new MarcStreamReader(input);
\r
45 while (reader.hasNext()) {
\r
46 Record record = reader.next();
\r
48 // get data field 245
\r
49 DataField dataField = (DataField) record.getVariableField("245");
\r
51 // get indicator as int value
\r
52 char ind2 = dataField.getIndicator2();
\r
54 // get the title proper
\r
55 Subfield subfield = dataField.getSubfield('a');
\r
56 String title = subfield.getData();
\r
57 System.out.println("Title proper: " + title);
\r
59 // remove the non sorting characters
\r
60 int nonSort = Character.digit(ind2, 10);
\r
61 title = title.substring(nonSort);
\r
62 System.out.println("Title non-sort (" + nonSort + "): " + title
\r