List of usage examples for org.jdom2 Element getName
public String getName()
From source file:com.bc.fiduceo.reader.airs.AIRS_L1B_Reader.java
License:Open Source License
static String getElementValue(Element element, String attribute) { if (element.getName().equals(attribute)) { return element.getChild("VALUE").getValue(); }//from w ww .jav a2 s . c om for (Element subElement : element.getChildren()) { if (subElement.getName().equals(attribute)) { return subElement.getChild("VALUE").getValue(); } else { final String elementValue = getElementValue(subElement, attribute); if (StringUtils.isNotNullAndNotEmpty(elementValue)) { return elementValue; } } } return null; }
From source file:com.bc.fiduceo.reader.airs.EosCoreMetaParser.java
License:Open Source License
private void endGroup(Element current, String line) { StringTokenizer stoke = new StringTokenizer(line, "="); String toke = stoke.nextToken(); assert toke.equals("END_GROUP"); String name = stoke.nextToken(); assert name.equals(current.getName()); }
From source file:com.bc.fiduceo.reader.airs.EosCoreMetaParser.java
License:Open Source License
private void endObject(Element current, String line) { StringTokenizer stoke = new StringTokenizer(line, "="); String toke = stoke.nextToken(); assert toke.equals("END_OBJECT"); String name = stoke.nextToken(); assert name.equals(current.getName()) : name + " !+ " + current.getName(); }
From source file:com.c4om.utils.xmlutils.JDOMUtils.java
License:Apache License
/** * Method that checks whether two elements are the same in the following way: * <ul>/* w ww . ja v a2s . co m*/ * <li>Have the same name</li> * <li>Have the same namespace URI</li> * <li>Have the same attribute sets (names, namespaces and values)</li> * </ul> * @param element1 one element * @param element2 another element * @return the result of the comparison */ public static boolean elementsEqualAtCNameAndAttributes(Element element1, Element element2) { boolean haveSameName = element1.getName().equals(element2.getName()); boolean haveSameNamespaceURI = element1.getNamespaceURI().equals(element2.getNamespaceURI()); Set<Attribute> attrSet1 = new HashSet<>(element1.getAttributes()); Set<Attribute> attrSet2 = new HashSet<>(element2.getAttributes()); boolean attrSetsEquals = attrSet1.equals(attrSet2); return haveSameName && haveSameNamespaceURI & attrSetsEquals; }
From source file:com.dexterapps.android.translator.TranslateTextForAndroid.java
License:Apache License
private void parseXMLAndGenerateDom(String sourceFile) { SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(sourceFile); //System.out.println(xmlFile.getAbsolutePath()); try {/*from w ww .j a v a2 s . c o m*/ /*Navigate the XML DOM and populate the string array for translation We also map the XML in java object so we can use to navigate it again for generating the xml back */ Document document = (Document) builder.build(xmlFile); Element rootNode = document.getRootElement(); List list = rootNode.getChildren(); for (int i = 0; i < list.size(); i++) { AndroidStringMapping stringElement = new AndroidStringMapping(); Element stringNode = (Element) list.get(i); if (stringNode.getName().equalsIgnoreCase("string")) { stringElement.setType("string"); stringElement.setAttributeName(stringNode.getAttributeValue("name")); stringElement.setAttributeValue(stringNode.getText()); baseLanguageStringForTranslation.add(stringNode.getText()); baseStringResourcesMapping.put(stringNode.getText(), i); } else if (stringNode.getName().equalsIgnoreCase("string-array")) { List stringArrayNodeList = stringNode.getChildren(); ArrayList<String> stringArrayItems = new ArrayList<String>(); for (int j = 0; j < stringArrayNodeList.size(); j++) { Element stringArrayNode = (Element) stringArrayNodeList.get(j); baseLanguageStringForTranslation.add(stringArrayNode.getText()); baseStringResourcesMapping.put(stringArrayNode.getText(), i + j); stringArrayItems.add(stringArrayNode.getText()); } stringElement.setType("string-array"); stringElement.setAttributeName(stringNode.getAttributeValue("name")); stringElement.setAttributeValue(stringArrayItems); } else { List stringPluralNodeList = stringNode.getChildren(); ArrayList<AndroidStringPlurals> stringPluralsItems = new ArrayList<AndroidStringPlurals>(); for (int j = 0; j < stringPluralNodeList.size(); j++) { Element stringPluralNode = (Element) stringPluralNodeList.get(j); baseLanguageStringForTranslation.add(stringPluralNode.getText()); baseStringResourcesMapping.put(stringPluralNode.getText(), i + j); AndroidStringPlurals pluralItem = new AndroidStringPlurals(); pluralItem.setAttributeName(stringPluralNode.getAttributeValue("quantity")); pluralItem.setAttributeValue(stringPluralNode.getText()); stringPluralsItems.add(pluralItem); } stringElement.setType("plurals"); stringElement.setAttributeName(stringNode.getAttributeValue("name")); stringElement.setAttributeValue(stringPluralsItems); } stringXmlDOM.add(stringElement); } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } }
From source file:com.doubotis.sc2dd.util.FontStyleXMLAnalyzer.java
private void computeAnalyze(Document doc) { mRacine = doc.getRootElement();//from ww w . j ava 2 s.co m List<Element> els = mRacine.getChildren(); for (Element el : els) { if (el.getName().equals("Constant")) { String constantName = el.getAttributeValue("name"); String constantValue = el.getAttributeValue("val"); SFontStyle.SFontStyleConstant constant = new SFontStyle.SFontStyleConstant(constantName, constantValue); System.out.println(" -XML- Created Constant " + constant.toString()); mConstants.put(constant.name, constant); continue; } if (el.getName().equals("Style")) { String styleName = el.getAttributeValue("name"); SFontStyle fontStyle = new SFontStyle(styleName); // Reading Styles on XML. String template = el.getAttributeValue("template"); String font = el.getAttributeValue("font"); String height = el.getAttributeValue("height"); String vjustify = el.getAttributeValue("vjustify"); String hjustify = el.getAttributeValue("hjustify"); String fontflags = el.getAttributeValue("fontflags"); String styleflags = el.getAttributeValue("styleflags"); String textcolor = el.getAttributeValue("textcolor"); String disabledcolor = el.getAttributeValue("disabledcolor"); String highlightcolor = el.getAttributeValue("highlightcolor"); String hotkeycolor = el.getAttributeValue("hotkeycolor"); String hyperlinkcolor = el.getAttributeValue("hyperlinkcolor"); String glowcolor = el.getAttributeValue("glowcolor"); String shadowoffset = el.getAttributeValue("shadowoffset"); fontStyle.template = template; fontStyle.font = font; fontStyle.height = height; fontStyle.vJustify = vjustify; fontStyle.hJustify = hjustify; fontStyle.fontFlags = fontflags; fontStyle.styleFlags = styleflags; fontStyle.textColor = textcolor; fontStyle.disabledColor = disabledcolor; fontStyle.highlightColor = highlightcolor; fontStyle.hotkeyColor = hotkeycolor; fontStyle.hyperlinkColor = hyperlinkcolor; fontStyle.glowColor = glowcolor; fontStyle.shadowOffset = shadowoffset; if (template != null && !template.equals("")) { SFontStyle templateStyle = loadTemplate(template); if (templateStyle != null) { SFontStyle foreignStyle = copy(templateStyle); foreignStyle.name = styleName; foreignStyle.template = template; foreignStyle.font = (fontStyle.font != null) ? fontStyle.font : foreignStyle.font; foreignStyle.height = (fontStyle.height != null) ? fontStyle.height : foreignStyle.height; foreignStyle.vJustify = (fontStyle.vJustify != null) ? fontStyle.vJustify : foreignStyle.vJustify; foreignStyle.hJustify = (fontStyle.hJustify != null) ? fontStyle.hJustify : foreignStyle.hJustify; foreignStyle.fontFlags = (fontStyle.fontFlags != null) ? fontStyle.fontFlags : foreignStyle.fontFlags; foreignStyle.styleFlags = (fontStyle.styleFlags != null) ? fontStyle.styleFlags : foreignStyle.styleFlags; foreignStyle.textColor = (fontStyle.textColor != null) ? fontStyle.textColor : foreignStyle.textColor; foreignStyle.disabledColor = (fontStyle.disabledColor != null) ? fontStyle.disabledColor : foreignStyle.disabledColor; foreignStyle.highlightColor = (fontStyle.highlightColor != null) ? fontStyle.highlightColor : foreignStyle.highlightColor; foreignStyle.hotkeyColor = (fontStyle.hotkeyColor != null) ? fontStyle.hotkeyColor : foreignStyle.hotkeyColor; foreignStyle.hyperlinkColor = (fontStyle.hyperlinkColor != null) ? fontStyle.hyperlinkColor : foreignStyle.hyperlinkColor; foreignStyle.glowColor = (fontStyle.glowColor != null) ? fontStyle.glowColor : foreignStyle.glowColor; foreignStyle.shadowOffset = (fontStyle.shadowOffset != null) ? fontStyle.shadowOffset : foreignStyle.shadowOffset; // Transfer the values into fontStyle. fontStyle = foreignStyle; } } // Now convert constants to true values. fontStyle.font = getConstantValueIfExists(fontStyle.font); fontStyle.height = getConstantValueIfExists(fontStyle.height); fontStyle.vJustify = getConstantValueIfExists(fontStyle.vJustify); fontStyle.hJustify = getConstantValueIfExists(fontStyle.hJustify); fontStyle.fontFlags = getConstantValueIfExists(fontStyle.fontFlags); fontStyle.styleFlags = getConstantValueIfExists(fontStyle.styleFlags); fontStyle.textColor = getConstantValueIfExists(fontStyle.textColor); fontStyle.disabledColor = getConstantValueIfExists(fontStyle.disabledColor); fontStyle.highlightColor = getConstantValueIfExists(fontStyle.highlightColor); fontStyle.hotkeyColor = getConstantValueIfExists(fontStyle.hotkeyColor); fontStyle.hyperlinkColor = getConstantValueIfExists(fontStyle.hyperlinkColor); fontStyle.glowColor = getConstantValueIfExists(fontStyle.glowColor); fontStyle.shadowOffset = getConstantValueIfExists(fontStyle.shadowOffset); // The Font Style is computed! Add it to the list of done styles! System.out.println(" -XML- Created Style " + fontStyle.toString()); mStyles.put(fontStyle.name, fontStyle); continue; } } }
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 ww w.j a va 2 s . co 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();//from 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 . j a v a 2 s.com 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);// w ww. j ava2s . c o m 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; }