package edu.vt.marian.Document;
import java.io.*;
import java.net.*;
import java.util.*;
import edu.vt.marian.common.*;
/**
A "variable field" in a US MARC record that contains a corporate name:
that is, a 110, 410, 610, 710, or 810 field.
@author Robert France
*/
public class MarcCorpNameField extends PresentableMarcVarField
{
/** Labels for subfields reported in a long description.
*/
private final static String corp_name_labels = "abcdeknpqt";
/**
Create a MarcCorpNameField object with no subfields.
@param id -- the variable field id.
@param xMap -- used to convert ANSEL to (e.g.) XML.
@param debug -- used for debugging
*/
public MarcCorpNameField(int id, EntityMap xMap, Debug debug)
{
super(id, xMap, debug);
isCorpName = true;
}
/**
"Short" presentation for a corporate name variable field: use 'a' and 'b'
subfields.
@param markupType see edu.vt.marian.common.DigInfObj
@param out A BufferedWriter (presumably String or OutputStream) to present on.
@return OK -- everything jake.
IO_ERROR or PARSE_ERROR -- problems.
*/
public int presentShort(int markupType, BufferedWriter out) throws IOException
{
int Err;
switch ( markupType )
{
default:
debug.dumpTrace("MarcCorpNameField.presentShort(): Unexpected markup type " +
markupType + ": treating as ASCII.");
// Fall through:
case DigInfObj.XML:
case DigInfObj.SGML:
case DigInfObj.HTML:
case DigInfObj.ASCII:
case DigInfObj.ANSEL:
Enumeration subfld = subfields.elements();
try { while ( true )
{
MarcSubField sf = (MarcSubField) subfld.nextElement();
if ( ( sf.getLabel() == 'a' ) || ( sf.getLabel() == 'b' ) )
if ( (Err = sf.present(markupType, out)) != ReturnCodes.OK )
return( Err );
if ( subfld.hasMoreElements() )
out.write(' ');
} } catch( NoSuchElementException e) {};
}
return( ReturnCodes.OK );
}
/**
"Long" presentation for a corporate name variable field.
@param markupType see edu.vt.marian.common.DigInfObj
@param out A BufferedWriter (presumably String or OutputStream) to present on.
@return OK -- everything jake.
IO_ERROR or PARSE_ERROR -- problems.
*/
public int presentLong(int markupType, BufferedWriter out) throws IOException
{
int Err;
Enumeration subfld = subfields.elements();
switch ( markupType )
{
case DigInfObj.XML: // Use default.
case DigInfObj.SGML:
return( super.presentLong(markupType, out) );
case DigInfObj.HTML:
// Presentation: make the (unique) 'a' (meeting name) subfield a
// hot link using itself as (approximate) query text.
try { while ( true )
{
MarcSubField sf = (MarcSubField) subfld.nextElement();
if (sf.getLabel() == 'a')
{
// Build URL.
StringWriter sw = new StringWriter();
BufferedWriter bsw = new BufferedWriter( sw );
if ( (Err = sf.present(DigInfObj.ANSEL, bsw))
!= ReturnCodes.OK )
return( Err );
bsw.flush();
String queryString = "text1_type=Conference as Author/text1=" +
sw.toString();
presentUrl(queryString, out);
if ( (Err = sf.present(markupType, out)) != ReturnCodes.OK )
return( Err );
out.write("");
}
else if (sf.getLabel() == '4')
{
out.write("[");
if ( (Err = sf.present(markupType, out)) != ReturnCodes.OK )
return( Err );
out.write("]");
}
else if (corp_name_labels.indexOf(sf.getLabel()) != -1)
{
if ( (Err = sf.present(markupType, out)) != ReturnCodes.OK )
return( Err );
}
if ( subfld.hasMoreElements() )
out.write(' ');
} } catch( NoSuchElementException e) {};
return( ReturnCodes.OK );
default:
debug.dumpTrace("MarcCorpNameField.presentLong(): Unexpected markup type " +
markupType + ": treating as ASCII.");
// Fall through:
case DigInfObj.ASCII:
case DigInfObj.ANSEL:
try { while ( true )
{
MarcSubField sf = (MarcSubField) subfld.nextElement();
if (sf.getLabel() == '4')
{
out.write("[");
if ( (Err = sf.present(markupType, out)) != ReturnCodes.OK )
return( Err );
out.write("]");
}
else if (corp_name_labels.indexOf(sf.getLabel()) != -1)
{
if ( (Err = sf.present(markupType, out)) != ReturnCodes.OK )
return( Err );
}
if ( subfld.hasMoreElements() )
out.write(' ');
} } catch( NoSuchElementException e) {};
return( ReturnCodes.OK );
}
}
}