Search in sources :

Example 61 with Document

use of io.atlasmap.v2.Document in project ldapchai by ldapchai.

the class NmasResponseSet method parseNmasPolicyXML.

static List<Challenge> parseNmasPolicyXML(final String str, final Locale locale) throws IOException, JDOMException {
    final List<Challenge> returnList = new ArrayList<Challenge>();
    final Reader xmlreader = new StringReader(str);
    final SAXBuilder builder = new SAXBuilder();
    final Document doc = builder.build(xmlreader);
    final boolean required = doc.getRootElement().getName().equals("RequiredQuestions");
    for (final Iterator questionIterator = doc.getDescendants(new ElementFilter("Question")); questionIterator.hasNext(); ) {
        final Element loopQ = (Element) questionIterator.next();
        final int maxLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MaxLength"), 255);
        final int minLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MinLength"), 1);
        final String challengeText = readDisplayString(loopQ, locale);
        final Challenge challenge = new ChaiChallenge(required, challengeText, minLength, maxLength, true, 0, false);
        returnList.add(challenge);
    }
    for (Iterator iter = doc.getDescendants(new ElementFilter("UserDefined")); iter.hasNext(); ) {
        final Element loopQ = (Element) iter.next();
        final int maxLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MaxLength"), 255);
        final int minLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MinLength"), 1);
        final Challenge challenge = new ChaiChallenge(required, null, minLength, maxLength, false, 0, false);
        returnList.add(challenge);
    }
    return returnList;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) Document(org.jdom2.Document) Challenge(com.novell.ldapchai.cr.Challenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge) ElementFilter(org.jdom2.filter.ElementFilter) StringReader(java.io.StringReader) Iterator(java.util.Iterator) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge)

Example 62 with Document

use of io.atlasmap.v2.Document in project pwm by pwm-project.

the class StoredConfigurationImpl method fromXml.

public static StoredConfigurationImpl fromXml(final InputStream xmlData) throws PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    // validateXmlSchema(xmlData);
    final Document inputDocument = XmlUtil.parseXml(xmlData);
    final StoredConfigurationImpl newConfiguration = StoredConfigurationImpl.newStoredConfiguration();
    try {
        newConfiguration.document = inputDocument;
        // verify create time;
        newConfiguration.createTime();
        ConfigurationCleaner.cleanup(newConfiguration);
    } catch (Exception e) {
        final String errorMsg = "error reading configuration file format, error=" + e.getMessage();
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { errorMsg });
        throw new PwmUnrecoverableException(errorInfo);
    }
    checkIfXmlRequiresUpdate(newConfiguration);
    LOGGER.debug("successfully loaded configuration (" + TimeDuration.compactFromCurrent(startTime) + ")");
    return newConfiguration;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) Instant(java.time.Instant) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) Document(org.jdom2.Document) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Example 63 with Document

use of io.atlasmap.v2.Document in project pwm by pwm-project.

the class XmlUtil method parseXml.

public static Document parseXml(final Reader inputStream) throws PwmUnrecoverableException {
    final SAXBuilder builder = getBuilder();
    final Document inputDocument;
    try {
        inputDocument = builder.build(inputStream);
    } catch (Exception e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { "error parsing xml data: " + e.getMessage() }));
    }
    return inputDocument;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) SAXBuilder(org.jdom2.input.SAXBuilder) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) Document(org.jdom2.Document) IOException(java.io.IOException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 64 with Document

use of io.atlasmap.v2.Document in project pwm by pwm-project.

the class PwmSettingXml method readXml.

private static Document readXml() {
    final Document docRefCopy = xmlDocCache;
    if (docRefCopy == null) {
        // validateXmlSchema();
        final InputStream inputStream = PwmSetting.class.getClassLoader().getResourceAsStream(SETTING_XML_FILENAME);
        final SAXBuilder builder = new SAXBuilder();
        try {
            final Document newDoc = builder.build(inputStream);
            xmlDocCache = newDoc;
            // clear cached dom after 30 seconds.
            final Thread t = new Thread("PwmSettingXml static cache clear thread") {

                @Override
                public void run() {
                    JavaHelper.pause(30 * 1000);
                    xmlDocCache = null;
                }
            };
            t.setDaemon(true);
            t.start();
            return newDoc;
        } catch (JDOMException e) {
            throw new IllegalStateException("error parsing " + SETTING_XML_FILENAME + ": " + e.getMessage());
        } catch (IOException e) {
            throw new IllegalStateException("unable to load " + SETTING_XML_FILENAME + ": " + e.getMessage());
        }
    }
    return docRefCopy;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputStream(java.io.InputStream) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 65 with Document

use of io.atlasmap.v2.Document in project tests by datanucleus.

the class RelationshipsTest method testOneToManyBidirMappedByDotNotation.

/**
 * Test of 1-N bidir with element having embedded PC, and 1-1 bidir with embedded PC, and using "mappedBy" with DOT notation.
 */
public void testOneToManyBidirMappedByDotNotation() {
    try {
        EntityManager em = getEM();
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            Contact c1 = new Contact("John Doe");
            Document d1 = new Document("Doc1", c1);
            Document d2 = new Document("Doc2", c1);
            c1.setMainDocument(d1);
            d1.getDetails().setOwner(c1);
            c1.getDocuments().add(d2);
            d2.getDetails().setOwner(c1);
            em.persist(c1);
            em.persist(d1);
            em.persist(d2);
            Contact c2 = new Contact("Jane Dose");
            em.persist(c2);
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Exception thrown while creating data");
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
        // Query the datastore and check the results
        em = getEM();
        tx = em.getTransaction();
        List<Document> documents = null;
        try {
            tx.begin();
            TypedQuery<Document> query = em.createQuery("SELECT d FROM Document d JOIN FETCH d.details.owner owner_1 WHERE d.name = 'Doc2'", Document.class);
            documents = query.getResultList();
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Exception thrown while retrieving data");
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
        assertEquals(1, documents.size());
        assertEquals("Doc2", documents.get(0).getName());
        assertEquals("John Doe", documents.get(0).getDetails().getOwner().getName());
        em = getEM();
        tx = em.getTransaction();
        try {
            tx.begin();
            // Null out the relations
            TypedQuery<Contact> query = em.createQuery("SELECT c FROM " + Contact.class.getName() + " c", Contact.class);
            List<Contact> contacts = query.getResultList();
            for (Contact c : contacts) {
                c.setMainDocument(null);
                c.getDocuments().clear();
            }
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Exception thrown while retrieving data");
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
    } finally {
        clean(Contact.class);
        clean(Document.class);
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) Document(org.datanucleus.samples.annotations.one_many.bidir_3.Document) Contact(org.datanucleus.samples.annotations.one_many.bidir_3.Contact)

Aggregations

Document (org.jdom2.Document)403 Element (org.jdom2.Element)248 Test (org.junit.Test)111 SAXBuilder (org.jdom2.input.SAXBuilder)95 IOException (java.io.IOException)74 File (java.io.File)58 XMLOutputter (org.jdom2.output.XMLOutputter)55 JDOMException (org.jdom2.JDOMException)44 Field (io.atlasmap.v2.Field)40 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 ArrayList (java.util.ArrayList)30 Test (org.junit.jupiter.api.Test)27 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 InputStream (java.io.InputStream)23 JsonField (io.atlasmap.json.v2.JsonField)22 MCRContent (org.mycore.common.content.MCRContent)22 Document (com.google.cloud.language.v1.Document)21 HashMap (java.util.HashMap)21 MCRException (org.mycore.common.MCRException)21