@Test public void testWritePackage() throws Exception { CejshConfig cejshConfig = new CejshConfig(); CejshBuilder cb = new CejshBuilder(cejshConfig, appConfig.getExportOptions()); CejshContext ctx = new CejshContext(temp.getRoot(), new CejshStatusHandler(), cejshConfig, appConfig.getExportOptions()); cb.setTitle(new Title()); cb.getTitle().setIssn("1111-1111"); cb.setVolume(new Volume()); cb.getVolume().setVolumeNumber("2"); cb.getVolume().setVolumeId("uuid-volume"); cb.getVolume().setYear("1980"); cb.setIssue(new Issue()); cb.getIssue().setIssn("0231-5955"); cb.getIssue().setIssueNumber("3"); cb.getIssue().setIssueId("uuid-issue"); Document articleDoc = cb.getDocumentBuilder().parse(CejshBuilderTest.class.getResource("article_mods.xml").toExternalForm()); Article addArticle = cb.addArticle(articleDoc, DigitalObjectElement.NULL, ctx); assertNotNull(addArticle); assertTrue(addArticle.isReviewed()); File resultPkg = cb.writePackage(DigitalObjectElement.NULL, Arrays.asList(addArticle), ctx); assertTrue(ctx.getStatus().isOk()); assertNotNull(resultPkg); assertTrue(resultPkg.isDirectory()); assertTrue(new File(resultPkg.getAbsolutePath() + ".zip").exists()); assertTrue(new File(resultPkg, CejshBuilder.IMPORT_PROPERTIES_FILENAME).exists()); assertTrue(new File(new File(resultPkg, CejshBuilder.IMPORTS_NEW_FILENAME), CejshBuilder.P0XML_FILENAME).exists()); }
public File writePackage(DigitalObjectElement packageElm, List<Article> articles, CejshContext p) { if (articles == null || articles.isEmpty()) { return null; } File packageFolder = null; try { Document doc = mergeElements(articles); String pkgName = createPackageName(); packageFolder = ExportUtils.createFolder(p.getOutput(), pkgName, options.isOverwritePackage()); File importFolder = new File(packageFolder, IMPORTS_NEW_FILENAME); importFolder.mkdirs(); writeProperties(packageFolder, articles.size()); File p0xml = new File(importFolder, P0XML_FILENAME); DOMSource domSource = new DOMSource(doc); TransformErrorListener cejshXslErrors = createCejshXml(domSource, new StreamResult(p0xml)); if (!cejshXslErrors.getErrors().isEmpty()) { p.getStatus().error(packageElm, "Validation error!", cejshXslErrors.getErrors().toString(), null); return packageFolder; } List<String> validationErrors = validateCejshXml(new StreamSource(p0xml)); if (validationErrors.isEmpty()) { writeZip(packageFolder, p.getStatus(), packageElm); } else { p.getStatus().error(packageElm, "Validation error!", ExportUtils.toString(validationErrors), null); } } catch (Exception ex) { p.getStatus().error(packageElm, "Unexpected error!", null, ex); } return packageFolder; }
CejshBuilder { public File writePackage(DigitalObjectElement packageElm, List<Article> articles, CejshContext p) { if (articles == null || articles.isEmpty()) { return null; } File packageFolder = null; try { Document doc = mergeElements(articles); String pkgName = createPackageName(); packageFolder = ExportUtils.createFolder(p.getOutput(), pkgName, options.isOverwritePackage()); File importFolder = new File(packageFolder, IMPORTS_NEW_FILENAME); importFolder.mkdirs(); writeProperties(packageFolder, articles.size()); File p0xml = new File(importFolder, P0XML_FILENAME); DOMSource domSource = new DOMSource(doc); TransformErrorListener cejshXslErrors = createCejshXml(domSource, new StreamResult(p0xml)); if (!cejshXslErrors.getErrors().isEmpty()) { p.getStatus().error(packageElm, "Validation error!", cejshXslErrors.getErrors().toString(), null); return packageFolder; } List<String> validationErrors = validateCejshXml(new StreamSource(p0xml)); if (validationErrors.isEmpty()) { writeZip(packageFolder, p.getStatus(), packageElm); } else { p.getStatus().error(packageElm, "Validation error!", ExportUtils.toString(validationErrors), null); } } catch (Exception ex) { p.getStatus().error(packageElm, "Unexpected error!", null, ex); } return packageFolder; } }
CejshBuilder { public File writePackage(DigitalObjectElement packageElm, List<Article> articles, CejshContext p) { if (articles == null || articles.isEmpty()) { return null; } File packageFolder = null; try { Document doc = mergeElements(articles); String pkgName = createPackageName(); packageFolder = ExportUtils.createFolder(p.getOutput(), pkgName, options.isOverwritePackage()); File importFolder = new File(packageFolder, IMPORTS_NEW_FILENAME); importFolder.mkdirs(); writeProperties(packageFolder, articles.size()); File p0xml = new File(importFolder, P0XML_FILENAME); DOMSource domSource = new DOMSource(doc); TransformErrorListener cejshXslErrors = createCejshXml(domSource, new StreamResult(p0xml)); if (!cejshXslErrors.getErrors().isEmpty()) { p.getStatus().error(packageElm, "Validation error!", cejshXslErrors.getErrors().toString(), null); return packageFolder; } List<String> validationErrors = validateCejshXml(new StreamSource(p0xml)); if (validationErrors.isEmpty()) { writeZip(packageFolder, p.getStatus(), packageElm); } else { p.getStatus().error(packageElm, "Validation error!", ExportUtils.toString(validationErrors), null); } } catch (Exception ex) { p.getStatus().error(packageElm, "Unexpected error!", null, ex); } return packageFolder; } CejshBuilder(CejshConfig config, ExportOptions options); }
CejshBuilder { public File writePackage(DigitalObjectElement packageElm, List<Article> articles, CejshContext p) { if (articles == null || articles.isEmpty()) { return null; } File packageFolder = null; try { Document doc = mergeElements(articles); String pkgName = createPackageName(); packageFolder = ExportUtils.createFolder(p.getOutput(), pkgName, options.isOverwritePackage()); File importFolder = new File(packageFolder, IMPORTS_NEW_FILENAME); importFolder.mkdirs(); writeProperties(packageFolder, articles.size()); File p0xml = new File(importFolder, P0XML_FILENAME); DOMSource domSource = new DOMSource(doc); TransformErrorListener cejshXslErrors = createCejshXml(domSource, new StreamResult(p0xml)); if (!cejshXslErrors.getErrors().isEmpty()) { p.getStatus().error(packageElm, "Validation error!", cejshXslErrors.getErrors().toString(), null); return packageFolder; } List<String> validationErrors = validateCejshXml(new StreamSource(p0xml)); if (validationErrors.isEmpty()) { writeZip(packageFolder, p.getStatus(), packageElm); } else { p.getStatus().error(packageElm, "Validation error!", ExportUtils.toString(validationErrors), null); } } catch (Exception ex) { p.getStatus().error(packageElm, "Unexpected error!", null, ex); } return packageFolder; } CejshBuilder(CejshConfig config, ExportOptions options); XPathExpression getDateIssuedPath(); XPathExpression getIssnPath(); XPathExpression getPartNumberPath(); XPathExpression getReviewedArticlePath(); Article addArticle(DigitalObjectElement article, CejshContext p); File writePackage(DigitalObjectElement packageElm, List<Article> articles, CejshContext p); Title getTitle(); void setTitle(Title title); Volume getVolume(); void setVolume(Volume volume); Issue getIssue(); void setIssue(Issue issue); }
CejshBuilder { public File writePackage(DigitalObjectElement packageElm, List<Article> articles, CejshContext p) { if (articles == null || articles.isEmpty()) { return null; } File packageFolder = null; try { Document doc = mergeElements(articles); String pkgName = createPackageName(); packageFolder = ExportUtils.createFolder(p.getOutput(), pkgName, options.isOverwritePackage()); File importFolder = new File(packageFolder, IMPORTS_NEW_FILENAME); importFolder.mkdirs(); writeProperties(packageFolder, articles.size()); File p0xml = new File(importFolder, P0XML_FILENAME); DOMSource domSource = new DOMSource(doc); TransformErrorListener cejshXslErrors = createCejshXml(domSource, new StreamResult(p0xml)); if (!cejshXslErrors.getErrors().isEmpty()) { p.getStatus().error(packageElm, "Validation error!", cejshXslErrors.getErrors().toString(), null); return packageFolder; } List<String> validationErrors = validateCejshXml(new StreamSource(p0xml)); if (validationErrors.isEmpty()) { writeZip(packageFolder, p.getStatus(), packageElm); } else { p.getStatus().error(packageElm, "Validation error!", ExportUtils.toString(validationErrors), null); } } catch (Exception ex) { p.getStatus().error(packageElm, "Unexpected error!", null, ex); } return packageFolder; } CejshBuilder(CejshConfig config, ExportOptions options); XPathExpression getDateIssuedPath(); XPathExpression getIssnPath(); XPathExpression getPartNumberPath(); XPathExpression getReviewedArticlePath(); Article addArticle(DigitalObjectElement article, CejshContext p); File writePackage(DigitalObjectElement packageElm, List<Article> articles, CejshContext p); Title getTitle(); void setTitle(Title title); Volume getVolume(); void setVolume(Volume volume); Issue getIssue(); void setIssue(Issue issue); static final String NS_BWMETA105; }