Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added factory pattern in dataImport and decorator pattern in pages #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 12 additions & 30 deletions src/edu/indiana/dlib/catalog/dataimport/DataImportProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,17 @@ public File getFile() {
return fileToImport;
}

//create a new Records object by using parseFactory
//based on the type of the file
public void setFile(File file, String originalName) throws Exception {
fileToImport = file;
originalFilename = originalName;
if (originalName.endsWith(".xml")) {
try {
parseFilemakerFile();
} catch (Exception ex) {
// not a filemaker file
records = null;
throw ex;
}
} else if (originalName.endsWith("xls") || originalName.endsWith("xlsx")) {
try {
parseSpreadsheetFile();
} catch (Exception ex) {
// not a parsable spreadsheet
records = null;
throw ex;
}
}

ParseFactory factory = new ParseFactory();
records = factory.getRecords(file,originalName);

if(records == null) {
throw new Exception("Problem in parsing");
}

}

public void setRecordImportOperation(RecordImportOperation op) {
Expand All @@ -102,17 +93,6 @@ public void setRecordImportOperation(RecordImportOperation op) {
public RecordImportOperation getRecordImportOperation() {
return importOperation;
}

private void parseFilemakerFile() throws Exception {
// try it as a filemaker database
FilemakerXML filemaker = new FilemakerXML(fileToImport);
records = filemaker;
}

private void parseSpreadsheetFile() throws InvalidFormatException, IOException {
SpreadsheetRecords spreadsheet = new SpreadsheetRecords(fileToImport);
records = spreadsheet;
}

public Records getRecords() {
return records;
Expand Down Expand Up @@ -140,3 +120,5 @@ public static void writeStreamToFile(InputStream is, File file) throws IOExcepti
outputChannel.close();
}
}


31 changes: 31 additions & 0 deletions src/edu/indiana/dlib/catalog/dataimport/ParseFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package edu.indiana.dlib.catalog.dataimport;

import java.io.File;

import edu.indiana.dlib.catalog.dataimport.filemaker.FilemakerXML;
import edu.indiana.dlib.catalog.dataimport.spreadsheet.SpreadsheetRecords;

//creates an object based on given file type and return the object
public class ParseFactory {

public Records getRecords(File file, String originalName) {
Records records = null;
try {

if (originalName.endsWith(".xml")) {
records = new FilemakerXML(file);
}else if (originalName.endsWith("xls") || originalName.endsWith("xlsx")) {

records = new SpreadsheetRecords(file);
}


}catch (Exception ex) {
// not a parsable spreadsheet or filemaker file
records = null;
}
return records;

}

}
17 changes: 11 additions & 6 deletions src/edu/indiana/dlib/catalog/pages/BorderPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

import edu.indiana.dlib.catalog.accesscontrol.AuthenticationException;
import edu.indiana.dlib.catalog.accesscontrol.UserInfo;
import edu.indiana.dlib.catalog.pages.decorators.BreadcrumbDecorator;
import edu.indiana.dlib.catalog.pages.decorators.RootMenuDecorator;
import edu.indiana.dlib.catalog.pages.decorators.TitleDecorator;

/**
* A template that contains the header and footer and all
Expand Down Expand Up @@ -91,12 +94,14 @@ public boolean onSecurityCheck() {
return true;
}

public void onRender() {
super.onRender();
rootMenu = getMenu();
breadcrumbs = getBreadcrumbs();
title = getTitle();
}
public void onRender() {
new RootMenuDecorator(getMenu(),
new BreadcrumbDecorator(getBreadcrumbs(),
new TitleDecorator(getTitle(), this)
)
).onRender();
super.onRender();
}

protected Menu getMenu() {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package edu.indiana.dlib.catalog.pages.decorators;

import org.apache.click.Page;

public class BreadcrumbDecorator extends Page {
public String breadcrumb;
private Page p;

public BreadcrumbDecorator(String breadcrumb, Page p) {
this.breadcrumb = breadcrumb;
this.p = p;
}

public void onRender() {
p.onRender();
// Additional logic for rendering the breadcrumb goes here
super.onRender();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package edu.indiana.dlib.catalog.pages.decorators;

import org.apache.click.Page;
import org.apache.click.extras.control.Menu;

public class RootMenuDecorator extends Page {
public Menu rootMenu;
private Page p;

public RootMenuDecorator(Menu rootMenu, Page p) {
this.rootMenu = rootMenu;
this.p = p;
}

public void onRender() {
p.onRender();
// Additional logic for rendering the root menu
super.onRender();
}
}
21 changes: 21 additions & 0 deletions src/edu/indiana/dlib/catalog/pages/decorators/TitleDecorator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.indiana.dlib.catalog.pages.decorators;

import org.apache.click.Page;

public class TitleDecorator extends Page {
public String title;
private Page p;

public TitleDecorator(String title, Page p) {
this.title = title;
this.p = p;
}

public void onRender() {
p.onRender();
// Any additional logic for rending the title goes here

// Render the title
super.onRender();
}
}