List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname)
From source file:com.cisco.oss.foundation.logging.structured.AbstractFoundationLoggingMarker.java
License:Apache License
private static boolean buildFromXml(Element markerElement, StringBuilder builder) { Element defaultAppender = markerElement.getChild("defaultAppender"); List<Element> appenders = markerElement.getChildren("appender"); String markerId = markerElement.getAttributeValue("id"); if (appenders != null) { for (Element appender : appenders) { String appenderId = appender.getAttributeValue("id"); if (appenderId == null) { LOGGER.error("the appender element must have an id poiting to a valid appender name"); } else { buildFromAppenderElement(markerId, appenderId, appender, builder, false, appenderId); }/* w w w. j av a 2s. c o m*/ } } if (defaultAppender == null) { LOGGER.error("The marker element: '{}' must contain a 'defaultAppender' element", markerId); builder.append("return null;"); } else { buildFromAppenderElement(markerId, "defaultAppender", defaultAppender, builder, true, "DEFAULT"); } return true; }
From source file:com.cisco.oss.foundation.logging.structured.AbstractFoundationLoggingMarker.java
License:Apache License
private static void buildFromAppenderElement(String markerId, String appenderId, Element appenderElement, StringBuilder builder, boolean isDefault, String appenderName) { if (!isDefault) { builder.append("if (\"").append(appenderName).append("\".equals(").append("appenderName)){\n"); }/* w ww . jav a 2 s .c o m*/ Element criteriaElement = appenderElement.getChild("criteria"); if (criteriaElement != null) { List<Element> criterionList = criteriaElement.getChildren("criterion"); if (criterionList != null) { for (Element criterionElement : criterionList) { String result = criterionElement.getAttributeValue("format"); List<Element> fieldList = criterionElement.getChildren("field"); if (fieldList != null) { for (int i = 0; i < fieldList.size(); i++) { Element fieldElement = fieldList.get(i); String key = fieldElement.getAttributeValue("name"); String value = fieldElement.getAttributeValue("equals"); String getterField = "marker.get" + WordUtils.capitalize(key) + "()"; if (i == 0) { builder.append("if (").append(getterField).append(" != null && \"").append(value) .append("\".equals(").append(getterField).append(".toString())"); } else { builder.append(" && ").append(getterField).append(" != null && \"").append(value) .append("\".equals(").append(getterField).append(".toString())"); } } builder.append(")\n\treturn \"").append(result).append("\";\n"); } } } } else { LOGGER.info("The marker element '{}' does not contain a 'criteria' element for appender: '{}'", markerId, appenderId); } String defaultFormat = appenderElement.getAttributeValue("defaultFormat"); if (defaultFormat == null) { LOGGER.error("The marker element: '{}' must contain a 'defaultFormat' element", markerId); } builder.append("return \"" + defaultFormat + "\";"); if (!isDefault) { builder.append("\n}\n"); } }
From source file:com.forum.action.eder.PerfilACT.java
public String execute() throws Exception { int c0 = 0, c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0, c10 = 0; Model modelo = ModelFactory.createDefaultModel(); FileManager.get().readModel(modelo,//from w w w . ja v a2 s.c o m ServletActionContext.getServletContext().getRealPath("/") + "/usuarios.rdf"); Resource perfil = modelo.getResource("http://comunipn.multiaportes.com/rdf/" + nick); NodeIterator amigos = modelo.listObjectsOfProperty( modelo.getResource("http://comunipn.multiaportes.com/rdf/" + solicitante), FOAF.knows); while (amigos.hasNext()) { RDFNode amigo = amigos.next(); Resource amigo1 = (Resource) amigo; // Resource es clase hija de RDFNode if (amigo1.getProperty(FOAF.nick).getObject().toString().equals(nick)) es_conocido = "1"; else es_conocido = "0"; } ServletContext context = ServletActionContext.getServletContext(); String url = context.getRealPath("/"); Document document = getDocument(url + "/database.xml"); Element root = document.getRootElement(); Element temas = root.getChild("respuestas"); List<Element> child = temas.getChildren(); for (Element tema : child) { for (Element respuesta : tema.getChildren()) { if (respuesta.getAttributeValue("usuario").equals(nick)) { switch (Integer.parseInt(respuesta.getAttributeValue("calificacion"))) { case 0: c0++; break; case 1: c1++; break; case 2: c2++; break; case 3: c3++; break; case 4: c4++; break; case 5: c5++; break; case 6: c6++; break; case 7: c7++; break; case 8: c8++; break; case 9: c9++; break; case 10: c10++; break; } } } } detalles = new Perfil(perfil.getProperty(FOAF.givenname).getObject().toString(), perfil.getProperty(FOAF.family_name).getObject().toString(), "Alumno", perfil.getProperty(FOAF.schoolHomepage).getObject().toString()); calificaciones = new EstadisticasIndiv(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10); return SUCCESS; }
From source file:com.forum.action.eder.TemaACT.java
private Hilo tema(int id, String url) { String megacadena = ""; Hilo h = new Hilo(); Document document = getDocument(url); Element root = document.getRootElement(); Element temas = root.getChild("temas"); List<Element> child = temas.getChildren(); for (Element e : child) { try {/* w w w. j av a2 s . c o m*/ if (e.getAttribute("id").getIntValue() == id) { h.setTitulo(e.getChildText("titulo")); h.setDetalles(e.getChildText("detalles")); List<Element> e2 = e.getChildren("tags"); for (int i = 0; i < e2.size(); i++) { megacadena += e2.get(i).getValue() + ","; } h.setEtiquetas(megacadena); break; } } catch (DataConversionException ex) { } } return h; }
From source file:com.forum.action.eder.TemaACT.java
private ArrayList<Respuesta> respuestasTema(int id, String url) { ArrayList<Respuesta> arreglo = new ArrayList<>(); Document document = getDocument(url); Element root = document.getRootElement(); Element temas = root.getChild("respuestas"); List<Element> child = temas.getChildren(); for (Element e : child) { if (Integer.parseInt(e.getAttributeValue("id")) != id) continue; List<Element> child2 = e.getChildren(); for (Element e2 : child2) { arreglo.add(new Respuesta(e2.getAttributeValue("usuario"), e2.getValue(), Integer.parseInt(e2.getAttributeValue("id")), Integer.parseInt(e2.getAttributeValue("calificacion")))); }// w w w.ja v a 2 s . c o m } return arreglo; }
From source file:com.github.lucapino.sheetmaker.renderer.GmTemplateRenderer.java
public JPanel renderTemplate(URL templateXML, Map<String, String> tokenMap, String backgroundFilePath, String fanArt1FilePath, String fanArt2FilePath, String fanArt3FilePath, String coverFilePath) throws Exception { this.tokenMap = tokenMap; String templatePath = templateXML.getFile(); File templateFile = new File(templatePath); // set basePath basePath = templateFile.getParentFile().getAbsolutePath(); logger.info("Loading template..."); // load template String templateString = IOUtils.toString(checkForUtf8BOMAndDiscardIfAny(new FileInputStream(templateFile)), "ISO-8859-1"); // filter placeHolder logger.info("Parsing template for substitution..."); templateString = templateString.replaceAll("%PATH%", basePath); templateString = templateString.replaceAll("%BACKGROUND%", backgroundFilePath); templateString = templateString.replaceAll("%FANART1%", fanArt1FilePath); templateString = templateString.replaceAll("%FANART2%", fanArt2FilePath); templateString = templateString.replaceAll("%FANART3%", fanArt3FilePath); templateString = templateString.replaceAll("%COVER%", coverFilePath); StringReader templateReader = new StringReader(templateString); System.out.println(templateString); logger.info("Template parsed..."); // parse XML// w ww . j a v a 2 s.co m // the SAXBuilder is the easiest way to create the JDOM2 objects. SAXBuilder jdomBuilder = new SAXBuilder(); // jdomDocument is the JDOM2 Object Document jdomDocument = jdomBuilder.build(templateReader); Element rootElement = jdomDocument.getRootElement(); // process Settings logger.info("Caching settings..."); Element settingsElement = rootElement.getChild(SETTINGS); settings = new TemplateSettings(settingsElement); // process SoundFormats logger.info("Caching soundFormats..."); Element soundFormatsElement = rootElement.getChild(SOUND_FORMATS); cacheElements(soundFormatsElement, soundFormats); // process Resolutions logger.info("Caching resolutions..."); Element resolutionsElement = rootElement.getChild(RESOLUTIONS); cacheElements(resolutionsElement, resolutions); // process MediaFormats logger.info("Caching mediaFormats..."); Element mediaFormatsElement = rootElement.getChild(MEDIA_FORMATS); cacheElements(mediaFormatsElement, mediaFormats); // process VideoFormats logger.info("Caching videoFormats..."); Element videoFormatsElement = rootElement.getChild(VIDEO_FORMATS); cacheElements(videoFormatsElement, videoFormats); // process ImageDrawTemplate Element drawImageTemplateElement = rootElement.getChild(IMAGE_DRAW_TEMPLATE); logger.info("Drawing images..."); return drawTemplate(drawImageTemplateElement); }
From source file:com.github.lucapino.sheetmaker.renderer.GmTemplateRenderer.java
private ImagePanel drawTemplate(Element drawImageTemplateElement) throws Exception { // OutputImageSettings logger.info("reading ImageDrawTemlate attributes..."); Element outputImageSettingsElement = drawImageTemplateElement.getChild(OUTPUT_IMAGE_SETTINGS); String colorDepth = outputImageSettingsElement.getAttributeValue("ColorDepth"); String imageForat = outputImageSettingsElement.getAttributeValue("ImageFormat"); String jpegCompressionLevel = outputImageSettingsElement.getAttributeValue("JpegCompressionLevel"); String dpi = outputImageSettingsElement.getAttributeValue("Dpi"); logger.info("Reading Canvas attributes..."); // Canvas/*from w w w . j av a 2s .c o m*/ Element canvasElement = drawImageTemplateElement.getChild(CANVAS); String autoSize = canvasElement.getAttributeValue("AutoSize"); String centerElements = canvasElement.getAttributeValue("CenterElements"); int height = Integer.valueOf(canvasElement.getAttributeValue("Height")); int width = Integer.valueOf(canvasElement.getAttributeValue("Width")); String fill = canvasElement.getAttributeValue("Fill"); // create image of specified dimensions logger.info("Creating working image..."); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // Elements logger.info("Processing elements..."); Element elementsElement = drawImageTemplateElement.getChild("Elements"); for (Element element : elementsElement.getChildren()) { switch (element.getName()) { case "ImageElement": image = processImageElement(image, element); break; case "TextElement": image = processTextElement(image, element); break; } } return new ImagePanel(image); }
From source file:com.github.lucapino.sheetmaker.renderer.GmTemplateRenderer.java
private BufferedImage processActions(Element imageElement, BufferedImage tmpImage) throws IM4JavaException, InterruptedException, IOException { BufferedImage result = tmpImage; // verify if there are filters Element actions = imageElement.getChild("Actions"); if (actions != null) { List<Element> filters = actions.getChildren(); for (Element filter : filters) { Stream2BufferedImage s2b = new Stream2BufferedImage(); // TODO: implement filters switch (filter.getName()) { // Crop case "Crop": break; // GlassTable case "GlassTable": break; // Glow case "Glow": break; // GaussianBlur case "GaussianBlur": double sigma = Double.valueOf(filter.getAttributeValue("Radius")); double radius = sigma * 3; convert.setOutputConsumer(s2b); IMOperation op = new IMOperation(); op.addImage();/* w w w .j av a 2s.c om*/ op.blur(sigma, radius); op.addImage("png:-"); convert.run(op, tmpImage); result = s2b.getImage(); break; // AdjustHue case "AdjustHue": break; // AdjustGamma case "AdjustGamma": break; // RoundCorners case "RoundCorners": break; // AdjustSaturation case "AdjustSaturation": break; // AdjustBrightness case "AdjustBrightness": break; // AdjustOpacity case "AdjustOpacity": int opacity = Integer.valueOf(filter.getAttributeValue("Opacity")) * 255 / 100; OpacityFilter opacityFilter = new OpacityFilter(opacity); result = opacityFilter.filter(tmpImage, null); break; // PerspectiveView case "PerspectiveView": break; // Rotate case "Rotate": break; // DropShadow case "DropShadow": break; // Skew case "Skew": break; // Flip case "Flip": break; } } } return result; }
From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java
public JPanel renderTemplate(URL templateXML, Map<String, String> tokenMap, String backgroundFilePath, String fanArt1FilePath, String fanArt2FilePath, String fanArt3FilePath, String coverFilePath) throws Exception { this.tokenMap = tokenMap; String templatePath = templateXML.getFile(); File templateFile = new File(templatePath); // set basePath basePath = templateFile.getParentFile().getAbsolutePath().replaceAll("\\\\", "/"); logger.info("Loading template..."); // load template String templateString = IOUtils.toString(checkForUtf8BOMAndDiscardIfAny(new FileInputStream(templateFile)), "ISO-8859-1"); // filter placeHolder logger.info("Parsing template for substitution..."); templateString = templateString.replaceAll("%PATH%", basePath); templateString = templateString.replaceAll("%BACKGROUND%", backgroundFilePath); templateString = templateString.replaceAll("%FANART1%", fanArt1FilePath); templateString = templateString.replaceAll("%FANART2%", fanArt2FilePath); templateString = templateString.replaceAll("%FANART3%", fanArt3FilePath); templateString = templateString.replaceAll("%COVER%", coverFilePath); StringReader templateReader = new StringReader(templateString); System.out.println(templateString); logger.info("Template parsed..."); // parse XML/*from w w w.j a va 2s .c om*/ // the SAXBuilder is the easiest way to create the JDOM2 objects. SAXBuilder jdomBuilder = new SAXBuilder(); // jdomDocument is the JDOM2 Object Document jdomDocument = jdomBuilder.build(templateReader); Element rootElement = jdomDocument.getRootElement(); // process Settings logger.info("Caching settings..."); Element settingsElement = rootElement.getChild(SETTINGS); settings = new TemplateSettings(settingsElement); // process SoundFormats logger.info("Caching soundFormats..."); Element soundFormatsElement = rootElement.getChild(SOUND_FORMATS); cacheElements(soundFormatsElement, soundFormats); // process Resolutions logger.info("Caching resolutions..."); Element resolutionsElement = rootElement.getChild(RESOLUTIONS); cacheElements(resolutionsElement, resolutions); // process MediaFormats logger.info("Caching mediaFormats..."); Element mediaFormatsElement = rootElement.getChild(MEDIA_FORMATS); cacheElements(mediaFormatsElement, mediaFormats); // process VideoFormats logger.info("Caching videoFormats..."); Element videoFormatsElement = rootElement.getChild(VIDEO_FORMATS); cacheElements(videoFormatsElement, videoFormats); // process ImageDrawTemplate Element drawImageTemplateElement = rootElement.getChild(IMAGE_DRAW_TEMPLATE); logger.info("Drawing images..."); return drawTemplate(drawImageTemplateElement); }
From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java
private ImagePanel drawTemplate(Element drawImageTemplateElement) throws Exception { // OutputImageSettings logger.info("reading ImageDrawTemlate attributes..."); Element outputImageSettingsElement = drawImageTemplateElement.getChild(OUTPUT_IMAGE_SETTINGS); String colorDepth = outputImageSettingsElement.getAttributeValue("ColorDepth"); String imageForat = outputImageSettingsElement.getAttributeValue("ImageFormat"); String jpegCompressionLevel = outputImageSettingsElement.getAttributeValue("JpegCompressionLevel"); String dpi = outputImageSettingsElement.getAttributeValue("Dpi"); logger.info("Reading Canvas attributes..."); // Canvas//from www . ja v a2s .c om Element canvasElement = drawImageTemplateElement.getChild(CANVAS); String autoSize = canvasElement.getAttributeValue("AutoSize"); String centerElements = canvasElement.getAttributeValue("CenterElements"); int width = Integer.valueOf(canvasElement.getAttributeValue("Width")); int height = Integer.valueOf(canvasElement.getAttributeValue("Height")); String fill = canvasElement.getAttributeValue("Fill"); // create image of specified dimensions logger.info("Creating working image..."); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // Elements logger.info("Processing elements..."); Element elementsElement = drawImageTemplateElement.getChild("Elements"); for (Element element : elementsElement.getChildren()) { switch (element.getName()) { case "ImageElement": processImageElement(g2, element); break; case "TextElement": processTextElement(g2, element); break; } } return new ImagePanel(image); }