Search in sources :

Example 66 with Document

use of io.atlasmap.v2.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 67 with Document

use of io.atlasmap.v2.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)

Example 68 with Document

use of io.atlasmap.v2.Document in project collect by openforis.

the class SamplingPointDataKmlGenerator method generate.

public void generate() {
    Kml kml = KmlFactory.createKml();
    Document doc = kml.createAndSetDocument();
    List<SamplingDesignItem> samplingDesignItems = loadSamplingDesignItems();
    for (SamplingDesignItem item : samplingDesignItems) {
        Coordinate coordinate = new Coordinate(item.getX(), item.getY(), item.getSrsId());
        LngLat lngLatAlt = createLngLat(coordinate);
        doc.createAndAddPlacemark().withName(Strings.joinNotBlank(item.getLevelCodes(), "|")).withOpen(true).createAndSetPoint().addToCoordinates(lngLatAlt.getLongitude(), lngLatAlt.getLatitude());
    }
    this.kml = kml;
}
Also used : LngLat(org.openforis.collect.model.LngLat) Coordinate(org.openforis.idm.model.Coordinate) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Document(de.micromata.opengis.kml.v_2_2_0.Document) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 69 with Document

use of io.atlasmap.v2.Document in project pom-manipulation-ext by release-engineering.

the class PomIO method write.

private void write(final Project project, final File pom, final Model model) throws ManipulationException {
    try {
        final String manifestInformation = project.isInheritanceRoot() ? ManifestUtils.getManifestInformation() : null;
        MavenJDOMWriter mjw = new MavenJDOMWriter(model);
        // We possibly could store the EOL type in the Project when we first read
        // the file but we would then have to do a dual read, then write as opposed
        // to a read, then read + write now.
        LineSeparator ls = determineEOL(pom);
        mjw.setLineSeparator(ls);
        mjw.write(model, pom, new DocumentModifier() {

            @Override
            public void postProcess(final Document doc) {
                // Only add the modified by to the top level pom.
                if (project.isExecutionRoot()) {
                    final Iterator<Content> it = doc.getContent(new ContentFilter(ContentFilter.COMMENT)).iterator();
                    while (it.hasNext()) {
                        final Comment c = (Comment) it.next();
                        if (c.toString().contains(MODIFIED_BY)) {
                            it.remove();
                        }
                    }
                    doc.addContent(Collections.<Content>singletonList(new Comment("\nModified by POM Manipulation Extension for Maven " + manifestInformation + "\n")));
                }
            }
        });
    } catch (final IOException e) {
        throw new ManipulationException("Failed to read POM for rewrite: %s. Reason: %s", e, pom, e.getMessage());
    } catch (final JDOMException e) {
        throw new ManipulationException("Failed to parse POM for rewrite: %s. Reason: %s", e, pom, e.getMessage());
    }
}
Also used : Comment(org.jdom2.Comment) IOException(java.io.IOException) MavenJDOMWriter(org.apache.maven.model.io.jdom.MavenJDOMWriter) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) LineSeparator(org.jdom2.output.LineSeparator) ContentFilter(org.jdom2.filter.ContentFilter) DocumentModifier(org.apache.maven.io.util.DocumentModifier) Content(org.jdom2.Content) Iterator(java.util.Iterator) ManipulationException(org.commonjava.maven.ext.common.ManipulationException)

Example 70 with Document

use of io.atlasmap.v2.Document in project java-docs-samples by GoogleCloudPlatform.

the class Analyze method analyzeEntitiesFile.

/**
 * Identifies entities in the contents of the object at the given GCS {@code path}.
 */
public static void analyzeEntitiesFile(String gcsUri) throws Exception {
    // Instantiate the Language client com.google.cloud.language.v1.LanguageServiceClient
    try (LanguageServiceClient language = LanguageServiceClient.create()) {
        // set the GCS Content URI path to the file to be analyzed
        Document doc = Document.newBuilder().setGcsContentUri(gcsUri).setType(Type.PLAIN_TEXT).build();
        AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder().setDocument(doc).setEncodingType(EncodingType.UTF16).build();
        AnalyzeEntitiesResponse response = language.analyzeEntities(request);
        // Print the response
        for (Entity entity : response.getEntitiesList()) {
            System.out.printf("Entity: %s", entity.getName());
            System.out.printf("Salience: %.3f\n", entity.getSalience());
            System.out.println("Metadata: ");
            for (Map.Entry<String, String> entry : entity.getMetadataMap().entrySet()) {
                System.out.printf("%s : %s", entry.getKey(), entry.getValue());
            }
            for (EntityMention mention : entity.getMentionsList()) {
                System.out.printf("Begin offset: %d\n", mention.getText().getBeginOffset());
                System.out.printf("Content: %s\n", mention.getText().getContent());
                System.out.printf("Type: %s\n\n", mention.getType());
            }
        }
    }
// [END analyze_entities_gcs]
}
Also used : LanguageServiceClient(com.google.cloud.language.v1.LanguageServiceClient) Entity(com.google.cloud.language.v1.Entity) AnalyzeEntitiesRequest(com.google.cloud.language.v1.AnalyzeEntitiesRequest) EntityMention(com.google.cloud.language.v1.EntityMention) AnalyzeEntitiesResponse(com.google.cloud.language.v1.AnalyzeEntitiesResponse) Document(com.google.cloud.language.v1.Document) Map(java.util.Map)

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