Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
$URL: https://source.sakaiproject.org/svn/help/tags/sakai-10.4/help-component/src/java/org/sakaiproject/component/app/help/RestConfigurationImpl.java $ $Id: RestConfigurationImpl.java 105079 2012-02-24 23:08:11Z ottenhoff@longsight.com $ Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 The Sakai Foundation Licensed under the Educational Community 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.opensource.org/licenses/ECL-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. /
 
 package org.sakaiproject.component.app.help;
 
 import java.net.URL;
 
 

Author(s):
Jarrod Lannan
Version:
$Id: RestConfigurationImpl.java 105079 2012-02-24 23:08:11Z ottenhoff@longsight.com $
 
 public class RestConfigurationImpl implements RestConfiguration
 {

  
user:pass as string ... will be converted to Base64
 
   private String restCredentials;
 
   private String organization;
   private String restDomain;
   private String restUrl;
   private long cacheInterval;
 
   private static String REST_DOMAIN_URL;
   private static String REST_CORPUS_URL;
 
   private final static Log LOG = LogFactory.getLog(RestConfigurationImpl.class);

  
 
   public String getOrganization()
   {
     return ;
   }

  
 
   public void setOrganization(String organization)
   {
     this. = organization;
   }

  
 
   public String getRestCredentials()
   {
     return ;
   }

  
 
   public void setRestCredentials(String restCredentials)
   {
     this. = restCredentials;
   }

  
 
  public String getRestDomain()
  {
    return ;
  }

  
  public void setRestDomain(String restDomain)
  {
    this. = restDomain;
  }

  
  public String getRestUrl()
  {
    return ;
  }

  
  public void setRestUrl(String restUrl)
  {
    this. = restUrl;
  }

  
  public long getCacheInterval()
  {
    return ;
  }

  
  public void setCacheInterval(long cacheInterval)
  {
    this. = cacheInterval;
  }

  
  {
    if ( != null)
    {
      return ;
    }
    else
    {
      return  = getRestUrl() + "/" + getRestDomain() + "/"
          + "document/" + getRestDomain() + "/";
    }
  }

  
  {
    if ( != null)
    {
      return ;
    }
    else
    {
      return  = getRestUrl() + "/" + getRestDomain() + "/"
          + "documents";
    }
  }

  
  {
    if (.isDebugEnabled())
    {
      .debug("getCorpusDocument()");
    }
    URL url = null;
    StringBuilder sBuffer = new StringBuilder();
    BufferedReader br = null;
    try
    {
      url = new URL(getRestCorpusUrl());
      URLConnection urlConnection = url.openConnection();
      String basicAuthUserPass = getRestCredentials();
      String encoding = Base64.encodeBase64(basicAuthUserPass.getBytes("utf-8")).toString();
      
      urlConnection.setRequestProperty("Authorization""Basic " + encoding);
      br = new BufferedReader(new InputStreamReader(urlConnection
          .getInputStream()), 512);
      int readReturn = 0;
      char[] cbuf = new char[512];
      while ((readReturn = br.read(cbuf, 0, 512)) != -1)
      {
        sBuffer.append(cbuf, 0, readReturn);
      }
    }
    catch (MalformedURLException e)
    {
      .error("Malformed URL in REST document: " + url.getPath(), e);
    }
    catch (IOException e)
    {
      .error("Could not open connection to REST document: " + url.getPath(),
          e);
    }
    finally
    {
      try
      {
        if (br != null)
        {
          br.close();
        }
      }
      catch (IOException e)
      {
        .error("error closing corpus doc"e);
      }
    }
    return sBuffer.toString();
  }

  
  {
    try
    {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setNamespaceAware(true);
      DocumentBuilder builder = dbf.newDocumentBuilder();
      StringReader sReader = new StringReader(xml);
      InputSource inputSource = new org.xml.sax.InputSource(sReader);
      org.w3c.dom.Document xmlDocument = builder.parse(inputSource);
      sReader.close();
      
      NodeList nodeList = xmlDocument.getElementsByTagName("kbq");
      
      int nodeListLength = nodeList.getLength();
      for (int i = 0; i < nodeListLengthi++){
        Node currentNode = nodeList.item(i);
        
        NodeList nlChildren = currentNode.getChildNodes();
        
        for (int j = 0; j < nlChildren.getLength(); j++){
          if (nlChildren.item(j).getNodeType() == .){
            return nlChildren.item(j).getNodeValue();
          }
        }
      }
      return null;
    }            
    catch (Exception e)
    {
      .error(e.getMessage(), e);
    }     
    
    return null;
  }
New to GrepCode? Check out our FAQ X