Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

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

Prototype

public String getChildText(final String cname) 

Source Link

Document

Returns the textual content of the named child element, or null if there's no such child.

Usage

From source file:org.artifactory.version.VersionParser.java

License:Open Source License

/**
 * Parses the received input string info an ArtifactoryVersioning object
 *
 * @param input String containing the XML of the versioning info file
 * @return ArtifactoryVersioning - Object representation of the versioning info xml
 *///  w ww.  ja v a 2  s  . c o m
public static ArtifactoryVersioning parse(String input) {
    Document doc = XmlUtils.parse(input);
    Element root = doc.getRootElement();
    Element version = root.getChild("versioning");
    if (version == null) {
        throw new RuntimeException("No version is defined");
    }

    VersionHolder latest = null;
    VersionHolder release = null;
    List children = version.getChildren();
    for (Object child : children) {
        Element holder = (Element) child;
        String versionNumber = holder.getChildText("version");
        String revisionNumber = holder.getChildText("revision");
        String wikiUrl = holder.getChildText("wikiUrl");
        String downloadUrl = holder.getChildText("downloadUrl");
        if ("latest".equals(holder.getName())) {
            latest = new VersionHolder(versionNumber, revisionNumber, wikiUrl, downloadUrl);
        } else if ("release".equals(holder.getName())) {
            release = new VersionHolder(versionNumber, revisionNumber, wikiUrl, downloadUrl);
        }
    }

    if ((latest == null) || (release == null)) {
        throw new IllegalArgumentException("Latest and stable version and revisions are not defined properly");
    }

    return new ArtifactoryVersioning(latest, release);
}

From source file:org.chibios.tools.eclipse.config.handlers.GenerateFiles.java

License:Open Source License

/**
 * the command has been executed, so extract extract the needed information
 * from the application context./*from   w  ww.j  av  a 2s. c  om*/
 */
public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    ISelection selection = window.getSelectionService().getSelection();
    if (selection instanceof IStructuredSelection) {

        /* Retrieves the full path of the configuration file. */
        IPath cfgfilepath = ((IFile) ((IStructuredSelection) selection).getFirstElement()).getLocation();

        /* DOM tree creation. */
        SAXBuilder builder = new SAXBuilder();
        Document document;
        try {
            document = builder.build(cfgfilepath.toFile());
        } catch (JDOMException e) {
            return null;
        } catch (IOException e) {
            return null;
        }

        /* Retrieving configuration settings info.*/
        Element settings = document.getRootElement().getChild("configuration_settings");
        String templates_path = settings.getChildText("templates_path");
        String output_path = settings.getChildText("output_path");

        /* Calculating derived paths. */
        IPath tpath = new Path(templates_path);
        try {
            Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
            tpath = new Path(FileLocator.toFileURL(FileLocator.find(bundle, tpath, null)).getFile());
        } catch (IOException e) {
            MessageDialog.openInformation(window.getShell(), "Path Error", e.getMessage());
            return null;
        }

        /* Templates execution. */
        try {
            TemplateEngine.process(cfgfilepath.toFile(), tpath.toFile(), new File(output_path));
        } catch (TemplateException e) {
            MessageDialog.openInformation(window.getShell(), "Processing Error", e.getMessage());
            return null;
        }

        /* Destination directory refresh.*/
        IContainer container = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(cfgfilepath)
                .getParent();
        try {
            container.refreshLocal(IResource.DEPTH_INFINITE, null);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:org.chibios.tools.eclipse.config.wizards.ConfigurationNewWizardPage.java

License:Open Source License

/**
 * @see IDialogPage#createControl(Composite)
 *//* w w w . j  av  a  2 s  . c  o m*/
@Override
public void createControl(Composite parent) {
    container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;
    layout.verticalSpacing = 9;

    Label lbl1 = new Label(container, SWT.NULL);
    lbl1.setText("Configuration template:");

    configurationTemplatesCombo = new Combo(container, SWT.READ_ONLY);
    configurationTemplatesCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lbl2 = new Label(container, SWT.NULL);
    lbl2.setText("Configuration project filename:");

    confProjectFilenameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    confProjectFilenameText.setText("config.chcfg");
    confProjectFilenameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    confProjectFilenameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            confProjectFilenameUpdated();
        }
    });

    /* Note, it must stay after the creation of the text fields. */
    configurationTemplatesCombo.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            Element processor = getSelectedTemplate();
            String basefilename = processor.getChildText("basefilename");
            confProjectFilenameText.setText(basefilename.concat(".chcfg"));
            currentDefaultDataFile = processor.getChildText("default");
        }
    });

    initialize();
    setControl(container);
}

From source file:org.chibios.tools.eclipse.config.wizards.ConfigurationNewWizardPage.java

License:Open Source License

/**
 * Tests if the current workbench selection is a suitable container to use.
 *///from  w w  w .  j  av  a 2 s  .co  m
private void initialize() {

    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() > 1)
            return;
        Object obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            if (obj instanceof IContainer)
                resourceContainer = (IContainer) obj;
            else
                resourceContainer = ((IResource) obj).getParent();
        }
    } else {
        MessageDialog.openError(getShell(), "Error", "Container for the resource not selected.");
        container.setEnabled(false);
        updateStatus("Container for the resource not selected.");
    }

    /* Retrieving the resource path of the processors.xml file. */
    String fpath;
    try {
        Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
        IPath path = new Path("resources/gencfg/processors/processors.xml");
        fpath = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    /* DOM tree creation. */
    SAXBuilder builder = new SAXBuilder();
    try {
        processorsDocument = builder.build(fpath);
    } catch (JDOMException e) {
        e.printStackTrace();
        return;
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    /* Parsing the content of the processors.xml file in order to populate the
       panel objects.*/
    Element root = processorsDocument.getRootElement();
    for (Element processor : root.getChildren("processor")) {
        String name = processor.getChildText("name");
        configurationTemplatesCombo.add(name);
    }
    configurationTemplatesCombo.select(0);
}

From source file:org.chibios.tools.eclipse.config.wizards.ConfigurationNewWizardPage.java

License:Open Source License

/**
 * Returns the XML Element associated to the current selection in the combo
 * box./*  w w  w  .jav  a 2s. c  om*/
 * 
 * @return An Element Object.
 */
private Element getSelectedTemplate() {

    for (Element processor : processorsDocument.getRootElement().getChildren("processor")) {
        String name = processor.getChildText("name");
        String item = configurationTemplatesCombo.getItem(configurationTemplatesCombo.getSelectionIndex());
        if (name.compareTo(item) == 0) {
            return processor;
        }
    }
    return null;
}

From source file:org.educautecisystems.core.chat.elements.UserChat.java

License:Open Source License

public static ArrayList<UserChat> generateListFromXML(String xml) {
    StringReader xmlSR = new StringReader(xml);
    ArrayList<UserChat> response = new ArrayList<UserChat>();

    SAXBuilder builder = new SAXBuilder();

    try {//from w w  w  .  j  av  a 2s  .c o  m
        Document documentXML = builder.build(xmlSR);

        Element root = documentXML.getRootElement();
        Namespace baseNamespace = Namespace.getNamespace("chat", "http://free.chat.com/");

        /* Get all users */
        List<Element> users = root.getChildren("user", baseNamespace);

        for (Element user : users) {
            String id_string = user.getChildText("id");
            int id = 0;
            String realName = user.getChildText("real_name");
            String nickName = user.getChildText("nickname");

            try {
                id = Integer.parseInt(id_string);
            } catch (NumberFormatException nfe) {
                return null;
            }

            UserChat newUserChat = new UserChat(id, realName, nickName);
            response.add(newUserChat);
        }
    } catch (JDOMException jdome) {
        return null;
    } catch (IOException ioe) {
        return null;
    }

    return response;
}

From source file:org.educautecisystems.core.Sistema.java

License:Open Source License

private static void cargarConfPrincipal(File archivoConfPrincipal) {
    SAXBuilder builder = new SAXBuilder();
    Document documento = null;//from  www  . jav  a 2  s  .  c o  m

    try {
        documento = builder.build(archivoConfPrincipal);
    } catch (JDOMException jdome) {
        System.err.println("JDOME: " + jdome);
    } catch (IOException ioe) {
        System.err.println("IOE: " + ioe);
    }

    Namespace baseNamespace = Namespace.getNamespace("eus", "http://educautecisystems.org/");
    Element root = documento.getRootElement();

    /* Informacin de la base de datos. */
    Element eBaseDeDatos = root.getChild("database", baseNamespace);
    confBaseDeDatos.setHost(eBaseDeDatos.getChildText("host"));
    confBaseDeDatos.setPort(eBaseDeDatos.getChildText("port"));
    confBaseDeDatos.setUser(eBaseDeDatos.getChildText("user"));
    confBaseDeDatos.setPassword(eBaseDeDatos.getChildText("password"));
    confBaseDeDatos.setEsquema(eBaseDeDatos.getChildText("esquema"));
}

From source file:org.educautecisystems.core.Sistema.java

License:Open Source License

private static void cargarChatConf(File archivoConfChatXML) {
    ChatServerConf lChatServerConf = new ChatServerConf();
    ChatSessionConf lChatSessionConf = new ChatSessionConf();

    SAXBuilder builder = new SAXBuilder();
    Document documento = null;//from w  ww  . jav  a2s . c  o  m

    try {
        documento = builder.build(archivoConfChatXML);
    } catch (JDOMException jdome) {
        System.err.println("JDOME: " + jdome);
    } catch (IOException ioe) {
        System.err.println("IOE: " + ioe);
    }

    Namespace baseNamespace = Namespace.getNamespace("chat", "http://free.chat.com/");
    Element root = documento.getRootElement();

    /* Datos del servidor */
    Element eServidor = root.getChild("server", baseNamespace);
    lChatServerConf.setIp(eServidor.getChildText("ip"));
    lChatServerConf.setPort(eServidor.getChildText("port"));

    /* Datos de la sesin */
    Element eSession = root.getChild("session", baseNamespace);
    lChatSessionConf.setNickname(eSession.getChildText("nickname"));
    lChatSessionConf.setRealName(eSession.getChildText("real_name"));

    /* Guardar informacin */
    Sistema.chatServerConf = lChatServerConf;
    Sistema.chatSessionConf = lChatSessionConf;
}

From source file:org.esa.s1tbx.io.terrasarx.TerraSarXProductDirectory.java

License:Open Source License

private MetadataElement addMetaDataForTanDemX() throws IOException {

    // xmlDoc is the "main" annotation (i.e., the file with name "TDM... .xml")
    final Element mainRootElement = xmlDoc.getRootElement();

    final String inSARmasterID = mainRootElement.getChild("commonAcquisitionInfo").getChild("inSARmasterID")
            .getText().toLowerCase();/*from w w  w  . j a  v  a2  s.c  om*/
    final String inSARslaveID = inSARmasterID.endsWith("1") ? "sat2" : "sat1";
    masterSatellite = mainRootElement.getChild("commonAcquisitionInfo").getChild("satelliteID" + inSARmasterID)
            .getText();
    slaveSatellite = mainRootElement.getChild("commonAcquisitionInfo").getChild("satelliteID" + inSARslaveID)
            .getText();

    final List<Element> componentList = mainRootElement.getChild("productComponents").getChildren("component");
    Element masterAnnotationComponent = null;
    Element slaveAnnotationComponent = null;
    for (Element component : componentList) {
        final String satId = component.getChild("instrument").getChildText("satIDs");
        if (component.getChildText("name").startsWith("cossc_annotation")) {
            if (satId.equals(masterSatellite)) {
                masterAnnotationComponent = component;
            }
            if (satId.equals(slaveSatellite)) {
                slaveAnnotationComponent = component;
            }
        }
        if (masterAnnotationComponent != null && slaveAnnotationComponent != null) {
            break;
        }
    }
    if (masterAnnotationComponent == null) {
        throw new IOException(
                "Cannot locate primary annotation component (master product) in main annotation of TDM product");
    }
    if (slaveAnnotationComponent == null) {
        throw new IOException(
                "Cannot locate secondary annotation component (slave product) in main annotation of TDM product");
    }

    final String masterHeader = masterAnnotationComponent.getChild("file").getChild("location")
            .getChildText("name");
    masterProductName = masterHeader.substring(0, masterHeader.indexOf("/"));

    // Build the slave metadata

    final String slaveHeader = slaveAnnotationComponent.getChild("file").getChild("location")
            .getChildText("name");
    slaveProductName = slaveHeader.substring(0, slaveHeader.indexOf("/"));

    final Document slaveDoc = XMLSupport.LoadXML(getInputStream(slaveHeader));
    final Element slaveRootElement = slaveDoc.getRootElement();

    final MetadataElement slaveRoot = new MetadataElement("Slave_Metadata");
    AbstractMetadataIO.AddXMLMetadata(slaveRootElement, AbstractMetadata.addOriginalProductMetadata(slaveRoot));
    addAbstractedMetadataHeader(slaveRoot);

    final MetadataElement slaveAbstractedMetadataElem = slaveRoot.getElement("Abstracted_Metadata");

    // Add Product_Information to slave Abstracted_Metadata
    final MetadataElement productInfo = new MetadataElement("Product_Information");
    final MetadataElement inputProd = new MetadataElement("InputProducts");
    productInfo.addElement(inputProd);
    inputProd.setAttributeString("InputProduct", slaveProductName);
    slaveAbstractedMetadataElem.addElement(productInfo);

    // Change the name from Abstracted_Metadata to the slave product name
    slaveAbstractedMetadataElem.setName(slaveProductName);

    // Remove Original_Product_Data from Slave_Metadata
    slaveRoot.removeElement(slaveRoot.getElement("Original_Product_Metadata"));

    // Use the master's annotation to build the Abstracted_Metadata and Original_Product_Metadata.

    final MetadataElement metadataRoot = new MetadataElement(Product.METADATA_ROOT_NAME);
    final Document masterDoc = XMLSupport.LoadXML(getInputStream(masterHeader));
    final Element masterRootElement = masterDoc.getRootElement();
    AbstractMetadataIO.AddXMLMetadata(masterRootElement,
            AbstractMetadata.addOriginalProductMetadata(metadataRoot));

    addAbstractedMetadataHeader(metadataRoot);

    // Replace the product name (which right now is the master product) with the TDM product.
    // Replace data in Abstracted_Metadata with TDM values.

    MetadataElement abstractedMetadata = metadataRoot.getElement("Abstracted_Metadata");

    // Turn on the coregistration flag
    abstractedMetadata.setAttributeInt("coregistered_stack", 1);

    // Replace PRODUCT
    productName = getHeaderFileName().substring(0, getHeaderFileName().length() - 4);
    replaceAbstractedMetadataField(abstractedMetadata, "PRODUCT", productName);

    // Replace PRODUCT_TYPE
    productType = mainRootElement.getChild("productInfo").getChildText("productType");
    replaceAbstractedMetadataField(abstractedMetadata, "PRODUCT_TYPE", productType);

    // Replace SPH_DESCRIPTOR
    replaceAbstractedMetadataField(abstractedMetadata, "SPH_DESCRIPTOR",
            mainRootElement.getChild("generalHeader").getChildText("itemName"));

    // Replace mission
    replaceAbstractedMetadataField(abstractedMetadata, "MISSION", "TDM");

    // Add the CoSSC metadata, i.e., the "main" annotation from the file with name "TDM... .xml"
    final MetadataElement cosscMetadataElem = new MetadataElement("CoSSC_Metadata");
    AbstractMetadataIO.AddXMLMetadata(mainRootElement, cosscMetadataElem);
    metadataRoot.addElement(cosscMetadataElem);

    // Turn on the bi-static flag
    abstractedMetadata.setAttributeInt("bistatic_stack", 1);

    // Add the slave metadata
    metadataRoot.addElement(slaveRoot);

    return metadataRoot;
}

From source file:org.fiware.cybercaptor.server.flowmatrix.FlowMatrixLine.java

License:Open Source License

/**
 * Create a flow matrix line from a XML DOM element
 *
 * @param element  the XML DOM Element//from   ww w  . j  a v a  2s.c  o m
 * @param topology the network topology object
 */
public FlowMatrixLine(Element element, Topology topology) {
    if (element == null)
        throw new IllegalArgumentException("The flow matrix line element is null");
    source = new FlowMatrixElement(element.getChild("source"), topology);
    destination = new FlowMatrixElement(element.getChild("destination"), topology);
    source_port = PortRange.fromString(element.getChildText("source_port"));
    destination_port = PortRange.fromString(element.getChildText("destination_port"));
    protocol = FirewallRule.Protocol.getProtocolFromString(element.getChildText("protocol"));
}