Search in sources :

Example 76 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project step by STEPBible.

the class JSwordPassageServiceImplTest method testComparing.

/**
 * tests that the XSLT transformation is handled correctly
 *
 * @throws BookException      uncaught exception
 * @throws NoSuchKeyException uncaught exception
 * @throws IOException        uncaught exception
 * @throws JDOMException      uncaught exception
 */
@Test
public void testComparing() throws BookException, NoSuchKeyException, JDOMException, IOException {
    final Book currentBook = Books.installed().getBook("ESV_th");
    final Book secondaryBook = Books.installed().getBook("KJV");
    final String reference = "Psalm.3";
    final BookData bookData = new BookData(new Book[] { currentBook, secondaryBook }, currentBook.getKey(reference), true);
    final Element osisFragment = bookData.getOsisFragment();
    final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
    LOGGER.info(xmlOutputter.outputString(osisFragment));
    // do the test
    final List<LookupOption> options = new ArrayList<LookupOption>();
    final String osisText = this.jsi.getInterleavedVersions(new String[] { currentBook.getInitials(), secondaryBook.getInitials() }, reference, options, InterlinearMode.INTERLEAVED_COMPARE, "en").getValue();
    final SAXBuilder sb = new SAXBuilder();
    final Document d = sb.build(new StringReader(osisText));
    LOGGER.info("\n {}", xmlOutputter.outputString(d));
    Assert.assertTrue(osisText.contains("span"));
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) LookupOption(com.tyndalehouse.step.core.models.LookupOption) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) BookData(org.crosswire.jsword.book.BookData) Document(org.jdom2.Document) Test(org.junit.Test)

Example 77 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project plexus-containers by codehaus-plexus.

the class AbstractMerger method mergeDescriptors.

public void mergeDescriptors(File outputDescriptor, List<File> descriptors) throws IOException {
    SAXBuilder builder = new SAXBuilder(new XMLReaderSAX2Factory(false, Driver.class.getName()));
    Document finalDoc = null;
    for (File f : descriptors) {
        try {
            Document doc = builder.build(f);
            if (finalDoc != null) {
                // Last specified has dominance
                finalDoc = merge(doc, finalDoc);
            } else {
                finalDoc = doc;
            }
        } catch (JDOMException e) {
            throw new IOException("Invalid input descriptor for merge: " + f + " --> " + e.getMessage());
        } catch (MergeException e) {
            throw new IOException("Error merging descriptor: " + f + " --> " + e.getMessage());
        }
    }
    if (finalDoc != null) {
        try {
            writeMergedDocument(finalDoc, outputDescriptor);
        } catch (IOException e) {
            throw new IOException("Error writing merged descriptor: " + outputDescriptor);
        }
    }
}
Also used : XMLReaderSAX2Factory(org.jdom2.input.sax.XMLReaderSAX2Factory) SAXBuilder(org.jdom2.input.SAXBuilder) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) File(java.io.File)

Example 78 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project plexus-containers by codehaus-plexus.

the class ComponentsXmlMerger method merge.

/**
 * @see Merger#merge(Document, Document)
 */
public Document merge(Document dDocument, Document rDocument) throws MergeException {
    // TODO: Ideally we don't want to manipulate the original
    // dominant document but use its copy for merge.
    // Document mDoc = (Document) dDocument.clone();        // doesn't merge properly
    Document mDoc = dDocument;
    ComponentSetElement dCSE = new ComponentSetElement(mDoc.getRootElement());
    ComponentSetElement rCSE = new ComponentSetElement(rDocument.getRootElement());
    dCSE.merge(rCSE);
    // the contents are merged into the dominant document DOM.
    return mDoc;
}
Also used : Document(org.jdom2.Document) ComponentSetElement(org.codehaus.plexus.metadata.merge.support.ComponentSetElement)

Example 79 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project plexus-containers by codehaus-plexus.

the class PlexusXmlMerger method merge.

/**
 * {@inheritDoc}
 */
public Document merge(Document dDocument, Document rDocument) throws MergeException {
    // TODO: Ideally we don't want to manipulate the original
    // dominant document but use its copy for merge.
    // Document mDoc = (Document) dDocument.clone();        // doesn't merge properly
    Document mDoc = dDocument;
    PlexusRootElement dCSE = new PlexusRootElement(mDoc.getRootElement());
    PlexusRootElement rCSE = new PlexusRootElement(rDocument.getRootElement());
    dCSE.merge(rCSE);
    // the contents are merged into the dominant document DOM.
    return mDoc;
}
Also used : PlexusRootElement(org.codehaus.plexus.metadata.merge.support.PlexusRootElement) Document(org.jdom2.Document)

Example 80 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project Squid by CIRDLES.

the class CommonPbXMLConverterTest method testCommonPbXMLConverter.

@Test
public void testCommonPbXMLConverter() {
    try {
        ResourceExtractor extractor = new ResourceExtractor(CommonPbModel.class);
        File initialFile = extractor.extractResourceAsFile("Stacey-Kramers@559.0Ma (z6266) v.1.0.xml");
        CommonPbModel model = new CommonPbModel();
        model = (CommonPbModel) model.readXMLObject(initialFile.getAbsolutePath(), false);
        File convertedFile = new File("commonPbCopy.xml");
        model.serializeXMLObject(convertedFile.getAbsolutePath());
        model = (CommonPbModel) model.readXMLObject(convertedFile.getAbsolutePath(), false);
        File convertedConvertedFile = new File("commonPbCopyOfCopy.xml");
        model.serializeXMLObject(convertedConvertedFile.getAbsolutePath());
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(convertedFile);
        Element initialElement = doc.getRootElement();
        doc = builder.build(convertedConvertedFile);
        Element convertedElement = doc.getRootElement();
        convertedFile.delete();
        convertedConvertedFile.delete();
        assertTrue(ElementComparer.compareElements(initialElement, convertedElement));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) CommonPbModel(org.cirdles.squid.parameters.parameterModels.commonPbModels.CommonPbModel) ResourceExtractor(org.cirdles.commons.util.ResourceExtractor) Test(org.junit.Test)

Aggregations

Document (org.jdom2.Document)1034 Element (org.jdom2.Element)587 Test (org.junit.Test)340 SAXBuilder (org.jdom2.input.SAXBuilder)271 IOException (java.io.IOException)266 XMLOutputter (org.jdom2.output.XMLOutputter)182 JDOMException (org.jdom2.JDOMException)162 File (java.io.File)148 ArrayList (java.util.ArrayList)75 InputStream (java.io.InputStream)74 StringReader (java.io.StringReader)63 Path (java.nio.file.Path)59 HashMap (java.util.HashMap)57 DocumentHelper.getDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getDocument)53 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)53 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 PID (edu.unc.lib.boxc.model.api.ids.PID)47 Attribute (org.jdom2.Attribute)44 List (java.util.List)42 Namespace (org.jdom2.Namespace)39