2 new revisions: Revision: 8d8d5ea6e6be Branch: rt2091-tPagesGui Author: Corey Knapp <cknapp.code@xxxxxxxxx> Date: Thu Feb 19 18:50:16 2015 UTC Log: Changed dialog to work better on low resolutions https://code.google.com/p/brailleblaster/source/detail?r=8d8d5ea6e6be Revision: 68bdc1590399 Branch: rt2091-tPagesGui Author: Corey Knapp <cknapp.code@xxxxxxxxx> Date: Thu Feb 19 22:06:53 2015 UTC Log: Improved accuracy of autoPopulate https://code.google.com/p/brailleblaster/source/detail?r=68bdc1590399 ============================================================================== Revision: 8d8d5ea6e6be Branch: rt2091-tPagesGui Author: Corey Knapp <cknapp.code@xxxxxxxxx> Date: Thu Feb 19 18:50:16 2015 UTC Log: Changed dialog to work better on low resolutions https://code.google.com/p/brailleblaster/source/detail?r=8d8d5ea6e6be Modified: /src/main/org/brailleblaster/logback/LogFileFinder.java /src/main/org/brailleblaster/tpages/TPagesDialog.java /src/main/org/brailleblaster/tpages/TPagesGenerator.java =======================================--- /src/main/org/brailleblaster/logback/LogFileFinder.java Thu Jul 17 14:18:39 2014 UTC +++ /src/main/org/brailleblaster/logback/LogFileFinder.java Thu Feb 19 18:50:16 2015 UTC
@@ -10,7 +10,7 @@public class LogFileFinder extends PropertyDefinerBase implements PropertyDefiner {
private File logPath; - public LogFileFinder() { + public LogFileFinder() { File bbHome = new File(System.getProperty("user.home"), ".brlblst"); if (SWT.getPlatform().equals("win32")) { bbHome = new File(System.getenv("APPDATA"), "brlblst"); =======================================--- /src/main/org/brailleblaster/tpages/TPagesDialog.java Wed Feb 18 17:52:54 2015 UTC +++ /src/main/org/brailleblaster/tpages/TPagesDialog.java Thu Feb 19 18:50:16 2015 UTC
@@ -25,6 +25,7 @@ import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.TabFolder; @@ -46,6 +47,7 @@ Button copyrightButton, copySymbolButton; TPagesGenerator tpGenerator; HashMap<String, String> xmlmap;+ Group titleGroup, authorGroup, printGroup, publisherGroup, transcriberGroup;
public TPagesDialog(Shell parent, int style, Manager brailleViewController){
super(parent, style); @@ -60,6 +62,9 @@if(m.getDocumentName().substring(m.getDocumentName().length()-4).equals(".xml"))
tpGenerator.autoPopulate(m.getDocumentName()); xmlmap = tpGenerator.getXmlMap(); + //if(xmlmap.isEmpty()){ + //xmlmap = tpGenerator.getEmptyXmlMap(); + //} uimap = new HashMap<Text, String>(); createContents(); @@ -103,136 +108,58 @@ ///////////////////////////// ///////Title Page Tab//////// ///////////////////////////// - ScrolledComposite sc = new ScrolledComposite(folder, SWT.V_SCROLL); - sc.setLayout(new FillLayout()); - Composite titleComposite = new Composite(sc, SWT.NONE); - GridLayout titlePageLayout = new GridLayout(2,false); - titleComposite.setLayout(new RowLayout(SWT.VERTICAL)); + final Composite titleComposite = new Composite(folder, SWT.NONE); + titleComposite.setLayout(new GridLayout(2, false));//titleComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 1, 1));
- Group titleGroup = new Group(titleComposite, SWT.NONE); - titleGroup.setText("Title"); - titleGroup.setLayout(titlePageLayout);+ final List titlePageList = new List(titleComposite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);
+ titlePageList.add("Title"); + titlePageList.add("Author"); + titlePageList.add("Publisher"); + titlePageList.add("Printing"); + titlePageList.add("Transcription");+ GridData listData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true, 1, 6);
+ listData.widthHint = 100; + titlePageList.setLayoutData(listData); - createLabel(titleGroup, "Title", 1); - titleText = createText(titleGroup, 1, "title"); + createTitleGroup(titleComposite); + /*createAuthorGroup(titleComposite); + createPublisherGroup(titleComposite); + createPrintGroup(titleComposite); + createTranscriberGroup(titleComposite);*/ - createLabel(titleGroup, "Grade Level", 1); - gradeLevelText = createText(titleGroup, 1, "gradelevel"); - - createLabel(titleGroup, "Subtitle", 1); - subtitleText = createText(titleGroup, 1, "subtitle"); - - createLabel(titleGroup, "Series Name", 1); - seriesText = createText(titleGroup, 1, "seriesname"); - - createLabel(titleGroup, "Edition Name or Number", 1); - editionText = createText(titleGroup, 1, "editionname"); - - Group authorGroup = new Group(titleComposite, SWT.NONE); - authorGroup.setText("Author"); - authorGroup.setLayout(new GridLayout(2,false)); - - createLabel(authorGroup, "Author(s)", 1);- authorText = new Text(authorGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
- GridData newData = newTpData(1); - newData.widthHint = TEXT_BOX_WIDTH; - newData.heightHint = 70; - if(xmlmap.get("authors")!=null) - authorText.setText(xmlmap.get("authors").replaceAll(";", "\r\n")); - authorText.setLayoutData(newData); - - createLabel(authorGroup, "Translator", 1); - translatorText = createText(authorGroup, 1, "translator"); - - Group publisherGroup = new Group(titleComposite, SWT.NONE); - publisherGroup.setText("Publisher"); - publisherGroup.setLayout(new GridLayout(2,false)); - - createLabel(publisherGroup, "Permission", 1); - permissionCombo = new Combo(publisherGroup, SWT.READ_ONLY); - permissionCombo.setLayoutData(newTpData(1));- permissionCombo.setItems(new String[]{"Published by", "With permission of the publisher,"});
- permissionCombo.select(0); - if(xmlmap.get("pubpermission")!=null){- if (xmlmap.get("pubpermission").equals("0")|| xmlmap.get("pubpermission").equals("1"))
- permissionCombo.select(Integer.parseInt(xmlmap.get("pubpermission"))); - } - - createLabel(publisherGroup, "Publisher", 1); - publisherText = createText(publisherGroup, 1, "publisher"); - - createLabel(publisherGroup, "City and State", 1); - pubLocationText = createText(publisherGroup, 1, "location"); - - createLabel(publisherGroup, "Website", 1); - pubWebsiteText = createText(publisherGroup, 1, "website"); - - Group printGroup = new Group (titleComposite, SWT.NONE); - printGroup.setText("Printing Info"); - printGroup.setLayout(new GridLayout(2,false)); - - copyrightButton = new Button(printGroup, SWT.CHECK); - copyrightButton.setText("Copyright");- copyrightButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 1, 1));
- if(xmlmap.get("copyrighted")!=null){ - copyrightButton.setSelection(xmlmap.get("copyrighted").equals("true")); - } else{ - copyrightButton.setSelection(true); - } - copySymbolButton = new Button(printGroup, SWT.CHECK); - copySymbolButton.setText("Copyright Symbol");- copySymbolButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 1, 1));
- if(xmlmap.get("copyrightsymbol")!=null){- copySymbolButton.setSelection(xmlmap.get("copyrightsymbol").equals("true"));
- } else{ - copySymbolButton.setSelection(true); - } - - createLabel(printGroup, "Copyright Date", 1); - copyDateText = createText(printGroup, 1, "copyrightdate"); - - createLabel(printGroup, "Copyright Text", 1); - copyText = createText(printGroup, 1, "copyrighttext"); - - createLabel(printGroup, "Reproduction Notice", 1); - reproText = createText(printGroup, 1, "repronotice"); - - createLabel(printGroup,"ISBN-13", 1); - isbn13Text = createText(printGroup, 1, "isbn13"); - - createLabel(printGroup, "ISBN-10", 1); - isbn10Text = createText(printGroup, 1, "isbn10"); - - createLabel(printGroup, "Printing History", 1); - printHistoryText = createText(printGroup, 1, "printhistory"); - - Group transcriberGroup = new Group (titleComposite, SWT.NONE); - transcriberGroup.setText("Transcriber"); - transcriberGroup.setLayout(new GridLayout(2, false)); - - createLabel(transcriberGroup, "Transcription Year", 1); - transYearText = createText(transcriberGroup, 1, "year"); - - createLabel(transcriberGroup, "Transcriber", 1); - transText = createText(transcriberGroup, 1, "transcriber"); - - createLabel(transcriberGroup, "Tactile Graphics Specialist", 1); - tgsText = createText(transcriberGroup, 1, "tgs"); - - createLabel(transcriberGroup, "Affiliation", 1); - affiliationText = createText(transcriberGroup, 1, "affiliation"); - - Group volumesGroup = new Group (titleComposite, SWT.NONE); + /*final Group volumesGroup = new Group (titleComposite, SWT.NONE); volumesGroup.setText("Volumes"); volumesGroup.setLayout(new GridLayout(2,false)); - createLabel(volumesGroup, "Not yet implemented", 1); + volumesGroup.setVisible(false); + createLabel(volumesGroup, "Not yet implemented", 1);*/ - sc.setContent(titleComposite); - sc.setExpandVertical(true); - sc.setExpandHorizontal(true); - sc.setMinHeight(500); - sc.setSize(800, 500); - titleTab.setControl(sc); + titlePageList.addSelectionListener(new SelectionListener(){ + @Override + public void widgetSelected(SelectionEvent e){ + saveCurrentGroup(); + disposeAll(); + if(titlePageList.getSelection()[0].equals("Title")) + createTitleGroup(titleComposite); + if(titlePageList.getSelection()[0].equals("Author")) + createAuthorGroup(titleComposite); + if(titlePageList.getSelection()[0].equals("Printing")) + createPrintGroup(titleComposite); + if(titlePageList.getSelection()[0].equals("Publisher")) + createPublisherGroup(titleComposite); + if(titlePageList.getSelection()[0].equals("Transcription")) + createTranscriberGroup(titleComposite); + updateContents(); + shlTPages.pack(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + }); + titlePageList.select(0); + + titleTab.setControl(titleComposite); ///////////////////////////// ///////////////////////////// @@ -298,6 +225,7 @@ String filePath = openFile.open(); if(filePath!=null){ if(openFromXml(filePath)){ + xmlmap = tpGenerator.getXmlMap(); updateContents(); } else {createError("Error reading file. Was this file created by this dialog?");
@@ -321,14 +249,14 @@ generateButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { - authorText.setText(authorText.getText().replaceAll("\r\n", ";")); + /*authorText.setText(authorText.getText().replaceAll("\r\n", ";")); xmlmap.put("authors", authorText.getText()); xmlmap.put("pubpermission", "" + permissionCombo.getSelectionIndex());xmlmap.put("copyrighted", String.valueOf(copyrightButton.getSelection())); xmlmap.put("copyrightsymbol", String.valueOf(copySymbolButton.getSelection()));
for(Map.Entry<Text, String> entry : uimap.entrySet()) - xmlmap.put(entry.getValue(), entry.getKey().getText()); - + xmlmap.put(entry.getValue(), entry.getKey().getText());*/ + saveCurrentGroup(); FileDialog saveFile = new FileDialog(shlTPages, SWT.SAVE); saveFile.setFilterExtensions(new String[] { "*.xml" }); String result = saveFile.open(); @@ -347,7 +275,7 @@ shlTPages.pack(true); } - + public void createError(String errorMessage){MessageBox errorDialog = new MessageBox(shlTPages, SWT.ICON_ERROR | SWT.OK);
errorDialog.setText("Error"); @@ -356,13 +284,63 @@ } private void updateContents(){ - for(Map.Entry<Text, String> entry : uimap.entrySet()) + /*for(Map.Entry<Text, String> entry : uimap.entrySet()) entry.getKey().setText(xmlmap.get(entry.getValue())); permissionCombo.select(Integer.parseInt(xmlmap.get("pubpermission"))); copyrightButton.setSelection(xmlmap.get("copyrighted").equals("true"));copySymbolButton.setSelection(xmlmap.get("copyrightsymbol").equals("true"));
authorText.setText(xmlmap.get("authors").replaceAll(";", "\r\n")); - affiliationText.setText(xmlmap.get("affiliation")); + affiliationText.setText(xmlmap.get("affiliation"));*/ + if(titleText!=null && !titleText.isDisposed()) + titleText.setText(xmlmap.get("booktitle")); + if(gradeLevelText!=null && !gradeLevelText.isDisposed()) + gradeLevelText.setText(xmlmap.get("gradelevel")); + if(subtitleText!=null && !subtitleText.isDisposed()) + subtitleText.setText(xmlmap.get("subtitle")); + if(seriesText!=null && !seriesText.isDisposed()) + seriesText.setText(xmlmap.get("seriesname")); + if(editionText!=null && !editionText.isDisposed()) + editionText.setText(xmlmap.get("editionname")); + if(authorText!=null && !authorText.isDisposed()) + authorText.setText(xmlmap.get("authors").replaceAll(";", "\r\n")); + if(translatorText!=null && !translatorText.isDisposed()) + translatorText.setText(xmlmap.get("translator")); + if(permissionCombo!= null && !permissionCombo.isDisposed()){ + if(xmlmap.get("pubpermission").equals("1")) + permissionCombo.select(1); + else + permissionCombo.select(0); + } + if(publisherText!=null && !publisherText.isDisposed()) + publisherText.setText(xmlmap.get("publisher")); + if(pubLocationText!=null && !pubLocationText.isDisposed()) + pubLocationText.setText(xmlmap.get("location")); + if(pubWebsiteText!=null && !pubWebsiteText.isDisposed()) + pubWebsiteText.setText(xmlmap.get("website")); + if(copyrightButton!=null && !copyrightButton.isDisposed()) + copyrightButton.setSelection(xmlmap.get("copyrighted").equals("true")); + if(copySymbolButton!=null && !copySymbolButton.isDisposed())+ copySymbolButton.setSelection(xmlmap.get("copyrightsymbol").equals("true"));
+ if(copyDateText!=null && !copyDateText.isDisposed()) + copyDateText.setText(xmlmap.get("copyrighttext")); + if(copyText!=null && !copyText.isDisposed()) + copyText.setText(xmlmap.get("copyrighttext")); + if(reproText!=null && !reproText.isDisposed()) + reproText.setText(xmlmap.get("repronotice")); + if(isbn13Text!=null && !isbn13Text.isDisposed()) + isbn13Text.setText(xmlmap.get("isbn13")); + if(isbn10Text!=null && !isbn10Text.isDisposed()) + isbn10Text.setText(xmlmap.get("isbn10")); + if(printHistoryText!=null && !printHistoryText.isDisposed()) + printHistoryText.setText(xmlmap.get("printhistory")); + if(transYearText!=null && !transYearText.isDisposed()) + transYearText.setText(xmlmap.get("year")); + if(transText!=null && !transText.isDisposed()) + transText.setText(xmlmap.get("transcriber")); + if(tgsText!=null && !tgsText.isDisposed()) + tgsText.setText(xmlmap.get("tgs")); + if(affiliationText!=null && !affiliationText.isDisposed()) + affiliationText.setText(xmlmap.get("affiliation")); } private boolean openFromXml(String filepath){ @@ -375,6 +353,189 @@ private GridData newTpData(int columns){return new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, columns, 1);
} + + private void createTitleGroup(Composite comp){ + GridLayout titlePageLayout = new GridLayout(2,false); + titleGroup = new Group(comp, SWT.NONE); + titleGroup.setText("Title"); + titleGroup.setLayout(titlePageLayout); + createLabel(titleGroup, "Title", 1); + titleText = createText(titleGroup, 1, "booktitle"); + createLabel(titleGroup, "Grade Level", 1); + gradeLevelText = createText(titleGroup, 1, "gradelevel"); + createLabel(titleGroup, "Subtitle", 1); + subtitleText = createText(titleGroup, 1, "subtitle"); + createLabel(titleGroup, "Series Name", 1); + seriesText = createText(titleGroup, 1, "seriesname"); + createLabel(titleGroup, "Edition Name or Number", 1); + editionText = createText(titleGroup, 1, "editionname"); + comp.layout(true); + } + + private void createAuthorGroup(Composite comp){ + authorGroup = new Group(comp, SWT.NONE); + authorGroup.setText("Author"); + authorGroup.setLayout(new GridLayout(2,false)); + + createLabel(authorGroup, "Author(s)", 1);+ authorText = new Text(authorGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
+ GridData newData = newTpData(1); + newData.widthHint = TEXT_BOX_WIDTH - 17; + newData.heightHint = 70; + if(xmlmap.get("authors")!=null) + authorText.setText(xmlmap.get("authors").replaceAll(";", "\r\n")); + authorText.setLayoutData(newData); + + createLabel(authorGroup, "Translator", 1); + translatorText = createText(authorGroup, 1, "translator"); + comp.layout(true); + } + + private void createPublisherGroup(Composite comp){ + publisherGroup = new Group(comp, SWT.NONE); + publisherGroup.setText("Publisher"); + publisherGroup.setLayout(new GridLayout(2,false)); + + createLabel(publisherGroup, "Permission", 1); + permissionCombo = new Combo(publisherGroup, SWT.READ_ONLY); + permissionCombo.setLayoutData(newTpData(1));+ permissionCombo.setItems(new String[]{"Published by", "With permission of the publisher,"});
+ permissionCombo.select(0); + if(xmlmap.get("pubpermission")!=null){+ if (xmlmap.get("pubpermission").equals("0")|| xmlmap.get("pubpermission").equals("1"))
+ permissionCombo.select(Integer.parseInt(xmlmap.get("pubpermission"))); + } + createLabel(publisherGroup, "Publisher", 1); + publisherText = createText(publisherGroup, 1, "publisher"); + createLabel(publisherGroup, "City and State", 1); + pubLocationText = createText(publisherGroup, 1, "location"); + createLabel(publisherGroup, "Website", 1); + pubWebsiteText = createText(publisherGroup, 1, "website"); + comp.layout(true); + } + + private void createPrintGroup(Composite comp){ + printGroup = new Group (comp, SWT.NONE); + printGroup.setText("Printing Info"); + printGroup.setLayout(new GridLayout(2,false)); + + copyrightButton = new Button(printGroup, SWT.CHECK); + copyrightButton.setText("Copyright");+ copyrightButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 1, 1));
+ if(xmlmap.get("copyrighted")!=null){ + copyrightButton.setSelection(xmlmap.get("copyrighted").equals("true")); + } else{ + copyrightButton.setSelection(true); + } + copySymbolButton = new Button(printGroup, SWT.CHECK); + copySymbolButton.setText("Copyright Symbol");+ copySymbolButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 1, 1));
+ if(xmlmap.get("copyrightsymbol")!=null){+ copySymbolButton.setSelection(xmlmap.get("copyrightsymbol").equals("true"));
+ } else{ + copySymbolButton.setSelection(true); + } + + createLabel(printGroup, "Copyright Date", 1); + copyDateText = createText(printGroup, 1, "copyrightdate"); + + createLabel(printGroup, "Copyright Text", 1); + copyText = createText(printGroup, 1, "copyrighttext"); + + createLabel(printGroup, "Reproduction Notice", 1); + reproText = createText(printGroup, 1, "repronotice"); + + createLabel(printGroup,"ISBN-13", 1); + isbn13Text = createText(printGroup, 1, "isbn13"); + + createLabel(printGroup, "ISBN-10", 1); + isbn10Text = createText(printGroup, 1, "isbn10"); + + createLabel(printGroup, "Printing History", 1); + printHistoryText = createText(printGroup, 1, "printhistory"); + comp.layout(true); + } + + private void createTranscriberGroup(Composite comp){ + transcriberGroup = new Group (comp, SWT.NONE); + transcriberGroup.setText("Transcriber"); + transcriberGroup.setLayout(new GridLayout(2, false)); + + createLabel(transcriberGroup, "Transcription Year", 1); + transYearText = createText(transcriberGroup, 1, "year"); + + createLabel(transcriberGroup, "Transcriber", 1); + transText = createText(transcriberGroup, 1, "transcriber"); + + createLabel(transcriberGroup, "Tactile Graphics Specialist", 1); + tgsText = createText(transcriberGroup, 1, "tgs"); + + createLabel(transcriberGroup, "Affiliation", 1); + affiliationText = createText(transcriberGroup, 1, "affiliation"); + comp.layout(true); + } + private void disposeAll(){ + if(titleGroup!=null&&!titleGroup.isDisposed()) + titleGroup.dispose(); + if(authorGroup!=null&&!authorGroup.isDisposed()) + authorGroup.dispose(); + if(publisherGroup!=null&&!publisherGroup.isDisposed()) + publisherGroup.dispose(); + if(printGroup!=null&&!printGroup.isDisposed()) + printGroup.dispose(); + if(transcriberGroup!=null&&!transcriberGroup.isDisposed()) + transcriberGroup.dispose(); + } + + private void saveCurrentGroup(){ + if(!titleText.isDisposed()) + xmlmap.put("booktitle", titleText.getText()); + if(!gradeLevelText.isDisposed()) + xmlmap.put("gradelevel", gradeLevelText.getText()); + if(!subtitleText.isDisposed()) + xmlmap.put("subtitle", subtitleText.getText()); + if(!seriesText.isDisposed()) + xmlmap.put("seriesname", seriesText.getText()); + if(!editionText.isDisposed()) + xmlmap.put("editionname", editionText.getText()); + if(authorText!=null && !authorText.isDisposed()){ + xmlmap.put("authors", authorText.getText().replaceAll("\r\n", ";")); + } + if(translatorText!=null && !translatorText.isDisposed()) + xmlmap.put("translator", translatorText.getText()); + if(permissionCombo!=null && !permissionCombo.isDisposed()) + xmlmap.put("pubpermission", "" + permissionCombo.getSelectionIndex()); + if(publisherText!=null && !publisherText.isDisposed()) + xmlmap.put("publisher", publisherText.getText()); + if(pubLocationText!=null && !pubLocationText.isDisposed()) + xmlmap.put("location", pubLocationText.getText()); + if(pubWebsiteText!=null && !pubWebsiteText.isDisposed()) + xmlmap.put("website", pubWebsiteText.getText()); + if(copyrightButton!=null && !copyrightButton.isDisposed())+ xmlmap.put("copyrighted", String.valueOf(copyrightButton.getSelection()));
+ if(copySymbolButton!=null && !copySymbolButton.isDisposed())+ xmlmap.put("copyrightsymbol", String.valueOf(copySymbolButton.getSelection()));
+ if(copyDateText!=null && !copyDateText.isDisposed()) + xmlmap.put("copyrightdate", copyDateText.getText()); + if(copyText!=null && !copyText.isDisposed()) + xmlmap.put("copyrighttext", copyText.getText()); + if(reproText!=null && !reproText.isDisposed()) + xmlmap.put("repronotice", reproText.getText()); + if(isbn13Text!=null && !isbn13Text.isDisposed()) + xmlmap.put("isbn13", isbn13Text.getText()); + if(isbn10Text!=null && !isbn10Text.isDisposed()) + xmlmap.put("isbn10", isbn10Text.getText()); + if(printHistoryText!=null && !printHistoryText.isDisposed()) + xmlmap.put("printhistory", printHistoryText.getText()); + if(transYearText!=null && !transYearText.isDisposed()) + xmlmap.put("year", transYearText.getText()); + if(transText!=null && !transText.isDisposed()) + xmlmap.put("transcriber", transText.getText()); + if(tgsText!=null && !tgsText.isDisposed()) + xmlmap.put("tgs", tgsText.getText()); + if(affiliationText!=null && !affiliationText.isDisposed()) + xmlmap.put("affiliation", affiliationText.getText()); + } private Label createLabel(Composite comp, String text, int horizSpan){ Label newLabel = new Label(comp, SWT.NONE); =======================================--- /src/main/org/brailleblaster/tpages/TPagesGenerator.java Wed Feb 18 17:52:54 2015 UTC +++ /src/main/org/brailleblaster/tpages/TPagesGenerator.java Thu Feb 19 18:50:16 2015 UTC
@@ -22,6 +22,7 @@ import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; +import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.w3c.dom.Node; @@ -31,7 +32,7 @@ */ public class TPagesGenerator { String programDataPath;- String[] xmlElements = {"title", "gradelevel", "subtitle", "seriesname", "editionname", "authors", "translator", + String[] xmlElements = {"booktitle", "gradelevel", "subtitle", "seriesname", "editionname", "authors", "translator", "pubpermission", "publisher", "location", "website", "copyrighted", "copyrightsymbol", "copyrightdate", "copyrighttext", "repronotice", "isbn13", "isbn10", "printhistory", "year", "transcriber", "tgs", "affiliation"}; String pub, pubLoc, pubWeb, copyright, isbn13 = "", isbn10 = "", printHistory;
@@ -39,7 +40,7 @@ public TPagesGenerator(){ programDataPath = BBIni.getProgramDataPath(); - xmlmap = new HashMap<String, String>(); + xmlmap = getEmptyXmlMap();//= new HashMap<String, String>(); } /* @@ -53,12 +54,48 @@DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = docBuilder.parse(file); doc.getDocumentElement().normalize(); - if(!doc.getFirstChild().getNodeName().equals("tpage")){ - return false; + if(doc.getFirstChild().getNodeType() == Node.ELEMENT_NODE){ + Element rootE = (Element)doc.getFirstChild(); + if(!doc.getFirstChild().getNodeName().equals("dtbook")){ + if(!rootE.getAttribute("type").equals("tpage")) + return false; + } } for (int i = 0; i < xmlElements.length; i++){xmlmap.put(xmlElements[i], doc.getElementsByTagName(xmlElements[i]).item(0).getTextContent());
} + String tempAuthorString = "";+ for (int q = 0; q < doc.getElementsByTagName("author").getLength(); q++){ + tempAuthorString += ";" + doc.getElementsByTagName("author").item(q).getTextContent();
+ }+ while(tempAuthorString.charAt(0)==' ' || tempAuthorString.charAt(0)==';'){
+ tempAuthorString = tempAuthorString.substring(1); + } + xmlmap.put("authors", tempAuthorString); + //This will probably all change when I figure out how to do templates + if(xmlmap.get("booktitle").contains(": ")) + xmlmap.put("booktitle", xmlmap.get("booktitle").replace(": ", "")); + if(xmlmap.get("pubpermission").equals("Published by ")) + xmlmap.put("pubpermission", "0");+ if(xmlmap.get("pubpermission").equals("With permission of the publisher, "))
+ xmlmap.put("pubpermission", "1"); + if(xmlmap.get("copyrighted").equals("Copyright ")) + xmlmap.put("copyrighted", "true"); + if(xmlmap.get("copyrighted").equals("Printed ")) + xmlmap.put("copyrighted", "false"); + if(xmlmap.get("copyrightsymbol").equals("© ")) + xmlmap.put("copyrightsymbol", "true"); + else + xmlmap.put("copyrightsymbol", "false"); + xmlmap.put("isbn13", xmlmap.get("isbn13").replace(" ISBN-13: ", "")); + xmlmap.put("isbn10", xmlmap.get("isbn10").replace(" ISBN-10: ", "")); + if(xmlmap.get("year").contains("Transcribed")){ + xmlmap.put("year", xmlmap.get("year").replace("Transcribed ", "")); + xmlmap.put("year", xmlmap.get("year").replace(" by", "")); + } + xmlmap.put("transcriber", xmlmap.get("transcriber").replace(" ", ""));+ xmlmap.put("tgs", xmlmap.get("tgs").replace("Tactile Graphics by ", "")); //This will need to change when I properly format it
+ } else { return false; } @@ -88,59 +125,95 @@ } /*- * User is using T-Pages for the first time. This will at some point require a String argument for the filename
+ * User is using T-Pages for the first time. */ public boolean createNewTPageXML(String filename){ try{DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument();+ DocumentType docType = doc.getImplementation().createDocumentType("doctype", "-//NISO//DTD dtbook 2005-3//EN", "http://www.daisy.org/z3986/2005/dtbook-2005-3.dtd";);
- Element rootElement = doc.createElement("tpage"); + Element rootElement = doc.createElement("dtbook"); + rootElement.setAttribute("type", "tpage"); doc.appendChild(rootElement); + Element bookElement = doc.createElement("book"); + rootElement.appendChild(bookElement); + + Element levelElement = doc.createElement("level1"); + bookElement.appendChild(levelElement); + Element titleInfo = doc.createElement("titleinfo"); - rootElement.appendChild(titleInfo); + levelElement.appendChild(titleInfo); - titleInfo.appendChild(doc.createElement("title")); - titleInfo.appendChild(doc.createElement("gradelevel")); - titleInfo.appendChild(doc.createElement("subtitle")); - titleInfo.appendChild(doc.createElement("seriesname")); - titleInfo.appendChild(doc.createElement("editionname")); + Element ptag = newPTag(doc, titleInfo); + + Element title = doc.createElement("booktitle"); + ptag.appendChild(title); + Element gradeLevel = doc.createElement("gradelevel"); + ptag.appendChild(gradeLevel); + + newPTag(doc, titleInfo).appendChild(doc.createElement("subtitle")); + + newPTag(doc, titleInfo).appendChild(doc.createElement("seriesname")); + + newPTag(doc, titleInfo).appendChild(doc.createElement("editionname")); + + Element linebreak = doc.createElement("p"); + linebreak.setTextContent("----------------------------------------"); + levelElement.appendChild(linebreak); Element authorInfo = doc.createElement("authorinfo"); - rootElement.appendChild(authorInfo); + levelElement.appendChild(authorInfo); - authorInfo.appendChild(doc.createElement("authors")); - authorInfo.appendChild(doc.createElement("translator")); + newPTag(doc, authorInfo).appendChild(doc.createElement("authors")); + + newPTag(doc, authorInfo).appendChild(doc.createElement("translator")); + + Element linebreak2 = doc.createElement("p"); + linebreak2.setTextContent("----------------------------------------"); + levelElement.appendChild(linebreak2); Element publisherInfo = doc.createElement("publisherinfo"); - rootElement.appendChild(publisherInfo); + levelElement.appendChild(publisherInfo); - publisherInfo.appendChild(doc.createElement("pubpermission")); - publisherInfo.appendChild(doc.createElement("publisher")); - publisherInfo.appendChild(doc.createElement("location")); - publisherInfo.appendChild(doc.createElement("website")); + Element ptag2 = newPTag(doc, publisherInfo); + ptag2.appendChild(doc.createElement("pubpermission")); + ptag2.appendChild(doc.createElement("publisher")); + + newPTag(doc, publisherInfo).appendChild(doc.createElement("location")); + newPTag(doc, publisherInfo).appendChild(doc.createElement("website")); + + Element linebreak3 = doc.createElement("p"); + linebreak3.setTextContent("----------------------------------------"); + levelElement.appendChild(linebreak3); Element printInfo = doc.createElement("printinfo"); - rootElement.appendChild(printInfo); + levelElement.appendChild(printInfo); - printInfo.appendChild(doc.createElement("copyrighted")); - printInfo.appendChild(doc.createElement("copyrightsymbol")); - printInfo.appendChild(doc.createElement("copyrightdate")); - printInfo.appendChild(doc.createElement("copyrighttext")); - printInfo.appendChild(doc.createElement("repronotice")); - printInfo.appendChild(doc.createElement("isbn13")); - printInfo.appendChild(doc.createElement("isbn10")); - printInfo.appendChild(doc.createElement("printhistory")); + Element ptag3 = newPTag(doc, printInfo); + ptag3.appendChild(doc.createElement("copyrighted")); + ptag3.appendChild(doc.createElement("copyrightsymbol")); + ptag3.appendChild(doc.createElement("copyrightdate")); + ptag3.appendChild(doc.createElement("copyrighttext")); + + newPTag(doc, printInfo).appendChild(doc.createElement("repronotice")); + newPTag(doc, printInfo).appendChild(doc.createElement("isbn13")); + newPTag(doc, printInfo).appendChild(doc.createElement("isbn10")); + newPTag(doc, printInfo).appendChild(doc.createElement("printhistory")); + + Element linebreak4 = doc.createElement("p"); + linebreak4.setTextContent("----------------------------------------"); + levelElement.appendChild(linebreak4); Element transcriptionInfo = doc.createElement("transcriptioninfo"); - rootElement.appendChild(transcriptionInfo); + levelElement.appendChild(transcriptionInfo); - transcriptionInfo.appendChild(doc.createElement("year")); - transcriptionInfo.appendChild(doc.createElement("transcriber")); - transcriptionInfo.appendChild(doc.createElement("tgs")); - transcriptionInfo.appendChild(doc.createElement("affiliation")); + newPTag(doc, transcriptionInfo).appendChild(doc.createElement("year"));+ newPTag(doc, transcriptionInfo).appendChild(doc.createElement("transcriber"));
+ newPTag(doc, transcriptionInfo).appendChild(doc.createElement("tgs"));+ newPTag(doc, transcriptionInfo).appendChild(doc.createElement("affiliation"));
TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); @@ -148,6 +221,8 @@ StreamResult result = new StreamResult(new File(filename)); transformer.setOutputProperty(OutputKeys.INDENT, "yes");transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount";, "2"); + transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, docType.getPublicId()); + transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, docType.getSystemId());
transformer.transform(source, result); } catch(ParserConfigurationException e){ @@ -159,21 +234,86 @@ } return true; } + + private Element newPTag(Document doc, Element parent){ + Element ptag = doc.createElement("p"); + parent.appendChild(ptag); + return ptag; + }public boolean saveNewTPage(String filename, HashMap<String, String> newXmlMap){
File file = new File(filename); - if(!checkForFile(filename)) + //if(!checkForFile(filename)) createNewTPageXML(filename); - Set mapSet = newXmlMap.entrySet(); - Iterator iterator = mapSet.iterator(); + /*Set mapSet = newXmlMap.entrySet(); + Iterator iterator = mapSet.iterator();*/ try{DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = docBuilder.parse(file); - while(iterator.hasNext()){ + /*while(iterator.hasNext()){ Map.Entry mapEntry = (Map.Entry)iterator.next();doc.getElementsByTagName((String)mapEntry.getKey()).item(0).setTextContent((String)mapEntry.getValue());
+ }*/ + if(newXmlMap.get("booktitle") != null){ + if(!newXmlMap.get("gradelevel").equals("")){+ doc.getElementsByTagName("booktitle").item(0).setTextContent(newXmlMap.get("booktitle") + ": "); + doc.getElementsByTagName("gradelevel").item(0).setTextContent(newXmlMap.get("gradelevel"));
+ } else {+ doc.getElementsByTagName("booktitle").item(0).setTextContent(newXmlMap.get("booktitle"));
+ } }+ doc.getElementsByTagName("subtitle").item(0).setTextContent(newXmlMap.get("subtitle")); + doc.getElementsByTagName("seriesname").item(0).setTextContent(newXmlMap.get("seriesname")); + doc.getElementsByTagName("editionname").item(0).setTextContent(newXmlMap.get("editionname"));
+ + String[] authors = newXmlMap.get("authors").split(";"); + for (String tempAuthor : authors){ + Element newAuthor = doc.createElement("author"); + newAuthor.setTextContent(tempAuthor);+ newPTag(doc, (Element)doc.getElementsByTagName("authors").item(0)).appendChild(newAuthor);
+ } ++ doc.getElementsByTagName("translator").item(0).setTextContent(newXmlMap.get("translator"));
+ + if(newXmlMap.get("pubpermission").equals("0")){+ doc.getElementsByTagName("pubpermission").item(0).setTextContent("Published by ");
+ } else{+ doc.getElementsByTagName("pubpermission").item(0).setTextContent("With permission of the publisher, ");
+ }+ doc.getElementsByTagName("publisher").item(0).setTextContent(newXmlMap.get("publisher")); + doc.getElementsByTagName("location").item(0).setTextContent(newXmlMap.get("location")); + doc.getElementsByTagName("website").item(0).setTextContent(newXmlMap.get("website"));
+ + if(newXmlMap.get("copyrighted").equals("true")){+ doc.getElementsByTagName("copyrighted").item(0).setTextContent("Copyright ");
+ } else {+ doc.getElementsByTagName("copyrighted").item(0).setTextContent("Printed ");
+ } + if(newXmlMap.get("copyrightsymbol").equals("true")){+ doc.getElementsByTagName("copyrightsymbol").item(0).setTextContent("© ");
+ }+ doc.getElementsByTagName("copyrightdate").item(0).setTextContent(newXmlMap.get("copyrightdate") + " "); + doc.getElementsByTagName("copyrighttext").item(0).setTextContent(newXmlMap.get("copyrighttext")); + doc.getElementsByTagName("repronotice").item(0).setTextContent(newXmlMap.get("repronotice")); + if(newXmlMap.get("isbn13").length() > 1 || newXmlMap.get("isbn10").length() > 1){ + //doc.insertBefore(doc.getElementsByTagName("isbn13").item(0), doc.createTextNode("Transcription of")); //Probably doesn't work
+ } + if(newXmlMap.get("isbn13").length() > 1){+ doc.getElementsByTagName("isbn13").item(0).setTextContent(" ISBN-13: " +newXmlMap.get("isbn13"));
+ } + if(newXmlMap.get("isbn10").length() > 1){+ doc.getElementsByTagName("isbn10").item(0).setTextContent(" ISBN-10: " +newXmlMap.get("isbn10"));
+ }+ doc.getElementsByTagName("printhistory").item(0).setTextContent(newXmlMap.get("printhistory"));
+ if(newXmlMap.get("transcriber").length() > 1){+ doc.getElementsByTagName("year").item(0).setTextContent("Transcribed " + newXmlMap.get("year") + " by"); + doc.getElementsByTagName("transcriber").item(0).setTextContent(" " + newXmlMap.get("transcriber"));
+ } + if(newXmlMap.get("tgs").length()>1){+ doc.getElementsByTagName("tgs").item(0).setTextContent("Tactile Graphics by " + newXmlMap.get("tgs"));
+ }+ doc.getElementsByTagName("affiliation").item(0).setTextContent(newXmlMap.get("affiliation"));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(); @@ -209,6 +349,9 @@ Document doc = docBuilder.parse(book); Node fmNode = doc.getElementsByTagName("frontmatter").item(0); + if(fmNode == null){ + return; + } ///////Title String title = findTitle(doc); @@ -233,7 +376,7 @@ while(authors.charAt(0)==' ' || authors.charAt(0)==';'){ authors = authors.substring(1); } - xmlmap.put("title", title); + xmlmap.put("booktitle", title); xmlmap.put("subtitle", subtitle); xmlmap.put("authors", authors); @@ -295,7 +438,7 @@ tempInt++; }- if(copyYear.length()==4){ //If the copyright year isn't 4 digits, we were likely very off. Throw it all out! + if(copyYear.length()==4){ //If the copyright year isn't 4 digits, we were probably very off. Throw it all out!
xmlmap.put("copyrightdate", copyYear); xmlmap.put("copyrighttext", copyPub); } @@ -420,4 +563,12 @@ public HashMap<String, String> getXmlMap(){ return xmlmap; } + + public HashMap<String, String> getEmptyXmlMap(){ + HashMap<String, String> newMap = new HashMap<String,String>(); + for (int i = 0; i < xmlElements.length; i++){ + newMap.put(xmlElements[i], ""); + } + return newMap; + } } ============================================================================== Revision: 68bdc1590399 Branch: rt2091-tPagesGui Author: Corey Knapp <cknapp.code@xxxxxxxxx> Date: Thu Feb 19 22:06:53 2015 UTC Log: Improved accuracy of autoPopulate https://code.google.com/p/brailleblaster/source/detail?r=68bdc1590399 Modified: /src/main/org/brailleblaster/tpages/TPagesDialog.java /src/main/org/brailleblaster/tpages/TPagesGenerator.java =======================================--- /src/main/org/brailleblaster/tpages/TPagesDialog.java Thu Feb 19 18:50:16 2015 UTC +++ /src/main/org/brailleblaster/tpages/TPagesDialog.java Thu Feb 19 22:06:53 2015 UTC
@@ -42,7 +42,7 @@ HashMap<Text, String> uimap;Text titleText, gradeLevelText, subtitleText, seriesText, editionText, authorText, translatorText, publisherText, pubLocationText, pubWebsiteText, copyDateText, copyText, reproText, isbn13Text, isbn10Text, printHistoryText,
- transYearText, transText, tgsText, affiliationText; + transYearText, transText, tgsText, affiliationText, transNotesText; Combo permissionCombo; Button copyrightButton, copySymbolButton; TPagesGenerator tpGenerator; @@ -184,8 +184,13 @@ Group transNotesGroup = new Group(transNotesComposite, SWT.NONE); transNotesGroup.setLayout(new GridLayout(1,false)); + transNotesGroup.setText("Transcriber's Notes"); - createLabel(transNotesGroup, "Not yet implemented", 1);+ transNotesText = new Text(transNotesGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
+ GridData newData = newTpData(1); + newData.widthHint = 700; + newData.heightHint = 300; + transNotesText.setLayoutData(newData); transNotesTab.setControl(transNotesComposite); ///////////////////////////// @@ -322,7 +327,7 @@ if(copySymbolButton!=null && !copySymbolButton.isDisposed())copySymbolButton.setSelection(xmlmap.get("copyrightsymbol").equals("true"));
if(copyDateText!=null && !copyDateText.isDisposed()) - copyDateText.setText(xmlmap.get("copyrighttext")); + copyDateText.setText(xmlmap.get("copyrightdate")); if(copyText!=null && !copyText.isDisposed()) copyText.setText(xmlmap.get("copyrighttext")); if(reproText!=null && !reproText.isDisposed()) =======================================--- /src/main/org/brailleblaster/tpages/TPagesGenerator.java Thu Feb 19 18:50:16 2015 UTC +++ /src/main/org/brailleblaster/tpages/TPagesGenerator.java Thu Feb 19 22:06:53 2015 UTC
@@ -8,6 +8,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.brailleblaster.BBIni; @@ -24,6 +26,7 @@ import org.w3c.dom.Document; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NodeList; import org.w3c.dom.Node; import org.xml.sax.SAXException; @@ -35,7 +38,7 @@String[] xmlElements = {"booktitle", "gradelevel", "subtitle", "seriesname", "editionname", "authors", "translator", "pubpermission", "publisher", "location", "website", "copyrighted", "copyrightsymbol", "copyrightdate", "copyrighttext", "repronotice", "isbn13", "isbn10", "printhistory", "year", "transcriber", "tgs", "affiliation"}; - String pub, pubLoc, pubWeb, copyright, isbn13 = "", isbn10 = "", printHistory; + String copyright, isbn13 = "", isbn10 = "", printHistoryGuess, titleGuess, authorGuess, publisherGuess, websiteGuess;
private HashMap<String, String> xmlmap; public TPagesGenerator(){ @@ -352,9 +355,21 @@ if(fmNode == null){ return; } + + //////Begin iterating through Head tags + Node headNode = doc.getElementsByTagName("head").item(0); + if(headNode != null) + parseHeadTags(headNode); + + if(publisherGuess != null) + xmlmap.put("publisher", publisherGuess); ///////Title - String title = findTitle(doc); + String title;+ if(titleGuess==null) //Couldn't find anything defined in Head tags. Search for <doctitle>
+ title = findTitle(doc); + else + title = titleGuess; String subtitle = ""; if(title.contains(":")){ //There is probably a subtitle subtitle = title.substring(title.indexOf(":") + 2); @@ -367,7 +382,11 @@ title = title.substring(1); } //////////Authors - String authors = findAuthors(doc); + String authors;+ if(authorGuess == null) //Couldn't find anything defined in Head tags. Search for <docauthor>
+ authors = findAuthors(doc); + else + authors = authorGuess; if(authors.contains("by")){ authors = authors.substring(authors.indexOf("by") + 2); } @@ -382,9 +401,17 @@ ///////Begin iterating through front matter parseFrontMatter(fmNode); + xmlmap.put("isbn13", isbn13); xmlmap.put("isbn10", isbn10); + if(websiteGuess != null){ + xmlmap.put("website", websiteGuess); + } + if(printHistoryGuess != null){ + xmlmap.put("printhistory", printHistoryGuess); + } + if(copyright!=null){ if(copyright.contains("©")){ xmlmap.put("copyrighted", "true"); @@ -438,10 +465,8 @@ tempInt++; }- if(copyYear.length()==4){ //If the copyright year isn't 4 digits, we were probably very off. Throw it all out!
- xmlmap.put("copyrightdate", copyYear); - xmlmap.put("copyrighttext", copyPub); - } + xmlmap.put("copyrightdate", copyYear); + xmlmap.put("copyrighttext", copyPub); } } @@ -459,6 +484,27 @@ } } + private void parseHeadTags(Node head) { + List<Node> children = getAllChildren(head); + NamedNodeMap attrMap; + for(int i = 0; i < children.size(); i++){ + if(children.get(i).getNodeName().equals("meta")){ + attrMap = children.get(i).getAttributes(); + if(attrMap.getNamedItem("name")!=null){ + if(attrMap.getNamedItem("name").getNodeValue().equals("dc:Title")){ + titleGuess = attrMap.getNamedItem("content").getNodeValue(); + } + if(attrMap.getNamedItem("name").getNodeValue().equals("dc:Creator")){ + authorGuess += ";" + attrMap.getNamedItem("content").getNodeValue(); + }+ if(attrMap.getNamedItem("name").getNodeValue().equals("dc:Publisher")){
+ publisherGuess = attrMap.getNamedItem("content").getNodeValue(); + } + } + } + } + } +private List<Node> getAllChildren(Node parent){ // Could likely be made more efficient
List<Node> returnedNodes = new ArrayList<Node>(); NodeList nodes = parent.getChildNodes(); @@ -497,59 +543,46 @@ private void parseFrontMatter(Node parent){ NodeList nodes = parent.getChildNodes();+ Pattern isbn13pattern = Pattern.compile("(?<!\\S)[\\d]+-[\\d]+-[\\d]+-[\\d]+-[\\d]\\b"); + Pattern isbn10pattern = Pattern.compile("(?<!\\S)[\\d]+-[\\d]+-[\\d]+-[\\d]\\b"); + Pattern copyrightpattern1 = Pattern.compile("(Copyright [\\d][\\d][\\d][\\d])"); + Pattern copyrightpattern2 = Pattern.compile("© [\\d][\\d][\\d][\\d]"); // Only way I can get it to work
+ Pattern websitepattern = Pattern.compile("www[.][\\w]*[.]com");+ Pattern printpattern = Pattern.compile("[\\d]+ [\\d]+ [\\d]+ [\\d]+ [\\d]+ [\\d]+");
for(int i = 0; i < nodes.getLength(); i++){ Node tempNode = nodes.item(i); if(tempNode.getNodeName().equals("#text")){ String nodeVal = tempNode.getNodeValue(); //////Copyright- if(nodeVal.contains("Copyright") || nodeVal.contains("©") || nodeVal.contains("©")){
+ Matcher copyMatcher1 = copyrightpattern1.matcher(nodeVal); + Matcher copyMatcher2 = copyrightpattern2.matcher(nodeVal); + if(copyMatcher1.find()){ copyright = nodeVal; + } else if (copyMatcher2.find()){ + copyright = nodeVal; } //////ISBN - if(nodeVal.contains("ISBN-")){ - if(nodeVal.contains("ISBN-13")){- for(int q = nodeVal.indexOf("ISBN-13") + 8; q < nodeVal.length(); q++){
- if(Character.isDigit(nodeVal.charAt(q))||nodeVal.charAt(q) == '-'){ - isbn13 += nodeVal.charAt(q); - } - if(nodeVal.charAt(q)==' ' && !isbn13.equals("")){ - break; - } - } - } - if(nodeVal.contains("ISBN-10")){- for(int q = nodeVal.indexOf("ISBN-10") + 8; q < nodeVal.length(); q++){
- if(Character.isDigit(nodeVal.charAt(q))||nodeVal.charAt(q) == '-'){ - isbn10 += nodeVal.charAt(q); - } - if(nodeVal.charAt(q)==' ' && !isbn10.equals("")){ - break; - } - } - } - } else if (nodeVal.contains("ISBN")){ - String tempIsbn = ""; - int numbers = 0; - for(int q = nodeVal.indexOf("ISBN") + 4; q < nodeVal.length(); q++){ - if(Character.isDigit(nodeVal.charAt(q))){ - tempIsbn += nodeVal.charAt(q); - numbers++; - } - if(nodeVal.charAt(q)=='-'){ - tempIsbn += nodeVal.charAt(q); - } - if(nodeVal.charAt(q)==' '&&!tempIsbn.equals("")){ - break; - } - } - if(numbers==13){ - isbn13 = tempIsbn; - } - if(numbers==10){ - isbn10 = tempIsbn; - } - + Matcher isbn13Matcher = isbn13pattern.matcher(nodeVal); + if(isbn13Matcher.find()){ + isbn13 = isbn13Matcher.group(); + } + + Matcher isbn10Matcher = isbn10pattern.matcher(nodeVal); + if(isbn10Matcher.find()){ + isbn10 = isbn10Matcher.group(); + } + + //////Website + Matcher websiteMatcher = websitepattern.matcher(nodeVal); + if(websiteMatcher.find()){ + websiteGuess = websiteMatcher.group(); + } + + ////Print History + Matcher printMatcher = printpattern.matcher(nodeVal); + if(printMatcher.find()){ + printHistoryGuess = nodeVal; } }