Example usage for org.jdom2 Element Element

List of usage examples for org.jdom2 Element Element

Introduction

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

Prototype

public Element(final String name) 

Source Link

Document

Create a new element with the supplied (local) name and no namespace.

Usage

From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java

License:Apache License

/**
 * ??  ?   ?// w w  w . j  a v  a 2 s. co  m
 * 
 * @param data
 * @param upload
 * @return
 */
public static List<Element> setExceptionData(PDFMetadataDefinition data, Upload upload) {

    List<Element> childs = new ArrayList<Element>();

    Element section;
    for (ExceptionInfo comm : data.getExceptionInfoList()) {
        section = new Element("section");
        section.setAttribute("title", comm.getLocation());

        if (comm.getComments() != null && comm.getComments().length() > 0)
            section.addContent(new Element("text").setText(comm.getComments()));

        section.addContent(new Element("box").setText(comm.getStackTrace()));

        childs.add(section);
    }

    return childs;
}

From source file:com.bc.fiduceo.reader.airs.EosCoreMetaParser.java

License:Open Source License

Element parseFromString(String text) {

    Element rootElem = new Element("odl");
    Element current = rootElem;/*from w w w.j  ava 2  s.co m*/
    StringTokenizer lineFinder = new StringTokenizer(text, "\n");

    while (lineFinder.hasMoreTokens()) {
        String line = lineFinder.nextToken();
        line = line.trim();
        if (line.isEmpty()) {
            continue;
        }
        if (line.startsWith("GROUP")) {
            if (line.contains("GROUPTYPE")) {
                continue;
            }
            current = this.startGroup(current, line);
        } else if (line.startsWith("OBJECT")) {
            current = this.startObject(current, line);
        } else if (line.startsWith("END_OBJECT")) {
            this.endObject(current, line);
            current = current.getParentElement();
        } else if (line.startsWith("END_GROUP")) {
            this.endGroup(current, line);
            current = current.getParentElement();
        } else {
            this.addField(current, line);
        }
    }
    return rootElem;
}

From source file:com.bc.fiduceo.reader.airs.EosCoreMetaParser.java

License:Open Source License

private Element startGroup(Element parent, String line) {
    StringTokenizer stoke = new StringTokenizer(line, "=");
    String toke = stoke.nextToken();
    assert toke.equals("GROUP");
    String name = stoke.nextToken();
    Element group = new Element(name);
    parent.addContent(group);/*from www.  j a  va 2s  .  c  o  m*/
    return group;
}

From source file:com.bc.fiduceo.reader.airs.EosCoreMetaParser.java

License:Open Source License

private Element startObject(Element parent, String line) {
    StringTokenizer stoke = new StringTokenizer(line, "=");
    String toke = stoke.nextToken();
    assert toke.equals("OBJECT");
    String name = stoke.nextToken();
    Element obj = new Element(name);
    parent.addContent(obj);//  w  ww  . j  av  a2  s.c o  m
    return obj;
}

From source file:com.bc.fiduceo.reader.airs.EosCoreMetaParser.java

License:Open Source License

private void addField(Element parent, String line) {
    StringTokenizer stoke = new StringTokenizer(line, "=");
    String name = stoke.nextToken();
    if (stoke.hasMoreTokens()) {
        Element field = new Element(name);
        parent.addContent(field);//from   w  w w.j a  v  a2  s. co  m
        String value = stoke.nextToken();
        if (value.startsWith("(")) {
            this.parseValueCollection(field, value);
            return;
        }
        value = this.stripQuotes(value);
        field.addContent(value);
    }
}

From source file:com.bc.fiduceo.reader.airs.EosCoreMetaParser.java

License:Open Source License

private void parseValueCollection(Element field, String value) {
    if (value.startsWith("(")) {
        value = value.substring(1);// w w  w  .  j a  va2  s  . c  o m
    }

    if (value.endsWith(")")) {
        value = value.substring(0, value.length() - 1);
    }

    StringTokenizer stoke = new StringTokenizer(value, "\",");

    while (stoke.hasMoreTokens()) {
        field.addContent((new Element("value")).addContent(this.stripQuotes(stoke.nextToken())));
    }

}

From source file:com.bio4j.neo4jdb.model.util.GoUtil.java

License:Open Source License

/**
 * /*www . ja  va 2s  . co m*/
 * @param proteins
 * @param slimSetXML
 * @param manager
 * @param goAnnotationXML
 * @return GO Slim in xml format
 */
public static GOSlimXML getGoSlim(ArrayList<ProteinXML> proteins, SlimSetXML slimSetXML, Bio4jManager manager,
        GoAnnotationXML goAnnotationXML) {

    GOSlimXML goSlimXML = new GOSlimXML();

    if (goAnnotationXML == null) {
        goAnnotationXML = GoUtil.getGoAnnotation(proteins, manager);
    }

    //int goTermsLostNotIncludedInSlimSet = 0;

    Index<Node> goTermIdIndex = manager.getGoTermIdIndex();

    if (goAnnotationXML != null) {

        List<GoTermXML> goAnnotators = goAnnotationXML.getAnnotatorGoTerms();

        //IndexService indexService = manager.getIndexService();

        // in this hash map there is one entry for each annotator go term
        // the hash-set contains every slim-set go term including the annotator
        HashMap<String, HashSet<String>> goAnnotatorsIncludingSlimSetTermsMap = new HashMap<String, HashSet<String>>();

        //Here are the xml elements of the Go terms from the slim set termid --> term xml
        HashMap<String, GoTermXML> slimSetGos = new HashMap<String, GoTermXML>();

        //Here are the number of proteins annotated for each go term of the slim set termid --> number of proteins annotated
        HashMap<String, Integer> slimSetTermsAnnotationCounts = new HashMap<String, Integer>();

        //Now I extract the ids of the SlimSet
        List<Element> slimElements = slimSetXML.asJDomElement().getChildren(GoTermXML.TAG_NAME);
        for (Element slimElement : slimElements) {
            GoTermXML tempGo = new GoTermXML(slimElement);

            //--completing data of slimset go terms-----
            GoTermNode tempGoNode = new GoTermNode(
                    manager.getGoTermIdIndex().get(GoTermNode.GO_TERM_ID_INDEX, tempGo.getId()).getSingle());
            tempGo.setAspect(tempGoNode.getNamespace());
            tempGo.setGoName(tempGoNode.getName());
            //------------------------

            slimSetGos.put(tempGo.getId(), tempGo);

            //initializing annotation counts map
            slimSetTermsAnnotationCounts.put(tempGo.getId(), 0);
        }
        //--------------------------------------------

        //            logger.log(Level.INFO, "slimsetIds:");
        //            for (String slimId : slimSetIds) {
        //                logger.log(Level.INFO, ("slimId:" + slimId));
        //            }

        //Now it is time for goAnnotatorsIncludingSlimSetTermsMap initialization
        for (GoTermXML goAnnotator : goAnnotators) {
            goAnnotatorsIncludingSlimSetTermsMap.put(goAnnotator.getId(), new HashSet<String>());
        }
        //------------------------------------------------------

        try {

            IsAGoRel goParentRel = new IsAGoRel(null);

            //Now I search the way up of every go Annotator and check if in the way I find
            //any of the terms included in the slim set.

            //logger.log(Level.INFO, "lalalala");

            int callCounter = 0;

            for (GoTermXML goAnnotator : goAnnotators) {
                //this array includes the term own id and every ancestor id
                HashSet<String> ancestorsIds = new HashSet<String>();

                GoTermNode goTermNode = new GoTermNode(
                        goTermIdIndex.get(GoTermNode.GO_TERM_ID_INDEX, goAnnotator.getId()).getSingle());

                //logger.log(Level.INFO, goTermNode.toString());

                fillUpAncestorIds(goTermNode, ancestorsIds, goParentRel, manager.getIsAGoRelIndex(),
                        callCounter);

                for (String ancestorId : ancestorsIds) {
                    //If the ancestor is included in the slim set, it means that this term
                    //from the slim set includes the goAnnotator 
                    if (slimSetGos.keySet().contains(ancestorId)) {
                        HashSet<String> hashSet = goAnnotatorsIncludingSlimSetTermsMap.get(goAnnotator.getId());
                        hashSet.add(ancestorId); //ancestorId is actually one of the slim-set terms ids.
                    }
                }

                callCounter++;
            }

            //So now I should have every goAnnotator with its corresponing slimSet terms

            List<Element> proteinList = goAnnotationXML.getProteinAnnotations()
                    .getChildren(ProteinXML.TAG_NAME);

            Element proteinsElem = new Element(GOSlimXML.PROTEINS_TAG_NAME);

            int sampleAnnotatedGeneNumber = 0;

            for (Element currentElem : proteinList) {

                boolean annotated = false;

                //getting the protein
                ProteinXML currentProteinXML = new ProteinXML(currentElem);

                //initializing inductors map                    
                HashMap<String, String> currentProteinSlimTermInductors = new HashMap<String, String>();
                //proteinSlimTermsAndInductorTermsMap.put(currentProteinXML.getId(), currentProteinSlimTermInductors);

                //System.out.println("currentProteinXML.getId() = " + currentProteinXML.getId());

                //--------now we access to its go annotations-------------
                List<GoTermXML> proteinTerms = new ArrayList<GoTermXML>();
                List<GoTermXML> bpTerms = currentProteinXML.getBiologicalProcessGoTerms();
                List<GoTermXML> ccTerms = currentProteinXML.getCellularComponentGoTerms();
                List<GoTermXML> mfTerms = currentProteinXML.getMolecularFunctionGoTerms();
                if (bpTerms != null) {
                    proteinTerms.addAll(bpTerms);
                }
                if (ccTerms != null) {
                    proteinTerms.addAll(ccTerms);
                }
                if (mfTerms != null) {
                    proteinTerms.addAll(mfTerms);
                }
                //------------------------------------------------------
                //creating the result xml protein
                ProteinXML proteinResult = new ProteinXML();
                proteinResult.setId(currentProteinXML.getId());
                HashSet<String> proteinSlimTems = new HashSet<String>();
                for (GoTermXML goTermXML : proteinTerms) {
                    HashSet<String> hashSet = goAnnotatorsIncludingSlimSetTermsMap.get(goTermXML.getId());

                    System.out.println("");

                    if (hashSet != null) {
                        if (hashSet.size() > 0) {
                            proteinSlimTems.addAll(hashSet);
                            for (String tempSlimTermId : hashSet) {
                                currentProteinSlimTermInductors.put(tempSlimTermId, goTermXML.getId());
                            }
                            annotated = true;
                        } else {
                            //-----The go term annotation lost is stored-------
                            goSlimXML.addGoTermLostNotIncludedInSlimSet(
                                    new GoTermXML((Element) goTermXML.asJDomElement().clone()));
                            System.out.println("holaaa!" + goTermXML.getId());
                        }
                    }
                }

                //now we get the info from the slimset go terms
                for (String string : proteinSlimTems) {
                    //logger.log(Level.INFO, ("string: " + string));
                    GoTermXML tempGoTerm = new GoTermXML(
                            (Element) slimSetGos.get(string).asJDomElement().clone());

                    //------Adding protein annotation term leading to slim set term -----------
                    String termInductorId = currentProteinSlimTermInductors.get(tempGoTerm.getId());
                    //look for inductor info                        
                    for (GoTermXML goTermXML : proteinTerms) {
                        //System.out.println("goTermXML = " + goTermXML);
                        if (goTermXML.getId().equals(termInductorId)) {
                            tempGoTerm.setProteinAnnotationLeadingToSlimTerm(
                                    new GoTermXML((Element) goTermXML.asJDomElement().clone()));
                            break;
                        }
                    }
                    //--------------------------------------------------------------------------

                    //logger.log(Level.INFO, ("tempGoTerm: " + tempGoTerm));
                    proteinResult.addGoTerm(tempGoTerm, true);

                    //updating annotation counts
                    slimSetTermsAnnotationCounts.put(string, slimSetTermsAnnotationCounts.get(string) + 1);
                }

                proteinsElem.addContent(proteinResult.asJDomElement());

                if (annotated) {
                    sampleAnnotatedGeneNumber++;
                }

            }

            //updating slimset annotation counts
            List<Element> slimSetElems = slimSetXML.asJDomElement().getChildren(GoTermXML.TAG_NAME);
            for (Element slimSetElem : slimSetElems) {
                GoTermXML slimSetGo = new GoTermXML(slimSetElem);
                slimSetGo.setAnnotationsCount(slimSetTermsAnnotationCounts.get(slimSetGo.getId()));
            }

            goSlimXML.asJDomElement().addContent(proteinsElem);
            slimSetXML.detach();
            goSlimXML.setSlimSet(slimSetXML);
            goSlimXML.setSampleGeneNumber(proteinList.size());
            goSlimXML.setSampleAnnotatedGeneNumber(sampleAnnotatedGeneNumber);
            //goSlimXML.set

        } catch (Exception e) {
            logger.log(Level.SEVERE, e.getMessage());
            StackTraceElement[] trace = e.getStackTrace();
            for (StackTraceElement stackTraceElement : trace) {
                logger.log(Level.SEVERE, stackTraceElement.toString());
            }
            goSlimXML = null;
        }

    } else {
        goSlimXML = null;
    }

    return goSlimXML;
}

From source file:com.cats.version.VersionCfgParseAndSave.java

License:Apache License

public boolean saveVersionInfo(List<VersionInfo> infos, String fullPath) {
    try {//from  w w w.  j  a v a 2 s .  c  o m
        Document doc = new Document();
        Element root = new Element("software-group");
        for (VersionInfo info : infos) {
            Element softEle = new Element("software");
            softEle.setAttribute("name", info.getAppName());
            Element versionCodeEle = new Element("latest-version-code");
            Element versionNameEle = new Element("latest-version");
            Element versionPathEle = new Element("latest-version-abspath");
            Element startupNameEle = new Element("latest-version-startup");

            versionCodeEle.setText(String.valueOf(info.getVersionCode()));
            versionNameEle.setText(info.getVersion());
            versionPathEle.setText(info.getPath());
            startupNameEle.setText(info.getStartupName());
            softEle.addContent(versionCodeEle);
            softEle.addContent(versionNameEle);
            softEle.addContent(versionPathEle);
            softEle.addContent(startupNameEle);

            List<VersionInfoDetail> details = info.getDetails();
            if (null != details) {
                Element detailEles = new Element("latest-version-detail");
                for (VersionInfoDetail verDetail : details) {
                    Element itemElem = new Element("item");
                    itemElem.setAttribute("name", verDetail.getTitle());

                    List<String> detailList = verDetail.getDetail();
                    for (String detailInfo : detailList) {
                        Element detailEle = new Element("detail");
                        detailEle.setText(detailInfo);
                        itemElem.addContent(detailEle);
                    }
                    detailEles.addContent(itemElem);
                }
                softEle.addContent(detailEles);
            }

            List<String> ignoreFiles = info.getIgnoreFiles();
            if (ignoreFiles != null) {
                Element ignoreEles = new Element("ignore-files");
                for (String ignoreInfo : ignoreFiles) {
                    Element ignoreItemEle = new Element("item");
                    ignoreItemEle.setText(ignoreInfo);
                    ignoreEles.addContent(ignoreItemEle);
                }
                softEle.addContent(ignoreEles);
            }
            root.addContent(softEle);
        }
        doc.setRootElement(root);

        //Save to xml file
        XMLOutputter xmlOut = null;
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(fullPath);
            xmlOut = new XMLOutputter(Format.getPrettyFormat());
            xmlOut.output(doc, fos);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != fos) {
                try {
                    fos.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.collir24.policyextractor.Extract.java

License:Apache License

private static Document buildDocument(List<ModulePermissions> modulePermissions) {
    Element modulePolicy = new Element("modulePolicy");
    for (ModulePermissions mps : modulePermissions) {
        Element module = new Element("module");
        module.setAttribute("name", mps.getModuleName());
        Set<String> policySet = new HashSet<String>();
        for (ModulePermission mp : mps.getPermissions()) {
            Element permRequired = new Element("permRequired");
            permRequired.setAttribute("line", Integer.toString(mp.getLine()));
            permRequired.setAttribute("className", mp.getClassName());
            for (String s : mp.getPolicy()) {
                Element perm = new Element("perm");
                perm.setText(s);//w  w w  .j a v  a  2  s.c o m
                permRequired.addContent(perm);
            }
            module.addContent(permRequired);
            // TODO: say what caused the permission to be required - see key
            policySet.addAll(mp.getPolicy());
        }
        CDATA policyData = new CDATA(generatePolicy(policySet));
        module.addContent(policyData);
        modulePolicy.addContent(module);
    }
    return new Document(modulePolicy);
}

From source file:com.compomics.pladipus.core.control.updates.ProcessingBeanUpdater.java

/**
 * Adds a new class to the bean definition
 * @param fullyDefinedClassName the fully defined class name
 * @throws IllegalArgumentException//from  w w w. ja  v a  2s  .co m
 * @throws IOException
 * @throws JDOMException
 */
public void addNewProcessingStep(String fullyDefinedClassName)
        throws IllegalArgumentException, IOException, JDOMException {
    String className = fullyDefinedClassName.substring(fullyDefinedClassName.lastIndexOf(".") + 1);

    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(beanXMLDefinitionFile);

    //check if the class is not already in there
    for (Element aBean : document.getRootElement().getChildren()) {
        if (aBean.getAttribute("class").getValue().equals(fullyDefinedClassName)) {
            throw new IllegalArgumentException(
                    "Class is already defined in the bean configuration for " + aBean.getAttributeValue("id"));
        } else if (aBean.getAttribute("id").getValue().equals(className)) {
            throw new IllegalArgumentException("Classname is already in use");
        }
    }

    Element newClassElement = new Element("bean").setAttribute("id", className)
            .setAttribute("class", fullyDefinedClassName).setAttribute("lazy-init", "true");
    document.getRootElement().addContent(newClassElement);
    XMLOutputter outputter = new XMLOutputter();
    try (StringWriter stringWriter = new StringWriter();
            FileWriter writer = new FileWriter(beanXMLDefinitionFile);) {
        outputter.output(document, stringWriter);
        String output = stringWriter.getBuffer().toString();
        //remove empty namespaces
        output = output.replace(" xmlns=\"\"", "");
        writer.append(output);
    }
}