Example usage for org.joda.time DateTime parse

List of usage examples for org.joda.time DateTime parse

Introduction

In this page you can find the example usage for org.joda.time DateTime parse.

Prototype

@FromString
public static DateTime parse(String str) 

Source Link

Document

Parses a DateTime from the specified string.

Usage

From source file:course_generator.SaxCGXHandler.java

License:Open Source License

@Override
public void endElement(String uri, String localname, String qName) throws SAXException {
    if (qName.equalsIgnoreCase("COURSEGENERATOR")) {
        level--;/*from  ww w .j a  va  2 s  .c  om*/
    }

    if (level == LEVEL_COURSEGENERATOR) {
        if (qName.equalsIgnoreCase("VERSION")) {
            cgx_version = ManageDouble(0.0, ERR_READ_VERSION);

            if (cgx_version > CgConst.MAX_CGX_VERSION_TO_READ) {
                errcode = ERR_READ_VERSION;
                errline = locator.getLineNumber();
                //TODO Afficher message de dfaut car version non lisible
            }
        } else if (qName.equalsIgnoreCase("TOTALDISTANCE")) {
            trkdata.setTotalDistance(ManageDouble(0.0, ERR_READ_DOUBLE));
        } else if (qName.equalsIgnoreCase("TOTALSECOND")) {
            trkdata.TotalTime = ManageInt(0, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("COURSENAME")) {
            trkdata.CourseName = ManageString();
        } else if (qName.equalsIgnoreCase("DESCRIPTION")) {
            trkdata.Description = ManageString();
        } else if (qName.equalsIgnoreCase("STARTTIME")) {
            try {
                trkdata.StartTime = DateTime.parse(characters);
                characters = "";
                if ((trkdata.StartTime.getYear() == 0) || (trkdata.StartTime.getMonthOfYear() == 0)
                        || (trkdata.StartTime.getDayOfMonth() == 0))
                    trkdata.StartTime = new DateTime();
            } catch (IllegalArgumentException e) {
                trkdata.StartTime = new DateTime();
                errcode = ERR_READ_TIME;
                errline = locator.getLineNumber();
                characters = "";
            }
        } else if (qName.equalsIgnoreCase("USEELEVEFFECT")) {
            trkdata.bElevEffect = ManageBoolean(false, ERR_READ_BOOL);
        } else if (qName.equalsIgnoreCase("USENIGHTCOEFF")) {
            trkdata.bNightCoeff = ManageBoolean(false, ERR_READ_BOOL);
        } else if (qName.equalsIgnoreCase("NIGHTSTARTTIME")) {
            try {
                trkdata.StartNightTime = DateTime.parse(characters, fmt);
                characters = "";
            } catch (IllegalArgumentException e) {
                trkdata.StartNightTime = new DateTime();
                errcode = ERR_READ_TIME;
                errline = locator.getLineNumber();
                characters = "";
            }
        } else if (qName.equalsIgnoreCase("NIGHTENDTIME")) {
            try {
                trkdata.EndNightTime = DateTime.parse(characters, fmt);
                characters = "";
            } catch (IllegalArgumentException e) {
                trkdata.EndNightTime = new DateTime();
                errcode = ERR_READ_TIME;
                errline = locator.getLineNumber();
                characters = "";
            }
        } else if (qName.equalsIgnoreCase("NIGHTCOEFF")) {
            trkdata.NightCoeffAsc = ManageDouble(0.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("NIGHTCOEFFDESC")) {
            trkdata.NightCoeffDesc = ManageDouble(0.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("STARTGLOBALCOEFF")) {
            trkdata.StartGlobalCoeff = ManageDouble(100.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("ENDGLOBALCOEFF")) {
            trkdata.EndGlobalCoeff = ManageDouble(100.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("TIMEZONE")) {
            trkdata.TrackTimeZone = ManageDouble(0.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("USESUMMERTIME")) {
            trkdata.TrackUseSumerTime = ManageBoolean(false, ERR_READ_BOOL);
        } else if (qName.equalsIgnoreCase("CURVE")) {
            curve = ManageString();
            if (!Utils.FileExist(Utils.GetHomeDir() + "/" + CgConst.CG_DIR + "/" + curve + ".par")) {
                JOptionPane.showMessageDialog(Parent, bundle.getString("loadCGX.CurveFileError"));
                trkdata.Paramfile = "Default";
            } else
                trkdata.Paramfile = curve;
        } else if (qName.equalsIgnoreCase("MRBSIZEW")) {
            trkdata.MrbSizeW = ManageInt(640, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("MRBSIZEH")) {
            trkdata.MrbSizeH = ManageInt(480, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("CLPROFILSIMPLEFILL")) {
            trkdata.clProfil_Simple_Fill = ManageColor(Color.BLACK, ERR_READ_COLOR);
        } else if (qName.equalsIgnoreCase("CLPROFILSIMPLEBORDER")) {
            trkdata.clProfil_Simple_Border = ManageColor(Color.BLACK, ERR_READ_COLOR);
        } else if (qName.equalsIgnoreCase("CLPROFILRSROAD")) {
            trkdata.clProfil_RS_Road = ManageColor(Color.BLACK, ERR_READ_COLOR);
        } else if (qName.equalsIgnoreCase("CLPROFILRSPATH")) {
            trkdata.clProfil_RS_Path = ManageColor(Color.BLACK, ERR_READ_COLOR);
        } else if (qName.equalsIgnoreCase("CLPROFILRSBORDER")) {
            trkdata.clProfil_RS_Border = ManageColor(Color.BLACK, ERR_READ_COLOR);
        } else if (qName.equalsIgnoreCase("CLPROFILSLOPEINF5")) {
            trkdata.clProfil_SlopeInf5 = ManageColor(Color.BLACK, ERR_READ_COLOR);
        } else if (qName.equalsIgnoreCase("CLPROFILSLOPEINF10")) {
            trkdata.clProfil_SlopeInf10 = ManageColor(Color.BLACK, ERR_READ_COLOR);
        } else if (qName.equalsIgnoreCase("CLPROFILSLOPEINF15")) {
            trkdata.clProfil_SlopeInf15 = ManageColor(Color.BLACK, ERR_READ_COLOR);
        } else if (qName.equalsIgnoreCase("CLPROFILSLOPESUP15")) {
            trkdata.clProfil_SlopeSup15 = ManageColor(Color.BLACK, ERR_READ_COLOR);
        } else if (qName.equalsIgnoreCase("CLPROFILSLOPEBORDER")) {
            trkdata.clProfil_SlopeBorder = ManageColor(Color.BLACK, ERR_READ_COLOR);
        } else if (qName.equalsIgnoreCase("MRBCURVEFILTER")) {
            trkdata.CurveFilter = ManageInt(4, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("WORDWRAPLENGTH")) {
            trkdata.WordWrapLength = ManageInt(25, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("LABELTOBOTTOM")) {
            trkdata.LabelToBottom = ManageBoolean(false, ERR_READ_BOOL);
        } else if (qName.equalsIgnoreCase("MRBTYPE")) {
            trkdata.MRBType = ManageInt(0, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("TOPMARGIN")) {
            trkdata.TopMargin = ManageInt(0, ERR_READ_INT);
        }
    } //End LEVEL_COURSEGENERATOR

    if (level == LEVEL_TRACKPOINT) {
        if (qName.equalsIgnoreCase("LATITUDEDEGREES")) {
            trkpt_lat = ManageDouble(0.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("LONGITUDEDEGREES")) {
            trkpt_lon = ManageDouble(0.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("ALTITUDEMETERS")) {
            trkpt_ele = ManageDouble(0.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("DISTANCEMETERS")) {
            trkpt_dist = ManageDouble(0.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("DISTANCEMETERSCUMUL")) {
            trkpt_distcumul = ManageDouble(0.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("SPEED")) {
            trkpt_speed = ManageDouble(0.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("DIFF")) {
            trkpt_diff = ManageDouble(0.0, ERR_READ_DOUBLE);
            if (cgx_version < 2.0) {
                trkpt_diff = 100.0 - (trkpt_diff - 1.0) * 100.0;
                if ((trkpt_diff > 100.0) || (trkpt_diff <= 0.0))
                    trkpt_diff = 100.0;
            }
        } else if (qName.equalsIgnoreCase("COEFF")) {
            trkpt_coeff = ManageDouble(0.0, ERR_READ_DOUBLE);
            if (cgx_version < 2.0) {
                trkpt_coeff = 100.0 - (trkpt_coeff - 1.0) * 100.0;
                if ((trkpt_coeff > 100.0) || (trkpt_coeff <= 0.0))
                    trkpt_coeff = 100.0;
            }
        } else if (qName.equalsIgnoreCase("RECUP")) {
            trkpt_recup = ManageDouble(0.0, ERR_READ_DOUBLE);
        } else if (qName.equalsIgnoreCase("TIMESECONDE")) {
            trkpt_timesecond = ManageInt(0, ERR_READ_INT);
            trkdata.isTimeLoaded = true;
        } else if (qName.equalsIgnoreCase("DELTATIMESECONDE")) {
            trkpt_dtime = ManageDouble(0.0, ERR_READ_DOUBLE);
            //TODO voir si utilis
        } else if (qName.equalsIgnoreCase("TIMELIMIT")) {
            trkpt_timelimit = ManageInt(0, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("EATTIME")) {
            trkpt_eattime = ManageInt(0, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("COMMENT")) {
            trkpt_name = ManageString();
        } else if (qName.equalsIgnoreCase("NAME")) {
            trkpt_name = ManageString();
        } else if (qName.equalsIgnoreCase("TAG")) {
            trkpt_tag = ManageInt(0, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("FMTLBMINIROADBOOK")) {
            trkpt_fmtmrb = ManageString();
        } else if (qName.equalsIgnoreCase("OPTMINIROADBOOK")) {
            trkpt_optmrb = ManageInt(0, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("VPOSMINIROADBOOK")) {
            trkpt_vposmrb = ManageInt(0, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("COMMENTMINIROADBOOK")) {
            trkpt_commentmrb = ManageString();
        } else if (qName.equalsIgnoreCase("FONTSIZEMINIROADBOOK")) {
            trkpt_FontSizemrb = ManageInt(0, ERR_READ_INT);
        } else if (qName.equalsIgnoreCase("TRACKPOINT")) {
            level--;
            if ((mode == 0) || (mode == 2)) {
                // Add data at the of the array
                Cmpt++;
                trkdata.data.add(new CgData(Cmpt, //double Num
                        trkpt_lat, //double Latitude
                        trkpt_lon, //double Longitude
                        trkpt_ele, //double Elevation
                        trkpt_ele, //double ElevationMemo
                        trkpt_tag, //int Tag
                        trkpt_dist, //double Dist
                        trkpt_distcumul, //double Total
                        trkpt_diff, //double Diff
                        trkpt_coeff, //double Coeff
                        trkpt_recup, //double Recup
                        0.0, //double Slope
                        trkpt_speed, //double Speed
                        0.0, //double dElevation
                        trkpt_timesecond, //int Time
                        trkpt_timesecond - old_time, //double dTime_f
                        trkpt_timelimit, //int TimeLimit
                        new DateTime(), //DateTime Hour
                        trkpt_eattime, //int Station
                        trkpt_name, //String Name
                        trkpt_comment, //String Comment
                        0.0, //double tmp1
                        0.0, //double tmp2
                        trkpt_fmtmrb, //String FmtLbMiniRoadbook
                        trkpt_optmrb, //int OptionMiniRoadbook
                        trkpt_vposmrb, //int VPosMiniRoadbook
                        trkpt_commentmrb, //String CommentMiniRoadbook
                        trkpt_FontSizemrb //int FontSizeMiniRoadbook
                ));
            } else {
                trkdata.data.add(Cmpt, new CgData(Cmpt, //double Num
                        trkpt_lat, //double Latitude
                        trkpt_lon, //double Longitude
                        trkpt_ele, //double Elevation
                        trkpt_ele, //double ElevationMemo
                        trkpt_tag, //int Tag
                        trkpt_dist, //double Dist
                        trkpt_distcumul, //double Total
                        trkpt_diff, //double Diff
                        trkpt_coeff, //double Coeff
                        trkpt_recup, //double Recup
                        0.0, //double Slope
                        trkpt_speed, //double Speed
                        0.0, //double dElevation
                        trkpt_timesecond, //int Time
                        trkpt_timesecond - old_time, //double dTime_f
                        trkpt_timelimit, //int TimeLimit
                        new DateTime(), //DateTime Hour
                        trkpt_eattime, //int Station
                        trkpt_name, //String Name
                        trkpt_comment, //String Comment
                        0.0, //double tmp1
                        0.0, //double tmp2
                        trkpt_fmtmrb, //String FmtLbMiniRoadbook
                        trkpt_optmrb, //int OptionMiniRoadbook
                        trkpt_vposmrb, //int VPosMiniRoadbook
                        trkpt_commentmrb, //String CommentMiniRoadbook
                        trkpt_FontSizemrb //int FontSizeMiniRoadbook
                ));
            } //else
            Cmpt++;
            old_time = trkpt_timesecond;
        }
    } //End LEVEL_TRACKPOINT

}

From source file:course_generator.SaxGPXHandler.java

License:Open Source License

@Override
public void endElement(String uri, String localname, String qName) throws SAXException {
    if (qName.equalsIgnoreCase("GPX")) {
        level--;//  w w  w.  j  a v  a 2s  .c om
    } else if (qName.equalsIgnoreCase("TRK")) {
        level--;
    } else if (qName.equalsIgnoreCase("TRKSEG")) {
        level--;
    } else if ((level == LEVEL_TRK) && qName.equalsIgnoreCase("NAME")) {
        trk_name = characters;
        characters = "";
    } else if ((level == LEVEL_TRKPT) && qName.equalsIgnoreCase("NAME")) {
        trkpt_name = characters;
        characters = "";
    } else if ((level == LEVEL_TRKPT) && qName.equalsIgnoreCase("ELE")) {
        try {
            trkpt_ele = Double.parseDouble(characters);
            characters = "";
        } catch (NumberFormatException e) {
            trkpt_ele = 0.0;
            errcode = ERR_READ_ELE;
            errline = locator.getLineNumber();
            characters = "";
        }
    } else if ((level == LEVEL_TRKPT) && qName.equalsIgnoreCase("TIME")) {
        try {
            if (first) {
                first = false;
                trkpt_time = DateTime.parse(characters);
                StartTime = trkpt_time;
                old_time = StartTime;
                Time_s = 0;
                dTime_f = 0.0;
                characters = "";
            } else {
                trkpt_time = DateTime.parse(characters);
                Time_s = (int) ((new Interval(StartTime, trkpt_time)).toDurationMillis() / 1000);
                dTime_f = ((new Interval(old_time, trkpt_time)).toDurationMillis() / 1000.0);
                characters = "";
            }
            trkdata.isTimeLoaded = true;
        } catch (IllegalArgumentException e) {
            trkpt_time = new DateTime(1970, 1, 1, 0, 0, 0);
            errcode = ERR_READ_TIME;
            errline = locator.getLineNumber();
            characters = "";
        }
    } else if (((level == LEVEL_TRKPT)) && qName.equalsIgnoreCase("TRKPT")) {
        level--;

        if ((mLat != trkpt_lat) || (mLon != trkpt_lon) || (!trkdata.isTimeLoaded)) {
            if ((mode == 0) || (mode == 2)) {
                // Add data at the of the array
                Cmpt++;
                trkdata.data.add(new CgData(Cmpt, //double Num
                        trkpt_lat, //double Latitude
                        trkpt_lon, //double Longitude
                        trkpt_ele, //double Elevation
                        trkpt_ele, //double ElevationMemo
                        0, //int Tag
                        0.0, //double Dist
                        0.0, //double Total
                        100.0, //double Diff
                        100.0, //double Coeff
                        0.0, //double Recup
                        0.0, //double Slope
                        0.0, //double Speed
                        0.0, //double dElevation
                        Time_s, //int Time //Temps total en seconde
                        dTime_f, //double dTime_f  //temps de parcours du tronon en seconde (avec virgule)
                        0, //int TimeLimit //Barrire horaire
                        trkpt_time, //DateTime Hour //Contient la date et l'heure de passage
                        0, //int Station
                        "", //String Name
                        "", //String Comment
                        0.0, //double tmp1
                        0.0, //double tmp2
                        CgConst.DEFAULTMRBFORMAT, //String FmtLbMiniRoadbook
                        CgConst.MRBOPT_SEL | CgConst.MRBOPT_LEFT | CgConst.MRBOPT_SHOWTAGS, //int OptionMiniRoadbook
                        0, //int VPosMiniRoadbook
                        "", //String CommentMiniRoadbook
                        CgConst.DEFAULTMRBFONTSIZE //int FontSizeMiniRoadbook
                ));
            } else {
                trkdata.data.add(Cmpt, new CgData(Cmpt, //double Num
                        trkpt_lat, //double Latitude
                        trkpt_lon, //double Longitude
                        trkpt_ele, //double Elevation
                        trkpt_ele, //double ElevationMemo
                        0, //int Tag
                        0.0, //double Dist
                        0.0, //double Total
                        100.0, //double Diff
                        100.0, //double Coeff
                        0.0, //double Recup
                        0.0, //double Slope
                        0.0, //double Speed
                        0.0, //double dElevation
                        Time_s, //int Time
                        dTime_f, //double dTime_f
                        0, //int TimeLimit
                        trkpt_time, //DateTime Hour
                        0, //int Station
                        "", //String Name
                        "", //String Comment
                        0.0, //double tmp1
                        0.0, //double tmp2
                        CgConst.DEFAULTMRBFORMAT, //String FmtLbMiniRoadbook
                        CgConst.MRBOPT_SEL | CgConst.MRBOPT_LEFT | CgConst.MRBOPT_SHOWTAGS, //int OptionMiniRoadbook
                        0, //int VPosMiniRoadbook
                        "", //String CommentMiniRoadbook
                        CgConst.DEFAULTMRBFONTSIZE //int FontSizeMiniRoadbook
                ));
            } //else
            Cmpt++;
        }
        mLat = trkpt_lat;
        mLon = trkpt_lon;
        mEle = trkpt_ele;
        old_time = trkpt_time;
    }
}

From source file:cz.cesnet.shongo.connector.device.AdobeConnectConnector.java

@Override
public Collection<RoomSummary> listRooms() throws CommandException {
    RequestAttributeList attributes = new RequestAttributeList();
    attributes.add("filter-type", "meeting");

    Element response = execApi("report-bulk-objects", attributes);

    List<RoomSummary> meetings = new ArrayList<RoomSummary>();

    for (Element room : response.getChild("report-bulk-objects").getChildren("row")) {
        if (room.getChildText("name").matches("(?i).*Template")) {
            continue;
        }//from   www .  jav  a 2  s.  c o  m

        RoomSummary roomSummary = new RoomSummary();
        roomSummary.setId(room.getAttributeValue("sco-id"));
        roomSummary.setName(room.getChildText("name"));
        roomSummary.setDescription(room.getChildText("description"));
        roomSummary.setAlias(room.getChildText("url"));

        String dateCreated = room.getChildText("date-created");
        if (dateCreated != null) {
            roomSummary.setStartDateTime(DateTime.parse(dateCreated));
        }

        meetings.add(roomSummary);
    }

    return Collections.unmodifiableList(meetings);
}

From source file:cz.cuni.mff.peckam.ais.AISProductReader.java

License:Open Source License

/**
 * Read all AIS records from the given file.
 * /*  w  w  w.  j av  a  2  s.  c o m*/
 * @param aisFile The file to read records from.
 * @return All records from the given file.
 * 
 * @throws IOException If read errors occur.
 * @throws FileNotFoundException If the given file cannot be found.
 */
public AISProduct[] readFile(File aisFile) throws IOException, FileNotFoundException {
    final AISProduct[] result = new AISProduct[(int) (aisFile.length() / AIS_RECORD_SIZE)];

    try (final DataInputStream stream = new DataInputStream(
            new BufferedInputStream(new FileInputStream(aisFile), AIS_RECORD_SIZE))) {

        for (int i = 0; i < result.length; i++) {
            // maybe needs to consider it is unsigned int
            @SuppressWarnings("unused")
            final int sclk_second = stream.readInt();
            @SuppressWarnings("unused")
            final int sclk_column = stream.readUnsignedShort();
            @SuppressWarnings("unused")
            final int sclk_fine = stream.readUnsignedShort();
            @SuppressWarnings("unused")
            final int scet_days = stream.readInt();
            @SuppressWarnings("unused")
            final int scet_msec = stream.readInt();

            // unused 8 bytes
            stream.readLong();

            final byte[] scet_string_bytes = new byte[24];
            stream.readFully(scet_string_bytes);
            final String scet_string = new String(scet_string_bytes).trim();

            final DateTime spacecraft_clock = DateTime.parse(scet_string);

            final byte process_id = stream.readByte();
            final byte instrument_mode = stream.readByte();

            // unused 9 bytes
            stream.readLong();
            stream.readByte();

            final byte transmit_power = stream.readByte();
            final byte frequency_table_number = stream.readByte();
            final int frequency_number = stream.readUnsignedByte();
            final byte band_number = stream.readByte();
            final byte receiver_attenuation = stream.readByte();

            // unused 12 bytes
            stream.readLong();
            stream.readInt();

            final float frequency = stream.readFloat();
            final Float[][] spectral_density = new Float[1][NUM_DENSITY_ITEMS];
            for (int j = 0; j < NUM_DENSITY_ITEMS; j++) {
                spectral_density[0][j] = stream.readFloat();
            }

            result[i] = new AISProduct(spacecraft_clock, process_id, instrument_mode, instrument_mode,
                    transmit_power, frequency_table_number, frequency_number, band_number, receiver_attenuation,
                    frequency, spectral_density);
        }
    }

    return result;
}

From source file:dao.OuvrageDao.java

private Ouvrage DocToObject(JsonDocument doc) {

    if (doc == null)
        return null; // Doc supprimer

    Ouvrage ouvrage = new Ouvrage();
    ouvrage.setId(doc.id());/*from   w  ww  . j  a  v  a 2 s  .  c o  m*/
    ouvrage.setIsbn(doc.content().getString("isbn"));
    ouvrage.setTitre(doc.content().getString("titre"));
    ouvrage.setAuteur(doc.content().getString("auteur"));
    ouvrage.setNumBC(doc.content().getString("numBC"));
    ouvrage.setNumBL(doc.content().getString("numBL"));
    ouvrage.setCategorie(categorieDao.findById(doc.content().getString("categorie")));
    ouvrage.setEdition(doc.content().getString("edition"));
    ouvrage.setLibrairie(doc.content().getString("librairie"));
    ouvrage.setPrixUnitaire(doc.content().getDouble("prix"));
    DateTime date = DateTime.parse(doc.content().getString("datePublication"));
    ouvrage.setDatePublication(date.toDate());
    return ouvrage;
}

From source file:dao.PretDao.java

private Pret DocToObject(JsonDocument doc) {

    if (doc == null)
        return null; // Doc supprimer

    Pret pret = new Pret();
    pret.setId(doc.id());//from ww w.j a v  a2s .  c  o m
    pret.setOuvrage(ouvrageDao.findById(doc.content().getString("idOuvrage")));
    pret.setEtudiant(etudiantDao.findById(doc.content().getString("idEtudiant")));
    pret.setProfesseur(professeurDao.findById(doc.content().getString("idProfesseur")));

    DateTime datePret = DateTime.parse(doc.content().getString("datePret"));
    pret.setDatePret(datePret.toDate());

    DateTime dateRetour = DateTime.parse(doc.content().getString("dateRetour"));
    pret.setDateRetour(datePret.toDate());

    return pret;
}

From source file:ddf.security.assertion.impl.SecurityAssertionImpl.java

License:Open Source License

/**
 * Parses the SecurityToken by wrapping within an AssertionWrapper.
 *
 * @param securityToken SecurityToken//ww w  .  j  ava2s . co m
 */
private void parseToken(SecurityToken securityToken) {
    XMLStreamReader xmlStreamReader = StaxUtils.createXMLStreamReader(securityToken.getToken());

    try {
        AttrStatement attributeStatement = null;
        AuthenticationStatement authenticationStatement = null;
        Attr attribute = null;
        int attrs = 0;
        while (xmlStreamReader.hasNext()) {
            int event = xmlStreamReader.next();
            switch (event) {
            case XMLStreamConstants.START_ELEMENT: {
                String localName = xmlStreamReader.getLocalName();
                switch (localName) {
                case NameID.DEFAULT_ELEMENT_LOCAL_NAME:
                    name = xmlStreamReader.getElementText();
                    for (int i = 0; i < xmlStreamReader.getAttributeCount(); i++) {
                        if (xmlStreamReader.getAttributeLocalName(i).equals(NameID.FORMAT_ATTRIB_NAME)) {
                            nameIDFormat = xmlStreamReader.getAttributeValue(i);
                            break;
                        }
                    }
                    break;
                case AttributeStatement.DEFAULT_ELEMENT_LOCAL_NAME:
                    attributeStatement = new AttrStatement();
                    attributeStatements.add(attributeStatement);
                    break;
                case AuthnStatement.DEFAULT_ELEMENT_LOCAL_NAME:
                    authenticationStatement = new AuthenticationStatement();
                    authenticationStatements.add(authenticationStatement);
                    attrs = xmlStreamReader.getAttributeCount();
                    for (int i = 0; i < attrs; i++) {
                        String name = xmlStreamReader.getAttributeLocalName(i);
                        String value = xmlStreamReader.getAttributeValue(i);
                        if (AuthnStatement.AUTHN_INSTANT_ATTRIB_NAME.equals(name)) {
                            authenticationStatement.setAuthnInstant(DateTime.parse(value));
                        }
                    }
                    break;
                case AuthnContextClassRef.DEFAULT_ELEMENT_LOCAL_NAME:
                    if (authenticationStatement != null) {
                        String classValue = xmlStreamReader.getText();
                        classValue = classValue.trim();
                        AuthenticationContextClassRef authenticationContextClassRef = new AuthenticationContextClassRef();
                        authenticationContextClassRef.setAuthnContextClassRef(classValue);
                        AuthenticationContext authenticationContext = new AuthenticationContext();
                        authenticationContext.setAuthnContextClassRef(authenticationContextClassRef);
                        authenticationStatement.setAuthnContext(authenticationContext);
                    }
                    break;
                case Attribute.DEFAULT_ELEMENT_LOCAL_NAME:
                    attribute = new Attr();
                    if (attributeStatement != null) {
                        attributeStatement.addAttribute(attribute);
                    }
                    attrs = xmlStreamReader.getAttributeCount();
                    for (int i = 0; i < attrs; i++) {
                        String name = xmlStreamReader.getAttributeLocalName(i);
                        String value = xmlStreamReader.getAttributeValue(i);
                        if (Attribute.NAME_ATTTRIB_NAME.equals(name)) {
                            attribute.setName(value);
                        } else if (Attribute.NAME_FORMAT_ATTRIB_NAME.equals(name)) {
                            attribute.setNameFormat(value);
                        }
                    }
                    break;
                case AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME:
                    XSString xsString = new XMLString();
                    xsString.setValue(xmlStreamReader.getElementText());
                    if (attribute != null) {
                        attribute.addAttributeValue(xsString);
                    }
                    break;
                case Issuer.DEFAULT_ELEMENT_LOCAL_NAME:
                    issuer = xmlStreamReader.getElementText();
                    break;
                case Conditions.DEFAULT_ELEMENT_LOCAL_NAME:
                    attrs = xmlStreamReader.getAttributeCount();
                    for (int i = 0; i < attrs; i++) {
                        String name = xmlStreamReader.getAttributeLocalName(i);
                        String value = xmlStreamReader.getAttributeValue(i);
                        if (Conditions.NOT_BEFORE_ATTRIB_NAME.equals(name)) {
                            notBefore = DatatypeConverter.parseDateTime(value).getTime();
                        } else if (Conditions.NOT_ON_OR_AFTER_ATTRIB_NAME.equals(name)) {
                            notOnOrAfter = DatatypeConverter.parseDateTime(value).getTime();
                        }
                    }
                    break;
                case SubjectConfirmation.DEFAULT_ELEMENT_LOCAL_NAME:
                    attrs = xmlStreamReader.getAttributeCount();
                    for (int i = 0; i < attrs; i++) {
                        String name = xmlStreamReader.getAttributeLocalName(i);
                        String value = xmlStreamReader.getAttributeValue(i);
                        if (SubjectConfirmation.METHOD_ATTRIB_NAME.equals(name)) {
                            subjectConfirmations.add(value);
                        }
                    }
                    break;
                case Assertion.DEFAULT_ELEMENT_LOCAL_NAME:
                    attrs = xmlStreamReader.getAttributeCount();
                    for (int i = 0; i < attrs; i++) {
                        String name = xmlStreamReader.getAttributeLocalName(i);
                        String value = xmlStreamReader.getAttributeValue(i);
                        if (Assertion.VERSION_ATTRIB_NAME.equals(name)) {
                            if ("2.0".equals(value)) {
                                tokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0";
                            } else if ("1.1".equals(value)) {
                                tokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1";
                            }
                        }
                    }
                }
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                String localName = xmlStreamReader.getLocalName();
                switch (localName) {
                case AttributeStatement.DEFAULT_ELEMENT_LOCAL_NAME:
                    attributeStatement = null;
                    break;
                case Attribute.DEFAULT_ELEMENT_LOCAL_NAME:
                    attribute = null;
                    break;
                default:
                    break;
                }
                break;
            }
            }
        }
    } catch (XMLStreamException e) {
        LOGGER.info("Unable to parse security token.", e);
    } finally {
        try {
            xmlStreamReader.close();
        } catch (XMLStreamException ignore) {
            //ignore
        }
    }
}

From source file:ddf.security.assertion.saml.impl.SecurityAssertionSaml.java

License:Open Source License

/**
 * Parses the SecurityToken by wrapping within an AssertionWrapper.
 *
 * @param securityToken SecurityToken/*from   www .  j  a  va2 s  .  c o  m*/
 */
private void parseToken(SecurityToken securityToken) {
    XMLStreamReader xmlStreamReader = StaxUtils.createXMLStreamReader(securityToken.getToken());

    try {
        AttributeStatement attributeStatement = null;
        AuthenticationStatement authenticationStatement = null;
        Attribute attribute = null;
        int attrs = 0;
        while (xmlStreamReader.hasNext()) {
            int event = xmlStreamReader.next();
            switch (event) {
            case XMLStreamConstants.START_ELEMENT: {
                String localName = xmlStreamReader.getLocalName();
                switch (localName) {
                case NameID.DEFAULT_ELEMENT_LOCAL_NAME:
                    name = xmlStreamReader.getElementText();
                    for (int i = 0; i < xmlStreamReader.getAttributeCount(); i++) {
                        if (xmlStreamReader.getAttributeLocalName(i).equals(NameID.FORMAT_ATTRIB_NAME)) {
                            nameIDFormat = xmlStreamReader.getAttributeValue(i);
                            break;
                        }
                    }
                    break;
                case org.opensaml.saml.saml2.core.AttributeStatement.DEFAULT_ELEMENT_LOCAL_NAME:
                    attributeStatement = new AttributeStatementSaml();
                    attributeStatements.add(attributeStatement);
                    break;
                case AuthnStatement.DEFAULT_ELEMENT_LOCAL_NAME:
                    authenticationStatement = new AuthenticationStatementSaml();
                    authenticationStatements.add(authenticationStatement);
                    attrs = xmlStreamReader.getAttributeCount();
                    for (int i = 0; i < attrs; i++) {
                        String name = xmlStreamReader.getAttributeLocalName(i);
                        String value = xmlStreamReader.getAttributeValue(i);
                        if (AuthnStatement.AUTHN_INSTANT_ATTRIB_NAME.equals(name)) {
                            authenticationStatement.setAuthnInstant(DateTime.parse(value));
                        }
                        if (AuthnStatement.SESSION_INDEX_ATTRIB_NAME.equals(name)) {
                            authenticationStatement.setSessionIndex(value);
                        }
                    }
                    break;
                case AuthnContextClassRef.DEFAULT_ELEMENT_LOCAL_NAME:
                    if (authenticationStatement != null) {
                        String classValue = xmlStreamReader.getText();
                        classValue = classValue.trim();
                        authenticationStatement.setAuthnContextClassRef(classValue);
                    }
                    break;
                case org.opensaml.saml.saml2.core.Attribute.DEFAULT_ELEMENT_LOCAL_NAME:
                    attribute = new AttributeSaml();
                    if (attributeStatement != null) {
                        attributeStatement.addAttribute(attribute);
                    }
                    attrs = xmlStreamReader.getAttributeCount();
                    for (int i = 0; i < attrs; i++) {
                        String name = xmlStreamReader.getAttributeLocalName(i);
                        String value = xmlStreamReader.getAttributeValue(i);
                        if (org.opensaml.saml.saml2.core.Attribute.NAME_ATTTRIB_NAME.equals(name)) {
                            attribute.setName(value);
                        } else if (org.opensaml.saml.saml2.core.Attribute.NAME_FORMAT_ATTRIB_NAME
                                .equals(name)) {
                            attribute.setNameFormat(value);
                        }
                    }
                    break;
                case AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME:
                    if (attribute != null) {
                        attribute.addValue(xmlStreamReader.getElementText());
                    }
                    break;
                case Issuer.DEFAULT_ELEMENT_LOCAL_NAME:
                    issuer = xmlStreamReader.getElementText();
                    break;
                case Conditions.DEFAULT_ELEMENT_LOCAL_NAME:
                    attrs = xmlStreamReader.getAttributeCount();
                    for (int i = 0; i < attrs; i++) {
                        String name = xmlStreamReader.getAttributeLocalName(i);
                        String value = xmlStreamReader.getAttributeValue(i);
                        if (Conditions.NOT_BEFORE_ATTRIB_NAME.equals(name)) {
                            notBefore = DatatypeConverter.parseDateTime(value).getTime();
                        } else if (Conditions.NOT_ON_OR_AFTER_ATTRIB_NAME.equals(name)) {
                            notOnOrAfter = DatatypeConverter.parseDateTime(value).getTime();
                        }
                    }
                    break;
                case SubjectConfirmation.DEFAULT_ELEMENT_LOCAL_NAME:
                    attrs = xmlStreamReader.getAttributeCount();
                    for (int i = 0; i < attrs; i++) {
                        String name = xmlStreamReader.getAttributeLocalName(i);
                        String value = xmlStreamReader.getAttributeValue(i);
                        if (SubjectConfirmation.METHOD_ATTRIB_NAME.equals(name)) {
                            subjectConfirmations.add(value);
                        }
                    }
                    break;
                case Assertion.DEFAULT_ELEMENT_LOCAL_NAME:
                    attrs = xmlStreamReader.getAttributeCount();
                    for (int i = 0; i < attrs; i++) {
                        String name = xmlStreamReader.getAttributeLocalName(i);
                        String value = xmlStreamReader.getAttributeValue(i);
                        if (Assertion.VERSION_ATTRIB_NAME.equals(name)) {
                            if ("2.0".equals(value)) {
                                tokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0";
                            } else if ("1.1".equals(value)) {
                                tokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1";
                            }
                        }
                    }
                }
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                String localName = xmlStreamReader.getLocalName();
                switch (localName) {
                case org.opensaml.saml.saml2.core.AttributeStatement.DEFAULT_ELEMENT_LOCAL_NAME:
                    attributeStatement = null;
                    break;
                case org.opensaml.saml.saml2.core.Attribute.DEFAULT_ELEMENT_LOCAL_NAME:
                    attribute = null;
                    break;
                default:
                    break;
                }
                break;
            }
            }
        }
    } catch (XMLStreamException e) {
        LOGGER.info("Unable to parse security token.", e);
    } finally {
        try {
            xmlStreamReader.close();
        } catch (XMLStreamException ignore) {
            // ignore
        }
    }
}

From source file:de.fraunhofer.iosb.ilt.sta.model.ext.TimeInstant.java

License:Open Source License

public static TimeInstant parse(String value) {
    return new TimeInstant(DateTime.parse(value));
}

From source file:de.fraunhofer.iosb.ilt.sta.query.expression.constant.DateTimeConstant.java

License:Open Source License

public DateTimeConstant(String value) {
    if (value.lastIndexOf('-') <= 0) {
        // We do not want simple integers be interpreted as a year.
        throw new IllegalArgumentException("Not a date: " + value);
    }//  w w  w  .  j a v a  2s.  c o  m
    this.value = DateTime.parse(value);
}