Example usage for org.jdom2 Element getText

List of usage examples for org.jdom2 Element getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the textual content directly held under this element as a string.

Usage

From source file:Content.java

public void showPlaylist(String playlistName) {
    if (playlistName.equals("Library")) {
        setRightClick(true);/*from   w  w w  .  j  a  va  2s  .  c  o m*/
    } else {
        setRightClick(false);
    }

    if (nowPlayingInfo != null) {
        try {
            nowPlayingInfo.setVisible(false);
            remove(nowPlayingInfo);
        } catch (Exception e) {
        }
    }

    currentPlaylist = playlistName;
    eventEnabled = false;

    int count = model.getRowCount();
    for (int n = 0; n < count; n++) {
        model.removeRow(0);
    }

    if (playlistName.equals("Now Playing")) {
        playlist.setVisible(false);

        if (mediaPlayer != null) {
            try {
                String loc = mediaPlayer.getMedia().getSource();

                for (int i = 0; i < Library.getLib().size(); i++) {
                    if (("file:///" + ((Element) Library.getLib().get(i)).getChildText("url")).equals(loc)) {
                        Element el = ((Element) Library.getLib().get(i));
                        nowPlayingSong = new JLabel(el.getChildText("name"));
                        nowPlayingArtist = new JLabel(el.getChildText("artist"));
                        nowPlayingAlbum = new JLabel(el.getChildText("album"));
                        nowPlayingInfo = new JPanel();

                        nowPlayingInfo.setLayout(new BoxLayout(nowPlayingInfo, BoxLayout.PAGE_AXIS));
                        nowPlayingInfo.add(nowPlayingSong);
                        nowPlayingInfo.add(nowPlayingArtist);
                        nowPlayingInfo.add(nowPlayingAlbum);
                        nowPlayingInfo.setVisible(true);
                        add(nowPlayingInfo, BorderLayout.CENTER);

                        break;
                    }
                }

            } catch (Exception e) {
            }
        }
    } else if (playlistName.equals("Library")) {
        playlist.setVisible(true);
        List lib = Library.getLib();

        for (int i = 0; i < lib.size(); i++) {
            Element song = (Element) lib.get(i);

            Vector<String> row = new Vector<String>();
            row.add(song.getChildText("name"));
            row.add(song.getChildText("artist"));
            row.add(song.getChildText("album"));

            model.addRow(row);
        }
    } else {
        playlist.setVisible(true);
        List list = Library.getList();

        for (int i = 0; i < list.size(); i++) {
            Element node = (Element) list.get(i);

            if (node.getAttributeValue("id") == playlistName) {
                List children = node.getChildren();

                for (int j = 0; j < children.size(); j++) {
                    Element entry = (Element) children.get(j);
                    String entryNum = entry.getText();

                    List lib = Library.getLib();
                    for (int k = 0; k < lib.size(); k++) {
                        if (((Element) lib.get(k)).getAttributeValue("id").equals(entryNum)) {
                            Element song = (Element) lib.get(k);
                            Vector<String> row = new Vector<String>();
                            row.add(song.getChildText("name"));
                            row.add(song.getChildText("artist"));
                            row.add(song.getChildText("album"));
                            model.addRow(row);
                        }
                    }
                }
            }
        }

        playlist.revalidate();
        revalidate();
        eventEnabled = true;
    }
}

From source file:Content.java

public void playSelected() {
    if (playlist.getSelectedRow() == -1) {
        try {//from   w  ww. jav a 2  s.  com
            playlist.setRowSelectionInterval(0, 0);
        } catch (Exception e) {
            return;
        }
    }
    if (currentPlaylist.equals("Library")) {
        if (mediaPlayer != null) {
            mediaPlayer.stop();
        }

        try {
            List lib = Library.getLib();
            Element child = (Element) lib.get(playlist.getSelectedRow());

            if (child.getChildText("url").indexOf("http://") != -1) {
                Desktop.getDesktop().browse(new URI(child.getChildText("url")));
                return;
            }
            if (child.getChildText("url").toLowerCase().indexOf("youtube") != -1) {
                Desktop.getDesktop().browse(new URI(child.getChildText("url")));
                return;
            }
            if (child.getChildText("url").toLowerCase().indexOf(".com") != -1) {
                Desktop.getDesktop().browse(new URI(child.getChildText("url")));
                return;
            }

            String loc = "file:///" + child.getChildText("url");
            Media media = new Media(loc);
            mediaPlayer = new MediaPlayer(media);
            nowPlayingIndex = playlist.getSelectedRow();
            mediaPlayer.play();
            mediaPlayer.setOnEndOfMedia(new Runnable() {
                public void run() {
                    playNext();
                }
            });
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error playing media - please check the song location");
        }
    } else {
        if (mediaPlayer != null) {
            mediaPlayer.stop();
        }

        List list = Library.getList();

        for (int i = 0; i < list.size(); i++) {
            Element node = (Element) list.get(i);

            if (node.getAttributeValue("id").equals(currentPlaylist)) {
                Element elem = (Element) node.getChildren().get(playlist.getSelectedRow());
                String entryNum = elem.getText();

                try {
                    if (mediaPlayer != null) {
                        mediaPlayer.stop();
                    }

                    for (int j = 0; j < Library.getLib().size(); j++) {
                        Element current = (Element) Library.getLib().get(j);

                        if (current.getAttributeValue("id").equals(entryNum)) {
                            if (current.getChildText("url").indexOf("http://") != -1) {
                                Desktop.getDesktop().browse(new URI(current.getChildText("url")));
                                return;
                            }
                            if (current.getChildText("url").toLowerCase().indexOf("youtube") != -1) {
                                Desktop.getDesktop().browse(new URI(current.getChildText("url")));
                                return;
                            }
                            if (current.getChildText("url").toLowerCase().indexOf(".com") != -1) {
                                Desktop.getDesktop().browse(new URI(current.getChildText("url")));
                                return;
                            }

                            String loc = "file:///" + current.getChildText("url");
                            Media media = new Media(loc);
                            mediaPlayer = new MediaPlayer(media);
                            mediaPlayer.play();
                            nowPlayingIndex = playlist.getSelectedRow();

                            mediaPlayer.setOnEndOfMedia(new Runnable() {
                                public void run() {
                                    playNext();
                                }
                            });
                        }
                    }
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(this, "Error playing media - please check the song location");
                }
            }
        }
    }
}

From source file:amara.applications.ingame.entitysystem.templates.CustomSerializer_Ingame.java

public static void registerClasses() {
    BitstreamClassManager.getInstance().register(ArrayList.class,
            //physics/HitboxComponent
            Circle.class, Rectangle.class, RegularCyclic.class, Shape.class, ConvexShape.class,
            SimpleConvexPolygon.class, PointShape.class, Transform2D.class, Vector2D.class, PolygonShape.class,
            BoundRectangle.class, Polygon.class, SetPolygon.class, HolePolygon.class, SimplePolygon.class,
            //units/DamageHistoryComponent
            DamageHistoryComponent.DamageHistoryEntry.class);
    ComponentsRegistrator.registerComponents();
    try {/*from w  w  w.  j  ava 2s  .c  o m*/
        ComponentSerializer.registerFieldSerializer(
                new Field[] { Vector2f.class.getDeclaredField("x"), Vector2f.class.getDeclaredField("y") },
                new FieldSerializer_Float(20, 8));
        ComponentSerializer.registerFieldSerializer(new Field[] { Vector2D.class.getDeclaredField("x"),
                Vector2D.class.getDeclaredField("y"), Transform2D.class.getDeclaredField("scalecos"),
                Transform2D.class.getDeclaredField("scalesin"), Transform2D.class.getDeclaredField("x"),
                Transform2D.class.getDeclaredField("y"), Circle.class.getDeclaredField("localRadius"), },
                new FieldSerializer_DoubleAsFloat(20, 8));
    } catch (NoSuchFieldException ex) {
        ex.printStackTrace();
    }
    XMLTemplateManager xmlTemplateManager = XMLTemplateManager.getInstance();
    //effects/physics
    xmlTemplateManager
            .registerComponent(new XMLComponentConstructor<AddCollisionGroupsComponent>("addCollisionGroups") {

                @Override
                public AddCollisionGroupsComponent construct(EntityWorld entityWorld, Element element) {
                    long targetOf = getCollisionGroupBitMask(element.getAttributeValue("targetOf"));
                    long targets = getCollisionGroupBitMask(element.getAttributeValue("targets"));
                    return new AddCollisionGroupsComponent(targetOf, targets);
                }
            });
    xmlTemplateManager.registerComponent(
            new XMLComponentConstructor<RemoveCollisionGroupsComponent>("removeCollisionGroups") {

                @Override
                public RemoveCollisionGroupsComponent construct(EntityWorld entityWorld, Element element) {
                    long targetOf = getCollisionGroupBitMask(element.getAttributeValue("targetOf"));
                    long targets = getCollisionGroupBitMask(element.getAttributeValue("targets"));
                    return new RemoveCollisionGroupsComponent(targetOf, targets);
                }
            });
    //physics
    xmlTemplateManager.registerComponent(new XMLComponentConstructor<HitboxComponent>("hitbox") {

        @Override
        public HitboxComponent construct(EntityWorld entityWorld, Element element) {
            Shape shape = null;
            Element childElement = (Element) element.getChildren().get(0);
            String shapeType = childElement.getName();
            double x = 0;
            String xText = childElement.getAttributeValue("x");
            if (xText != null) {
                x = Double.parseDouble(xText);
            }
            double y = 0;
            String yText = childElement.getAttributeValue("y");
            if (yText != null) {
                y = Double.parseDouble(yText);
            }
            if (shapeType.equals("regularCyclic")) {
                int edges = Integer.parseInt(childElement.getAttributeValue("edges"));
                double radius = Double.parseDouble(childElement.getAttributeValue("radius"));
                shape = new RegularCyclic(edges, radius);
            } else if (shapeType.equals("circle")) {
                double radius = Double.parseDouble(childElement.getAttributeValue("radius"));
                shape = new Circle(x, y, radius);
            } else if (shapeType.equals("rectangle")) {
                double width = Double.parseDouble(childElement.getAttributeValue("width"));
                double height = Double.parseDouble(childElement.getAttributeValue("height"));
                shape = new Rectangle(x, y, width, height);
            } else if (shapeType.equals("point")) {
                Vector2D localPoint = new Vector2D();
                String[] positionCoordinates = element.getText().split(",");
                if (positionCoordinates.length > 1) {
                    double localPointX = Double
                            .parseDouble(xmlTemplateManager.parseValue(entityWorld, positionCoordinates[0]));
                    double localPointY = Double
                            .parseDouble(xmlTemplateManager.parseValue(entityWorld, positionCoordinates[1]));
                    localPoint = new Vector2D(localPointX, localPointY);
                }
                shape = new PointShape(localPoint);
            }
            if (shape == null) {
                throw new UnsupportedOperationException("Unsupported shape type '" + shapeType + "'.");
            }
            return new HitboxComponent(shape);
        }
    });
    //spawns
    xmlTemplateManager.registerComponent(new XMLComponentConstructor<SpawnTemplateComponent>("spawnTemplate") {

        @Override
        public SpawnTemplateComponent construct(EntityWorld entityWorld, Element element) {
            String[] templates = element.getText().split("\\|");
            for (int i = 0; i < templates.length; i++) {
                templates[i] = xmlTemplateManager.parseTemplate(entityWorld, templates[i]);
            }
            return new SpawnTemplateComponent(templates);
        }
    });
    //spells
    xmlTemplateManager.registerComponent(new XMLComponentConstructor<CastTypeComponent>("castType") {

        @Override
        public CastTypeComponent construct(EntityWorld entityWorld, Element element) {
            return new CastTypeComponent(CastTypeComponent.CastType.valueOf(element.getText().toUpperCase()));
        }
    });
    //units
    xmlTemplateManager
            .registerComponent(new XMLComponentConstructor<CollisionGroupComponent>("collisionGroup") {

                @Override
                public CollisionGroupComponent construct(EntityWorld entityWorld, Element element) {
                    long targetOf = getCollisionGroupBitMask(element.getAttributeValue("targetOf"));
                    long targets = getCollisionGroupBitMask(element.getAttributeValue("targets"));
                    return new CollisionGroupComponent(targetOf, targets);
                }
            });
    xmlTemplateManager
            .registerComponent(new XMLComponentConstructor<HealthBarStyleComponent>("healthBarStyle") {

                @Override
                public HealthBarStyleComponent construct(EntityWorld entityWorld, Element element) {
                    return new HealthBarStyleComponent(
                            HealthBarStyleComponent.HealthBarStyle.valueOf(element.getText().toUpperCase()));
                }
            });
}

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.DOMFormulaConverter.java

License:Open Source License

/**
 * Recursive function to render all FormulaElements
 * Converts MathML to HTML//from  w  w  w.  j  a  v  a  2s  . c  o  m
 *
 * @param cur the current processed MathML JDOM2 Element (a node or leaf inside MathML's DOM tree)
 * @return an object which implements the FormulaElement interface, so it can be rendered to HTML
 */
private FormulaElement renderElement(Element cur) {

    String name = cur.getName();
    String mathvariant = null;
    FormulaElement output;

    // Based on the MathML tag a corresponding class will be chosen and output will be rendered
    switch (name.toLowerCase()) {

    // Superscripts
    case "msup":
        Msup msup = new Msup();
        msup.setBase(renderElement(cur.getChildren().get(0)));
        msup.setSuperscript(renderElement(cur.getChildren().get(1)));
        output = msup;
        break;

    // Subscripts
    case "msub":
        Msub msub = new Msub();
        msub.setBase(renderElement(cur.getChildren().get(0)));
        msub.setSubscript(renderElement(cur.getChildren().get(1)));
        output = msub;
        break;

    // Subscript-superscript Pairs
    case "msubsup":
        Msubsup msubsup = new Msubsup();
        msubsup.setBase(renderElement(cur.getChildren().get(0)));
        msubsup.setSubscript(renderElement(cur.getChildren().get(1)));
        msubsup.setSuperscript(renderElement(cur.getChildren().get(2)));
        output = msubsup;
        break;

    // Rows
    case "mrow":
        Mrow mrow = new Mrow();
        Iterator<Element> iterator = cur.getChildren().iterator();

        while (iterator.hasNext()) {
            Element element = iterator.next();
            FormulaElement rowElement = renderElement(element);
            mrow.addElement(rowElement);
        }

        output = mrow;
        break;

    // operators
    case "mo":
        Mo mo;
        String operator = cur.getText();

        // find operator in dictionary
        mo = MathmlCharacterDictionary.findOperator(operator, cur.getAttributeValue("form", "infix"));

        if (mo == null) {
            mo = new Mo();
            mo.setValue(operator);

            // Parse attributes
            mo.setAccent(Boolean.parseBoolean(cur.getAttributeValue("accent", "false")));
            mo.setSeparator(Boolean.parseBoolean(cur.getAttributeValue("separator", "false")));
            mo.setFence(Boolean.parseBoolean(cur.getAttributeValue("fence", "false")));
            mo.setMovablelimits(Boolean.parseBoolean(cur.getAttributeValue("movablelimits", "false")));
            mo.setLargeop(Boolean.parseBoolean(cur.getAttributeValue("largeop", "false")));
            mo.setStretchy(Boolean.parseBoolean(cur.getAttributeValue("stretchy", "false")));

            mo.setLspace(Unit.parse(cur.getAttributeValue("lspace", "thickmathspace")));
            mo.setRspace(Unit.parse(cur.getAttributeValue("rspace", "thickmathspace")));
            mo.setMinsize(Unit.parse(cur.getAttributeValue("minsize")));
            mo.setMaxsize(Unit.parse(cur.getAttributeValue("maxsize")));
        }
        output = mo;
        break;

    // numbers
    case "mn":
        Mn mn = new Mn();
        mn.setValue(cur.getText());
        output = mn;
        break;

    // identifiers
    case "mi":
        Mi mi = new Mi();
        mi.setValue(cur.getText());
        mathvariant = cur.getAttributeValue("mathvariant");
        if (mathvariant != null && mathvariant.isEmpty() == false) {
            mi.setMathvariant(mathvariant);
            mathvariant = null;
        }
        output = mi;
        break;

    // fractions
    case "mfrac":
        Mfrac mfrac = new Mfrac();
        mfrac.setNumerator(renderElement(cur.getChildren().get(0)));
        mfrac.setDenominator(renderElement(cur.getChildren().get(1)));

        String linethickness = cur.getAttributeValue("linethickness");
        if (linethickness != null) {
            mfrac.setLinethickness(linethickness);
        }

        output = mfrac;
        break;

    // Expression Inside Pair of Fences
    case "mfenced":
        Mfenced mfenced = new Mfenced();
        mfenced.setOpened(cur.getAttributeValue("open"));
        mfenced.setClosed(cur.getAttributeValue("close"));
        mfenced.setSeparators(cur.getAttributeValue("separators"));

        List<Element> children = cur.getChildren();
        if (children.isEmpty() == false) {
            List<FormulaElement> renderedChildren = new ArrayList<>();
            for (Element child : children) {
                FormulaElement renderedChild = renderElement(child);
                renderedChildren.add(renderedChild);
            }
            mfenced.setContent(renderedChildren);
        }
        output = mfenced;
        break;

    // Space
    case "mspace":
        Mspace mspace = new Mspace();

        // Parse attributes
        String widthAttribute = cur.getAttributeValue("width");
        if (widthAttribute != null) {
            mspace.setWidth(Unit.parse(widthAttribute));
        }
        String heightAttribute = cur.getAttributeValue("height");
        if (heightAttribute != null) {
            mspace.setHeight(Unit.parse(heightAttribute));
        }

        // linebreaks will be ignored for now

        output = mspace;
        break;

    // Square root
    case "msqrt":
        Mroot msqrt = new Mroot();
        msqrt.setBase(renderElement(cur.getChildren().get(0)));
        // no index
        output = msqrt;
        break;

    // Root
    case "mroot":
        Mroot mroot = new Mroot();
        mroot.setBase(renderElement(cur.getChildren().get(0)));
        mroot.setDegree(renderElement(cur.getChildren().get(1)));
        output = mroot;
        break;

    // String literal
    case "ms":
        Ms ms = new Ms();
        ms.setValue(cur.getText());
        output = ms;
        break;

    // Text
    case "mtext":
        Mtext mtext = new Mtext();
        mtext.setValue(cur.getText());
        output = mtext;
        break;

    // Style change
    case "mstyle":
        Mstyle mstyle = new Mstyle();

        mathvariant = cur.getAttributeValue("mathvariant");
        if (mathvariant != null && mathvariant.isEmpty() == false) {
            mstyle.setStyle(mathvariant);
            mathvariant = null;
        }

        Iterator<Element> mstyleIterator = cur.getChildren().iterator();
        while (mstyleIterator.hasNext()) {
            mstyle.addBaseElement(renderElement(mstyleIterator.next()));
        }
        output = mstyle;
        break;

    // Overscript
    case "mover":
        Mover mover = new Mover();
        mover.setBase(renderElement(cur.getChildren().get(0)));
        mover.setOverscript(renderElement(cur.getChildren().get(1)));
        output = mover;
        break;

    // Underscript
    case "munder":
        Munder munder = new Munder();
        munder.setBase(renderElement(cur.getChildren().get(0)));
        munder.setUnderscript(renderElement(cur.getChildren().get(1)));
        output = munder;
        break;

    // Matrices & tables
    case "mtable":
        Mtable mtable = new Mtable();
        Iterator<Element> mRowIterator = cur.getChildren().iterator();
        while (mRowIterator.hasNext()) {
            Mtr mtr = (Mtr) renderElement(mRowIterator.next());
            mtable.getRows().add(mtr);
        }
        output = mtable;
        break;

    // Table rows
    case "mtr":
        Mtr mtr = new Mtr();
        Iterator<Element> mCellIterator = cur.getChildren().iterator();
        while (mCellIterator.hasNext()) {
            Mtd mtd = (Mtd) renderElement(mCellIterator.next());
            mtr.getTds().add(mtd);
        }
        output = mtr;
        break;

    // Table cells
    case "mtd":
        Mtd mtd = new Mtd();
        Mrow tdContent = new Mrow();
        Iterator<Element> mContentIterator = cur.getChildren().iterator();
        while (mContentIterator.hasNext()) {
            tdContent.addElement(renderElement(mContentIterator.next()));
        }
        mtd.setContent(tdContent);
        output = mtd;
        break;
    default:
        logger.info("MathML conversion of element <" + cur.getName() + "> NOT YET IMPLEMENTED");
        output = null;
        break;

    }

    return output;
}

From source file:br.com.gsoftwares.util.ImportClient.java

private void trataElement(Element element) throws Exception {

    //Recuperamos os atributos filhos (Attributes)  
    List atributes = element.getAttributes();
    Iterator i_atr = atributes.iterator();

    //Iteramos com os atributos filhos  
    while (i_atr.hasNext()) {
        Attribute atrib = (Attribute) i_atr.next();
        //System.out.println("\nattribute de (" + element.getName() + "):" + atrib.getName() + " - valor: " + atrib.getValue());
    }/*from  ww w . j a va  2s  .c om*/
    //Recuperamos os elementos filhos (children)  
    List elements = element.getChildren();
    Iterator it = elements.iterator();

    //Iteramos com os elementos filhos, e filhos do dos filhos  
    while (it.hasNext()) {
        Element el = (Element) it.next();
        //System.out.println(el.getName() + " - " + el.getText());
        switch (el.getName()) {
        case "CPF":
            CPF = el.getText();
            Tipo = "F";
            break;
        case "CNPJ":
            CPF = el.getText();
            Tipo = "J";
            break;
        case "xNome":
            Nome = el.getText();
            Apelido = "";
            break;
        case "xLgr":
            Rua = el.getText();
            break;
        case "nro":
            numero = el.getText();
            break;
        case "xCpl":
            Comp = el.getText();
            break;
        case "xBairro":
            Bairro = el.getText();
            break;
        case "cMun":
            Cod_Mun = el.getText();
            break;
        case "xMun":
            Cidade = el.getText();
            break;
        case "UF":
            Estado = el.getText();
            break;
        case "CEP":
            Cep = el.getText();
            break;
        case "fone":
            Telefone = el.getText();
            break;
        case "IE":
            if (el.getText().equals("ISENTO")) {
                Tipo_ins = "2";
                Ins = "ISENTO";
            } else {
                if (el.getText().contains("^[0-9]*$")) {
                    Tipo_ins = "1";
                    Ins = el.getText();
                } else {
                    Tipo_ins = "9";
                    Ins = "";
                }
                break;
            }
        case "email":
            email = el.getText();
            break;
        }

        trataElement(el);
    }
}

From source file:br.com.gsoftwares.util.ImportProduto.java

private void trataElement(Element element) throws Exception {

    //Recuperamos os atributos filhos (Attributes)  
    List atributes = element.getAttributes();
    Iterator i_atr = atributes.iterator();

    //Iteramos com os atributos filhos  
    while (i_atr.hasNext()) {
        Attribute atrib = (Attribute) i_atr.next();
        //System.out.println("\nattribute de (" + element.getName() + "):" + atrib.getName() + " - valor: " + atrib.getValue());
    }//from w  ww  . ja va2  s .  c o  m
    //Recuperamos os elementos filhos (children)  
    List elements = element.getChildren();
    Iterator it = elements.iterator();

    //Iteramos com os elementos filhos, e filhos do dos filhos  
    while (it.hasNext()) {
        Element el = (Element) it.next();
        System.out.println(el.getName() + " - " + el.getText());
        switch (el.getName()) {
        case "cProd":
            CPF = el.getText();
            Tipo = "F";
            break;
        case "xProd":
            CPF = el.getText();
            Tipo = "J";
            break;
        case "NCM":
            Nome = el.getText();
            Apelido = "";
            break;
        case "uCom":
            Rua = el.getText();
            break;
        case "orig":
            numero = el.getText();
            break;
        }

        trataElement(el);
    }
}

From source file:br.com.nfe.util.Chave.java

@Override
public void run() {

    while (true) {
        String chave = "";
        Document doc = null;// www .j a  v a2  s  . com
        SAXBuilder builder = new SAXBuilder();

        Path path = Paths.get("c:/unimake/uninfe/" + pasta + "/Retorno");
        WatchService watchService = null;
        try {
            watchService = FileSystems.getDefault().newWatchService();
            path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE,
                    StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE);

        } catch (IOException io) {
            io.printStackTrace();
        }
        WatchKey key = null;

        while (true) {
            try {
                key = watchService.take();

                for (WatchEvent<?> event : key.pollEvents()) {
                    Kind<?> kind = event.kind();
                    System.out.println("Evento em " + event.context().toString() + " " + kind);
                    try {

                        doc = builder.build(
                                "c:/unimake/uninfe/" + pasta + "/Retorno/" + cNf + "-ret-gerar-chave.xml");

                        Element retorno = doc.getRootElement();

                        List<Element> lista = retorno.getChildren();

                        for (Element e : lista) {

                            chave = e.getAttributeValue("chaveNFe");
                            chave = e.getText();

                        }
                        mudaChave(chave);
                        if (chave.isEmpty() == false) {
                            allDone = true;
                        }
                    } catch (Exception e) {

                        e.printStackTrace();

                    }

                }
            } catch (InterruptedException ie) {
                ie.printStackTrace();
            }

            boolean reset = key.reset();
            if (!reset) {
                break;
            }
            if (allDone) {
                return;
            }
        }

    }
}

From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a UserRequest object from a JDOM element.
 *
 * @param element The UserRequest JDOM element.
 * @return A UserRequest object.//from   w  w  w  .j a va  2  s.c  o m
 * @throws ReaderException
 */
protected final UserRequest getUserRequest(Element element) throws ReaderException {
    // user element of the UserRequest element
    Element userElement = element.getChild(USER);
    if (userElement == null) {
        String error = "user element not found in userRequest element";
        throw new ReaderException(error);
    }
    User user = getUser(userElement);

    // password element of the userRequest element
    Element passwordElement = element.getChild(PASSWORD);
    if (passwordElement == null) {
        String error = "password element not found in userRequest element";
        throw new ReaderException(error);
    }
    String password = passwordElement.getText();

    return new UserRequest(user, password.toCharArray());
}

From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a Principal object from a JDOM element.
 *
 * @param element The Principal JDOM element.
 * @return A Principal object./*w w w.j  a  v a2  s . c o  m*/
 * @throws ReaderException
 */
protected final Principal getPrincipal(Element element) throws ReaderException {
    if (element == null) {
        String error = "null identity element";
        throw new ReaderException(error);
    }

    if (!element.getName().equals(IDENTITY)) {
        String error = "expected identity element name, found " + element.getName();
        throw new ReaderException(error);
    }

    String type = element.getAttributeValue(TYPE);
    if (type == null) {
        String error = "type attribute not found in identity element" + element.getName();
        throw new ReaderException(error);
    }

    String identity = element.getText();
    Principal principal;
    if (type.equals(IdentityType.OPENID.getValue())) {
        principal = new OpenIdPrincipal(identity);
    } else if (type.equals(IdentityType.CADC.getValue())) {
        principal = new NumericPrincipal(UUID.fromString(identity));
    } else if (type.equals(IdentityType.USERNAME.getValue())) {
        principal = new HttpPrincipal(identity);
    } else if (type.equals(IdentityType.X500.getValue())) {
        principal = new X500Principal(identity);
    } else if (type.equals(IdentityType.ENTRY_DN.getValue())) {
        principal = new DNPrincipal(identity);
    } else {
        String error = "Unknown type attribute: " + type;
        throw new ReaderException(error);
    }

    return principal;
}

From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a PosixDetails object from a JDOM element.
 *
 * @param element The PosixDetails JDOM element.
 * @return A PosixDetails object./*from   w  w  w.j av  a  2s.  c  o m*/
 * @throws ReaderException
 */
protected final PosixDetails getPosixDetails(Element element) throws ReaderException {
    if (element == null) {
        String error = "null posixDetails element";
        throw new ReaderException(error);
    }

    // userName
    Element userNameElement = element.getChild(USERNAME);
    if (userNameElement == null) {
        String error = "posixDetails missing required element username";
        throw new ReaderException(error);
    }
    String username = userNameElement.getText();

    // uid
    Element uidElement = element.getChild(UID);
    if (uidElement == null) {
        String error = "posixDetails missing required element uid";
        throw new ReaderException(error);
    }
    long uid;
    try {
        uid = Long.valueOf(uidElement.getText());
    } catch (NumberFormatException e) {
        String error = "Cannot parse posixDetails uid to a long";
        throw new ReaderException(error);
    }

    // gid
    Element gidElement = element.getChild(GID);
    if (gidElement == null) {
        String error = "posixDetails missing required element gid";
        throw new ReaderException(error);
    }
    long gid;
    try {
        gid = Long.valueOf(gidElement.getText());
    } catch (NumberFormatException e) {
        String error = "Cannot parse posixDetails gid to a long";
        throw new ReaderException(error);
    }

    // homeDirectory
    Element homeDirElement = element.getChild(HOME_DIRECTORY);
    if (homeDirElement == null) {
        String error = "posixDetails missing required element homeDirectory";
        throw new ReaderException(error);
    }
    String homeDirectory = homeDirElement.getText();

    return new PosixDetails(username, uid, gid, homeDirectory);
}