Search in sources :

Example 71 with Attribute

use of com.mindbright.security.x509.Attribute in project vsp-playgrounds by matsim-vsp.

the class XMLWriter method addLink.

public void addLink(Element route, Link link) {
    Element link_element = new Element("link");
    // Temporarily for teleportation
    link_element.setAttribute(new Attribute("refId", ""));
    route.addContent(link_element);
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 72 with Attribute

use of com.mindbright.security.x509.Attribute in project vsp-playgrounds by matsim-vsp.

the class XMLWriter method addStop.

public void addStop(Element transitRoute, Stop st) {
    Element stop = new Element("stop");
    stop.setAttribute(new Attribute("awaitDeparture", Boolean.toString(st.getAwaitDeparture())));
    stop.setAttribute(new Attribute("departureOffset", st.getDepartureOffset()));
    stop.setAttribute(new Attribute("arrivalOffset", st.getArrivalOffset()));
    stop.setAttribute(new Attribute("refId", st.getId()));
    transitRoute.addContent(stop);
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 73 with Attribute

use of com.mindbright.security.x509.Attribute in project mars-sim by mars-sim.

the class CrewConfig method createItemDoc.

/**
 * Creates an XML document for this crew.
 *
 * @return
 */
@Override
protected Document createItemDoc(Crew roster) {
    Element root = new Element(CREW_COFIG);
    Document doc = new Document(root);
    root.setAttribute(new Attribute(NAME_ATTR, roster.getName()));
    root.setAttribute(new Attribute(DESC_ATTR, roster.getDescription()));
    Element crewList = new Element(CREW_LIST);
    List<Element> personList = new ArrayList<>();
    for (Member person : roster.getTeam()) {
        Element personElement = new Element(PERSON);
        personElement.setAttribute(new Attribute(NAME_ATTR, person.getName()));
        personElement.setAttribute(new Attribute(GENDER, person.getGender().name()));
        personElement.setAttribute(new Attribute(AGE, person.getAge()));
        personElement.setAttribute(new Attribute(PERSONALITY_TYPE, person.getMBTI()));
        saveOptionalAttribute(personElement, SPONSOR, person.getSponsorCode());
        personElement.setAttribute(new Attribute(COUNTRY, person.getCountry()));
        personElement.setAttribute(new Attribute(JOB, person.getJob()));
        saveOptionalAttribute(personElement, ACTIVITY, person.getActivity());
        saveOptionalAttribute(personElement, MAIN_DISH, person.getMainDish());
        saveOptionalAttribute(personElement, SIDE_DISH, person.getSideDish());
        saveOptionalAttribute(personElement, DESSERT, person.getDessert());
        // 
        // Element traitList = new Element(PERSONALITY_TRAIT_LIST);
        // 
        // Element trait0 = new Element(PERSONALITY_TRAIT);
        // trait0.setAttribute(new Attribute(NAME, "openness"));
        // trait0.setAttribute(new Attribute(VALUE, "25"));
        // traitList.addContent(trait0);
        personList.add(personElement);
    }
    crewList.addContent(personList);
    doc.getRootElement().addContent(crewList);
    return doc;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Document(org.jdom2.Document)

Example 74 with Attribute

use of com.mindbright.security.x509.Attribute in project geonetwork by georchestra.

the class Harvester method createDIFMetadata.

// ---------------------------------------------------------------------------
/**
 * Process one dataset by extracting its metadata, writing to DIF
 * and using xslt to transform to the required ISO format.
 *
 * @param ds     the dataset to be processed
 */
private void createDIFMetadata(InvDataset ds) {
    try {
        // add coordinate systems if not DIF relaxed
        boolean addCoordSys = false;
        // --- TODO: Thredds has a metadata converter interface and some other
        // --- methods of handling metadata (including XML of different
        // --- namespaces) in the catalog - this is a place holder for getting
        // --- this info in future
        List<InvMetadata> mds = ds.getMetadata();
        log.info("Dataset has " + mds.size() + " metadata elements");
        for (InvMetadata md : mds) {
            log.info("Found metadata " + md.toString());
        }
        // --- check and see whether this dataset is DIF writeable
        DIFWriter difWriter = new DIFWriter();
        StringBuffer sBuff = new StringBuffer();
        Element dif = null;
        if (difWriter.isDatasetUseable(ds, sBuff)) {
            log.info("Yay! Dataset has DIF compatible metadata " + sBuff.toString());
            dif = difWriter.writeOneEntry(ds, sBuff);
        } else {
            log.info("Dataset does not have DIF compatible metadata so we will write a relaxed DIF entry\n" + sBuff.toString());
            dif = difWriter.writeOneRelaxedEntry(ds, sBuff);
            addCoordSys = true;
        }
        // --- get the UUID assigned to the DIF record
        String uuid = dif.getChild("Entry_ID", difNS).getText();
        boolean isCollection = ds.hasNestedDatasets();
        log.info("Dataset is a collection dataset? " + isCollection);
        // --- now convert DIF entry into an ISO entry using the appropriate
        // --- difToIso converter (only schemas with a DIF converter are
        // --- supplied to the user for choice)
        Element md = null;
        if (isCollection) {
            String difToIsoStyleSheet = schemaMan.getSchemaDir(params.outputSchemaOnCollectionsDIF) + Geonet.Path.DIF_STYLESHEETS + "/DIFToISO.xsl";
            log.info("Transforming collection dataset to " + params.outputSchemaOnCollectionsDIF);
            md = Xml.transform(dif, difToIsoStyleSheet);
        } else {
            String difToIsoStyleSheet = schemaMan.getSchemaDir(params.outputSchemaOnAtomicsDIF) + Geonet.Path.DIF_STYLESHEETS + "/DIFToISO.xsl";
            log.info("Transforming atomic dataset to " + params.outputSchemaOnAtomicsDIF);
            md = Xml.transform(dif, difToIsoStyleSheet);
        }
        // --- create a netcdfInfo for addition to the ISO record
        if (addCoordSys) {
            boolean globalAttributes = false;
            if (!isCollection) {
                // open up atomic dataset for info
                log.info("Opening dataset to get global attributes");
                // --- open and check global attributes for metadata conventions
                try {
                    NetcdfDataset ncD = NetcdfDataset.openDataset("thredds:" + ds.getCatalogUrl());
                    Attribute mdCon = ncD.findGlobalAttributeIgnoreCase("metadata_conventions");
                    if (mdCon != null) {
                        List<Attribute> ga = ncD.getGlobalAttributes();
                        for (Attribute att : ga) {
                            if (log.isDebugEnabled())
                                log.debug("Attribute found " + att.toString());
                        // --- TODO: Attach the attributes to the metadata node
                        // --- for conversion into the ISO record by an xslt
                        }
                    } else {
                        if (log.isDebugEnabled())
                            log.debug("No global attribute with metadata conventions found");
                    }
                    ncD.close();
                } catch (Exception e) {
                    log.info("Exception raised in netcdfDataset ops: " + e);
                    e.printStackTrace();
                }
            }
            // --- if no metadata conventions then find the coordinate systems
            // --- and add these to the appropriate place in whatever ISO or ISO
            // --- profile we are using - MCP: mcp:dataParameters & gmd:keywords,
            // --- ISO: gmd:keywords
            boolean foundNetcdfInfo = false;
            if (!globalAttributes && !isCollection) {
                log.info("No global attributes describing metadata so opening dataset to get coordinate systems");
                try {
                    NetcdfDatasetInfo ncDI = new NetcdfDatasetInfo("thredds:" + ds.getCatalogUrl());
                    log.info("Coordinate systems builder is " + ncDI.getConventionUsed());
                    if (!ncDI.getConventionUsed().equals("None")) {
                        Document doc = ncDI.makeDocument();
                        Element coords = doc.detachRootElement();
                        log.info("Coordinate systems of dataset are: \n" + Xml.getString(coords));
                        setCoordsStyleSheet(isCollection);
                        addKeywordsAndDataParams(coords, md);
                        foundNetcdfInfo = true;
                    } else {
                        if (log.isDebugEnabled())
                            log.debug("Coordinate system convention is not recognized");
                    }
                    ncDI.close();
                } catch (Exception e) {
                    log.info("Exception raised in netcdfDatasetInfo ops: " + e);
                    e.printStackTrace();
                }
            }
            // --- or atomic
            if (!globalAttributes && !foundNetcdfInfo) {
                // --- get ThreddsMetadata.Variables and create a netcdfDatasetInfo
                // --- document if possible
                List<ThreddsMetadata.Variables> vsL = ds.getVariables();
                if (vsL != null && vsL.size() > 0) {
                    for (ThreddsMetadata.Variables vs : vsL) {
                        String vHref = vs.getVocabHref();
                        URI vUri = vs.getVocabUri();
                        String vocab = vs.getVocabulary();
                        Element coords = new Element("netcdfDatasetInfo");
                        for (ThreddsMetadata.Variable v : vs.getVariableList()) {
                            Element varX = new Element("variable");
                            varX.setAttribute("name", v.getName());
                            varX.setAttribute("decl", v.getDescription());
                            varX.setAttribute("units", v.getUnits());
                            // - these three attributes are new but then there is no
                            // - xsd for this so we can add as we want!
                            varX.setAttribute("vocab", vocab);
                            varX.setAttribute("vocaburi", vUri.toString());
                            varX.setAttribute("vocabhref", vHref);
                            coords.addContent(varX);
                        }
                        log.info("Coordinate systems from ThreddsMetadata are: \n" + Xml.getString(coords));
                        setCoordsStyleSheet(isCollection);
                        addKeywordsAndDataParams(coords, md);
                    }
                }
            }
        }
        // --- write metadata
        saveMetadata(md, uuid, getUri(ds));
        // --- update totals
        if (isCollection) {
            result.collectionDatasetRecords++;
        } else {
            result.atomicDatasetRecords++;
        }
    } catch (Exception e) {
        log.error("Thrown Exception " + e + " during dataset processing");
        e.printStackTrace();
    }
}
Also used : Attribute(ucar.nc2.Attribute) Element(org.jdom.Element) ThreddsMetadata(thredds.catalog.ThreddsMetadata) NetcdfDataset(ucar.nc2.dataset.NetcdfDataset) Document(org.jdom.Document) URI(java.net.URI) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DIFWriter(thredds.catalog.dl.DIFWriter) NetcdfDatasetInfo(ucar.nc2.dataset.NetcdfDatasetInfo) InvMetadata(thredds.catalog.InvMetadata)

Example 75 with Attribute

use of com.mindbright.security.x509.Attribute in project PGM by PGMDev.

the class FilterParser method parseFiltersProperty.

/**
 * Return a list containing any and all of the following: - A filter reference in an attribute of
 * the given name - Inline filters inside child tags of the given name
 */
public List<Filter> parseFiltersProperty(Element el, String name) throws InvalidXMLException {
    List<Filter> filters = new ArrayList<>();
    Attribute attr = el.getAttribute(name);
    if (attr != null) {
        filters.add(this.parseReference(new Node(attr)));
    }
    for (Element elFilter : el.getChildren(name)) {
        filters.addAll(this.parseChildren(elFilter));
    }
    return filters;
}
Also used : Filter(tc.oc.pgm.api.filter.Filter) Attribute(org.jdom2.Attribute) Node(tc.oc.pgm.util.xml.Node) Element(org.jdom2.Element) ArrayList(java.util.ArrayList)

Aggregations

Attribute (org.jdom2.Attribute)316 Element (org.jdom2.Element)210 Attribute (ucar.nc2.Attribute)65 IOException (java.io.IOException)55 ArrayList (java.util.ArrayList)51 Document (org.jdom2.Document)43 Variable (ucar.nc2.Variable)39 List (java.util.List)31 HashMap (java.util.HashMap)25 Namespace (org.jdom2.Namespace)24 File (java.io.File)21 Array (ucar.ma2.Array)21 DataConversionException (org.jdom2.DataConversionException)19 Test (org.junit.Test)19 Dimension (ucar.nc2.Dimension)19 Map (java.util.Map)17 JDOMException (org.jdom2.JDOMException)16 XmlDslUtils.addMigrationAttributeToElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement)15 Editor (jmri.jmrit.display.Editor)15 NamedIcon (jmri.jmrit.catalog.NamedIcon)13