Example usage for org.jdom2 Element getText

List of usage examples for org.jdom2 Element getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the textual content directly held under this element as a string.

Usage

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

License:Open Source License

private void loadPinMapFromXml(SimpleLibraryCell libCell, Element belEl, BelId belId) {
    Element belPinsEl = belEl.getChild("pins");
    if (belPinsEl == null) {
        for (LibraryPin pin : libCell.getLibraryPins()) {
            ArrayList<String> possPins = new ArrayList<>(1);
            possPins.add(pin.getName());
            pin.getPossibleBelPins().put(belId, possPins);
        }/* w  w w .j  a  v  a2s.c o  m*/
    } else {
        Set<LibraryPin> unmappedPins = new HashSet<>();

        // Create the bel pin mappings for each cell pin
        for (Element belPinEl : belPinsEl.getChildren("pin")) {

            String pinName = belPinEl.getChildText("name");
            LibraryPin pin = libCell.getLibraryPin(pinName);

            // skip pins that have no default mapping
            if (belPinEl.getChild("no_map") != null) {
                unmappedPins.add(pin);
                continue;
            }

            ArrayList<String> possibles = new ArrayList<>();
            for (Element possibleEl : belPinEl.getChildren("possible")) {
                possibles.add(possibleEl.getText());
            }
            possibles.trimToSize();
            pin.getPossibleBelPins().put(belId, possibles);
        }

        // Look for cell pins without a bel pin mapping. For these
        // pins, assume a bel pin name that is identical to the cell pin name
        for (LibraryPin pin : libCell.getLibraryPins()) {
            if (pin.getPossibleBelPins(belId) != null || unmappedPins.contains(pin)) {
                continue;
            }
            ArrayList<String> possPins = new ArrayList<>(1);
            possPins.add(pin.getName());
            pin.getPossibleBelPins().put(belId, possPins);
        }
    }
}

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

License:Open Source License

private static void modifyPrimitiveElement(PrimitiveDef def, Element modificationEl) {
    PrimitiveElement element = def.getElement(modificationEl.getChildText("name"));
    if (element == null)
        assert false;

    Element typeEl = modificationEl.getChild("type");
    if (typeEl != null) {
        element.setMux(false);//ww  w. j a v a 2  s  .  c om
        element.setBel(false);
        element.setConfiguration(false);
        element.setPin(false);

        switch (typeEl.getText()) {
        case "mux":
            element.setMux(true);
            break;
        case "bel":
            element.setBel(true);
            break;
        case "cfg":
            element.setConfiguration(true);
            break;
        case "pin":
            element.setPin(true);
            break;
        default:
            assert false;
        }
    }
}

From source file:edu.ucla.loni.server.ServerUtils.java

License:Open Source License

/** 
 * Get the text value of children joined by separator
 *//*from w ww  .j  a  va 2 s.  c  o  m*/
private static String getChildrenText(Element element, String childName, String separator) {
    List<Element> children = element.getChildren(childName);
    int length = children.size();

    String ret = "";
    for (int i = 0; i < length; i++) {
        Element child = children.get(i);

        String text = child.getText();
        if (text != "") {
            ret += text + separator;
        }
    }

    // Remove the last separator
    if (ret != "") {
        ret = ret.substring(0, ret.length() - separator.length());
    }

    return ret;
}

From source file:edu.utep.cs.jasg.specificationGenerator.documentGenerator.ASTBehaviorDocumentFactory.java

License:Open Source License

private void parseAspectElement(Element aspectElement) {
    Element aspectNameElement = aspectElement.getChild("aspectName");
    //Append aspect start including aspect name
    try {/* w  ww  . j a v a  2 s  .com*/
        document.append(aspectStart(aspectNameElement.getText()));
    } catch (DocumentGeneratorException e) {
        e.printStackTrace();
    }

    Element ASTBehaviorsElement = aspectElement.getChild("ASTBehaviorElements");

    if (ASTBehaviorsElement != null) {

        //Get set of existing AST behavior elements 
        List<Element> ASTBehaviorList = ASTBehaviorsElement.getChildren();
        Iterator<Element> ASTBehaviorIterator = ASTBehaviorList.iterator();

        //Add existing behavior elements (i.e. attributes, rewrites)
        while (ASTBehaviorIterator.hasNext()) {
            document.append(formatASTBehavior(ASTBehaviorIterator.next().getText()));
        }
    }

    document.append(aspectEnd());
}

From source file:edu.utep.cs.jasg.specificationGenerator.documentGenerator.ASTDocumentFactory.java

License:Open Source License

private String parseASTDefinition(Element astDefinitionElement) {
    StringBuffer astDefinition = new StringBuffer();
    Element astName = astDefinitionElement.getChild("ast_name");
    Element astSuperClass = astDefinitionElement.getChild("ast_superClass");
    Attribute abstractAttribute = astDefinitionElement.getAttribute("abstract");
    Element astChildren = astDefinitionElement.getChild("ast_children");

    //Check if class is abstract
    if (abstractAttribute.equals("true")) {
        astDefinition.append("abstract ");
    }//from  w w  w  .j  av  a2s .com

    //Append AST node name
    astDefinition.append(astName.getText());

    //Check if node extends an existing AST node
    //TODO: this is where the tool should check if the parent is valid and 
    //necessary AST behaviors to implement
    if (astSuperClass != null) {
        astDefinition.append(": " + astSuperClass.getText());
    }

    //Parse AST children
    if (astChildren != null) {
        //Get set of existing AST children elements 
        List<Element> astChildrenList = astChildren.getChildren();
        Iterator<Element> astChildrenIterator = astChildrenList.iterator();

        //Append children operator
        if (astChildrenList.size() > 0)
            astDefinition.append(" ::= ");

        //Add AST children to definition
        while (astChildrenIterator.hasNext()) {
            astDefinition.append(astChildrenIterator.next().getText());
            if (astChildrenIterator.hasNext())
                astDefinition.append(" ");
        }
    }
    astDefinition.append(";\n");
    return astDefinition.toString();
}

From source file:edu.utep.cs.jasg.specificationGenerator.documentGenerator.JFlexDocumentFactory.java

License:Open Source License

protected String actionString(Element actionElement) {
    StringBuffer action = new StringBuffer();
    action.append("{ ");
    Element codeElement = actionElement.getChild("se_code");
    if (codeElement != null)
        action.append(codeElement.getText() + " ");

    Element terminalElement = actionElement.getChild("se_terminalName");
    action.append("return sym(Terminals." + terminalElement.getText() + "); }");
    return action.toString();
}

From source file:edu.utep.cs.jasg.specificationGenerator.documentGenerator.ParserDocumentFactory.java

License:Open Source License

public String parseRule(Element rule) {
    StringBuffer ruleBuffer = new StringBuffer();
    Element pe_idUse = rule.getChild("pe_idUse");
    Element pe_idDecl = rule.getChild("pe_idDecl");

    //Append ID use
    if (pe_idUse != null)
        ruleBuffer.append(pe_idUse.getText() + " ");

    //Append ID declaration
    ruleBuffer.append(pe_idDecl.getText() + " ");

    //Add definition symbol
    ruleBuffer.append(definitionSymbol());

    //Get rule definitions
    List<Element> pe_definitions = rule.getChildren("pe_definition");

    if (pe_definitions != null) {
        Iterator<Element> definitionIterator = pe_definitions.iterator();

        //Iterate through existing definitions
        while (definitionIterator.hasNext()) {
            //Parse definition
            Element pe_definition = definitionIterator.next();
            ruleBuffer.append(parseDefinition(pe_definition));

            if (definitionIterator.hasNext())
                ruleBuffer.append(elseSymbol());
        }// ww  w. j a  va 2s. com
    }
    return ruleBuffer.toString();
}

From source file:edu.utep.cs.jasg.specificationGenerator.documentGenerator.ParserDocumentFactory.java

License:Open Source License

protected String parseDefinition(Element pe_definition) {
    List<Element> pe_elements = pe_definition.getChildren("pe_element");
    StringBuffer ruleBuffer = new StringBuffer();
    if (pe_elements != null)
        if (pe_elements.size() > 0) {
            //Iterate through different 
            Iterator<Element> elementIterator = pe_elements.iterator();
            while (elementIterator.hasNext()) {
                Element pe_element = elementIterator.next();
                ruleBuffer.append(pe_element.getChild("pe_idUse").getText());
                ruleBuffer.append(idUseSeparator());
                Element pe_name = pe_element.getChild("pe_name");
                if (pe_name != null)
                    ruleBuffer.append(pe_name.getText() + " ");
            }/*from w ww.j a v  a 2 s  .  co  m*/
        }

    Element pe_code = pe_definition.getChild("pe_code");
    if (pe_code != null) {
        ruleBuffer.append(codeInit());
        ruleBuffer.append(pe_code.getText());
        ruleBuffer.append(codeEnd());
    }
    return ruleBuffer.toString();
}

From source file:edu.utep.cs.jasg.specificationGenerator.documentGenerator.ScannerDocumentFactory.java

License:Open Source License

protected String parseScannerRule(Element ruleElement) {
    StringBuffer rule = new StringBuffer();
    Element se_idDecl = ruleElement.getChild("se_idDecl");
    Element se_action = ruleElement.getChild("se_action");

    rule.append("\t" + ruleIDString(se_idDecl.getText()));
    rule.append(actionString(se_action));
    rule.append("\n");
    return rule.toString();
}

From source file:edu.utep.cs.jasg.specificationGenerator.documentGenerator.SpecificationGenerator.java

License:Open Source License

public void generateSpecification(String type, Element documentContent) throws DocumentGeneratorException {
    String fileName = "";
    String document = "";

    Element fileNameElement = documentContent.getChild("fileName");
    if (fileNameElement != null)
        fileName = fileNameElement.getText();
    else//  w w  w.ja  v a2s  . c  o m
        fileName = nameSpace;

    //Select document type
    switch (type) {
    case "parser": {
        ParserDocumentFactory parserDocumentFactory;
        String template = "";

        Element templateElement = documentContent.getChild("template");
        if (templateElement != null)
            template = templateElement.getText();
        else
            template = DEFAULT_PARSER;

        //Select parser document type
        switch (template) {
        //This is a JastAdd beaver specification template
        case "beaver": {
            parserDocumentFactory = new BeaverDocumentFactory(documentContent, template);
            document = parserDocumentFactory.generateDocument();
            if (fileName != null)
                fileFactory.createFile(document, nameSpace, fileName, type);
            break;
        }
        default:
            throw new DocumentGeneratorException("Invalid template name: " + template);
        }
        break;
    }

    case "scanner": {
        ScannerDocumentFactory scannerDocumentFactory;
        String template = "";

        Element templateElement = documentContent.getChild("template");
        if (templateElement != null)
            template = templateElement.getText();
        else
            template = DEFAULT_SCANNER;

        //Select scanner document type
        switch (template) {
        //this is really a slim jflex template
        case "jflex": {
            scannerDocumentFactory = new JFlexDocumentFactory(documentContent, template);
            document = scannerDocumentFactory.generateDocument();
            if (fileName != null)
                fileFactory.createFile(document, nameSpace, fileName, "flex");
            break;

        }
        default:
            throw new DocumentGeneratorException("Invalid template name: " + template);
        }
        break;
    }

    case "AST": {
        ASTDocumentFactory astDocumentFactory = new ASTDocumentFactory(documentContent);
        document = astDocumentFactory.generateDocument();
        if (fileName != null)
            fileFactory.createFile(document, nameSpace, fileName, "ast");
        break;

    }

    case "ASTBehavior": {
        ASTBehaviorDocumentFactory astBehaviorDocumentFactory = new ASTBehaviorDocumentFactory(documentContent);
        document = astBehaviorDocumentFactory.generateDocument();
        if (fileName != null)
            fileFactory.createFile(document, nameSpace, fileName, "jrag");
        break;

    }
    default:
        throw new DocumentGeneratorException("Invalid document type: " + type);
    }
}