Package org.jwat.common

Examples of org.jwat.common.Uri


            e.printStackTrace();
            Assert.fail("Unexpected exception!");
        }

        String uriStr = "urn:uuid:a1bc4f20-d057-44bd-a299-bdf31f4dfa53";
        Uri uriObj = Uri.create(uriStr);

        /*
         * Non warc headers.
         */

        header = getTestHeader();
        headerLine = header.addHeader("X-Header1", dateObj, dateStr);
        Assert.assertNotNull(headerLine);
        Assert.assertEquals("X-Header1", headerLine.name);
        Assert.assertEquals(dateStr, headerLine.value);
        headerLine = header.addHeader("X-Header2", dateObj, dateStr);
        Assert.assertNotNull(headerLine);
        Assert.assertEquals("X-Header2", headerLine.name);
        Assert.assertEquals(dateStr, headerLine.value);

        /*
         * Duplicate date headers.
         */

        header = getTestHeader();
        headerLine = header.addHeader("WARC-Date", dateObj, dateStr);
        Assert.assertNotNull(headerLine);
        Assert.assertEquals("WARC-Date", headerLine.name);
        Assert.assertEquals(dateStr, headerLine.value);
        errors = header.diagnostics.getErrors();
        warnings = header.diagnostics.getWarnings();
        Assert.assertEquals(0, errors.size());
        Assert.assertEquals(0, warnings.size());
        headerLine = header.addHeader("WARC-Date", dateObj, dateStr);
        Assert.assertNotNull(headerLine);
        Assert.assertEquals("WARC-Date", headerLine.name);
        Assert.assertEquals(dateStr, headerLine.value);
        errors = header.diagnostics.getErrors();
        warnings = header.diagnostics.getWarnings();
        Assert.assertEquals(1, errors.size());
        Assert.assertEquals(0, warnings.size());
        diagnosis = errors.get(0);
        Assert.assertEquals(DiagnosisType.DUPLICATE, diagnosis.type);
        Assert.assertEquals("'WARC-Date' header", diagnosis.entity);
        Assert.assertEquals(1, diagnosis.information.length);

        /*
         * Integer add header.
         */

        cases = generate_invalid_datatype_cases(integerObj, integerStr, WarcConstants.FN_WARC_SEGMENT_NUMBER, WarcConstants.FN_WARC_RECORD_ID);
        test_headeradd_object_cases(cases, WarcConstants.FDT_INTEGER);

        /*
         * Long add header.
         */

        cases = generate_invalid_datatype_cases(longObj, longStr, WarcConstants.FN_CONTENT_LENGTH, WarcConstants.FN_CONTENT_TYPE);
        test_headeradd_object_cases(cases, WarcConstants.FDT_LONG);

        /*
         * Digest add header.
         */

        cases = generate_invalid_datatype_cases(digestObj, digestStr, WarcConstants.FN_WARC_BLOCK_DIGEST, WarcConstants.FN_WARC_SEGMENT_NUMBER);
        test_headeradd_object_cases(cases, WarcConstants.FDT_DIGEST);

        /*
         * ContentType add header.
         */

        cases = generate_invalid_datatype_cases(contentTypeObj, contentTypeStr, WarcConstants.FN_CONTENT_TYPE, WarcConstants.FN_WARC_BLOCK_DIGEST);
        test_headeradd_object_cases(cases, WarcConstants.FDT_CONTENTTYPE);

        /*
         * Date add header.
         */

        cases = generate_invalid_datatype_cases(dateObj, dateStr, WarcConstants.FN_WARC_DATE, WarcConstants.FN_CONTENT_TYPE);
        test_headeradd_object_cases(cases, WarcConstants.FDT_DATE);

        /*
         * InetAddress add header.
         */

        cases = generate_invalid_datatype_cases(inetAddressObj, inetAddressStr, WarcConstants.FN_WARC_IP_ADDRESS, WarcConstants.FN_WARC_DATE);
        test_headeradd_object_cases(cases, WarcConstants.FDT_INETADDRESS);

        /*
         * URI add header.
         */

        cases = generate_invalid_datatype_cases(uriObj, "<" + uriStr + ">", WarcConstants.FN_WARC_RECORD_ID, WarcConstants.FN_WARC_IP_ADDRESS);
        test_headeradd_object_cases(cases, WarcConstants.FDT_URI);

        /*
         * Test datatype for headers.
         */

        /*
        WarcConstants.FN_WARC_TYPE
        WarcConstants.FN_WARC_TRUNCATED
        WarcConstants.FN_WARC_FILENAME
        WarcConstants.FN_WARC_PROFILE
        */

        /*
         * Integer.
         */

        String segmentNrStr = "42";
        Integer segmentNrObj = Integer.parseInt(segmentNrStr);
        cases = generate_header_datatype_cases(segmentNrObj, segmentNrStr, WarcConstants.FN_WARC_SEGMENT_NUMBER, "warcSegmentNumberStr", "warcSegmentNumber");
        test_headeradd_object_cases(cases, WarcConstants.FDT_INTEGER);

        /*
         * Long.
         */

        String contentLengthStr = "1234567890123456";
        Long contentLengthObj = Long.parseLong(contentLengthStr);
        cases = generate_header_datatype_cases(contentLengthObj, contentLengthStr, WarcConstants.FN_CONTENT_LENGTH, "contentLengthStr", "contentLength");
        test_headeradd_object_cases(cases, WarcConstants.FDT_LONG);

        String segmentTotalLengthStr = "9876543210987654";
        Long segmentTotalLengthObj = Long.parseLong(segmentTotalLengthStr);
        cases = generate_header_datatype_cases(segmentTotalLengthObj, segmentTotalLengthStr, WarcConstants.FN_WARC_SEGMENT_TOTAL_LENGTH, "warcSegmentTotalLengthStr", "warcSegmentTotalLength");
        test_headeradd_object_cases(cases, WarcConstants.FDT_LONG);

        /*
         * Digest.
         */

        String blockDigestStr = "sha1:Y4N5SWNQBIBIGQ66IFXDMLGJW6FZFV6U";
        WarcDigest blockDigestObj = WarcDigest.parseWarcDigest(blockDigestStr);
        cases = generate_header_datatype_cases(blockDigestObj, blockDigestStr, WarcConstants.FN_WARC_BLOCK_DIGEST, "warcBlockDigestStr", "warcBlockDigest");
        test_headeradd_object_cases(cases, WarcConstants.FDT_DIGEST);

        String payloadDigestStr = "sha1:BCCYP7NW6QIIOSM523Y5XHQKE5KWLMBD";
        WarcDigest payloadDigestObj = WarcDigest.parseWarcDigest(payloadDigestStr);
        cases = generate_header_datatype_cases(payloadDigestObj, payloadDigestStr, WarcConstants.FN_WARC_PAYLOAD_DIGEST, "warcPayloadDigestStr", "warcPayloadDigest");
        test_headeradd_object_cases(cases, WarcConstants.FDT_DIGEST);

        /*
         * ContentType.
         */

        contentTypeStr = "application/http; msgtype=request";
        contentTypeObj = ContentType.parseContentType(contentTypeStr);
        cases = generate_header_datatype_cases(contentTypeObj, contentTypeStr, WarcConstants.FN_CONTENT_TYPE, "contentTypeStr", "contentType");
        test_headeradd_object_cases(cases, WarcConstants.FDT_CONTENTTYPE);

        String identifiedPayloadTypeStr = "application/http; msgtype=response";
        ContentType identifiedPayloadTypeObj = ContentType.parseContentType(identifiedPayloadTypeStr);
        cases = generate_header_datatype_cases(identifiedPayloadTypeObj, identifiedPayloadTypeStr, WarcConstants.FN_WARC_IDENTIFIED_PAYLOAD_TYPE, "warcIdentifiedPayloadTypeStr", "warcIdentifiedPayloadType");
        test_headeradd_object_cases(cases, WarcConstants.FDT_CONTENTTYPE);

        /*
         * Date.
         */

        dateStr = "2010-06-23T13:33:21Z";
        dateObj = WarcDateParser.getDate(dateStr);
        cases = generate_header_datatype_cases(dateObj, dateStr, WarcConstants.FN_WARC_DATE, "warcDateStr", "warcDate");
        test_headeradd_object_cases(cases, WarcConstants.FDT_DATE);

        String refersToDateStr = "2010-06-23T13:33:21Z";
        Date refersToDateObj = WarcDateParser.getDate(refersToDateStr);
        cases = generate_header_datatype_cases(refersToDateObj, refersToDateStr, WarcConstants.FN_WARC_REFERS_TO_DATE, "warcRefersToDateStr", "warcRefersToDate");
        test_headeradd_object_cases(cases, WarcConstants.FDT_DATE);

        /*
         * InetAddress.
         */

        inetAddressStr = "174.36.20.141";
        inetAddressObj = null;
        try {
            inetAddressObj = InetAddress.getByName(inetAddressStr);
        } catch (UnknownHostException e) {
            e.printStackTrace();
            Assert.fail("Unexpected exception!");
        }
        cases = generate_header_datatype_cases(inetAddressObj, inetAddressStr, WarcConstants.FN_WARC_IP_ADDRESS, "warcIpAddress", "warcInetAddress");
        test_headeradd_object_cases(cases, WarcConstants.FDT_INETADDRESS);

        /*
         * URI.
         */

        String recordIdStr = "urn:uuid:12eab1ec-8615-4f09-b6d2-976d96552073";
        Uri recordIdObj = Uri.create(recordIdStr);
        cases = generate_header_datatype_cases(recordIdObj, "<" + recordIdStr + ">", WarcConstants.FN_WARC_RECORD_ID, "warcRecordIdStr", "warcRecordIdUri");
        test_headeradd_object_cases(cases, WarcConstants.FDT_URI);

        String refersToStr = "urn:uuid:bfa9d26b-ff19-402a-8508-e7ff852d4ded";
        Uri refersToObj = Uri.create(refersToStr);
        cases = generate_header_datatype_cases(refersToObj, "<" + refersToStr + ">", WarcConstants.FN_WARC_REFERS_TO, "warcRefersToStr", "warcRefersToUri");
        test_headeradd_object_cases(cases, WarcConstants.FDT_URI);

        String targetUriStr = "urn:uuid:de715d47-9f36-4cdf-84db-eb3b47dcd0e3";
        Uri targetUriObj = Uri.create(targetUriStr);
        cases = generate_header_datatype_cases(targetUriObj, targetUriStr, WarcConstants.FN_WARC_TARGET_URI, "warcTargetUriStr", "warcTargetUriUri");
        test_headeradd_object_cases(cases, WarcConstants.FDT_URI);

        String warcinfoIdStr = "urn:uuid:1cb0e3be-d9e2-4058-bf00-9775c75a71a6";
        Uri warcinfoIdObj = Uri.create(warcinfoIdStr);
        cases = generate_header_datatype_cases(warcinfoIdObj, "<" + warcinfoIdStr + ">", WarcConstants.FN_WARC_WARCINFO_ID, "warcWarcinfoIdStr", "warcWarcinfoIdUri");
        test_headeradd_object_cases(cases, WarcConstants.FDT_URI);

        String segmentOriginIdStr = "urn:uuid:c4fc410a-4c7b-4bcc-a251-382b1d669f9a";
        Uri segmentOriginIdObj = Uri.create(segmentOriginIdStr);
        cases = generate_header_datatype_cases(segmentOriginIdObj, "<" + segmentOriginIdStr + ">", WarcConstants.FN_WARC_SEGMENT_ORIGIN_ID, "warcSegmentOriginIdStr", "warcSegmentOriginIdUrl");
        test_headeradd_object_cases(cases, WarcConstants.FDT_URI);

        Object[][] concurrentHeaders = new Object[][] {
                {Uri.create("urn:uuid:173a3db1-9ba4-496e-9eaf-6e550a62fd88"), "<urn:uuid:173a3db1-9ba4-496e-9eaf-6e550a62fd88>"},
                {Uri.create("urn:uuid:660b74e7-076e-4698-abba-4eeeb8e09bf1"), "<urn:uuid:660b74e7-076e-4698-abba-4eeeb8e09bf1>"},
                {Uri.create("urn:uuid:e6c0d888-b384-4ef4-a698-6166bc0875b8"), "<urn:uuid:e6c0d888-b384-4ef4-a698-6166bc0875b8>"}
        };
        cases = generate_multivalue_cases(concurrentHeaders, WarcConstants.FN_WARC_CONCURRENT_TO, "warcConcurrentToList");
        test_headeradd_multivalue_object_cases(cases, WarcConstants.FDT_URI);

        String warcProfileStr = WarcConstants.PROFILE_IDENTICAL_PAYLOAD_DIGEST;
        Uri warcProfileObj = Uri.create(warcProfileStr);
        cases = generate_header_datatype_cases(warcProfileObj, warcProfileStr, WarcConstants.FN_WARC_PROFILE, "warcProfileStr", "warcProfileUri");
        test_headeradd_object_cases(cases, WarcConstants.FDT_URI);

        warcProfileStr = "urn:uuid:de715d47-9f36-4cdf-84db-eb3b47dcd0e3";
        warcProfileObj = Uri.create(warcProfileStr);
        cases = generate_header_datatype_cases(warcProfileObj, warcProfileStr, WarcConstants.FN_WARC_PROFILE, "warcProfileStr", "warcProfileUri");
        test_headeradd_object_cases(cases, WarcConstants.FDT_URI);

        String warcRefersToTargetUriStr = "urn:uuid:de715d47-9f36-4cdf-84db-eb3b47dcd0e3";
        Uri warcRefersToTargetUriObj = Uri.create(warcRefersToTargetUriStr);
        cases = generate_header_datatype_cases(warcRefersToTargetUriObj, warcRefersToTargetUriStr, WarcConstants.FN_WARC_REFERS_TO_TARGET_URI, "warcRefersToTargetUriStr", "warcRefersToTargetUriUri");
        test_headeradd_object_cases(cases, WarcConstants.FDT_URI);

        /*
        public List<WarcConcurrentTo> warcConcurrentToList = new LinkedList<WarcConcurrentTo>();
View Full Code Here


        }
        /*
         * URI.
         */
        String recordIdStr = "urn:uuid:12eab1ec-8615-4f09-b6d2-976d96552073";
        Uri recordIdObj = Uri.create(recordIdStr);
        String refersToStr = "urn:uuid:bfa9d26b-ff19-402a-8508-e7ff852d4ded";
        Uri refersToObj = Uri.create(refersToStr);
        String targetUriStr = "urn:uuid:de715d47-9f36-4cdf-84db-eb3b47dcd0e3";
        Uri targetUriObj = Uri.create(targetUriStr);
        String warcinfoIdStr = "urn:uuid:1cb0e3be-d9e2-4058-bf00-9775c75a71a6";
        Uri warcinfoIdObj = Uri.create(warcinfoIdStr);
        String segmentOriginIdStr = "urn:uuid:c4fc410a-4c7b-4bcc-a251-382b1d669f9a";
        Uri segmentOriginIdObj = Uri.create(segmentOriginIdStr);
        String refersToTargetUriStr = "urn:uuid:9c0433e9-7365-4228-a4b6-501d3c1ebc50";
        Uri refersToTargetUriObj = Uri.create(refersToTargetUriStr);
        /*
         * ConcurrentTo.
         */
        Object[][] concurrentHeaders = new Object[][] {
                {Uri.create("urn:uuid:173a3db1-9ba4-496e-9eaf-6e550a62fd88"), "urn:uuid:173a3db1-9ba4-496e-9eaf-6e550a62fd88"},
View Full Code Here

     * @param nullable allow empty or null value
     * @return an URL object holding the value of the specified string or null,
     * if unable to parse the value as an URL object
     */
    protected Uri parseUri(String uriStr, UriProfile uriProfile, String field, boolean nullable) {
        Uri uri = null;
        if ((uriStr != null) && (uriStr.length() != 0)) {
            try {
                uri = new Uri(uriStr, uriProfile);
            } catch (Exception e) {
                // Invalid URI.
                addInvalidExpectedError("'" + field + "' value",
                        uriStr,
                        e.getMessage());
            }
            if (uri != null) {
                String scheme = uri.getScheme();
                if (scheme == null) {
                    uri = null;
                    // Relative URI.
                    addInvalidExpectedError("'" + field + "' value",
                            uriStr,
View Full Code Here

     * @param bLtGt something
     * @return an URI object holding the value of the specified string or null,
     * if unable to parse the value as an URI object
     */
    protected Uri parseUri(String uriStr, boolean bLtGt, UriProfile uriProfile, String field) {
        Uri uri = null;
        String uriStrClean = uriStr;
        int ltGtBf = 0;
        if (uriStrClean != null && uriStrClean.length() != 0) {
            int fIdx = 0;
            int tIdx = uriStrClean.length();
            if (uriStrClean.startsWith("<")) {
                ltGtBf |= 2;
                ++fIdx;
            }
            if (uriStrClean.endsWith(">")) {
                ltGtBf |= 1;
                --tIdx;
            }
            if (ltGtBf != 0) {
                uriStrClean = uriStrClean.substring(fIdx, tIdx);
            }
            if (bLtGt) {
                switch (ltGtBf) {
                case 2:
                    addInvalidExpectedError("'" + field + "' value", uriStr, "Missing trailing '>' character");
                    break;
                case 1:
                    addInvalidExpectedError("'" + field + "' value", uriStr, "Missing leading '<' character");
                    break;
                case 0:
                    addInvalidExpectedError("'" + field + "' value", uriStr, "Missing encapsulating '<' and '>' characters");
                    break;
                case 3:
                default:
                    break;
                }
            } else {
                switch (ltGtBf) {
                case 2:
                    addInvalidExpectedError("'" + field + "' value", uriStr, "Unexpected leading '<' character");
                    break;
                case 1:
                    addInvalidExpectedError("'" + field + "' value", uriStr, "Unexpected trailing '>' character");
                    break;
                case 3:
                    addInvalidExpectedError("'" + field + "' value", uriStr, "Unexpected encapsulating '<' and '>' characters");
                    break;
                case 0:
                default:
                    break;
                }
            }
            try {
                uri = new Uri(uriStrClean, uriProfile);
            } catch (Exception e) {
                // Invalid URI.
                addInvalidExpectedError("'" + field + "' value",
                        uriStrClean,
                        e.getMessage());
            }
            if (uri != null) {
                String scheme = uri.getScheme();
                if (scheme == null) {
                    uri = null;
                    // Relative URI.
                    addInvalidExpectedError("'" + field + "' value",
                            uriStrClean,
View Full Code Here

                    contentTypeStr = fieldValue;
                    contentType = fieldParsers.parseContentType(fieldValue,
                            WarcConstants.FN_CONTENT_TYPE);
                    break;
                case WarcConstants.FN_IDX_WARC_CONCURRENT_TO:
                    Uri tmpUri = fieldParsers.parseUri(fieldValue, URI_LTGT,
                            uriProfile, WarcConstants.FN_WARC_CONCURRENT_TO);
                    if (fieldValue != null && fieldValue.trim().length() > 0) {
                        warcConcurrentTo = new WarcConcurrentTo();
                        warcConcurrentTo.warcConcurrentToStr = fieldValue;
                        warcConcurrentTo.warcConcurrentToUri = tmpUri;
View Full Code Here

TOP

Related Classes of org.jwat.common.Uri

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.