diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandlerWrapper.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandlerWrapper.java new file mode 100644 index 000000000..9aa419a3f --- /dev/null +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandlerWrapper.java @@ -0,0 +1,54 @@ +/* + * Copyright 2024 hbz + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.metafacture.biblio.marc21; + + +import org.metafacture.framework.FluxCommand; +import org.metafacture.framework.ObjectReceiver; +import org.metafacture.framework.StreamPipe; +import org.metafacture.framework.StreamReceiver; +import org.metafacture.framework.annotations.Description; +import org.metafacture.framework.annotations.In; +import org.metafacture.framework.annotations.Out; +import org.metafacture.framework.helpers.DefaultStreamPipe; + + +/** + * Acts as a wrapper: pipes input to Marc21Encoder which output is piped to Marc21Decoder which output is piped to MarcXmlHandler. + * + * @author Pascal Christoph (dr0i) + * + */ +@In(StreamReceiver.class) +@Out(String.class) +@Description("Encodes MARC21 records as MARCXML. Similar to encode-marcxml but safer e.g. when the 'leader' has to be computed.") +@FluxCommand("encode-marc21xml") +public class MarcXmlHandlerWrapper extends DefaultStreamPipe> { + private final Marc21Decoder marc21Decoder = new Marc21Decoder(); + private final MarcXmlEncoder marcXmlEncoder = new MarcXmlEncoder(); + + public MarcXmlHandlerWrapper() { + this(new Marc21Encoder()); + + } + public MarcXmlHandlerWrapper(StreamPipe> encoder) { + marc21Decoder.setEmitLeaderAsWhole(true); + marc21Decoder.setReceiver(marcXmlEncoder); + this.setReceiver(marc21Decoder); + } + + +} diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java index fcc19d492..5d74eebc5 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java @@ -58,9 +58,10 @@ public final class Marc21DecoderTest { // private static final String RECORD="03994nas a2200913 c 4500001001000000003000700010005001700017007000300034008004100037016002200078016001700100022001400117022001400131022001400145022001400159022001400173022001400187022001400201022001400215022001400229022001400243022001400257022001400271030001000285035002000295035002100315040002800336041000800364044001000372082002900382084001300411084002700424084004400451210002700495245011300522246000800635246002800643246001800671246002200689246005300711246003200764246004700796246003400843246002800877246003100905246004100936246001700977246002800994246003101022260003101053362001301084500003401097501033301131515003701464550003301501555010101534591004801635650005701683650005901740650005701799650005901856689005501915689005701970689001902027689005502046689005702101689001902158775007002177775008602247780007002333780008002403780007402483780010502557780008402662780006902746780008002815780009902895780008602994010000445DE-10120121114152453.0tu991118c19479999ne u||p|r ||| 0||||0eng c7 2DE-101a0100004457 2DE-600a60-7 a0006-3002 a0005-2728 a0005-2736 a0304-4165 a0167-4838 a1388-1981 a0167-4889 a0167-4781 a0304-419X a1570-9639 a0925-4439 a1874-9399 aBBACA a(DE-599)ZDB60-7 a(OCoLC)183277993 a9001bgercDE-101d0029 aeng cXA-NL74a570a540qDE-600222sdnb a122ssgn a570a540qDE-6002sdnb aHMZ bio 1031144/1145rotaWA 15000]2rvk10aBiochim. Biophys. Acta10aBiochimica et biophysica actabBBA ; international journal of biochemistry, biophysics and molecular biology13aBBA13aMolecular cell research13aBioenergetics13aReviews on cancer13aBiochimica et biophysica acta / General subjects13aLipids and lipid metabolism13aProtein structure and molecular enzymology13aGene structure and expression13aProteins and proteomics13aMolecular basis of disease13aMolecular and cell biology of lipids13aBiomembranes13aReviews on biomembranes13aGene regulatory mechanisms3 aAmsterdam [u.a.]bElsevier0 a1.1947 - aRepr.: New York, NY : Johnson aAb 1990 ersch. die früheren Unterreihen und neuere Sektionen wechselweise in einzelnen Bd.; neue Sektion ab 1990: Molecular basis of disease; ab 1998: Molecular and cell biology of lipids; ab 2002: Proteins and proteomics; Reviews in biomembranes ab 2002 enth. in Biomembranes; neue Sektion ab 2008: Gene regulatory mechanisms a1966 - 1967 auch Issue-Zählung aHrsg. früher: W.T. Astbury8 aIndex 1972/2000(2002) zur Unterreihe \"Reviews on biomembranes\" in: 1516.2002,1; 51/100.1961/65 - aAutopsie(keine 4245)Kopie bei 282711;s.Abl. 70(DE-588)4006891-20(DE-101)040068919aBiophysik2gnd 70(DE-588)4067488-50(DE-101)040674886aZeitschrift2gnd 70(DE-588)4006777-40(DE-101)040067777aBiochemie2gnd 70(DE-588)4067488-50(DE-101)040674886aZeitschrift2gnd000(DE-588)4006891-20(DE-101)040068919DsaBiophysik010(DE-588)4067488-50(DE-101)040674886DsaZeitschrift0 5DE-6005DE-600100(DE-588)4006777-40(DE-101)040067777DsaBiochemie110(DE-588)4067488-50(DE-101)040674886DsaZeitschrift1 5DE-6005DE-60008iCD-ROM-Ausg.tBBA on CD-ROMw(DE-600)1434539-0w(DE-101)01928629508iOnline-Ausg.tBiochimica et biophysica actaw(DE-600)1460387-1w(DE-101)01953770000iDarin aufgeg.tBioenergeticsw(DE-600)282711-6w(DE-101)01175997600iDarin aufgeg.tMolecular cell researchw(DE-600)283444-3w(DE-101)01176430900iDarin aufgeg.tReviews on cancerw(DE-600)192424-2w(DE-101)01107018800iDarin aufgeg.tBiochimica et biophysica acta / General subjectsw(DE-600)840755-1w(DE-101)01452479100iDarin aufgeg.tLipids and lipid metabolismw(DE-600)282393-7w(DE-101)01175787600iDarin aufgeg.tBiomembranesw(DE-600)282512-0w(DE-101)01175877500iDarin aufgeg.tReviews on biomembranesw(DE-600)195188-9w(DE-101)01109503200iDarin aufgeg.tProtein structure and molecular enzymologyw(DE-600)283435-2w(DE-101)01176425200iDarin aufgeg.tGene structure and expressionw(DE-600)283437-6w(DE-101)011764260"; - // private static final String RECORD= "02602pam a2200529 c 4500001001000000003000700010005001700017007000300034008004100037015003400078016002200112020005800134035002500192040003500217041000800252044001000260084001900270090000600289100006100295245012400356260011200480300002200592490008100614600007900695600007000774600007100844650005400915650007400969650005401043650007401097650005401171650007401225689007701299689005201376689007201428689001901500689006801519689005201587689007201639689001901711689006901730689005201799689007201851689001901923830012301942925000702065\u001E946638705\u001EDE-101\u001E20070429135622.0\u001Etu\u001E960123s2004 gw |||||r|||| 00||||eng \u001E \u001Fa05,A03,2104\u001Fz96,N47,0454\u001F2dnb\u001E7 \u001F2DE-101\u001Fa946638705\u001E \u001Fa0820431125\u001FcPp. : EUR 56.70, sfr 83.00\u001F90-8204-3112-5\u001E \u001Fa(DE-599)DNB946638705\u001E \u001Fa1140\u001Fbger\u001FcDE-101\u001Fd9999\u001Ferakwb\u001E \u001Faeng\u001E \u001FcXA-DE\u001E \u001Fa820\u001Fa890\u001F2sdnb\u001E \u001Fab\u001E1 \u001FaKim, Soonsik\u001F4aut\u001F0(DE-588a)11515454X\u001F0(DE-101)11515454X\u001E10\u001FaColonial and post-colonial discourse in the novels of Yo§am Sang-So§ap, Chinua Achebe and Salman Rushdie\u001FcSoonsik Kim\u001E3 \u001FaNew York\u001FaWashington, D.C./Baltimore\u001FaBern\u001FaFrankfurt am Main\u001FaBerlin\u001FaBrussels\u001FaVienna\u001FaOxford\u001FbLang\u001Fc2004\u001E \u001FaVI, 214 S.\u001Fc24 cm\u001E1 \u001FaComparative cultures and literatures\u001FvVol. 94201 Literaturverz. S. 197 - 207\u001E17\u001F0(DE-588c)4806527-4\u001F0(DE-101)129612111\u001F2swd\u001FaYo§am, Sang-so§ap\u001Fd1897-1963\u001E17\u001F0(DE-588c)4084672-6\u001F0(DE-101)118646680\u001F2swd\u001FaAchebe, Chinua\u001Fd1930-\u001E17\u001F0(DE-588c)4217069-2\u001F0(DE-101)118873520\u001F2swd\u001FaRushdie, Salman\u001Fd1947-\u001E 7\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001F2swd\u001FaRoman\u001E 7\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001F2swd\u001FaPostkolonialismus \u001E 7\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001F2swd\u001FaRoman\u001E 7\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001F2swd\u001FaPostkolonialismus \u001E 7\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001F2swd\u001FaRoman\u001E 7\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001F2swd\u001FaPostkolonialismus \u001E00\u001FAp\u001F0(DE-588c)4806527-4\u001F0(DE-101)129612111\u001FaYo§am, Sang-so§ap\u001Fd1897-1963\u001E01\u001FAs\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001FaRoman\u001E02\u001FAs\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001FaPostkolonialismus \u001E0 \u001F5DE-101\u001F5DE-101\u001E10\u001FAp\u001F0(DE-588c)4084672-6\u001F0(DE-101)118646680\u001FaAchebe, Chinua\u001Fd1930-\u001E11\u001FAs\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001FaRoman\u001E12\u001FAs\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001FaPostkolonialismus \u001E1 \u001F5DE-101\u001F5DE-101\u001E20\u001FAp\u001F0(DE-588c)4217069-2\u001F0(DE-101)118873520\u001FaRushdie, Salman\u001Fd1947-\u001E21\u001FAs\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001FaRoman\u001E22\u001FAs\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001FaPostkolonialismus \u001E2 \u001F5DE-101\u001F5DE-101\u001E 0\u001FaComparative cultures and literatures\u001FvVol. 94201 Literaturverz. S. 197 - 207\u001Fw(DE-101)025300458\u001Fw(DE-600)2126467-3\u001F919\u001Er \u001Fara\u001E\u001D"; + private static final String RECORD= "02602pam a2200529 c 4500001001000000003000700010005001700017007000300034008004100037015003400078016002200112020005800134035002500192040003500217041000800252044001000260084001900270090000600289100006100295245012400356260011200480300002200592490008100614600007900695600007000774600007100844650005400915650007400969650005401043650007401097650005401171650007401225689007701299689005201376689007201428689001901500689006801519689005201587689007201639689001901711689006901730689005201799689007201851689001901923830012301942925000702065\u001E946638705\u001EDE-101\u001E20070429135622.0\u001Etu\u001E960123s2004 gw |||||r|||| 00||||eng \u001E \u001Fa05,A03,2104\u001Fz96,N47,0454\u001F2dnb\u001E7 \u001F2DE-101\u001Fa946638705\u001E \u001Fa0820431125\u001FcPp. : EUR 56.70, sfr 83.00\u001F90-8204-3112-5\u001E \u001Fa(DE-599)DNB946638705\u001E \u001Fa1140\u001Fbger\u001FcDE-101\u001Fd9999\u001Ferakwb\u001E \u001Faeng\u001E \u001FcXA-DE\u001E \u001Fa820\u001Fa890\u001F2sdnb\u001E \u001Fab\u001E1 \u001FaKim, Soonsik\u001F4aut\u001F0(DE-588a)11515454X\u001F0(DE-101)11515454X\u001E10\u001FaColonial and post-colonial discourse in the novels of Yo§am Sang-So§ap, Chinua Achebe and Salman Rushdie\u001FcSoonsik Kim\u001E3 \u001FaNew York\u001FaWashington, D.C./Baltimore\u001FaBern\u001FaFrankfurt am Main\u001FaBerlin\u001FaBrussels\u001FaVienna\u001FaOxford\u001FbLang\u001Fc2004\u001E \u001FaVI, 214 S.\u001Fc24 cm\u001E1 \u001FaComparative cultures and literatures\u001FvVol. 94201 Literaturverz. S. 197 - 207\u001E17\u001F0(DE-588c)4806527-4\u001F0(DE-101)129612111\u001F2swd\u001FaYo§am, Sang-so§ap\u001Fd1897-1963\u001E17\u001F0(DE-588c)4084672-6\u001F0(DE-101)118646680\u001F2swd\u001FaAchebe, Chinua\u001Fd1930-\u001E17\u001F0(DE-588c)4217069-2\u001F0(DE-101)118873520\u001F2swd\u001FaRushdie, Salman\u001Fd1947-\u001E 7\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001F2swd\u001FaRoman\u001E 7\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001F2swd\u001FaPostkolonialismus \u001E 7\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001F2swd\u001FaRoman\u001E 7\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001F2swd\u001FaPostkolonialismus \u001E 7\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001F2swd\u001FaRoman\u001E 7\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001F2swd\u001FaPostkolonialismus \u001E00\u001FAp\u001F0(DE-588c)4806527-4\u001F0(DE-101)129612111\u001FaYo§am, Sang-so§ap\u001Fd1897-1963\u001E01\u001FAs\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001FaRoman\u001E02\u001FAs\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001FaPostkolonialismus \u001E0 \u001F5DE-101\u001F5DE-101\u001E10\u001FAp\u001F0(DE-588c)4084672-6\u001F0(DE-101)118646680\u001FaAchebe, Chinua\u001Fd1930-\u001E11\u001FAs\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001FaRoman\u001E12\u001FAs\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001FaPostkolonialismus \u001E1 \u001F5DE-101\u001F5DE-101\u001E20\u001FAp\u001F0(DE-588c)4217069-2\u001F0(DE-101)118873520\u001FaRushdie, Salman\u001Fd1947-\u001E21\u001FAs\u001F0(DE-588c)4050479-7\u001F0(DE-101)040504794\u001FaRoman\u001E22\u001FAs\u001F0(DE-588c)4681702-5\u001F0(DE-101)964233509\u001FaPostkolonialismus \u001E2 \u001F5DE-101\u001F5DE-101\u001E 0\u001FaComparative cultures and literatures\u001FvVol. 94201 Literaturverz. S. 197 - 207\u001Fw(DE-101)025300458\u001Fw(DE-600)2126467-3\u001F919\u001Er \u001Fara\u001E\u001D"; private Marc21Decoder marc21Decoder; - private static String RECORD=""; + private MarcXmlHandlerWrapper marcXmlHandlerWrapper; + // private static String RECORD=""; @Mock private ObjectReceiver receiver; @@ -68,18 +69,22 @@ public final class Marc21DecoderTest { @Before public void setup() { MockitoAnnotations.initMocks(this); - HttpOpener httpOpener = new HttpOpener(); - LineReader lineReader = new LineReader(); - httpOpener.setReceiver(lineReader); - marc21Decoder = new Marc21Decoder(); - Marc21Encoder marc21Encoder = new Marc21Encoder(); + // HttpOpener httpOpener = new HttpOpener(); + // LineReader lineReader = new LineReader(); + // httpOpener.setReceiver(lineReader); + marc21Decoder = new Marc21Decoder(); + /* Marc21Encoder marc21Encoder = new Marc21Encoder(); marc21Encoder.setReceiver(receiver); - marc21Decoder.setReceiver(marc21Encoder); - lineReader.setReceiver(marc21Decoder); + marc21Decoder.setReceiver(marc21Encoder);*/ + // lineReader.setReceiver(marc21Decoder); - httpOpener.process("https://raw.githubusercontent.com/gbv/Catmandu-Tutorial/master/data/marc.mrc"); - // marc21Decoder.setReceiver(receiver); + marcXmlHandlerWrapper =new MarcXmlHandlerWrapper(); + + marc21Decoder.setReceiver(marcXmlHandlerWrapper); + + // httpOpener.process("https://raw.githubusercontent.com/gbv/Catmandu-Tutorial/master/data/marc.mrc"); + } @After