Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion Mapping mediaType comme option #27

Open
Nugus53 opened this issue Aug 8, 2024 · 0 comments
Open

Suggestion Mapping mediaType comme option #27

Nugus53 opened this issue Aug 8, 2024 · 0 comments

Comments

@Nugus53
Copy link

Nugus53 commented Aug 8, 2024

function routes:document($resource as xs:string, $ref as xs:string, $start as xs:string, $end as xs:string, $tree as xs:string, $mediaType as xs:string, $filter) {
  (: ce système de paramètre pourrai être stocker dans global.xqm:)
  let $mapMedia := 
  map{'html': map{'Content-Type' : 'text/html','xsl':'hteiml/tei2html.xsl'}, 
      'text': map{'Content-Type' : 'text/plain', ,xsl':'hteiml/tei2text.xsl'}
  }
  (: a voir si ajouter un paramètre mode pour spécifier le mode de stockage est pertinent :)
  return 
  if ($resource != "")
  then
    let $dbName := db:get($G:dots)//dots:member/node()[@dtsResourceId = $resource]/@dbName
    return
      if ($dbName) 
      then 
        let $result := utils:document($resource, $ref, $start, $end, $tree, $filter)
        return
          if ($mediaType)
          then 
            if (map:contains($mapMedia,$mediaType))
              (:ici il y a surement moyen d'optimiser le code car on a 2 fois le rest: réponse :)
            then(
                let $f := map:get(map:get($mapMedia,$mediaType),'Content-Type')
                let $style := concat($G:xsl,map:get(map:get($mapMedia,$mediaType),'xsl'))
                let $result := switch (map:get(map:get($mapMedia,$mediaType),'method'))
                 case 'text' 
                   return xslt:transform-text($result, $style)
                case 'xml' 
                   return xslt:transform($result, $style)
               default
                     return "unknown"
                
                return (
                <rest:response>
                  <http:response status="200">
                    <http:header name="Content-Type" value="{concat($f, ' charset=utf-8')}"/>
                  </http:response>
                </rest:response>,
                $result ))
            else(
                 <rest:response>
                  <http:response status="200">
                    <http:header name="Content-Type" value="application/xml+tei"/>
                  </http:response>
                </rest:response>,
                $result
            )
            
          else
            $result
      else
        routes:badIdResource(xs:string($resource))
  else
    routes:badIdResource(xs:string($resource))
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant