Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

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

Prototype

public List<Element> getChildren() 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element, as Element objects.

Usage

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"))));
        }//from w w w.  j  a  v a  2 s  .com
    }
    return arreglo;
}

From source file:com.github.lucapino.sheetmaker.renderer.GmTemplateRenderer.java

private void cacheElements(Element element, Map<String, TemplateElement> cache) {
    for (Element child : element.getChildren()) {
        TemplateElement templateElement = new TemplateElement(child);
        cache.put(templateElement.getName(), templateElement);
    }/* ww  w.  j ava 2  s  .  co m*/
}

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   www .  ja v a2  s. c om
    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 ww .j a  v a  2  s .  co  m
                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

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/*ww w  .  jav a  2  s  . co  m*/
    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);
}

From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java

private BufferedImage processActions(Element imageElement, BufferedImage tmpImage) {
    // verify if there are filters
    Element actions = imageElement.getChild("Actions");
    if (actions != null) {
        List<Element> filters = actions.getChildren();
        for (Element filter : filters) {
            logger.info("Processing action {}", filter.getName());
            // TODO: implement filters
            switch (filter.getName()) {
            // Crop
            case "Crop":
                break;
            // GlassTable
            case "GlassTable":
                MirrorFilter mirrorFilter = new MirrorFilter();
                float reflectionOpacity = Float.valueOf(filter.getAttributeValue("ReflectionOpacity"));
                mirrorFilter.setOpacity(reflectionOpacity / 100);
                mirrorFilter.setCentreY(1f);
                mirrorFilter.setGap(0f);

                tmpImage = mirrorFilter.filter(tmpImage, null);
                break;
            // Glow
            case "Glow":
                GlowFilter glowFilter = new GlowFilter();
                float amount = Float.valueOf(filter.getAttributeValue("Amount"));
                glowFilter.setAmount(amount);
                tmpImage = glowFilter.filter(tmpImage, null);
                break;
            // GaussianBlur
            case "GaussianBlur":
                GaussianFilter gaussianFilter = new GaussianFilter();
                gaussianFilter.setRadius(Float.valueOf(filter.getAttributeValue("Radius")));
                tmpImage = gaussianFilter.filter(tmpImage, null);
                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 = (int) (Float.valueOf(filter.getAttributeValue("Opacity")) * 255 / 100);
                //                        OpacityFilter opacityFilter = new OpacityFilter(opacity);
                //                        tmpImage = opacityFilter.filter(tmpImage, null);
                break;
            // PerspectiveView
            case "PerspectiveView":
                break;
            // Rotate
            case "Rotate":
                RotateFilter rotateFilter = new RotateFilter();
                float rotateAngle = Float.valueOf(filter.getAttributeValue("Angle"));
                rotateFilter.setAngle(rotateAngle);
                tmpImage = rotateFilter.filter(tmpImage, null);
                break;
            // DropShadow
            case "DropShadow":
                logger.info("Dropping shadow...");
                ShadowFilter shadow = new ShadowFilter();
                float angle = Float.valueOf(filter.getAttributeValue("Angle"));
                shadow.setAngle(angle);//from  w  ww. j a v a2 s  .com
                float distance = Float.valueOf(filter.getAttributeValue("Distance"));
                shadow.setDistance(distance);
                // shadow.setRadius(3.0f);
                float opacity = Float.valueOf(filter.getAttributeValue("Opacity"));
                shadow.setOpacity(opacity / 100);
                tmpImage = shadow.filter(tmpImage, null);
                break;
            // Skew
            case "Skew":
                break;
            // Flip
            case "Flip":
                FlipFilter flipFilter = new FlipFilter();
                // Type can be "Horizontal" or "Vertical"
                String type = filter.getAttributeValue("Type");
                switch (type.toLowerCase()) {
                case "horizontal":
                    flipFilter.setOperation(FlipFilter.FLIP_H);
                    break;
                case "vertical":
                    flipFilter.setOperation(FlipFilter.FLIP_V);
                    break;
                }
                tmpImage = flipFilter.filter(tmpImage, null);
                break;

            }
        }
    }
    return tmpImage;
}

From source file:com.github.lucapino.sheetmaker.renderer.TemplateSettings.java

public TemplateSettings(Element settingsElement) {
    for (Element setting : settingsElement.getChildren()) {
        SettingsElement element = new SettingsElement(setting);
        settingsElements.put(setting.getName(), element);
    }/*from   w w  w.  ja  va 2s .  c o  m*/
    starsRatingFilename = settingsElement.getChild(RATING).getAttributeValue(RATING_FILENAME);
}

From source file:com.github.zdsiyan.maven.plugin.smartconfig.SmartconfigMojo.java

License:Apache License

private Smartconfig buildFastconfig() throws Exception {
    PluginParameterExpressionEvaluator pel = new PluginParameterExpressionEvaluator(session, execution);
    Smartconfig fastconfig = new Smartconfig();

    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(config);
    Element root = doc.getRootElement();

    // use scriptEngine, maybe we can extend it, not only javascript 
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("javascript");

    // load profile
    List<Profile> profiles = session.getCurrentProject().getActiveProfiles();
    profiles.forEach(profile -> profile.getProperties().keySet().forEach(key -> {
        Object value = profile.getProperties().get(key);
        engine.put(key.toString(), value);
        //getLog().warn("profile:"+key);
    }));// w w w.  j a v  a  2  s. co m
    // load user properties
    session.getUserProperties().keySet().forEach(key -> {
        Object value = session.getUserProperties().get(key);
        engine.put(key.toString(), value);
        //getLog().warn("user:"+key);
    });
    /* load sys properties
    session.getSystemProperties().keySet().forEach(key->{
       Object value = session.getSystemProperties().get(key);
       engine.put(key.toString(), value);
       getLog().warn("sys:"+key);
    });
    */

    session.getCurrentProject().getProperties().keySet().forEach(key -> {
        Object value = session.getCurrentProject().getProperties().get(key);
        engine.put(key.toString(), value);
        //getLog().warn("prop:"+key);
    });

    // config-file
    for (Element cf : root.getChildren()) {
        String path = String.valueOf(pel.evaluate(cf.getAttributeValue("path")));
        File file = new File(path);
        if (!file.isAbsolute()) {
            file = new File(outputDirectory, path);
        }

        boolean disable = false;
        //eval the script
        if (StringUtils.isNotEmpty(cf.getAttributeValue("disable"))) {
            Object result = engine.eval(cf.getAttributeValue("disable"));
            if (Boolean.TRUE.equals(result)) {
                disable = true;
            }
        }
        if (disable == true) {
            continue;
        }

        //rename to
        if (StringUtils.isNotEmpty(cf.getAttributeValue("replace"))) {
            String replace = String.valueOf(pel.evaluate(cf.getAttributeValue("replace")));
            //getLog().warn("filepath:"+file.getPath());
            File refile = new File(file.getParent() + File.separator + replace);
            //getLog().warn("refilepath:"+refile.getPath());
            FileUtils.rename(file, refile);
            continue;
        }

        ConfigFile.Mode mode;
        if (StringUtils.isNotEmpty(cf.getAttributeValue("mode"))) {
            mode = ConfigFile.Mode.valueOf(cf.getAttributeValue("mode"));
        } else {
            mode = toConfigMode(path.substring(path.lastIndexOf(".") + 1));
        }

        if (mode == null) {
            throw new SmartconfigException("Not found file[" + path + "] replace mode");
        }

        ConfigFile configFile = new ConfigFile(file, mode);

        for (Element rt : cf.getChildren()) {
            String expression = rt.getAttributeValue("expression");
            String value = String.valueOf(pel.evaluate(rt.getTextTrim()));
            PointHandle.Mode phMode;
            if (StringUtils.isNotEmpty(rt.getAttributeValue("mode"))) {
                phMode = PointHandle.Mode.valueOf(rt.getAttributeValue("mode"));
            } else {
                phMode = PointHandle.Mode.replace;
            }
            if (mode == null) {
                throw new SmartconfigException("Not found pointhandle mode");
            }
            configFile.addPointHandle(new PointHandle(expression, value, phMode));

        }
        fastconfig.addConfigFile(configFile);
    }
    return fastconfig;
}

From source file:com.globalsight.dispatcher.bo.JobTask.java

License:Apache License

private void setNamespace(Element p_element, Namespace p_namespace) {
    p_element.setNamespace(p_namespace);
    for (Element child : p_element.getChildren()) {
        setNamespace(child, p_namespace);
    }//from   www  . j  av  a 2s .  c om
}

From source file:com.hotaviano.tableexporter.csv.CSVExporter.java

License:Open Source License

private void createBody(Document doc, PrintWriter writer) {
    Element tbody = doc.getRootElement().getChild("tbody");

    for (Element tr : tbody.getChildren()) {
        String line = "";
        for (Element td : tr.getChildren()) {
            line += td.getText() + ",";
        }/* w  w w  .ja  v  a 2  s.  com*/

        writer.println(line.substring(0, line.length() - 1));
    }
}