Example usage for org.jdom2 Element getName

List of usage examples for org.jdom2 Element getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the (local) name of the element (without any namespace prefix).

Usage

From source file:de.openVJJ.basic.ProjectConf.java

License:Open Source License

public static void load(String fileName) {

    try {/* w ww .j a  va 2  s .co  m*/
        Document document = new SAXBuilder().build(fileName);
        Element rootElement = document.getRootElement();
        if (rootElement.getName() != ROOT_ELEMET_NAME) {
            System.err.println("is not an Open-VJJ 2 Project");
            return;
        }
        //         Element gpuElement = rootElement.getChild(GPU_ELEMENT_NAME);
        //         if(gpuElement != null){
        //            Attribute gpuActiv = gpuElement.getAttribute(GPU_ACTIV_ATTRIBUTE_NAME);
        //            if(gpuActiv != null){
        //               useGPU = gpuActiv.getBooleanValue();
        //            }
        //         }
        Element baseModuleElement = rootElement.getChild(ELEMET_NAME_BASE_MODULE);
        baseModule = new Module();
        baseModule.setBaseModule(true);
        baseModule.setConfig(baseModuleElement);
        if (projectFrame != null) {
            projectFrame.dispose();
        }
        openFrame();
    } catch (JDOMException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:de.openVJJ.InputComponents.java

License:Open Source License

public static void load(String fileName) {
    try {// w  w w.j  a va2s  .  c o m
        Document document = new SAXBuilder().build(fileName);
        Element rootElement = document.getRootElement();
        if (rootElement.getName() != ROOT_ELEMET_NAME) {
            System.err.println("is notan Open-VJJ Project");
            return;
        }
        Element gpuElement = rootElement.getChild(GPU_ELEMENT_NAME);
        if (gpuElement != null) {
            Attribute gpuActiv = gpuElement.getAttribute(GPU_ACTIV_ATTRIBUTE_NAME);
            if (gpuActiv != null) {
                useGPU = gpuActiv.getBooleanValue();
            }
        }
        removeAll();
        Element components = rootElement.getChild(COMPONENTS_ELEMENT_NAME);
        List<Element> elements = components.getChildren(COMPONENT_ELEMENT_NAME);
        for (Element rootComponente : elements) {
            addComponent((ImagePublisher) loadComponent(rootComponente));
        }
    } catch (JDOMException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilder.java

License:Apache License

private void handleChild(final ApplyToModule.Builder mBuilder, final XMLOutputter outputter,
        final Element child) {
    final String elementName = child.getName();
    if ("dependencies".equals(elementName)) {
        handleDependencies(mBuilder, outputter, child);
    } else if ("properties".equals(elementName)) {
        for (final Element propertyElement : child.getChildren("property", ModuleXmlBuilder.NS)) {
            final String name = propertyElement.getAttributeValue("name");
            final String fragment = outputter.outputString(propertyElement);
            mBuilder.addPropertyXml(name, fragment);
        }//from www.j  a va 2s .  c o m
    } else if ("exports".equals(elementName)) {
        final String fragment = outputter.outputString(child);
        mBuilder.withExportsXml(fragment);
    } else if ("main-class".equals(elementName)) {
        final String fragment = outputter.outputString(child);
        mBuilder.withMainClassXml(fragment);
    } else if ("resource-root".equals(elementName)) {
        final String fragment = outputter.outputString(child);
        mBuilder.addResourceRootXml(fragment);
    } else {
        // TODO warn or add to end?
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilder.java

License:Apache License

private void handleDependencies(final ApplyToModule.Builder mBuilder, final XMLOutputter outputter,
        final Element child) {
    int nonModuleCounter = 0;

    for (final Element childElement : child.getChildren()) {
        final String childElementName = childElement.getName();
        final String name;
        if ("module".equals(childElementName)) {
            name = childElement.getAttributeValue("name");
        } else {//from  w  w  w. j  av  a  2  s. c o m
            // i.e. system, maybe others.
            nonModuleCounter++;
            name = "non-module@" + nonModuleCounter;
        }
        final String fragment = outputter.outputString(childElement);
        mBuilder.addDependencyXml(name, fragment);
    }
}

From source file:de.sub.goobi.forms.MassImportForm.java

License:Open Source License

/**
 * generate a list with all possible collections for given project
 *//*from  w w w  .ja  v  a  2 s  .com*/

private void initializePossibleDigitalCollections() {
    this.possibleDigitalCollection = new ArrayList<>();
    ArrayList<String> defaultCollections = new ArrayList<>();
    String filename = this.help.getGoobiConfigDirectory() + "goobi_digitalCollections.xml";
    if (!StorageProvider.getInstance().isFileExists(Paths.get(filename))) {
        Helper.setFehlerMeldung("File not found: ", filename);
        return;
    }
    this.digitalCollections = new ArrayList<>();
    try {
        /* Datei einlesen und Root ermitteln */
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(filename);
        Element root = doc.getRootElement();
        /* alle Projekte durchlaufen */
        List<Element> projekte = root.getChildren();
        for (Iterator<Element> iter = projekte.iterator(); iter.hasNext();) {
            Element projekt = iter.next();

            // collect default collections
            if (projekt.getName().equals("default")) {
                List<Element> myCols = projekt.getChildren("DigitalCollection");
                for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) {
                    Element col = it2.next();

                    if (col.getAttribute("default") != null
                            && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                        digitalCollections.add(col.getText());
                    }

                    defaultCollections.add(col.getText());
                }
            } else {
                // run through the projects
                List<Element> projektnamen = projekt.getChildren("name");
                for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext();) {
                    Element projektname = iterator.next();
                    // all all collections to list
                    if (projektname.getText().equalsIgnoreCase(this.template.getProjekt().getTitel())) {
                        List<Element> myCols = projekt.getChildren("DigitalCollection");
                        for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) {
                            Element col = it2.next();

                            if (col.getAttribute("default") != null
                                    && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                                digitalCollections.add(col.getText());
                            }

                            this.possibleDigitalCollection.add(col.getText());
                        }
                    }
                }
            }
        }
    } catch (JDOMException e1) {
        log.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    } catch (IOException e1) {
        log.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    }

    if (this.possibleDigitalCollection.size() == 0) {
        this.possibleDigitalCollection = defaultCollections;
    }
}

From source file:de.sub.goobi.forms.ProzesskopieForm.java

License:Open Source License

private void initializePossibleDigitalCollections() {
    this.possibleDigitalCollection = new ArrayList<>();
    ArrayList<String> defaultCollections = new ArrayList<>();

    String filename = this.help.getGoobiConfigDirectory() + "goobi_digitalCollections.xml";
    if (!StorageProvider.getInstance().isFileExists(Paths.get(filename))) {
        Helper.setFehlerMeldung("File not found: ", filename);
        return;//from  w  w  w.j  a  v a  2 s . c o m
    }
    this.digitalCollections = new ArrayList<>();
    try {
        /* Datei einlesen und Root ermitteln */
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(filename);
        Element root = doc.getRootElement();
        /* alle Projekte durchlaufen */
        List<Element> projekte = root.getChildren();
        for (Iterator<Element> iter = projekte.iterator(); iter.hasNext();) {
            Element projekt = iter.next();

            // collect default collections
            if (projekt.getName().equals("default")) {
                List<Element> myCols = projekt.getChildren("DigitalCollection");
                for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) {
                    Element col = it2.next();

                    if (col.getAttribute("default") != null
                            && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                        digitalCollections.add(col.getText());
                    }

                    defaultCollections.add(col.getText());
                }
            } else {
                // run through the projects
                List<Element> projektnamen = projekt.getChildren("name");
                for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext();) {
                    Element projektname = iterator.next();
                    // all all collections to list
                    if (projektname.getText().equalsIgnoreCase(this.prozessKopie.getProjekt().getTitel())) {
                        List<Element> myCols = projekt.getChildren("DigitalCollection");
                        for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) {
                            Element col = it2.next();

                            if (col.getAttribute("default") != null
                                    && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                                digitalCollections.add(col.getText());
                            }

                            this.possibleDigitalCollection.add(col.getText());
                        }
                    }
                }
            }
        }
    } catch (JDOMException e1) {
        logger.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    } catch (IOException e1) {
        logger.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    }

    if (this.possibleDigitalCollection.size() == 0) {
        this.possibleDigitalCollection = defaultCollections;
    }

    // if only one collection is possible take it directly

    if (isSingleChoiceCollection()) {
        this.digitalCollections.add(getDigitalCollectionIfSingleChoice());
    }
}

From source file:de.tor.tribes.util.BuildingSettings.java

public static boolean loadSettings(String pServerID) {
    Arrays.fill(MAX_LEVEL, -1);/* w  w  w .  java2  s . c  o  m*/
    Arrays.fill(MIN_LEVEL, -1);

    Arrays.fill(BUILD_WOOD, -1);
    Arrays.fill(BUILD_STONE, -1);
    Arrays.fill(BUILD_IRON, -1);
    Arrays.fill(BUILD_POP, -1);
    Arrays.fill(BUILD_TIME, -1);
    Arrays.fill(BUILD_WOOD_FACTOR, Double.NaN);
    Arrays.fill(BUILD_STONE_FACTOR, Double.NaN);
    Arrays.fill(BUILD_IRON_FACTOR, Double.NaN);
    Arrays.fill(BUILD_POP_FACTOR, Double.NaN);
    Arrays.fill(BUILD_TIME_FACTOR, Double.NaN);

    try {
        logger.debug("Loading server buildings");
        String buildingsPath = Constants.SERVER_DIR + "/" + pServerID + "/buildings.xml";

        logger.debug("Parse buildings from '" + buildingsPath + "'");
        Document d = JDomUtils.getDocument(new File(buildingsPath));

        for (Element b : d.getRootElement().getChildren()) {
            String name = b.getName();
            int index = ArrayUtils.indexOf(BUILDING_NAMES, name);

            if (index < 0) {
                logger.warn("Found unknown Building {}", name);
                continue;
            }

            try {
                MAX_LEVEL[index] = Integer.parseInt(b.getChildTextTrim("max_level"));
                MIN_LEVEL[index] = Integer.parseInt(b.getChildTextTrim("min_level"));

                BUILD_WOOD[index] = Integer.parseInt(b.getChildTextTrim("wood"));
                BUILD_STONE[index] = Integer.parseInt(b.getChildTextTrim("stone"));
                BUILD_IRON[index] = Integer.parseInt(b.getChildTextTrim("iron"));
                BUILD_POP[index] = Integer.parseInt(b.getChildTextTrim("pop"));
                BUILD_TIME[index] = Integer.parseInt(b.getChildTextTrim("build_time"));
                BUILD_WOOD_FACTOR[index] = Double.parseDouble(b.getChildTextTrim("wood_factor"));
                BUILD_STONE_FACTOR[index] = Double.parseDouble(b.getChildTextTrim("stone_factor"));
                BUILD_IRON_FACTOR[index] = Double.parseDouble(b.getChildTextTrim("iron_factor"));
                BUILD_POP_FACTOR[index] = Double.parseDouble(b.getChildTextTrim("pop_factor"));
                BUILD_TIME_FACTOR[index] = Double.parseDouble(b.getChildTextTrim("build_time_factor"));
            } catch (Exception e) {
                logger.error("Got an excetion during reading of buildings", e);
            }
        }
    } catch (Exception e) {
        logger.error("Failed to load buildings", e);
        return false;
    }
    logger.info(Arrays.toString(MAX_LEVEL));
    logger.info(Arrays.toString(MIN_LEVEL));
    logger.info(Arrays.toString(BUILD_WOOD));
    logger.info(Arrays.toString(BUILD_STONE));
    logger.info(Arrays.toString(BUILD_IRON));
    logger.info(Arrays.toString(BUILD_POP));
    logger.info(Arrays.toString(BUILD_TIME));
    logger.info(Arrays.toString(BUILD_WOOD_FACTOR));
    logger.info(Arrays.toString(BUILD_STONE_FACTOR));
    logger.info(Arrays.toString(BUILD_IRON_FACTOR));
    logger.info(Arrays.toString(BUILD_POP_FACTOR));
    logger.info(Arrays.toString(BUILD_TIME_FACTOR));
    logger.debug("Successfully read buildings for server '" + pServerID + "'");
    return true;
}

From source file:delfos.configuration.scopes.ConfiguredDatasetsScope.java

License:Open Source License

private synchronized Collection<ConfiguredDataset> loadConfiguredDatasets() {
    File fileOfConfiguredDatasets = ConfigurationManager.getConfigurationFile(this);

    Collection<ConfiguredDataset> configuredDatasets = new ArrayList<>();

    if (!fileOfConfiguredDatasets.exists()) {
        Global.showWarning("The configured datasets file for this machine does not exists-");
        Global.showWarning("\tFile '" + fileOfConfiguredDatasets.getAbsolutePath() + "': not found.");
        Global.showWarning("The configured datasets file for this machine does not exists.");
        saveConfigurationScope();//w w  w .j  a va2 s . com
    } else {
        if (Global.isVerboseAnnoying()) {
            Global.showInfoMessage("Loading configured datasets from file '"
                    + fileOfConfiguredDatasets.getAbsolutePath() + "'\n");
        }
        try {
            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(fileOfConfiguredDatasets);

            Element rootElement = doc.getRootElement();
            if (!rootElement.getName().equals(CONFIGURED_DATASETS_ROOT_ELEMENT_NAME)) {
                IllegalArgumentException ex = new IllegalArgumentException(
                        "The XML does not contains the configured datasets.");
                ERROR_CODES.CANNOT_READ_CONFIGURED_DATASETS_FILE.exit(ex);
            }

            for (Element configuredDataset : rootElement.getChildren(CONFIGURED_DATASET_ELEMENT_NAME)) {
                String name = configuredDataset.getAttributeValue(CONFIGURED_DATASET_ELEMENT_NAME_ATTRIBUTE);
                String description = configuredDataset
                        .getAttributeValue(CONFIGURED_DATASET_ELEMENT_DESCRIPTION_ATTRIBUTE);
                Element datasetLoaderElement = configuredDataset.getChild(DatasetLoaderXML.ELEMENT_NAME);

                if (datasetLoaderElement == null) {
                    IllegalStateException ex = new IllegalStateException(
                            "Cannot retrieve configured dataset loader '" + name + "'");
                    ERROR_CODES.CANNOT_READ_CONFIGURED_DATASETS_FILE.exit(ex);
                }

                DatasetLoader<? extends Rating> datasetLoader = DatasetLoaderXML
                        .getDatasetLoader(datasetLoaderElement);

                if (Global.isVerboseAnnoying()) {
                    Global.showInfoMessage("\tConfigured dataset '" + name + "' loaded.\n");
                }

                configuredDatasets.add(new ConfiguredDataset(name, description, datasetLoader));

            }
            if (configuredDatasets.isEmpty()) {
                Global.showWarning("No configured datasets found, check configuration file.");
            }
        } catch (JDOMException | IOException ex) {
            ERROR_CODES.CANNOT_READ_CONFIGURED_DATASETS_FILE.exit(ex);
        }
    }

    return configuredDatasets;
}

From source file:delfos.group.grs.consensus.ConsensusOfIndividualRecommendationsToXML.java

License:Open Source License

public static ConsensusOutputModel readConsensusOutputXML(File consensusIntputXML)
        throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(consensusIntputXML);

    Element root = doc.getRootElement();
    if (!root.getName().equals(CONSENSUS_OUTPUT_ROOT_NAME)) {
        throw new IllegalArgumentException(
                "The XML does not contains a Case Study (" + consensusIntputXML.getAbsolutePath() + ")");
    }//from www . j  a  v a  2s.co  m

    Element consensus = root.getChild(CONSENSUS_OUTPUT_CONSENSUS_ELEMENT_NAME);

    int round = Integer.parseInt(consensus.getAttributeValue(CONSENSUS_OUTPUT_CONSENSUS_ATTRIBUTE_ROUND));
    double consensusDegree = Double
            .parseDouble(consensus.getAttributeValue(CONSENSUS_OUTPUT_CONSENSUS_ATTRIBUTE_CONSENSUS_DEGREE));

    Collection<Recommendation> consensusRecommendations = new ArrayList<>();

    for (Element alternative : consensus.getChildren(CONSENSUS_OUTPUT_ALTERNATVE_ELEMENT_NAME)) {
        int idItem = Integer
                .parseInt(alternative.getAttributeValue(CONSENSUS_OUTPUT_ALTERNATVE_ATTRIBUTE_ID_ITEM));
        double rank = Double
                .parseDouble(alternative.getAttributeValue(CONSENSUS_OUTPUT_ALTERNATVE_ATTRIBUTE_RANK));

        double preference = 1 / rank;
        consensusRecommendations.add(new Recommendation(idItem, preference));
    }

    return new ConsensusOutputModel(consensusDegree, round, consensusRecommendations);
}

From source file:delfos.group.io.xml.casestudy.GroupCaseStudyXML.java

License:Open Source License

/**
 * Carga la descripcin de un caso de estudio para sistemas de recomendacin
 * para grupos.//from w  w  w  . j ava 2  s  .  com
 *
 * @param file Archivo donde se encuentra almacenado el caso de estudio.
 * @return Caso de estudio recuperado del archivo.
 * @throws org.jdom2.JDOMException Cuando se intenta cargar un xml que no
 * tiene la estructura esperada. Chequear si esta desfasada la versin.
 * @throws IOException Cuando no se puede leer el archivo indicado o existe
 * algun fallo de conversin de datos al leer el contenido del mismo.
 */
public static GroupCaseStudyConfiguration loadGroupCaseDescription(File file)
        throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();

    Document doc = builder.build(file);
    Element caseStudy = doc.getRootElement();
    if (!caseStudy.getName().equals(CASE_ROOT_ELEMENT_NAME)) {
        throw new IllegalArgumentException("The XML does not contains a Case Study.");
    }
    GroupRecommenderSystem<Object, Object> groupRecommenderSystem = GroupRecommenderSystemXML
            .getGroupRecommenderSystem(caseStudy.getChild(GroupRecommenderSystemXML.ELEMENT_NAME));

    GroupFormationTechnique groupFormationTechnique = GroupFormationTechniqueXML
            .getGroupFormationTechnique(caseStudy.getChild(GroupFormationTechniqueXML.ELEMENT_NAME));
    ValidationTechnique validationTechnique = ValidationTechniqueXML
            .getValidationTechnique(caseStudy.getChild(ValidationTechniqueXML.ELEMENT_NAME));
    GroupPredictionProtocol groupPredictionProtocol = GroupPredictionProtocolXML
            .getGroupPredictionProtocol(caseStudy.getChild(GroupPredictionProtocolXML.ELEMENT_NAME));
    RelevanceCriteria relevanceCriteria = RelevanceCriteriaXML
            .getRelevanceCriteria(caseStudy.getChild(RelevanceCriteriaXML.ELEMENT_NAME));

    DatasetLoader<? extends Rating> datasetLoader = DatasetLoaderXML
            .getDatasetLoader(caseStudy.getChild(DatasetLoaderXML.ELEMENT_NAME));

    long seed = Long.parseLong(caseStudy.getAttributeValue(SeedHolder.SEED.getName()));
    int numExecutions = Integer.parseInt(caseStudy.getAttributeValue(NUM_EXEC_ATTRIBUTE_NAME));
    String caseStudyAlias = caseStudy.getAttributeValue(ParameterOwner.ALIAS.getName());

    return new GroupCaseStudyConfiguration(groupRecommenderSystem, datasetLoader, groupFormationTechnique,
            validationTechnique, groupPredictionProtocol, relevanceCriteria, caseStudyAlias, numExecutions,
            seed, null);
}