Skip to content

Commit 5da795e

Browse files
committed
Merge branch 'master' of https://github.com/NuGet/json-ld.net
2 parents 87ebeff + 143cbf3 commit 5da795e

23 files changed

+553
-194
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{F119722F-5E6A-4479-A4CF-0CE00FF29737}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>JsonLD.Portable</RootNamespace>
12+
<AssemblyName>JsonLD.Portable</AssemblyName>
13+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<TargetFrameworkProfile>Profile78</TargetFrameworkProfile>
15+
<FileAlignment>512</FileAlignment>
16+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
17+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
18+
<RestorePackages>true</RestorePackages>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>TRACE;DEBUG;PORTABLE</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE;PORTABLE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Compile Include="..\src\JsonLD\Core\Context.cs">
39+
<Link>Context.cs</Link>
40+
</Compile>
41+
<Compile Include="..\src\JsonLD\Core\DocumentLoader.cs">
42+
<Link>DocumentLoader.cs</Link>
43+
</Compile>
44+
<Compile Include="..\src\JsonLD\Core\IJSONLDTripleCallback.cs">
45+
<Link>IJSONLDTripleCallback.cs</Link>
46+
</Compile>
47+
<Compile Include="..\src\JsonLD\Core\IRDFParser.cs">
48+
<Link>IRDFParser.cs</Link>
49+
</Compile>
50+
<Compile Include="..\src\JsonLD\Core\JsonLdApi.cs">
51+
<Link>JsonLdApi.cs</Link>
52+
</Compile>
53+
<Compile Include="..\src\JsonLD\Core\JSONLDConsts.cs">
54+
<Link>JSONLDConsts.cs</Link>
55+
</Compile>
56+
<Compile Include="..\src\JsonLD\Core\JsonLdError.cs">
57+
<Link>JsonLdError.cs</Link>
58+
</Compile>
59+
<Compile Include="..\src\JsonLD\Core\JsonLdOptions.cs">
60+
<Link>JsonLdOptions.cs</Link>
61+
</Compile>
62+
<Compile Include="..\src\JsonLD\Core\JsonLdProcessor.cs">
63+
<Link>JsonLdProcessor.cs</Link>
64+
</Compile>
65+
<Compile Include="..\src\JsonLD\Core\JsonLdUtils.cs">
66+
<Link>JsonLdUtils.cs</Link>
67+
</Compile>
68+
<Compile Include="..\src\JsonLD\Core\NormalizeUtils.cs">
69+
<Link>NormalizeUtils.cs</Link>
70+
</Compile>
71+
<Compile Include="..\src\JsonLD\Core\RDFDataset.cs">
72+
<Link>RDFDataset.cs</Link>
73+
</Compile>
74+
<Compile Include="..\src\JsonLD\Core\RDFDatasetUtils.cs">
75+
<Link>RDFDatasetUtils.cs</Link>
76+
</Compile>
77+
<Compile Include="..\src\JsonLD\Core\Regex.cs">
78+
<Link>Regex.cs</Link>
79+
</Compile>
80+
<Compile Include="..\src\JsonLD\Core\RemoteDocument.cs">
81+
<Link>RemoteDocument.cs</Link>
82+
</Compile>
83+
<Compile Include="..\src\JsonLD\Core\UniqueNamer.cs">
84+
<Link>UniqueNamer.cs</Link>
85+
</Compile>
86+
<Compile Include="..\src\JsonLD\Impl\NQuadRDFParser.cs">
87+
<Link>NQuadRDFParser.cs</Link>
88+
</Compile>
89+
<Compile Include="..\src\JsonLD\Impl\NQuadTripleCallback.cs">
90+
<Link>NQuadTripleCallback.cs</Link>
91+
</Compile>
92+
<Compile Include="..\src\JsonLD\Impl\TurtleRDFParser.cs">
93+
<Link>TurtleRDFParser.cs</Link>
94+
</Compile>
95+
<Compile Include="..\src\JsonLD\Impl\TurtleTripleCallback.cs">
96+
<Link>TurtleTripleCallback.cs</Link>
97+
</Compile>
98+
<Compile Include="..\src\JsonLD\Util\JavaCompat.cs">
99+
<Link>JavaCompat.cs</Link>
100+
</Compile>
101+
<Compile Include="..\src\JsonLD\Util\JSONUtils.cs">
102+
<Link>JSONUtils.cs</Link>
103+
</Compile>
104+
<Compile Include="..\src\JsonLD\Util\Obj.cs">
105+
<Link>Obj.cs</Link>
106+
</Compile>
107+
<Compile Include="..\src\JsonLD\Util\URL.cs">
108+
<Link>URL.cs</Link>
109+
</Compile>
110+
<Compile Include="Properties\AssemblyInfo.cs" />
111+
</ItemGroup>
112+
<ItemGroup>
113+
<Reference Include="Newtonsoft.Json">
114+
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\portable-net45+wp80+win8\Newtonsoft.Json.dll</HintPath>
115+
</Reference>
116+
</ItemGroup>
117+
<ItemGroup>
118+
<None Include="packages.config" />
119+
</ItemGroup>
120+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
121+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
122+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
123+
<PropertyGroup>
124+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
125+
</PropertyGroup>
126+
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
127+
</Target>
128+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
129+
Other similar extension points exist, see Microsoft.Common.targets.
130+
<Target Name="BeforeBuild">
131+
</Target>
132+
<Target Name="AfterBuild">
133+
</Target>
134+
-->
135+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Resources;
2+
using System.Reflection;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
6+
// General Information about an assembly is controlled through the following
7+
// set of attributes. Change these attribute values to modify the information
8+
// associated with an assembly.
9+
[assembly: AssemblyTitle("JsonLD.Portable")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("JsonLD.Portable")]
14+
[assembly: AssemblyCopyright("Copyright © 2014")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
[assembly: NeutralResourcesLanguage("en")]
18+
19+
// Version information for an assembly consists of the following four values:
20+
//
21+
// Major Version
22+
// Minor Version
23+
// Build Number
24+
// Revision
25+
//
26+
// You can specify all the values or you can default the Build and Revision Numbers
27+
// by using the '*' as shown below:
28+
// [assembly: AssemblyVersion("1.0.*")]
29+
[assembly: AssemblyVersion("1.0.0.0")]
30+
[assembly: AssemblyFileVersion("1.0.0.0")]

JsonLD.Portable/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="portable-net45+wp80+win+MonoAndroid10+MonoTouch10" />
4+
</packages>

JsonLD.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{BADA6F
1414
EndProject
1515
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonLD.Test", "tests\JsonLD.Test\JsonLD.Test.csproj", "{D41C622A-4470-4BE1-AB20-D9862B628840}"
1616
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonLD.Portable", "JsonLD.Portable\JsonLD.Portable.csproj", "{F119722F-5E6A-4479-A4CF-0CE00FF29737}"
18+
EndProject
1719
Global
1820
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1921
Debug|Any CPU = Debug|Any CPU
@@ -28,6 +30,10 @@ Global
2830
{D41C622A-4470-4BE1-AB20-D9862B628840}.Debug|Any CPU.Build.0 = Debug|Any CPU
2931
{D41C622A-4470-4BE1-AB20-D9862B628840}.Release|Any CPU.ActiveCfg = Release|Any CPU
3032
{D41C622A-4470-4BE1-AB20-D9862B628840}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{F119722F-5E6A-4479-A4CF-0CE00FF29737}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{F119722F-5E6A-4479-A4CF-0CE00FF29737}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{F119722F-5E6A-4479-A4CF-0CE00FF29737}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{F119722F-5E6A-4479-A4CF-0CE00FF29737}.Release|Any CPU.Build.0 = Release|Any CPU
3137
EndGlobalSection
3238
GlobalSection(SolutionProperties) = preSolution
3339
HideSolutionNode = FALSE

src/JsonLD/Core/Context.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ namespace JsonLD.Core
1313
/// </summary>
1414
/// <author>tristan</author>
1515
//[System.Serializable]
16-
public class Context : JObject, ICloneable
16+
public class Context : JObject
17+
#if !PORTABLE
18+
, ICloneable
19+
#endif
1720
{
1821
private JsonLdOptions options;
1922

@@ -180,7 +183,20 @@ public virtual JsonLD.Core.Context Parse(JToken localContext, List<string> remot
180183
}
181184
remoteContexts.Add(uri);
182185
// 3.2.3: Dereference context
183-
RemoteDocument rd = this.options.documentLoader.LoadDocument(uri);
186+
RemoteDocument rd;
187+
try
188+
{
189+
rd = this.options.documentLoader.LoadDocument(uri);
190+
}
191+
catch (JsonLdError err)
192+
{
193+
if (err.Message.StartsWith(JsonLdError.Error.LoadingDocumentFailed.ToString()))
194+
{
195+
throw new JsonLdError(JsonLdError.Error.LoadingRemoteContextFailed);
196+
}
197+
else
198+
throw;
199+
}
184200
JToken remoteContext = rd.document;
185201
if (!(remoteContext is JObject) || !((JObject)remoteContext
186202
).ContainsKey("@context"))

src/JsonLD/Core/DocumentLoader.cs

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using System;
22
using System.Collections;
33
using System.IO;
4+
using System.Linq;
45
using JsonLD.Core;
56
using JsonLD.Util;
7+
using System.Net;
8+
using System.Collections.Generic;
69

710
namespace JsonLD.Core
811
{
@@ -11,21 +14,59 @@ public class DocumentLoader
1114
/// <exception cref="JsonLDNet.Core.JsonLdError"></exception>
1215
public virtual RemoteDocument LoadDocument(string url)
1316
{
17+
#if !PORTABLE
1418
RemoteDocument doc = new RemoteDocument(url, null);
1519
try
1620
{
17-
doc.Document = JSONUtils.FromURL(new Uri(url));
21+
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
22+
req.Accept = AcceptHeader;
23+
WebResponse resp = req.GetResponse();
24+
bool isJsonld = resp.Headers[HttpResponseHeader.ContentType] == "application/ld+json";
25+
if (!resp.Headers[HttpResponseHeader.ContentType].Contains("json"))
26+
{
27+
throw new JsonLdError(JsonLdError.Error.LoadingDocumentFailed, url);
28+
}
29+
30+
string[] linkHeaders = resp.Headers.GetValues("Link");
31+
if (!isJsonld && linkHeaders != null)
32+
{
33+
linkHeaders = linkHeaders.SelectMany((h) => h.Split(",".ToCharArray()))
34+
.Select(h => h.Trim()).ToArray();
35+
IEnumerable<string> linkedContexts = linkHeaders.Where(v => v.EndsWith("rel=\"http://www.w3.org/ns/json-ld#context\""));
36+
if (linkedContexts.Count() > 1)
37+
{
38+
throw new JsonLdError(JsonLdError.Error.MultipleContextLinkHeaders);
39+
}
40+
string header = linkedContexts.First();
41+
string linkedUrl = header.Substring(1, header.IndexOf(">") - 1);
42+
string resolvedUrl = URL.Resolve(url, linkedUrl);
43+
var remoteContext = this.LoadDocument(resolvedUrl);
44+
doc.contextUrl = remoteContext.documentUrl;
45+
doc.context = remoteContext.document;
46+
}
47+
48+
Stream stream = resp.GetResponseStream();
49+
50+
doc.DocumentUrl = req.Address.ToString();
51+
doc.Document = JSONUtils.FromInputStream(stream);
52+
}
53+
catch (JsonLdError)
54+
{
55+
throw;
1856
}
1957
catch (Exception)
2058
{
21-
throw new JsonLdError(JsonLdError.Error.LoadingRemoteContextFailed, url);
59+
throw new JsonLdError(JsonLdError.Error.LoadingDocumentFailed, url);
2260
}
2361
return doc;
62+
#else
63+
throw new NotImplementedException();
64+
#endif
2465
}
2566

26-
// /// <summary>An HTTP Accept header that prefers JSONLD.</summary>
27-
// /// <remarks>An HTTP Accept header that prefers JSONLD.</remarks>
28-
// public const string AcceptHeader = "application/ld+json, application/json;q=0.9, application/javascript;q=0.5, text/javascript;q=0.5, text/plain;q=0.2, */*;q=0.1";
67+
/// <summary>An HTTP Accept header that prefers JSONLD.</summary>
68+
/// <remarks>An HTTP Accept header that prefers JSONLD.</remarks>
69+
public const string AcceptHeader = "application/ld+json, application/json;q=0.9, application/javascript;q=0.5, text/javascript;q=0.5, text/plain;q=0.2, */*;q=0.1";
2970

3071
// private static volatile IHttpClient httpClient;
3172

src/JsonLD/Core/IJSONLDTripleCallback.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public interface IJSONLDTripleCallback
3636
/// used).
3737
/// </param>
3838
/// <returns>the resulting RDF object in the desired format</returns>
39-
JToken Call(RDFDataset dataset);
39+
object Call(RDFDataset dataset);
4040
}
4141
}

0 commit comments

Comments
 (0)