Example usage for org.jdom2 Document getRootElement

List of usage examples for org.jdom2 Document getRootElement

Introduction

In this page you can find the example usage for org.jdom2 Document getRootElement.

Prototype

public Element getRootElement() 

Source Link

Document

This will return the root Element for this Document

Usage

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

private void loadMacros(Document doc) {
    // Load all macro library cells into the cell library
    Element macrosEl = doc.getRootElement().getChild("macros");

    List<Element> childrenMacros = macrosEl.getChildren("macro");

    if (childrenMacros != null) {
        for (Element macroEl : childrenMacros) {
            loadMacroFromXml(macroEl);/*  ww  w  .  j ava 2  s  . co m*/
        }
    }
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

private void loadFromDoc(Document doc) {
    // get the family of the cell library.
    readFamilyType(doc.getRootElement().getChild("family"));

    Element cellsEl = doc.getRootElement().getChild("cells");
    Map<SiteType, Map<String, SiteProperty>> sitePropertiesMap = new HashMap<>();
    // first load the leaf cells
    for (Element cellEl : cellsEl.getChildren("cell")) {
        loadCellFromXml(cellEl, sitePropertiesMap);
    }/*from ww w .jav a 2 s . c  om*/
    // then load the macro cells if any exist
    Element macrosEl = doc.getRootElement().getChild("macros");

    if (macrosEl != null) {
        List<Element> childrenMacros = macrosEl.getChildren("macro");
        if (childrenMacros != null) {
            for (Element macroEl : childrenMacros) {
                loadMacroFromXml(macroEl);
            }
        }
    }
}

From source file:edu.byu.ece.rapidSmith.device.creation.DeviceGenerator.java

License:Open Source License

/**
 * Creates a map from pad bel name -> corresponding package pin. This
 * information is needed when generating Tincr Checkpoints from
 * RS to be loaded into Vivado.//  w  ww  .ja v a 2 s.c  om
 */
private static void createPackagePins(Device device, Document deviceInfo) {
    Element pinMapRootEl = deviceInfo.getRootElement().getChild("package_pins");

    if (pinMapRootEl == null) {
        throw new Exceptions.ParseException("No package pin information found in device info file: "
                + deviceInfo.getBaseURI() + ".\n"
                + "Either add the package pin mappings, or remove the device info file and regenerate.");
    }

    // Add the package pins to the device
    pinMapRootEl
            .getChildren("package_pin").stream().map(ppEl -> new PackagePin(ppEl.getChildText("name"),
                    ppEl.getChildText("bel"), ppEl.getChild("is_clock") != null))
            .forEach(packagePin -> device.addPackagePin(packagePin));

    if (device.getPackagePins().isEmpty()) {
        throw new Exceptions.ParseException("No package pin information found in device info file: "
                + deviceInfo.getBaseURI() + ".\n"
                + "Either add the package pin mappings, or remove the device info file and regenerate.");
    }
}

From source file:edu.byu.ece.rapidSmith.device.creation.PrimitiveDefsCorrector.java

License:Open Source License

private static Element getSiteTypeEl(Document deviceInfo, SiteType type) {
    Element siteTypesEl = deviceInfo.getRootElement().getChild("site_types");
    for (Element siteTypeEl : siteTypesEl.getChildren("site_type")) {
        if (siteTypeEl.getChildText("name").equals(type.name()))
            return siteTypeEl;
    }//from   ww  w.j  ava  2s. c o  m
    throw new FileFormatException("no site type " + type.name() + " in familyInfo.xml");
}

From source file:edu.co.usbcali.ir.util.ExtractReutersNews.java

public void extractNewsFromXml(String path) {
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File(path);

    String baseFileName = FilenameUtils.removeExtension(xmlFile.getName());
    String lineSeparator = System.getProperty("line.separator");

    try {/*from   w  ww. j  av a2 s . c  o m*/
        Document document = (Document) builder.build(xmlFile);
        Element rootNode = document.getRootElement();
        List listReuters = rootNode.getChildren("REUTERS");

        for (Object listElement : listReuters) {
            Element reuters = (Element) listElement;

            String newId = reuters.getAttributeValue("NEWID");
            String date = reuters.getChildText("DATE");

            List listText = reuters.getChildren("TEXT");
            Element text = (Element) listText.get(0);

            String title = text.getChildText("TITLE");
            String body = text.getChildText("BODY");

            String reuterContent = title + lineSeparator + date + lineSeparator + lineSeparator + body;
            String reuterPath = "reuters/" + baseFileName + "-" + newId + ".txt";

            WriteFile.writeFileContent(reuterContent, reuterPath);
        }
    } catch (JDOMException | IOException ex) {
        Logger.getLogger(ExtractReutersNews.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:edu.kit.iks.Cryptographics.Caesar.Demonstration.CryptoDemonstrationController.java

License:MIT License

/**
 * Constructor.//from   www  .j  a va2  s  .co  m
 * 
 * @param visualizationInfo
 */
public CryptoDemonstrationController(AbstractVisualizationInfo visualizationInfo) {
    super(visualizationInfo);

    SAXBuilder saxBuilder = new SAXBuilder();

    // obtain file object
    InputStream is = this.getClass().getResourceAsStream("/caesar/CaesarResources.xml");

    try {
        // converted file to document object
        Document document = saxBuilder.build(is);

        // get root node from xml
        this.cryptoResources = document.getRootElement();
    } catch (JDOMException | IOException e) {
        Logger.error(e);
    }
}

From source file:edu.kit.iks.Cryptographics.Caesar.Demonstration.IntroductionController.java

License:MIT License

/**
 * Constructor.//  ww  w  .ja  va  2 s .c o  m
 * 
 * @param visualizationInfo
 */
public IntroductionController(AbstractVisualizationInfo visualizationInfo) {
    super(visualizationInfo);

    SAXBuilder saxBuilder = new SAXBuilder();

    // obtain file object
    InputStream is = this.getClass().getResourceAsStream("/caesar/CaesarResources.xml");

    try {
        // converted file to document object
        Document document = saxBuilder.build(is);

        // get root node from xml
        this.caesarResources = document.getRootElement();
    } catch (JDOMException | IOException e) {
        Logger.error(e);
    }
}

From source file:edu.kit.iks.Cryptographics.Caesar.Experiment.CryptoExperimentController.java

License:MIT License

/**
 * Constructor./*ww  w.  j  a va  2 s .co  m*/
 * 
 * @param visualizationInfo
 */
public CryptoExperimentController(AbstractVisualizationInfo visualizationInfo) {
    super(visualizationInfo);

    SAXBuilder saxBuilder = new SAXBuilder();

    // obtain file object
    InputStream is = this.getClass().getResourceAsStream("/caesar/CaesarResources.xml");

    try {
        // converted file to document object
        Document document = saxBuilder.build(is);

        // get root node from xml
        this.cryptoResources = document.getRootElement();
    } catch (JDOMException | IOException e) {
        Logger.error(e);
    }

}

From source file:edu.kit.iks.Cryptographics.StartController.java

License:MIT License

/**
 * Loads the view/*from www.jav  a2s  .c o m*/
 */
@Override
public void loadView() {
    this.view = new JPanel(new GridBagLayout());
    this.view.setName("start-controller-view");

    SAXBuilder saxBuilder = new SAXBuilder();

    // obtain file object
    InputStream is = this.getClass().getResourceAsStream("/start/startResources.xml");

    try {
        // converted file to document object
        Document document = saxBuilder.build(is);

        // get root node from xml
        this.startResources = document.getRootElement();
    } catch (JDOMException | IOException e) {
        Logger.error(e);
    }

    // Add welcome view and its layout
    GridBagConstraints welcomeViewLayout = new GridBagConstraints();
    welcomeViewLayout.fill = GridBagConstraints.HORIZONTAL;
    welcomeViewLayout.gridy = 0;
    welcomeViewLayout.weighty = 0.95f;
    this.welcomeView = new WelcomeView();
    this.view.add(this.welcomeView, welcomeViewLayout);

    String path = startResources.getChild("welcomeImage").getAttributeValue("path");

    GridBagConstraints imgConstraint = new GridBagConstraints();
    imgConstraint.gridx = 0;
    imgConstraint.gridy = 1;
    imgConstraint.insets = new Insets(0, 0, 50, 0);
    ImageView imageToSet = new ImageView(path);
    this.view.add(imageToSet, imgConstraint);

    // Add timeline view and its layout
    GridBagConstraints timelineViewLayout = new GridBagConstraints();
    timelineViewLayout.fill = GridBagConstraints.HORIZONTAL;
    timelineViewLayout.weightx = 1.0f;
    timelineViewLayout.weighty = 0.05f;
    timelineViewLayout.gridy = 2;
    this.timelineView = new TimelineView(visualizationInfos);
    this.view.add(this.timelineView, timelineViewLayout);

    // Add event handlers
    for (VisualizationButton button : this.timelineView.getButtons()) {
        button.addMouseListener(new MouseClickListener() {
            @Override
            public void clicked(MouseEvent event) {
                VisualizationButton button = (VisualizationButton) event.getSource();
                presentPopoverAction(button.getVisualizationInfo(), button);
            }
        });
    }

    this.view.validate();
}

From source file:edu.kit.iks.Cryptographics.Vigenere.VigenereVisualizationInfo.java

License:MIT License

/**
 * loads the resources which are bundled with the jar file
 *//* w  w  w. j a v a 2s. c  om*/
private void loadResources() {
    SAXBuilder saxBuilder = new SAXBuilder();

    InputStream is = this.getClass().getResourceAsStream("/vigenere/VigenereResources.xml");

    try {
        // converted file to document object
        Document document = saxBuilder.build(is);

        // get root node from xml
        this.vigenereResources = document.getRootElement().getChild("vigenere");
    } catch (JDOMException | IOException e) {
        Logger.error(e);
    }
}