/** Display a single cluster and its sub-clusters. */ @SuppressWarnings({"unchecked"}) private static void display(Element group, int level) { final int recursiveDocumentCount = Integer.parseInt(group.attribute("size").getValue()); final String label = group.element("title").elementText("phrase"); for (int i = 0; i < level; i++) System.out.print(" "); System.out.println(label + " [" + recursiveDocumentCount + " document(s)]"); final Iterator<Element> i = group.elementIterator("group"); while (i.hasNext()) { display(i.next(), level + 1); } }
public void componentInfoReceived(IQ iq) { // Check if it's a Clearspace component boolean isClearspace = false; Element childElement = iq.getChildElement(); for (Iterator it = childElement.elementIterator("identity"); it.hasNext(); ) { Element identity = (Element) it.next(); if ("component".equals(identity.attributeValue("category")) && "clearspace".equals(identity.attributeValue("type"))) { isClearspace = true; } } // If component is Clearspace then keep track of the component if (isClearspace) { clearspaces.add(iq.getFrom().getDomain()); } }
/** * Simple parsing and display of the response. This method uses dom4j for parsing XML, feel free * to use anything that comes handy. */ @SuppressWarnings("unchecked") private static void displayResults(InputStream results) throws IOException { try { final SAXReader reader = new SAXReader(); final Document document = reader.read(results); final Iterator<Element> i = document.getRootElement().elementIterator("group"); while (i.hasNext()) { final Element group = i.next(); display(group, 1); } System.out.println(); } catch (DocumentException e) { throw new IOException("Could not parse response: " + e.getMessage()); } finally { if (results != null) { results.close(); } } }
/** * Read all printer formats from config file. * * <pre> * <bild-format name="13 x 15" papier-format="F2" breite-mm="130" hoehe-mm="150" /> * </pre> */ private void setPrinterFormat() { PM_PictureFormatCollection instance = PM_PictureFormatCollection.getInstance(); List formatList = PM_XML_Utils.getElementListe(document, "//" + TAG_BILD_FORMAT); // loop over all tags for (Iterator itFormate = formatList.iterator(); itFormate.hasNext(); ) { Element format = (Element) itFormate.next(); String name = PM_XML_Utils.getAttribute(format, ATTR_FORMAT_NAME); String papierFormatString = PM_XML_Utils.getAttribute(format, ATTR_FORMAT_FORMAT); int breite = PM_XML_Utils.getAttributeInt(format, ATTR_FORMAT_BREITE); int hoehe = PM_XML_Utils.getAttributeInt(format, ATTR_FORMAT_HOEHE); PM_PaperFormat papierFormat = PM_PaperFormat.getPaperFormat(papierFormatString); if (papierFormat == null) { continue; } if (hoehe == 0 || breite == 0) continue; // unzul�ssige Eingaben instance.addBildFormat( new PM_PictureFormatFix(papierFormat, new Rectangle(breite, hoehe), name)); } }
private void setAllPrinter() { java.util.List systemDruckerList = PM_XML_Utils.getElementListe(document, "//" + TAG_SYSTEM_DRUCKER); // -------------------------------------------------------------- // Loop ueber ALLE Systemdrucker // -------------------------------------------------------------- for (Iterator itSystemDrucker = systemDruckerList.iterator(); itSystemDrucker.hasNext(); ) { Element systemDrucker = (Element) itSystemDrucker.next(); String systemPrinterName = PM_XML_Utils.getAttribute(systemDrucker, ATTR_SYSTEM_DRUCKER_NAME); PM_SystemPrinter systemPrinter = systemPrinters.getSystemPrinter(systemPrinterName); if (systemPrinter == null) { continue; // system printer not found } // -------------------------------------------------------------- // loop ueber alle pm-drucker innerhalb EINES Systemdruckers // -------------------------------------------------------------- java.util.List pmDruckerList = PM_XML_Utils.getElementListe(systemDrucker, TAG_PM_DRUCKER); for (Iterator itPmDrucker = pmDruckerList.iterator(); itPmDrucker.hasNext(); ) { Element pmDrucker = (Element) itPmDrucker.next(); String pmDruckerName = PM_XML_Utils.getAttribute(pmDrucker, ATTR_PM_DRUCKER_NAME); // init pmPrinter PM_PmPrinter pmPrinter = new PM_PmPrinter(systemPrinter, pmDruckerName); // add to system printer systemPrinter.addPmDrucker(pmPrinter); // drucker.setPapierBereich(papierBereich); // ---- Druck-Bereich innerhalb eines pm-druckers ------- Element druckBereichElement = pmDrucker.element(TAG_DRUCK_BEREICH); if (druckBereichElement != null) { double oben = PM_XML_Utils.getAttributeDouble(druckBereichElement, ATTR_DRUCK_BEREICH_OBEN); double rechts = PM_XML_Utils.getAttributeDouble(druckBereichElement, ATTR_DRUCK_BEREICH_RECHTS); double unten = PM_XML_Utils.getAttributeDouble(druckBereichElement, ATTR_DRUCK_BEREICH_UNTEN); double links = PM_XML_Utils.getAttributeDouble(druckBereichElement, ATTR_DRUCK_BEREICH_LINKS); pmPrinter.setDruckBereichGesamtRaender(oben, rechts, unten, links); } } // ende alle pm-drucker fuer einen system-drucker } // ende alle Systemdrucker // Wenn kein Drucker, dann Default-Drucker anlegen }
public void print(Set set) { Iterator iter = set.iterator(); while (iter.hasNext()) { print(iter.next()); } }