Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1009F200B92 for ; Wed, 28 Sep 2016 15:52:04 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0ECCA160ADD; Wed, 28 Sep 2016 13:52:04 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4E74A160AC1 for ; Wed, 28 Sep 2016 15:52:03 +0200 (CEST) Received: (qmail 40373 invoked by uid 500); 28 Sep 2016 13:52:02 -0000 Mailing-List: contact commits-help@commonsrdf.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commonsrdf.incubator.apache.org Delivered-To: mailing list commits@commonsrdf.incubator.apache.org Received: (qmail 40328 invoked by uid 99); 28 Sep 2016 13:52:02 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Sep 2016 13:52:02 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id EFDD018050F for ; Wed, 28 Sep 2016 13:52:01 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id QDCx_C3xAZiZ for ; Wed, 28 Sep 2016 13:51:57 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id BE9A95FB81 for ; Wed, 28 Sep 2016 13:51:54 +0000 (UTC) Received: (qmail 38468 invoked by uid 99); 28 Sep 2016 13:51:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Sep 2016 13:51:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A93C1EEE26; Wed, 28 Sep 2016 13:51:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stain@apache.org To: commits@commonsrdf.incubator.apache.org Date: Wed, 28 Sep 2016 13:52:02 -0000 Message-Id: <7d0f3652f14944a7845f0c911e443721@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [10/36] incubator-commonsrdf git commit: Add guessRDFSyntax() convenience method archived-at: Wed, 28 Sep 2016 13:52:04 -0000 Add guessRDFSyntax() convenience method Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/478b20e2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/478b20e2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/478b20e2 Branch: refs/heads/master Commit: 478b20e27b2e24494d20d6edbf7a80c3604a7879 Parents: 8dfc3f4 Author: Stian Soiland-Reyes Authored: Sun Apr 3 00:53:48 2016 +0100 Committer: Stian Soiland-Reyes Committed: Sun Apr 3 01:07:39 2016 +0100 ---------------------------------------------------------------------- .../rdf/simple/AbstractRDFParserBuilder.java | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/478b20e2/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilder.java ---------------------------------------------------------------------- diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilder.java b/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilder.java index 925a365..b31251d 100644 --- a/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilder.java +++ b/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilder.java @@ -361,10 +361,51 @@ public abstract class AbstractRDFParserBuilder implements RDFParserBuilder, Clon URI baseUri = c.sourceFile.get().toRealPath().toUri(); c.base = Optional.of(internalRdfTermFactory.createIRI(baseUri.toString())); } + return c; } /** + * Guess RDFSyntax from a local file's extension. + *

+ * This method can be used by subclasses if {@link #getContentType()} is not + * present and {@link #getSourceFile()} is set. + * + * @param path Path which extension should be checked + * @return The {@link RDFSyntax} which has a matching {@link RDFSyntax#fileExtension}, + * otherwise {@link Optional#empty()}. + */ + protected static Optional guessRDFSyntax(Path path) { + return fileExtension(path).flatMap(RDFSyntax::byFileExtension); + } + + /** + * Return the file extension of a Path - if any. + *

+ * The returned file extension includes the leading . + *

+ * Note that this only returns the last extension, e.g. the + * file extension for archive.tar.gz would be .gz + * + * @param path Path which filename might contain an extension + * @return File extension (including the leading ., + * or {@link Optional#empty()} if the path has no extension + */ + private static Optional fileExtension(Path path) { + Path fileName = path.getFileName(); + if (fileName == null) { + return Optional.empty(); + } + String filenameStr = fileName.toString(); + int last = filenameStr.lastIndexOf("."); + if (last > -1) { + return Optional.of(filenameStr.substring(last)); + } + return Optional.empty(); + } + + + /** * Create a new {@link RDFTermFactory} for a parse session. *

* This is called by {@link #parse()} to set