/* The contents of this file are subject to the THDL Open Community License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License on the THDL web site (http://www.thdl.org/). Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific terms governing rights and limitations under the License. The Initial Developer of this software is the Tibetan and Himalayan Digital Library (THDL). Portions created by the THDL are Copyright 2001-2003 THDL. All Rights Reserved. Contributor(s): ______________________________________. */ package org.thdl.tib.bibl; import java.util.*; import org.jdom.*; import org.jdom.output.*; /** * The TitleFactory class extends the GenericTibFactory to provide means for locating and manipulating title elements * within a {@link TibDoc}. * * @author Than Garson, Tibetan and Himalayan Digital Library */ public class TitleFactory extends GenericTibFactory implements TibConstants { // Attributes private org.jdom.Element titlegrp, titleInfo, tdecl, normDecl, normTib, normEng, foreign; private org.jdom.Element tdiv, pagination, title, element, rs; private org.jdom.Element sections, num; private org.jdom.Element[] titles, tdivs, titleLists, titleItems, elements; private org.jdom.Element[] tibanals, chapters, chapterTitles; private Hashtable nums; private String type, subtype, text; int entryIndex; private TitleParser titleParser; // Accessors protected void processDoc() { // getting root elements for titles and chapters titlegrp = tibDoc.findElement(TITLEGRP); sections = tibDoc.findElement(SECTIONS); // setting Normalized title normDecl = titlegrp.getChild(TDECL); String normEngText = new String(); normDecl.removeChildren(FOREIGN); normTib = normDecl.getChild(TITLE); if(normTib == null) { System.out.println("No title element found in normalized title decl!"); System.out.println("Decl: " + TiblEdit.outputString(normDecl)); return; } String lang = normTib.getAttributeValue(LANG); if(lang == null || !lang.equals(TIB)) { System.out.println("The first title element in Normalized title decl is not a Tib title!"); System.out.println("Lang: " + lang); System.out.println("Title: " + TiblEdit.outputString(normTib)); } foreign = normTib.getChild(FOREIGN); if(foreign == null) { foreign = new org.jdom.Element(FOREIGN); foreign.setAttribute(LANG,ENG); normTib.addContent(foreign); } children = normDecl.getChildren(TITLE); if (children.size()>1) { it = children.iterator(); while(it.hasNext()) { element = (org.jdom.Element)it.next(); if(element.getAttributeValue(LANG).equalsIgnoreCase(ENG)) { foreign.setText(element.getText()); element.detach(); normEng = foreign; } } } normTib.setAttribute(CORRESP,NG); element = normTib.getChild(TITLE); if(element != null && (foreign.getText() == null || foreign.getText().trim().equals(""))) { foreign.setText(element.getText()); element.detach(); } // Setting title info titleInfo = titlegrp.getChild(TINFO); tdivs = tibDoc.toElementArray(titleInfo.getChildren(TDIV)); for(int n=0;n1) { outStyles.add(new ElementStyle(tibDoc.cleanString(foreign.getText())+"\n", TextPane.REG, foreign)); } List discList = el.getParent().getChildren(DISC); // Get Discussion element if there org.jdom.Element disc, discItem; disc = null; for(Iterator it=discList.iterator();it.hasNext();) { discItem = (org.jdom.Element)it.next(); String type = discItem.getAttributeValue(TYPE); if(type.equals(BRIEF) || type.equals(FULL)) { disc = discItem; break; } } List titleChilds = el.getParent().getChildren(TITLE); // Get all the title children if(titleChilds != null && titleChilds.size()>0 && el.equals((org.jdom.Element)titleChilds.get(titleChilds.size()-1))) { if(disc!=null && disc.getText()!=null && disc.getText().trim().length()>1) { outStyles.add(new ElementStyle("Show Discussion\n", TextPane.RED, disc)); } } } // Public Helpers public java.util.Collection getAllTitles() { outStyles = new Vector(); doNormalizedTitle(); doTitleLine(); doEOCtitles(); doClosingTitles(); doNonTibetan(); doChapters(); return ((java.util.Collection)outStyles); } // Constructor protected TitleFactory(TibDoc td) { super(td); } }