<commit_before># 
#    Copyright (c) 2011 Talis Inc., Some rights reserved
# 
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
# 
#        http://www.apache.org/licenses/LICENSE-2.0
# 
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

@prefix xsd:<http://www.w3.org/2001/XMLSchema#>.
@prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>.
@prefix owl:<http://www.w3.org/2002/07/owl#>.
@prefix foaf:<http://xmlns.com/foaf/0.1/>.
@prefix msg:<http://www.openrdf.org/rdf/2011/messaging#>.
@prefix calli:<http://callimachusproject.org/rdf/2009/framework#>.
@prefix :<#>.

<> a <SchemaGraph>.

<Page> a <Creatable>, owl:Class;
    rdfs:subClassOf calli:Page, <File>;
    rdfs:label "Page";
    rdfs:comment "New pages can be created in a folder";
    owl:equivalentClass </callimachus/Page>;
    rdfs:isDefinedBy <../../ontology>;
    calli:administrator </auth/groups/admin>;
    calli:author </auth/groups/staff>,</auth/groups/admin>;
    calli:icon <../images/page.png>;
    calli:edit <../templates/page-edit.xhtml>;
    calli:create <../templates/page-create.xhtml>;
    calli:mediaType "application/xhtml+xml";
    calli:documentTag <http://www.w3.org/1999/xhtml#html>.

# GET /page/MainPage.xhtml?view
:GetPage owl:intersectionOf (<viewable.ttl#GetViewPage>
        [owl:onProperty msg:target; owl:allValuesFrom <Page>]);
    calli:rel "alternate";
    calli:method "GET";
    calli:query "view";
    calli:requires calli:reader;
    calli:type "text/html";
    calli:header "cache-control:no-cache";
    calli:post "../pipelines/page-layout-html.xpl?results&target=$0&query=view\nContent-Location: $0\nContent-Type: application/xhtml+xml".

# GET /page/MainPage.xhtml?html
:GetHtml rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.Reader>];
    calli:method "GET";
    calli:query "html";
    calli:requires calli:reader;
    calli:type "text/html";
    calli:header "cache-control:no-cache";
    calli:post "../pipelines/page-layout-html.xpl?results\nContent-Location: $0\nContent-Type: application/xhtml+xml".

# GET /page/MainPage.xhtml
:GetPageSource rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.InputStream>];
    calli:method "GET";
    calli:rel "edit-media";
    calli:requires calli:reader;
    calli:type "application/xhtml+xml";
    calli:header "cache-control:no-cache";
    calli:header "cache-control:cache-range";
    calli:script "return this.openInputStream()".

# POST ?create=/callimachus/Page
:CreatePage owl:intersectionOf (<creatable.ttl#PostCreate>
        [owl:onProperty msg:target; owl:hasValue <Page> ]);
    calli:imports <java:org.openrdf.model.vocabulary.RDFS>;
    calli:imports <java:java.net.URLDecoder>;
    calli:imports <java:org.callimachusproject.server.exceptions.BadRequest>;
    calli:imports <java:org.callimachusproject.server.exceptions.InternalServerError>;
    calli:imports <File>;
    calli:imports calli:Page;
    calli:imports foaf:Document;
    calli:script """
        var con = this.objectConnection;
        var vf = con.valueFactory;
        if (!location)
            throw new BadRequest("Missing location request header");

        if (location instanceof File) {
            location = location.RemoveFile();
        }
        var created = location;

        var filename = created.resource.localName.replace(/([a-zA-Z_0-9])\\.[a-zA-Z]+$/, "$1");
        var label = vf.createLiteral(URLDecoder.decode(filename, "UTF-8").replace(/[_\\-\\+\\s]+/g, " "));
        con.add(created.resource, RDFS.LABEL, label, []);

        created = con.addDesignation(created, this.toString());
        created = con.addDesignation(created, Page);
        created = con.addDesignation(created, Document);

        created.UploadPage(body);
        return created;
    """.

# PUT /page/MainPage.xhtml
# Called by client, copy operation, create operation, and MainPage initialization
:UploadPage rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom owl:Nothing];
    calli:method "PUT";
    calli:requires calli:editor;
    calli:imports <java:org.openrdf.model.vocabulary.RDFS>;
    calli:imports <java:java.net.URLDecoder>;
    calli:imports <java:org.callimachusproject.server.HTTPObjectServer>;
    calli:imports <java:org.callimachusproject.server.exceptions.BadRequest>;
    calli:imports <java:org.callimachusproject.server.exceptions.ServiceUnavailable>;
    calli:script """
        var read;
        var buf = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024);
        var out = this.openOutputStream();
        try {
            while ((read = xhtmlStream.read(buf)) >= 0) {
                out.write(buf, 0, read);
            }
        } finally {
            out.close();
        }
        try {
            this.ValidatePage();
        } catch (e if e.javaException instanceof ServiceUnavailable) {
            java.lang.System.err.println("Storing " + this);
        }
        this.touchRevision();
        HTTPObjectServer.resetAllCache();
    """.

:xhtmlStream a owl:ObjectProperty; a owl:FunctionalProperty;
    rdfs:domain :UploadPage;
    rdfs:range <java:java.io.InputStream>;
    calli:type "application/xhtml+xml".

:ValidatePage rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom owl:Nothing];
    calli:post "../schemas/xhtml.rng?validate\nContent-Location:$0\nContent-Type: application/xhtml+xml".

# GET /page/MainPage.xhtml?element=content/1&realm=/
:GetElement rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.Reader>];
    calli:method "GET";
    calli:query "element";
    calli:requires calli:reader;
    calli:type "text/html";
    calli:post "../pipelines/page-element.xpl?results&element={element}&realm={elementRealm}\nContent-Location: $0\nContent-Type: application/xhtml+xml".

:element a owl:FunctionalProperty, owl:DatatypeProperty;
    rdfs:domain :GetElement;
    rdfs:range xsd:string;
    calli:query "element".

:elementRealm a owl:FunctionalProperty, owl:DatatypeProperty;
    rdfs:domain :GetElement;
    rdfs:range xsd:anyURI;
    calli:type "text/uri-list";
    calli:query "realm".

# GET /page/MainPag.xhtml?layout
:GetTemplate rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.InputStream>];
    calli:method "GET";<commit_msg>Remove realm parameter from GetElement (not used anymore)<commit_after># 
#    Copyright (c) 2011 Talis Inc., Some rights reserved
# 
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
# 
#        http://www.apache.org/licenses/LICENSE-2.0
# 
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

@prefix xsd:<http://www.w3.org/2001/XMLSchema#>.
@prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>.
@prefix owl:<http://www.w3.org/2002/07/owl#>.
@prefix foaf:<http://xmlns.com/foaf/0.1/>.
@prefix msg:<http://www.openrdf.org/rdf/2011/messaging#>.
@prefix calli:<http://callimachusproject.org/rdf/2009/framework#>.
@prefix :<#>.

<> a <SchemaGraph>.

<Page> a <Creatable>, owl:Class;
    rdfs:subClassOf calli:Page, <File>;
    rdfs:label "Page";
    rdfs:comment "New pages can be created in a folder";
    owl:equivalentClass </callimachus/Page>;
    rdfs:isDefinedBy <../../ontology>;
    calli:administrator </auth/groups/admin>;
    calli:author </auth/groups/staff>,</auth/groups/admin>;
    calli:icon <../images/page.png>;
    calli:edit <../templates/page-edit.xhtml>;
    calli:create <../templates/page-create.xhtml>;
    calli:mediaType "application/xhtml+xml";
    calli:documentTag <http://www.w3.org/1999/xhtml#html>.

# GET /page/MainPage.xhtml?view
:GetPage owl:intersectionOf (<viewable.ttl#GetViewPage>
        [owl:onProperty msg:target; owl:allValuesFrom <Page>]);
    calli:rel "alternate";
    calli:method "GET";
    calli:query "view";
    calli:requires calli:reader;
    calli:type "text/html";
    calli:header "cache-control:no-cache";
    calli:post "../pipelines/page-layout-html.xpl?results&target=$0&query=view\nContent-Location: $0\nContent-Type: application/xhtml+xml".

# GET /page/MainPage.xhtml?html
:GetHtml rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.Reader>];
    calli:method "GET";
    calli:query "html";
    calli:requires calli:reader;
    calli:type "text/html";
    calli:header "cache-control:no-cache";
    calli:post "../pipelines/page-layout-html.xpl?results\nContent-Location: $0\nContent-Type: application/xhtml+xml".

# GET /page/MainPage.xhtml
:GetPageSource rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.InputStream>];
    calli:method "GET";
    calli:rel "edit-media";
    calli:requires calli:reader;
    calli:type "application/xhtml+xml";
    calli:header "cache-control:no-cache";
    calli:header "cache-control:cache-range";
    calli:script "return this.openInputStream()".

# POST ?create=/callimachus/Page
:CreatePage owl:intersectionOf (<creatable.ttl#PostCreate>
        [owl:onProperty msg:target; owl:hasValue <Page> ]);
    calli:imports <java:org.openrdf.model.vocabulary.RDFS>;
    calli:imports <java:java.net.URLDecoder>;
    calli:imports <java:org.callimachusproject.server.exceptions.BadRequest>;
    calli:imports <java:org.callimachusproject.server.exceptions.InternalServerError>;
    calli:imports <File>;
    calli:imports calli:Page;
    calli:imports foaf:Document;
    calli:script """
        var con = this.objectConnection;
        var vf = con.valueFactory;
        if (!location)
            throw new BadRequest("Missing location request header");

        if (location instanceof File) {
            location = location.RemoveFile();
        }
        var created = location;

        var filename = created.resource.localName.replace(/([a-zA-Z_0-9])\\.[a-zA-Z]+$/, "$1");
        var label = vf.createLiteral(URLDecoder.decode(filename, "UTF-8").replace(/[_\\-\\+\\s]+/g, " "));
        con.add(created.resource, RDFS.LABEL, label, []);

        created = con.addDesignation(created, this.toString());
        created = con.addDesignation(created, Page);
        created = con.addDesignation(created, Document);

        created.UploadPage(body);
        return created;
    """.

# PUT /page/MainPage.xhtml
# Called by client, copy operation, create operation, and MainPage initialization
:UploadPage rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom owl:Nothing];
    calli:method "PUT";
    calli:requires calli:editor;
    calli:imports <java:org.openrdf.model.vocabulary.RDFS>;
    calli:imports <java:java.net.URLDecoder>;
    calli:imports <java:org.callimachusproject.server.HTTPObjectServer>;
    calli:imports <java:org.callimachusproject.server.exceptions.BadRequest>;
    calli:imports <java:org.callimachusproject.server.exceptions.ServiceUnavailable>;
    calli:script """
        var read;
        var buf = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024);
        var out = this.openOutputStream();
        try {
            while ((read = xhtmlStream.read(buf)) >= 0) {
                out.write(buf, 0, read);
            }
        } finally {
            out.close();
        }
        try {
            this.ValidatePage();
        } catch (e if e.javaException instanceof ServiceUnavailable) {
            java.lang.System.err.println("Storing " + this);
        }
        this.touchRevision();
        HTTPObjectServer.resetAllCache();
    """.

:xhtmlStream a owl:ObjectProperty; a owl:FunctionalProperty;
    rdfs:domain :UploadPage;
    rdfs:range <java:java.io.InputStream>;
    calli:type "application/xhtml+xml".

:ValidatePage rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom owl:Nothing];
    calli:post "../schemas/xhtml.rng?validate\nContent-Location:$0\nContent-Type: application/xhtml+xml".

# GET /page/MainPage.xhtml?element=content/1&realm=/
:GetElement rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.Reader>];
    calli:method "GET";
    calli:query "element";
    calli:requires calli:reader;
    calli:type "text/html";
    calli:post "../pipelines/page-element.xpl?results&element={element}\nContent-Location: $0\nContent-Type: application/xhtml+xml".

:element a owl:FunctionalProperty, owl:DatatypeProperty;
    rdfs:domain :GetElement;
    rdfs:range xsd:string;
    calli:query "element".

# GET /page/MainPag.xhtml?layout
:GetTemplate rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Page>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.InputStream>];
    calli:method "GET";
{'fraction_non_alphanumeric': 0.1423689426560044, 'fraction_numerical': 0.009158635773357938, 'mean_word_length': 3.8805870580386923, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 14, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5793400', 'n_tokens_mistral': 5110, 'n_tokens_neox': 4852, 'n_words': 910}