Example usage for org.jdom2 Element addNamespaceDeclaration

List of usage examples for org.jdom2 Element addNamespaceDeclaration

Introduction

In this page you can find the example usage for org.jdom2 Element addNamespaceDeclaration.

Prototype

public boolean addNamespaceDeclaration(final Namespace additionalNamespace) 

Source Link

Document

Adds a namespace declarations to this element.

Usage

From source file:org.mycore.frontend.indexbrowser.MCRGoogleSitemapCommon.java

License:Open Source License

/**
 * The method build the index sitemap_google.xml JDOM document.
 * //from   w w w  .ja v a  2 s. c  om
 * @param number
 *            number of indexed files (must greater than 1
 * @return The index sitemap_google.xml as JDOM document
 */
protected final Document buildSitemapIndex(int number) {
    LOGGER.debug("Build Google sitemap number " + Integer.toString(number));
    // build document frame
    Element index = new Element("sitemapindex", ns);
    index.addNamespaceDeclaration(XSI_NAMESPACE);
    index.setAttribute("schemaLocation", SITEINDEX_SCHEMA, XSI_NAMESPACE);
    Document jdom = new Document(index);
    // build over all files
    for (int i = 0; i < number; i++) {
        Element sitemap = new Element("sitemap", ns);
        index.addContent(sitemap);
        StringBuilder sb = new StringBuilder(128);
        sb.append(baseurl).append(getFileName(i + 2, false));
        sitemap.addContent(new Element("loc", ns).addContent(sb.toString().trim()));
        String datestr = formatter.format((new GregorianCalendar(SITEMAP_TIMEZONE, SITEMAP_LOCALE)).getTime());
        sitemap.addContent(new Element("lastmod", ns).addContent(datestr.trim()));
    }
    return jdom;
}

From source file:org.onebusaway.rss.impl.ServiceAlertRssModuleGenerator.java

License:Apache License

@Override
public void generate(Module module, Element element) {
    // this is not necessary, it is done to avoid the namespace definition in every item.
    Element root = element;
    while (root.getParent() != null && root.getParent() instanceof Element) {
        root = (Element) element.getParent();
    }/*from   w ww.ja  v a  2s.  com*/
    root.addNamespaceDeclaration(SERVICE_ALERT_NS);
    Element sas = null;

    Element channel = getElement(root, "channel");
    if (channel == null) {
        throw new RuntimeException("missing channel from element=" + root);
    }
    sas = getElement(channel, "ServiceAlerts");
    if (sas == null) {
        sas = generateSimpleElement("ServiceAlerts", "");
        sas.setName("ServiceAlerts");
        channel.addContent(sas);
    }

    if (module instanceof IServiceAlert) {
        IServiceAlert isa = (IServiceAlert) module;
        if (isa.getId() != null) {
            Element sa = generateSimpleElement("ServiceAlert", "");
            sa.setName("ServiceAlert");
            sa.addContent(generateSimpleElement("id", isa.getId()));
            sa.addContent(generateSimpleElement("summary", isa.getSummary()));
            sa.addContent(generateSimpleElement("description", isa.getDescription()));
            sa.addContent(generateSimpleElement("reason", isa.getReason()));
            sa.addContent(generateSimpleElement("severity", isa.getSeverity()));
            if (isa.getPublicationWindows() != null && !isa.getPublicationWindows().isEmpty()) {
                Element publicationWindows = generateSimpleElement("PublicationWindows", "");
                publicationWindows.setName("PublicationWindows");
                sa.addContent(publicationWindows);
                for (TimeRangeRssBean trb : isa.getPublicationWindows()) {
                    Element timeRange = generateSimpleElement("TimeRange", "");
                    timeRange.addContent(generateSimpleElement("from", "" + trb.getFrom()));
                    timeRange.addContent(generateSimpleElement("to", "" + trb.getTo()));
                    publicationWindows.addContent(timeRange);
                }
            }
            if (isa.getAffectsClauses() != null && !isa.getAffectsClauses().isEmpty()) {
                Element affectsClauses = generateSimpleElement("AffectsClauses", "");
                affectsClauses.setName("AffectsClauses");
                sa.addContent(affectsClauses);
                for (AffectsClauseRssBean acrb : isa.getAffectsClauses()) {
                    Element affect = generateSimpleElement("Affect", "");
                    if (acrb.getAgencyId() != null && acrb.getRouteId() == null && acrb.getStopId() == null
                            && acrb.getTripId() == null)
                        affect.addContent(generateAgencyElement("agencyId", acrb.getAgencyId()));
                    if (acrb.getRouteId() != null)
                        affect.addContent(generateAgencyElement("routeId", acrb.getRouteId()));
                    if (acrb.getStopId() != null)
                        affect.addContent(generateAgencyElement("stopId", acrb.getStopId()));
                    if (acrb.getTripId() != null)
                        affect.addContent(generateAgencyElement("tripId", acrb.getTripId()));
                    affectsClauses.addContent(affect);
                }
            }

            sas.addContent(sa);

        }
    } else {
        _log.error("unknown type=" + module);
    }

}

From source file:org.opengroup.archimate.xmlexchange.XMLModelExporter.java

License:Open Source License

/**
 * @param doc//from  w ww.  j  a  v  a2s.c  o  m
 * @return The Root JDOM Element
 */
Element createRootElement(Document doc) {
    Element rootElement = new Element(ELEMENT_MODEL, OPEN_GROUP_NAMESPACE);
    doc.setRootElement(rootElement);

    rootElement.addNamespaceDeclaration(JDOMUtils.XSI_Namespace);
    // rootElement.addNamespaceDeclaration(OPEN_GROUP_NAMESPACE_EMBEDDED); // Don't include this

    // DC Namespace
    if (hasMetadata()) {
        rootElement.addNamespaceDeclaration(DC_NAMESPACE);
    }

    /* 
     * Add Schema Location Attribute which is constructed from Target Namespaces and file names of Schemas
     */
    StringBuffer schemaLocationURI = new StringBuffer();

    // Open Group Schema Location
    schemaLocationURI.append(rootElement.getNamespace().getURI());
    schemaLocationURI.append(" "); //$NON-NLS-1$
    schemaLocationURI.append(OPEN_GROUP_SCHEMA_LOCATION);

    // DC Schema Location
    if (hasMetadata()) {
        schemaLocationURI.append(" "); //$NON-NLS-1$
        schemaLocationURI.append(DC_NAMESPACE.getURI());
        schemaLocationURI.append(" "); //$NON-NLS-1$
        schemaLocationURI.append(DC_SCHEMA_LOCATION);
    }

    rootElement.setAttribute(JDOMUtils.XSI_SchemaLocation, schemaLocationURI.toString(),
            JDOMUtils.XSI_Namespace);

    return rootElement;
}

From source file:org.rometools.feed.module.content.io.ContentModuleGenerator.java

License:Open Source License

public void generate(com.sun.syndication.feed.module.Module module, org.jdom2.Element element) {
    // this is not necessary, it is done to avoid the namespace definition in every item.
    Element root = element;

    while ((root.getParent() != null) && root.getParent() instanceof Element) {
        root = (Element) root.getParent();
    }/*from   w  w w .  j  ava2s.c o m*/

    root.addNamespaceDeclaration(CONTENT_NS);

    if (!(module instanceof ContentModule)) {
        return;
    }

    ContentModule cm = (ContentModule) module;

    List encodeds = cm.getEncodeds();

    //
    if (encodeds != null) {
        System.out.println(cm.getEncodeds().size());
        for (int i = 0; i < encodeds.size(); i++) {
            element.addContent(generateCDATAElement("encoded", encodeds.get(i).toString()));
        }
    }

    List contentItems = cm.getContentItems();

    if ((contentItems != null) && (contentItems.size() > 0)) {
        Element items = new Element("items", CONTENT_NS);
        Element bag = new Element("Bag", RDF_NS);
        items.addContent(bag);

        for (int i = 0; i < contentItems.size(); i++) {
            ContentItem contentItem = (ContentItem) contentItems.get(i);
            Element li = new Element("li", RDF_NS);
            Element item = new Element("item", CONTENT_NS);

            if (contentItem.getContentAbout() != null) {
                Attribute about = new Attribute("about", contentItem.getContentAbout(), RDF_NS);
                item.setAttribute(about);
            }

            if (contentItem.getContentFormat() != null) {
                //System.out.println( "Format");
                Element format = new Element("format", CONTENT_NS);
                Attribute formatResource = new Attribute("resource", contentItem.getContentFormat(), RDF_NS);
                format.setAttribute(formatResource);

                item.addContent(format);
            }

            if (contentItem.getContentEncoding() != null) {
                //System.out.println( "Encoding");
                Element encoding = new Element("encoding", CONTENT_NS);
                Attribute encodingResource = new Attribute("resource", contentItem.getContentEncoding(),
                        RDF_NS);
                encoding.setAttribute(encodingResource);
                item.addContent(encoding);
            }

            if (contentItem.getContentValue() != null) {
                Element value = new Element("value", RDF_NS);

                if (contentItem.getContentValueParseType() != null) {
                    Attribute parseType = new Attribute("parseType", contentItem.getContentValueParseType(),
                            RDF_NS);
                    value.setAttribute(parseType);
                }

                if (contentItem.getContentValueNamespaces() != null) {
                    List namespaces = contentItem.getContentValueNamespaces();

                    for (int ni = 0; ni < namespaces.size(); ni++) {
                        value.addNamespaceDeclaration((Namespace) namespaces.get(ni));
                    }
                }

                List detached = new ArrayList();

                for (int c = 0; c < contentItem.getContentValueDOM().size(); c++) {
                    detached.add(
                            ((Content) ((Content) contentItem.getContentValueDOM().get(c)).clone()).detach());
                }

                value.setContent(detached);
                item.addContent(value);
            } // end value

            li.addContent(item);
            bag.addContent(li);
        } //end contentItems loop

        element.addContent(items);
    }
}

From source file:org.rometools.feed.module.georss.GMLGenerator.java

License:Apache License

public void generate(Module module, Element element) {
    // this is not necessary, it is done to avoid the namespace definition
    // in every item.
    Element root = element;
    while (root.getParent() != null && root.getParent() instanceof Element) {
        root = (Element) element.getParent();
    }//from w  w w  .j  a v a  2 s.  c om
    root.addNamespaceDeclaration(GeoRSSModule.SIMPLE_NS);
    root.addNamespaceDeclaration(GeoRSSModule.GML_NS);

    Element whereElement = new Element("where", GeoRSSModule.SIMPLE_NS);
    element.addContent(whereElement);

    GeoRSSModule geoRSSModule = (GeoRSSModule) module;
    AbstractGeometry geometry = geoRSSModule.getGeometry();

    if (geometry instanceof Point) {
        Position pos = ((Point) geometry).getPosition();

        Element pointElement = new Element("Point", GeoRSSModule.GML_NS);
        whereElement.addContent(pointElement);

        Element posElement = new Element("pos", GeoRSSModule.GML_NS);
        posElement.addContent(String.valueOf(pos.getLatitude()) + " " + String.valueOf(pos.getLongitude()));
        pointElement.addContent(posElement);
    }

    else if (geometry instanceof LineString) {
        PositionList posList = ((LineString) geometry).getPositionList();

        Element lineElement = new Element("LineString", GeoRSSModule.GML_NS);
        lineElement.addContent(createPosListElement(posList));
        whereElement.addContent(lineElement);
    } else if (geometry instanceof Polygon) {
        Element polygonElement = new Element("Polygon", GeoRSSModule.GML_NS);
        {
            AbstractRing ring = ((Polygon) geometry).getExterior();
            if (ring instanceof LinearRing) {
                Element exteriorElement = new Element("exterior", GeoRSSModule.GML_NS);
                polygonElement.addContent(exteriorElement);
                Element ringElement = new Element("LinearRing", GeoRSSModule.GML_NS);
                exteriorElement.addContent(ringElement);
                ringElement.addContent(createPosListElement(((LinearRing) ring).getPositionList()));

            } else {
                System.err
                        .println("GeoRSS GML format can't handle rings of type: " + ring.getClass().getName());
            }
        }
        List interiorList = ((Polygon) geometry).getInterior();
        Iterator it = interiorList.iterator();
        while (it.hasNext()) {
            AbstractRing ring = (AbstractRing) it.next();
            if (ring instanceof LinearRing) {
                Element interiorElement = new Element("interior", GeoRSSModule.GML_NS);
                polygonElement.addContent(interiorElement);
                Element ringElement = new Element("LinearRing", GeoRSSModule.GML_NS);
                interiorElement.addContent(ringElement);
                ringElement.addContent(createPosListElement(((LinearRing) ring).getPositionList()));

            } else {
                System.err
                        .println("GeoRSS GML format can't handle rings of type: " + ring.getClass().getName());
            }
        }
        whereElement.addContent(polygonElement);
    } else if (geometry instanceof Envelope) {
        Envelope envelope = (Envelope) geometry;
        Element envelopeElement = new Element("Envelope", GeoRSSModule.GML_NS);
        whereElement.addContent(envelopeElement);

        Element lowerElement = new Element("lowerCorner", GeoRSSModule.GML_NS);
        lowerElement.addContent(
                String.valueOf(envelope.getMinLatitude()) + " " + String.valueOf(envelope.getMinLongitude()));
        envelopeElement.addContent(lowerElement);

        Element upperElement = new Element("upperCorner", GeoRSSModule.GML_NS);
        upperElement.addContent(
                String.valueOf(envelope.getMaxLatitude()) + " " + String.valueOf(envelope.getMaxLongitude()));
        envelopeElement.addContent(upperElement);

    } else {
        System.err
                .println("GeoRSS GML format can't handle geometries of type: " + geometry.getClass().getName());
    }
}

From source file:org.rometools.feed.module.georss.SimpleGenerator.java

License:Apache License

public void generate(Module module, Element element) {
    // this is not necessary, it is done to avoid the namespace definition
    // in every item.
    Element root = element;
    while (root.getParent() != null && root.getParent() instanceof Element) {
        root = (Element) element.getParent();
    }/*ww w. jav a2 s  . c  om*/
    root.addNamespaceDeclaration(GeoRSSModule.SIMPLE_NS);

    GeoRSSModule geoRSSModule = (GeoRSSModule) module;

    AbstractGeometry geometry = geoRSSModule.getGeometry();
    if (geometry instanceof Point) {
        Position pos = ((Point) geometry).getPosition();

        Element pointElement = new Element("point", GeoRSSModule.SIMPLE_NS);
        pointElement.addContent(pos.getLatitude() + " " + pos.getLongitude());
        element.addContent(pointElement);
    } else if (geometry instanceof LineString) {
        PositionList posList = ((LineString) geometry).getPositionList();

        Element lineElement = new Element("line", GeoRSSModule.SIMPLE_NS);

        lineElement.addContent(posListToString(posList));
        element.addContent(lineElement);
    } else if (geometry instanceof Polygon) {
        AbstractRing ring = ((Polygon) geometry).getExterior();
        if (ring instanceof LinearRing) {
            PositionList posList = ((LinearRing) ring).getPositionList();
            Element polygonElement = new Element("polygon", GeoRSSModule.SIMPLE_NS);

            polygonElement.addContent(posListToString(posList));
            element.addContent(polygonElement);
        } else {
            System.err.println("GeoRSS simple format can't handle rings of type: " + ring.getClass().getName());
        }
        if (((Polygon) geometry).getInterior() != null || !((Polygon) geometry).getInterior().isEmpty()) {
            System.err.println("GeoRSS simple format can't handle interior rings (ignored)");
        }
    } else if (geometry instanceof Envelope) {
        Envelope envelope = (Envelope) geometry;
        Element boxElement = new Element("box", GeoRSSModule.SIMPLE_NS);
        boxElement.addContent(envelope.getMinLatitude() + " " + envelope.getMinLongitude() + " "
                + envelope.getMaxLatitude() + " " + envelope.getMaxLongitude());
        element.addContent(boxElement);
    } else {
        System.err.println(
                "GeoRSS simple format can't handle geometries of type: " + geometry.getClass().getName());
    }
}

From source file:org.rometools.feed.module.georss.W3CGeoGenerator.java

License:Apache License

public void generate(Module module, Element element) {
    // this is not necessary, it is done to avoid the namespace definition
    // in every item.
    Element root = element;
    while (root.getParent() != null && root.getParent() instanceof Element) {
        root = (Element) element.getParent();
    }//from  w w w .  j av  a 2  s .c  om
    root.addNamespaceDeclaration(GeoRSSModule.W3CGEO_NS);

    Element pointElement = element;
    if (!isShort) {
        pointElement = new Element("Point", GeoRSSModule.W3CGEO_NS);
        element.addContent(pointElement);
    }

    GeoRSSModule geoRSSModule = (GeoRSSModule) module;
    AbstractGeometry geometry = geoRSSModule.getGeometry();

    if (geometry instanceof Point) {
        Position pos = ((Point) geometry).getPosition();

        Element latElement = new Element("lat", GeoRSSModule.W3CGEO_NS);
        latElement.addContent(String.valueOf(pos.getLatitude()));
        pointElement.addContent(latElement);
        Element lngElement = new Element("long", GeoRSSModule.W3CGEO_NS);
        lngElement.addContent(String.valueOf(pos.getLongitude()));
        pointElement.addContent(lngElement);
    } else {
        System.err.println("W3C Geo format can't handle geometries of type: " + geometry.getClass().getName());
    }
}

From source file:org.rometools.feed.module.itunes.io.ITunesGenerator.java

License:Open Source License

public void generate(Module module, Element element) {
    Element root = element;

    while ((root.getParent() != null) && root.getParent() instanceof Element) {
        root = (Element) root.getParent();
    }//from   w w  w  . j  a  v  a2s .  c  om

    root.addNamespaceDeclaration(NS);

    if (!(module instanceof AbstractITunesObject)) {
        return;
    }

    AbstractITunesObject itunes = (AbstractITunesObject) module;

    if (itunes instanceof FeedInformationImpl) {
        //Do Channel Specific Stuff.
        FeedInformationImpl info = (FeedInformationImpl) itunes;
        Element owner = this.generateSimpleElement("owner", "");
        Element email = this.generateSimpleElement("email", info.getOwnerEmailAddress());
        owner.addContent(email);

        Element name = this.generateSimpleElement("name", info.getOwnerName());
        owner.addContent(name);
        element.addContent(owner);

        if (info.getImage() != null) {
            Element image = this.generateSimpleElement("image", "");
            image.setAttribute("href", info.getImage().toExternalForm());
            element.addContent(image);
        }

        for (Iterator it = info.getCategories().iterator(); it.hasNext();) {
            Category cat = (Category) it.next();
            Element category = this.generateSimpleElement("category", "");
            category.setAttribute("text", cat.getName());

            if (cat.getSubcategory() != null) {
                Element subcat = this.generateSimpleElement("category", "");
                subcat.setAttribute("text", cat.getSubcategory().getName());
                category.addContent(subcat);
            }

            element.addContent(category);
        }
    } else if (itunes instanceof EntryInformationImpl) {
        EntryInformationImpl info = (EntryInformationImpl) itunes;

        if (info.getDuration() != null) {
            element.addContent(this.generateSimpleElement("duration", info.getDuration().toString()));
        }
    }

    if (itunes.getAuthor() != null) {
        element.addContent(this.generateSimpleElement("author", itunes.getAuthor()));
    }

    if (itunes.getBlock()) {
        element.addContent(this.generateSimpleElement("block", ""));
    }

    if (itunes.getExplicit()) {
        element.addContent(this.generateSimpleElement("explicit", "yes"));
    } else {
        element.addContent(this.generateSimpleElement("explicit", "no"));
    }

    if (itunes.getKeywords() != null) {
        StringBuffer sb = new StringBuffer();

        for (int i = 0; i < itunes.getKeywords().length; i++) {
            if (i != 0) {
                sb.append(", ");
            }

            sb.append(itunes.getKeywords()[i]);
        }

        element.addContent(this.generateSimpleElement("keywords", sb.toString()));
    }

    if (itunes.getSubtitle() != null) {
        element.addContent(this.generateSimpleElement("subtitle", itunes.getSubtitle()));
    }

    if (itunes.getSummary() != null) {
        element.addContent(this.generateSimpleElement("summary", itunes.getSummary()));
    }
}

From source file:projetxml.model.XMLManagement.java

private void ajouterDonnees(String nomFichier, Map<String, String> infos, Map<String, String> infosOmdb) {
    Element racine = documentOutput.getRootElement();
    Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    racine.addNamespaceDeclaration(xsi);
    racine.setAttribute("noNamespaceSchemaLocation", "input.xsd", xsi);

    Element episode = new Element("episode");
    racine.addContent(episode);/*from ww  w  .j a  v  a 2  s  . co m*/

    Element titre = new Element("titre");
    titre.setText(nomFichier);
    episode.addContent(titre);

    Element titreComplet = new Element("titreComplet");
    titreComplet.setText(infos.get("title"));
    episode.addContent(titreComplet);

    Element numero = new Element("numero");
    numero.setText(infos.get("episode"));
    episode.addContent(numero);

    Element saison = new Element("saison");
    saison.setText(infos.get("season"));
    episode.addContent(saison);

    Element qualite = new Element("qualite");
    qualite.setText(infos.get("quality"));
    episode.addContent(qualite);

    Element lien = new Element("lien");
    lien.setText(infos.get("link"));
    episode.addContent(lien);

    Element note = new Element("note");
    note.setText(infosOmdb.get("rated"));
    episode.addContent(note);

    Element description = new Element("description");
    description.setText(infosOmdb.get("plot"));
    episode.addContent(description);

    Element image = new Element("image");
    image.setText(infosOmdb.get("poster"));
    episode.addContent(image);

    Element torrent = new Element("torrent");
    episode.addContent(torrent);

    Element infoHash = new Element("infoHash");
    infoHash.setText(infos.get("infoHash"));
    torrent.addContent(infoHash);

    Element magnetURI = new Element("magnetURI");
    magnetURI.setText(infos.get("magnetURI"));
    torrent.addContent(magnetURI);

    Element seeds = new Element("seeds");
    seeds.setText(infos.get("seeds"));
    torrent.addContent(seeds);

    Element peers = new Element("peers");
    peers.setText(infos.get("peers"));
    torrent.addContent(peers);

    Element verified = new Element("verified");
    verified.setText(infos.get("verified"));
    torrent.addContent(verified);

    Element filename = new Element("filename");
    filename.setText(infos.get("filename"));
    torrent.addContent(filename);

    Element enclosure = new Element("enclosure");
    enclosure.setText(infos.get("enclosure"));
    torrent.addContent(enclosure);

}

From source file:pt.ist.socialsoftware.edition.export.ExpertEditionTEIExport.java

License:Creative Commons License

private Element generateCorpus() {
    this.jdomDoc = new Document();
    Element rootElement = new Element("teiCorpus");

    rootElement.setNamespace(this.xmlns);

    rootElement.addNamespaceDeclaration(Namespace.getNamespace("svg", "http://www.w3.org/2000/svg"));

    rootElement.addNamespaceDeclaration(Namespace.getNamespace("xi", "http://www.w3.org/2001/XInclude"));

    this.jdomDoc.setRootElement(rootElement);
    return rootElement;
}