List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * //from w w w.j a v a2s . co m * image * * @param section image section ? * @param e image element * @throws Exception */ public static void setImage(Section section, Element e) throws Exception { Image img = Image.getInstance(PDFDocGenerator.class.getResource(e.getText())); img.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); if (e.getAttributeValue("scale") != null) { float scale = Float.parseFloat(e.getAttributeValue("scale")); img.scalePercent(scale, scale); } section.add(img); }
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * // ww w .jav a 2 s . c om * chart * * @param section chart section ? * @param e chart element * @throws Exception */ public static void setChart(PdfWriter writer, Section section, Element e) throws Exception { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Element e1 : e.getChildren()) { if (!e1.getChild("column").getText().equals(FileType.DIRECTORY.toString()) && !e1.getChild("column").getText().equals(FileType.SUM.toString())) { dataset.setValue(Integer.parseInt(e1.getChild("value").getText()), e.getAttributeValue("title"), e1.getChild("column").getText()); } } JFreeChart chart = ChartFactory.createBarChart3D(e.getAttributeValue("title"), "", "", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); java.awt.Font labelFont = chart.getCategoryPlot().getDomainAxis().getLabelFont(); plot.getDomainAxis().setLabelFont(new java.awt.Font(labelFont.getName(), Font.NORMAL, 6)); plot.getDomainAxis().setTickLabelFont(new java.awt.Font(labelFont.getName(), Font.NORMAL, 6)); PdfContentByte cb = writer.getDirectContent(); PdfTemplate bar = cb.createTemplate(500, 150); Graphics2D g2d2 = new PdfGraphics2D(bar, 500, 150); Rectangle2D r2d2 = new Rectangle2D.Double(0, 0, 500, 150); chart.draw(g2d2, r2d2); g2d2.dispose(); Image image = Image.getInstance(bar); image.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); section.add(image); }
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * //from w w w.j a v a 2 s . com * ?? header * * @param e table element * @param t header table ? * @param colCount column * @throws Exception */ public static void setTableHeader(Element e, PdfPTable t, int colCount) throws Exception { t.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217)); t.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); ArrayList<Integer> colWidth = new ArrayList<Integer>(); for (Element e1 : e.getChild("header").getChildren()) { t.addCell(new Phrase(e1.getText(), fnNormalBold)); if (e1.getAttributeValue("width") != null) colWidth.add(Integer.parseInt(e1.getAttributeValue("width"))); } if (colCount == colWidth.size()) { int[] col = new int[colCount]; for (int i = 0; i < colCount; i++) col[i] = colWidth.get(i); t.setWidths(col); } }
From source file:com.aurum.whitehole.ObjectDB.java
License:Open Source License
public static void init() { fallback = true;/*w w w.j a v a 2s . c o m*/ timestamp = 0; categories = new LinkedHashMap(); objects = new LinkedHashMap(); File odbfile = new File("objectdb.xml"); if (!(odbfile.exists() && odbfile.isFile())) return; try { Element root = new SAXBuilder().build(odbfile).getRootElement(); timestamp = root.getAttribute("timestamp").getLongValue(); List<Element> catelems = root.getChild("categories").getChildren("category"); for (Element catelem : catelems) categories.put(catelem.getAttribute("id").getIntValue(), catelem.getText()); List<Element> objelems = root.getChildren("object"); for (Element objelem : objelems) { Object entry = new Object(); entry.ID = objelem.getAttributeValue("id"); entry.name = objelem.getChildText("name"); entry.category = objelem.getChild("category").getAttribute("id").getIntValue(); entry.type = objelem.getChild("preferredfile").getAttributeValue("name"); entry.notes = objelem.getChildText("notes"); Element flags = objelem.getChild("flags"); entry.games = flags.getAttribute("games").getIntValue(); entry.known = flags.getAttribute("known").getIntValue(); entry.complete = flags.getAttribute("complete").getIntValue(); if (entry.notes.isEmpty() || entry.notes.equals("")) entry.notes = "(No description found for this objects.)"; if (entry.type.isEmpty() || entry.notes.equals("")) entry.type = "Unknown"; entry.files = new ArrayList(); String files = objelem.getChildText("files"); for (String file : files.split("\n")) { entry.files.add(file); } List<Element> fields = objelem.getChildren("field"); entry.fields = new HashMap(fields.size()); if (!fields.isEmpty()) { for (Element field : fields) { Object.Field fielddata = new Object.Field(); fielddata.ID = field.getAttribute("id").getIntValue(); fielddata.type = field.getAttributeValue("type"); fielddata.name = field.getAttributeValue("name"); fielddata.values = field.getAttributeValue("values"); fielddata.notes = field.getAttributeValue("notes"); entry.fields.put(fielddata.ID, fielddata); } } objects.put(entry.ID, entry); } } catch (IOException | JDOMException ex) { timestamp = 0; return; } fallback = false; }
From source file:com.bc.ceres.binio.binx.BinX.java
License:Open Source License
private static String getAttributeValue(Element element, String name, boolean require) throws BinXException { final String value = element.getAttributeValue(name); if (require && value == null) { throw new BinXException( MessageFormat.format("Element ''{0}'': attribute ''{1}'' not found.", element.getName(), name)); }/*from w w w. j a v a 2 s .c o m*/ return value != null ? value.trim() : value; }
From source file:com.bc.ceres.jai.opimage.XmlRIF.java
License:Open Source License
private void parseSources(ParameterBlockJAI parameterBlock, Element targetElement, Map<String, Element> definedSourceElements, Map<String, Element> definedParameterElements, Map<String, Object> configuration, RenderingHints renderingHints) { List sourceElements = targetElement.getChildren(ENAME_SOURCE); for (int i = 0; i < sourceElements.size(); i++) { Element sourceElement = (Element) sourceElements.get(i); String sourceName = sourceElement.getAttributeValue(ANAME_ID); String sourceId = sourceElement.getAttributeValue(ANAME_REFID); Object source;// w w w. j a v a 2 s. c o m if (sourceId != null) { source = configuration.get(sourceId); if (source == null) { Element definedSourceElement = definedSourceElements.get(sourceId); if (definedSourceElement != null) { source = parseImage(definedSourceElement, definedSourceElements, definedParameterElements, configuration, renderingHints, parameterBlock.getMode()); configuration.put(sourceId, source); } } } else { source = parseImage(sourceElement, definedSourceElements, definedParameterElements, configuration, renderingHints, parameterBlock.getMode()); } if (sourceName != null) { parameterBlock.setSource(sourceName, source); } else { parameterBlock.setSource(source, i); } } }
From source file:com.bc.ceres.jai.opimage.XmlRIF.java
License:Open Source License
private void parseParameters(ParameterBlockJAI parameterBlock, Element targetElement, Map<String, Element> definedParameterElements, Map<String, Object> configuration) { List parameterElements = targetElement.getChildren(ENAME_PARAMETER); for (int i = 0; i < parameterElements.size(); i++) { Element parameterElement = (Element) parameterElements.get(i); String parameterName = parameterElement.getAttributeValue(ANAME_ID); if (parameterName == null) { String[] paramNames = parameterBlock.getParameterListDescriptor().getParamNames(); if (i < paramNames.length) { parameterName = paramNames[i]; } else { throw new IllegalArgumentException( MessageFormat.format("Operation ''{0}'': Unknown parameter #{1}'", parameterBlock.getOperationDescriptor().getName(), i)); }//www .j a va 2 s .c o m } String parameterId = parameterElement.getAttributeValue(ANAME_REFID); Object parameterValue; if (parameterId != null) { parameterValue = configuration.get(parameterId); if (parameterValue == null) { Element definedParameterElement = definedParameterElements.get(parameterId); parameterValue = parseParameterValue(parameterBlock, parameterName, definedParameterElement.getValue()); configuration.put(parameterId, parameterValue); } } else { parameterValue = parseParameterValue(parameterBlock, parameterName, parameterElement.getValue()); } if (parameterName != null) { parameterBlock.setParameter(parameterName, parameterValue); } else { parameterBlock.add(parameterValue); } } }
From source file:com.bc.ceres.jai.opimage.XmlRIF.java
License:Open Source License
private static Map<String, Element> getElementMap(Element rootElement, String elementName) { Map<String, Element> elementMap = new HashMap<String, Element>(); List elements = rootElement.getChildren(elementName); for (int i = 0; i < elements.size(); i++) { Element element = (Element) elements.get(i); String name = element.getAttributeValue(ANAME_ID); if (name == null) { throw new IllegalArgumentException(MessageFormat .format("Missing attribute ''{0}'' in element ''{1}''", ANAME_ID, elementName)); }/*from ww w .j a va2 s . c o m*/ elementMap.put(name, element); } return elementMap; }
From source file:com.bennavetta.util.tycho.XmlWrapDescriptorParser.java
License:Apache License
public WrapRequest createRequest(Document doc) throws Exception { log.info("Parsing wrapper configuration {} from {}", doc, doc.getBaseURI()); DefaultWrapRequest req = new DefaultWrapRequest(); if (doc.getRootElement().getChild("repositories") != null) { for (Element repoDescriptor : doc.getRootElement().getChild("repositories").getChildren("repository")) { Repository repo = new Repository(); repo.setId(repoDescriptor.getAttributeValue("id")); repo.setLayout(repoDescriptor.getAttributeValue("layout", "default")); repo.setName(repoDescriptor.getAttributeValue("name")); repo.setUrl(repoDescriptor.getAttributeValue("url")); log.debug("Adding repository {}", repo); req.addRepository(repo);/*from ww w. j ava 2 s .c om*/ } } String bndDir = doc.getRootElement().getChildText("bndDir"); if (bndDir != null) { req.setBndDirectory(new File(bndDir)); log.debug("Bnd directory: {}", bndDir); } Model parent = Maven.createModel(new File(doc.getRootElement().getChildText("parent"))); req.setParent(parent); log.debug("Parent: {}", parent); for (Element artifactDescriptor : doc.getRootElement().getChild("artifacts").getChildren("artifact")) { String groupId = artifactDescriptor.getAttributeValue("groupId"); String artifactId = artifactDescriptor.getAttributeValue("artifactId"); String version = artifactDescriptor.getAttributeValue("version"); log.debug("Adding artifact {}:{}:{}", groupId, artifactId, version); DefaultArtifactInfo info = new DefaultArtifactInfo( new DefaultArtifact(groupId + ":" + artifactId + ":" + version), artifactDescriptor.getAttributeValue("symbolicName")); req.addArtifact(info); } return req; }
From source file:com.bio4j.neo4jdb.programs.ImportProteinInteractions.java
License:Open Source License
public static void main(String[] args) throws IOException { if (args.length != 3) { System.out.println("This program expects the following parameters: \n" + "1. Uniprot xml filename \n" + "2. Bio4j DB folder\n" + "3. Batch inserter .properties file"); } else {//from w ww . j a va2 s . c o m long initTime = System.nanoTime(); File inFile = new File(args[0]); BatchInserter inserter = null; BatchInserterIndexProvider indexProvider = null; String accessionSt = ""; BufferedWriter statsBuff = null; int proteinCounter = 0; int limitForPrintingOut = 10000; try { // This block configure the logger with handler and formatter fh = new FileHandler("ImportProteinInteractions" + args[0].split("\\.")[0] + ".log", false); SimpleFormatter formatter = new SimpleFormatter(); fh.setFormatter(formatter); logger.addHandler(fh); logger.setLevel(Level.ALL); //--------------------------------- //---creating writer for stats file----- statsBuff = new BufferedWriter(new FileWriter( new File("ImportProteinInteractionsStats_" + inFile.getName().split("\\.")[0] + ".txt"))); // create the batch inserter inserter = BatchInserters.inserter(args[1], MapUtil.load(new File(args[2]))); // create the batch index service indexProvider = new LuceneBatchInserterIndexProvider(inserter); //------------------nodes properties maps----------------------------------- //--------------------------------------------------------------------- //-------------------relationships properties maps-------------------------- Map<String, Object> proteinProteinInteractionProperties = new HashMap<String, Object>(); Map<String, Object> proteinIsoformInteractionProperties = new HashMap<String, Object>(); //---------------------------------------------------------------------------- //--------------------------------relationships------------------------------------------ ProteinProteinInteractionRel proteinProteinInteractionRel = new ProteinProteinInteractionRel(null); ProteinIsoformInteractionRel proteinIsoformInteractionRel = new ProteinIsoformInteractionRel(null); //------------------------------------------------------------------------------------------------ //------------------indexes creation---------------------------------- BatchInserterIndex proteinAccessionIndex = indexProvider.nodeIndex( ProteinNode.PROTEIN_ACCESSION_INDEX, MapUtil.stringMap(PROVIDER_ST, LUCENE_ST, TYPE_ST, EXACT_ST)); BatchInserterIndex isoformIdIndex = indexProvider.nodeIndex(IsoformNode.ISOFORM_ID_INDEX, MapUtil.stringMap(PROVIDER_ST, LUCENE_ST, TYPE_ST, EXACT_ST)); //-------------------------------------------------------------------- BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line; StringBuilder entryStBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { if (line.trim().startsWith("<" + UniprotStuff.ENTRY_TAG_NAME)) { while (!line.trim().startsWith("</" + UniprotStuff.ENTRY_TAG_NAME + ">")) { entryStBuilder.append(line); line = reader.readLine(); } //linea final del organism entryStBuilder.append(line); //System.out.println("organismStBuilder.toString() = " + organismStBuilder.toString()); XMLElement entryXMLElem = new XMLElement(entryStBuilder.toString()); entryStBuilder.delete(0, entryStBuilder.length()); accessionSt = entryXMLElem.asJDomElement() .getChildText(UniprotStuff.ENTRY_ACCESSION_TAG_NAME); long currentProteinId = proteinAccessionIndex .get(ProteinNode.PROTEIN_ACCESSION_INDEX, accessionSt).getSingle(); List<Element> comments = entryXMLElem.asJDomElement() .getChildren(UniprotStuff.COMMENT_TAG_NAME); for (Element commentElem : comments) { String commentTypeSt = commentElem .getAttributeValue(UniprotStuff.COMMENT_TYPE_ATTRIBUTE); //----------interaction---------------- if (commentTypeSt.equals(ProteinProteinInteractionRel.UNIPROT_ATTRIBUTE_TYPE_VALUE)) { List<Element> interactants = commentElem.getChildren("interactant"); Element interactant1 = interactants.get(0); Element interactant2 = interactants.get(1); Element organismsDiffer = commentElem.getChild("organismsDiffer"); Element experiments = commentElem.getChild("experiments"); String intactId1St = interactant1.getAttributeValue("intactId"); String intactId2St = interactant2.getAttributeValue("intactId"); String organismsDifferSt = ""; String experimentsSt = ""; if (intactId1St == null) { intactId1St = ""; } if (intactId2St == null) { intactId2St = ""; } if (organismsDiffer != null) { organismsDifferSt = organismsDiffer.getText(); } if (experiments != null) { experimentsSt = experiments.getText(); } //----now we try to retrieve the interactant 2 accession-- String interactant2AccessionSt = interactant2.getChildText("id"); long protein2Id = -1; if (interactant2AccessionSt != null) { IndexHits<Long> protein2IdIndexHits = proteinAccessionIndex .get(ProteinNode.PROTEIN_ACCESSION_INDEX, interactant2AccessionSt); if (protein2IdIndexHits.hasNext()) { if (protein2IdIndexHits.size() == 1) { protein2Id = protein2IdIndexHits.getSingle(); } } if (protein2Id < 0) { //Since we did not find the protein we try to find a isoform instead long isoformId = -1; IndexHits<Long> isoformIdIndexHits = isoformIdIndex .get(IsoformNode.ISOFORM_ID_INDEX, interactant2AccessionSt); if (isoformIdIndexHits.hasNext()) { if (isoformIdIndexHits.size() == 1) { isoformId = isoformIdIndexHits.getSingle(); } } if (isoformId >= 0) { proteinIsoformInteractionProperties.put( ProteinIsoformInteractionRel.EXPERIMENTS_PROPERTY, experimentsSt); proteinIsoformInteractionProperties.put( ProteinIsoformInteractionRel.ORGANISMS_DIFFER_PROPERTY, organismsDifferSt); proteinIsoformInteractionProperties.put( ProteinIsoformInteractionRel.INTACT_ID_1_PROPERTY, intactId1St); proteinIsoformInteractionProperties.put( ProteinIsoformInteractionRel.INTACT_ID_2_PROPERTY, intactId2St); inserter.createRelationship(currentProteinId, isoformId, proteinIsoformInteractionRel, proteinIsoformInteractionProperties); } } else { proteinProteinInteractionProperties.put( ProteinProteinInteractionRel.EXPERIMENTS_PROPERTY, experimentsSt); proteinProteinInteractionProperties.put( ProteinProteinInteractionRel.ORGANISMS_DIFFER_PROPERTY, organismsDifferSt); proteinProteinInteractionProperties.put( ProteinProteinInteractionRel.INTACT_ID_1_PROPERTY, intactId1St); proteinProteinInteractionProperties.put( ProteinProteinInteractionRel.INTACT_ID_2_PROPERTY, intactId2St); inserter.createRelationship(currentProteinId, protein2Id, proteinProteinInteractionRel, proteinProteinInteractionProperties); } } } } proteinCounter++; if ((proteinCounter % limitForPrintingOut) == 0) { logger.log(Level.INFO, (proteinCounter + " proteins updated with interactions!!")); } } } reader.close(); } catch (Exception e) { logger.log(Level.SEVERE, ("Exception retrieving protein " + accessionSt)); logger.log(Level.SEVERE, e.getMessage()); StackTraceElement[] trace = e.getStackTrace(); for (StackTraceElement stackTraceElement : trace) { logger.log(Level.SEVERE, stackTraceElement.toString()); } } finally { //outbBuff.close(); try { // shutdown, makes sure all changes are written to disk indexProvider.shutdown(); inserter.shutdown(); //closing logger file handler fh.close(); //-----------------writing stats file--------------------- long elapsedTime = System.nanoTime() - initTime; long elapsedSeconds = Math.round((elapsedTime / 1000000000.0)); long hours = elapsedSeconds / 3600; long minutes = (elapsedSeconds % 3600) / 60; long seconds = (elapsedSeconds % 3600) % 60; statsBuff.write("Statistics for program ImportProteinInteractions:\nInput file: " + inFile.getName() + "\nThere were " + proteinCounter + " proteins analyzed.\n" + "The elapsed time was: " + hours + "h " + minutes + "m " + seconds + "s\n"); //---closing stats writer--- statsBuff.close(); } catch (Exception e) { logger.log(Level.SEVERE, ("Exception retrieving protein " + accessionSt)); logger.log(Level.SEVERE, e.getMessage()); StackTraceElement[] trace = e.getStackTrace(); for (StackTraceElement stackTraceElement : trace) { logger.log(Level.SEVERE, stackTraceElement.toString()); } //closing logger file handler fh.close(); } } } }