Search in sources :

Example 86 with Document

use of com.google.firestore.v1.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 87 with Document

use of com.google.firestore.v1.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 88 with Document

use of com.google.firestore.v1.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)

Example 89 with Document

use of com.google.firestore.v1.Document in project onebusaway-application-modules by camsys.

the class RssServiceAlertsSerivceImpl method pollServiceAdvisoryRssFeed.

protected List<ServiceAlertBean> pollServiceAdvisoryRssFeed() throws Exception {
    List<ServiceAlertBean> alerts = new ArrayList<ServiceAlertBean>();
    if (_serviceAdvisoryUrlString == null)
        return alerts;
    HttpMethod httpget = new GetMethod(_serviceAdvisoryUrlString);
    int response = _httpClient.executeMethod(httpget);
    if (response != HttpStatus.SC_OK) {
        throw new Exception("service status poll failed, returned status code: " + response);
    }
    Document doc = _builder.build(httpget.getResponseBodyAsStream());
    List<Element> elements = doc.getRootElement().getChild("channel").getChildren("item");
    String language = doc.getRootElement().getChild("channel").getChildText("language");
    if (language == null)
        // they don't send language for this feed currently, perhaps they'll start?
        language = _locale.getLanguage();
    if (language.equals("en-us")) {
        // java prefers en
        language = _locale.getLanguage();
    }
    for (Element itemElement : elements) {
        String title = itemElement.getChild("title").getValue();
        String link = itemElement.getChild("link").getValue();
        String description = itemElement.getChild("description").getValue();
        String pubDateString = itemElement.getChild("pubDate").getValue();
        // guid may spread across multiple routes, differentiate based on title
        String guid = itemElement.getChild("guid").getValue() + "_" + title;
        Date pubDate = _sdf.parse(pubDateString);
        List<SituationAffectsBean> affectedRouteIds = getRouteIds(title);
        ServiceAlertBean serviceAlertBean = new ServiceAlertBean();
        serviceAlertBean.setSource(_alertSource);
        serviceAlertBean.setAllAffects(affectedRouteIds);
        serviceAlertBean.setSeverity(ESeverity.UNKNOWN);
        serviceAlertBean.setSummaries(Arrays.asList(new NaturalLanguageStringBean[] { new NaturalLanguageStringBean(description, language) }));
        serviceAlertBean.setReason(ServiceAlerts.ServiceAlert.Cause.UNKNOWN_CAUSE.name());
        SituationConsequenceBean situationConsequenceBean = new SituationConsequenceBean();
        situationConsequenceBean.setEffect(EEffect.SIGNIFICANT_DELAYS);
        serviceAlertBean.setConsequences(Arrays.asList(new SituationConsequenceBean[] { situationConsequenceBean }));
        serviceAlertBean.setCreationTime(pubDate.getTime());
        serviceAlertBean.setDescriptions(Arrays.asList(new NaturalLanguageStringBean[] { new NaturalLanguageStringBean(description, language) }));
        serviceAlertBean.setId(new AgencyAndId(getAgencyId(), guid).toString());
        serviceAlertBean.setUrls(Arrays.asList(new NaturalLanguageStringBean[] { new NaturalLanguageStringBean(link, language) }));
        alerts.add(serviceAlertBean);
    }
    return alerts;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Element(org.jdom2.Element) Document(org.jdom2.Document) RemoteConnectFailureException(org.springframework.remoting.RemoteConnectFailureException) IOException(java.io.IOException) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 90 with Document

use of com.google.firestore.v1.Document in project onebusaway-application-modules by camsys.

the class RssServiceAlertsSerivceImpl method pollServiceStatusRssFeed.

protected List<ServiceAlertBean> pollServiceStatusRssFeed() throws Exception {
    List<ServiceAlertBean> alerts = new ArrayList<ServiceAlertBean>();
    if (_serviceStatusUrlString == null)
        return alerts;
    HttpMethod httpget = new GetMethod(_serviceStatusUrlString);
    int response = _httpClient.executeMethod(httpget);
    if (response != HttpStatus.SC_OK) {
        throw new Exception("service status poll failed, returned status code: " + response);
    }
    Document doc = _builder.build(httpget.getResponseBodyAsStream());
    List<Element> elements = doc.getRootElement().getChild("channel").getChildren("item");
    String language = doc.getRootElement().getChild("channel").getChildText("language");
    if (language == null) {
        language = _locale.getLanguage();
    }
    if (language.equals("en-us")) {
        language = _locale.getLanguage();
    }
    for (Element itemElement : elements) {
        String title = itemElement.getChild("title").getValue();
        String link = itemElement.getChild("link").getValue();
        String description = itemElement.getChild("description").getValue();
        String pubDateString = itemElement.getChild("pubDate").getValue();
        String guid = itemElement.getChild("guid").getValue();
        Date pubDate = _sdf.parse(pubDateString);
        List<SituationAffectsBean> affectedRouteIds = getRouteIds(title);
        ServiceAlertBean serviceAlertBean = new ServiceAlertBean();
        serviceAlertBean.setSource(_alertSource);
        serviceAlertBean.setAllAffects(affectedRouteIds);
        serviceAlertBean.setSeverity(ESeverity.UNKNOWN);
        serviceAlertBean.setSummaries(Arrays.asList(new NaturalLanguageStringBean[] { new NaturalLanguageStringBean(description, language) }));
        serviceAlertBean.setReason(ServiceAlerts.ServiceAlert.Cause.UNKNOWN_CAUSE.name());
        SituationConsequenceBean situationConsequenceBean = new SituationConsequenceBean();
        situationConsequenceBean.setEffect(EEffect.SIGNIFICANT_DELAYS);
        serviceAlertBean.setConsequences(Arrays.asList(new SituationConsequenceBean[] { situationConsequenceBean }));
        serviceAlertBean.setCreationTime(pubDate.getTime());
        serviceAlertBean.setDescriptions(Arrays.asList(new NaturalLanguageStringBean[] { new NaturalLanguageStringBean(description, language) }));
        serviceAlertBean.setId(new AgencyAndId(getAgencyId(), guid).toString());
        serviceAlertBean.setUrls(Arrays.asList(new NaturalLanguageStringBean[] { new NaturalLanguageStringBean(link, language) }));
        alerts.add(serviceAlertBean);
    }
    return alerts;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Element(org.jdom2.Element) Document(org.jdom2.Document) RemoteConnectFailureException(org.springframework.remoting.RemoteConnectFailureException) IOException(java.io.IOException) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Aggregations

Document (org.jdom2.Document)396 Element (org.jdom2.Element)244 Test (org.junit.Test)116 SAXBuilder (org.jdom2.input.SAXBuilder)89 IOException (java.io.IOException)72 File (java.io.File)56 XMLOutputter (org.jdom2.output.XMLOutputter)56 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 ArrayList (java.util.ArrayList)23 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 Document (com.google.cloud.language.v1.Document)21 MCRException (org.mycore.common.MCRException)21 HashMap (java.util.HashMap)20 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 InputStream (java.io.InputStream)18