Package org.apache.jetspeed.services.search

Examples of org.apache.jetspeed.services.search.BaseParsedObject


     * @param o
     * @return
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof URL) == false)
        {
            logger.error("URLToDocHandler: invalid object type: " + o);
            return null;
        }

        URL pageToAdd = (URL) o;

        HttpClient client = new HttpClient();
        client.startSession(pageToAdd);
        GetMethod method = new GetMethod(pageToAdd.getPath());
        method.setFollowRedirects(true);
        int statusCode = -1;
        int attempt = 0;

        // We will retry up to 3 times.
        while (statusCode == -1 && attempt < 3)
        {
            try
            {
                // execute the method.
                client.executeMethod(method);
                statusCode = method.getStatusCode();
                if (logger.isDebugEnabled())
                {
                    logger.debug("URL = " + pageToAdd.toString() + "Status code = " + statusCode);
                }
            }
            catch (HttpException e)
            {
                // We will retry
                attempt++;
            }
            catch (IOException e)
            {
                return null;
            }
        }
        // Check that we didn't run out of retries.
        if (statusCode != -1)
        {
            String content = null;
            try
            {
                content = method.getResponseBodyAsString();
            }
            catch (Exception ioe)
            {
                logger.error("Getting content for " + pageToAdd.toString(), ioe);
            }

            if (content != null)
            {
                try
                {
                    result.setKey(java.net.URLEncoder.encode(pageToAdd.toString()));
                    result.setType(ParsedObject.OBJECT_TYPE_URL);
                    // TODO: We should extract the <title> tag here.
                    result.setTitle(pageToAdd.toString());
                    result.setContent(content);
                    result.setDescription("");
                    result.setLanguage("");
                    result.setURL(pageToAdd);
                    result.setClassName(o.getClass().getName());
                    logger.info("Parsed '" + pageToAdd.toString() + "'");
                }
                catch (Exception e)
                {
                    e.printStackTrace();
View Full Code Here


    /* (non-Javadoc)
     * @see org.apache.jetspeed.services.search.ObjectHandler#parseObject(java.lang.Object)
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof Portlet) == false)
        {
            logger.error("PortletToDocHandler: invalid object type: " + o);
            return null;
        }

        Portlet portlet = (Portlet) o;
       
       
        JetspeedRunDataService rds = (JetspeedRunDataService) ((TurbineServices) TurbineServices.getInstance())
                                                                                  .getResources(RunDataService.SERVICE_NAME);
        result.setContent(portlet.getContent(rds.getCurrentRunData()).toString());
        result.setDescription(portlet.getDescription());
        result.setType(this.getClass().getName());
        //result.setFields();
        result.setKey(portlet.getName());
        //result.setKeywords();
        //result.setLanguage();
        result.setTitle(portlet.getTitle());
        //result.setURL();
       
        return result;
    }
View Full Code Here

     * @param o
     * @return
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof RegistryEntry) == false)
        {
            logger.error("RegistryEntryToDocHandler: invalid object type: " + o);
            return null;
        }

        RegistryEntry regEntry = (RegistryEntry) o;
        String desc = regEntry.getDescription();
        result.setDescription(desc == null ? regEntry.getName() : desc);
        result.setKey(regEntry.getName());
        String title = regEntry.getTitle();
        result.setTitle(title == null ? regEntry.getName() : title);
       
        result.setClassName(o.getClass().getName());
       
        return result;
    }
View Full Code Here

        int hitCount = hits.length();
        Document doc = null;
        SearchResults results = new SearchResults(hitCount);
        for (int counter = 0; counter < hitCount; counter++)
        {           
            ParsedObject result = new BaseParsedObject();
            try
            {
                doc = hits.doc(counter);
                addFieldsToParsedObject(doc, result);
               
                result.setScore(hits.score(counter));
                Field type = doc.getField(ParsedObject.FIELDNAME_TYPE);
                if(type != null)
                {
                    result.setType(type.stringValue());
                }
               
                Field key = doc.getField(ParsedObject.FIELDNAME_KEY);
                if(key != null)
                {
                    result.setKey(key.stringValue());
                }
               
                Field description = doc.getField(ParsedObject.FIELDNAME_DESCRIPTION);
                if(description != null)
                {
                    result.setDescription(description.stringValue());
                }
               
                Field title = doc.getField(ParsedObject.FIELDNAME_TITLE);
                if(title != null)
                {
                    result.setTitle(title.stringValue());
                }
               
                Field content = doc.getField(ParsedObject.FIELDNAME_CONTENT);
                if(content != null)
                {
                    result.setContent(content.stringValue());
                }
               
                Field language = doc.getField(ParsedObject.FIELDNAME_LANGUAGE);
                if (language != null)
                {
                  result.setLanguage(language.stringValue());
                }
               
                Field classname = doc.getField(ParsedObject.FIELDNAME_CLASSNAME);
                if (classname != null)
                {
                  result.setClassName(classname.stringValue());
                }
               
                Field url = doc.getField(ParsedObject.FIELDNAME_URL);
                if (url != null)
                {
                    result.setURL(new URL(url.stringValue()));
                }
               
                results.add(counter, result);
            }
            catch (Exception ioe)
View Full Code Here

     * @param o
     * @return
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof RegistryEntry) == false)
        {
            logger.error("RegistryEntryToDocHandler: invalid object type: " + o);
            return null;
        }

        RegistryEntry regEntry = (RegistryEntry) o;
        String desc = regEntry.getDescription();
        result.setDescription(desc == null ? regEntry.getName() : desc);
        result.setKey(regEntry.getName());
        String title = regEntry.getTitle();
        result.setTitle(title == null ? regEntry.getName() : title);
       
        return result;
    }
View Full Code Here

        int hitCount = hits.length();
        Document doc = null;
        SearchResults results = new SearchResults(hitCount);
        for (int counter = 0; counter < hitCount; counter++)
        {           
            ParsedObject result = new BaseParsedObject();
            try
            {
                doc = hits.doc(counter);
                result.setScore(hits.score(counter));
                result.setType(doc.getField(ParsedObject.FIELDNAME_TYPE).stringValue());
                result.setKey(doc.getField(ParsedObject.FIELDNAME_KEY).stringValue());
                result.setDescription(doc.getField(ParsedObject.FIELDNAME_DESCRIPTION).stringValue());
                result.setTitle(doc.getField(ParsedObject.FIELDNAME_TITLE).stringValue());
                Field url = doc.getField(ParsedObject.FIELDNAME_URL);
                if (url != null)
                {
                    result.setURL(new URL(url.stringValue()));
                }               
                results.add(counter, result);
            }
            catch (Exception ioe)
            {
View Full Code Here

     * @param o
     * @return
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof URL) == false)
        {
            logger.error("URLToDocHandler: invalid object type: " + o);
            return null;
        }

        URL pageToAdd = (URL) o;

        HttpClient client = new HttpClient();
        client.startSession(pageToAdd);
        GetMethod method = new GetMethod(pageToAdd.getPath());
        method.setFollowRedirects(true);
        int statusCode = -1;
        int attempt = 0;

        // We will retry up to 3 times.
        while (statusCode == -1 && attempt < 3)
        {
            try
            {
                // execute the method.
                client.executeMethod(method);
                statusCode = method.getStatusCode();
                if (logger.isDebugEnabled())
                {
                    logger.debug("URL = " + pageToAdd.toString() + "Status code = " + statusCode);
                }
            }
            catch (HttpException e)
            {
                // We will retry
            }
            catch (IOException e)
            {
                return null;
            }
        }
        // Check that we didn't run out of retries.
        if (statusCode != -1)
        {
            String content = null;
            try
            {
                content = method.getDataAsString();
            }
            catch (IOException ioe)
            {
                logger.error("Getting content for " + pageToAdd.toString(), ioe);
            }

            if (content != null)
            {
                try
                {
                    result.setKey(java.net.URLEncoder.encode(pageToAdd.toString()));
                    result.setType(ParsedObject.OBJECT_TYPE_URL);
                    // TODO: We should extract the <title> tag here.
                    result.setTitle(pageToAdd.toString());
                    result.setContent(content);
                    result.setDescription("");
                    result.setLanguage("");
                    result.setURL(pageToAdd);
                    logger.info("Parsed '" + pageToAdd.toString() + "'");
                }
                catch (Exception e)
                {
                    e.printStackTrace();
View Full Code Here

    /* (non-Javadoc)
     * @see org.apache.jetspeed.services.search.ObjectHandler#parseObject(java.lang.Object)
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof Portlet) == false)
        {
            logger.error("PortletToDocHandler: invalid object type: " + o);
            return null;
        }

        Portlet portlet = (Portlet) o;
       
       
        JetspeedRunDataService rds = (JetspeedRunDataService) ((TurbineServices) TurbineServices.getInstance())
                                                                                  .getResources(RunDataService.SERVICE_NAME);
        result.setContent(portlet.getContent(rds.getCurrentRunData()).toString());
        result.setDescription(portlet.getDescription());
        result.setType(this.getClass().getName());
        //result.setFields();
        result.setKey(portlet.getName());
        //result.setKeywords();
        //result.setLanguage();
        result.setTitle(portlet.getTitle());
        //result.setURL();
       
        return result;
    }
View Full Code Here

        int hitCount = hits.length();
        Document doc = null;
        SearchResults results = new SearchResults(hitCount);
        for (int counter = 0; counter < hitCount; counter++)
        {           
            ParsedObject result = new BaseParsedObject();
            try
            {
                doc = hits.doc(counter);
                addFieldsToParsedObject(doc, result);
               
                result.setScore(hits.score(counter));
                result.setType(doc.getField(ParsedObject.FIELDNAME_TYPE).stringValue());
                result.setKey(doc.getField(ParsedObject.FIELDNAME_KEY).stringValue());
                result.setDescription(doc.getField(ParsedObject.FIELDNAME_DESCRIPTION).stringValue());
                result.setTitle(doc.getField(ParsedObject.FIELDNAME_TITLE).stringValue());
                result.setContent(doc.getField(ParsedObject.FIELDNAME_CLASSNAME).stringValue());
                Field language = doc.getField(ParsedObject.FIELDNAME_LANGUAGE);
                if (language != null)
                {
                  result.setLanguage(language.stringValue());
                }
                Field classname = doc.getField(ParsedObject.FIELDNAME_CLASSNAME);
                if (classname != null)
                {
                  result.setClassName(classname.stringValue());
                }
                Field url = doc.getField(ParsedObject.FIELDNAME_URL);
                if (url != null)
                {
                    result.setURL(new URL(url.stringValue()));
                }
               
                results.add(counter, result);
            }
            catch (Exception ioe)
View Full Code Here

     * @param o
     * @return
     */
    public ParsedObject parseObject(Object o)
    {
        ParsedObject result = new BaseParsedObject();

        if ((o instanceof URL) == false)
        {
            logger.error("URLToDocHandler: invalid object type: " + o);
            return null;
        }

        URL pageToAdd = (URL) o;

        HttpClient client = new HttpClient();
        client.startSession(pageToAdd);
        GetMethod method = new GetMethod(pageToAdd.getPath());
        method.setFollowRedirects(true);
        int statusCode = -1;
        int attempt = 0;

        // We will retry up to 3 times.
        while (statusCode == -1 && attempt < 3)
        {
            try
            {
                // execute the method.
                client.executeMethod(method);
                statusCode = method.getStatusCode();
                if (logger.isDebugEnabled())
                {
                    logger.debug("URL = " + pageToAdd.toString() + "Status code = " + statusCode);
                }
            }
            catch (HttpException e)
            {
                // We will retry
            }
            catch (IOException e)
            {
                return null;
            }
        }
        // Check that we didn't run out of retries.
        if (statusCode != -1)
        {
            String content = null;
            try
            {
                content = method.getDataAsString();
            }
            catch (IOException ioe)
            {
                logger.error("Getting content for " + pageToAdd.toString(), ioe);
            }

            if (content != null)
            {
                try
                {
                    result.setKey(java.net.URLEncoder.encode(pageToAdd.toString()));
                    result.setType(ParsedObject.OBJECT_TYPE_URL);
                    // TODO: We should extract the <title> tag here.
                    result.setTitle(pageToAdd.toString());
                    result.setContent(content);
                    result.setDescription("");
                    result.setLanguage("");
                    result.setURL(pageToAdd);
                    result.setClassName(o.getClass().getName());
                    logger.info("Parsed '" + pageToAdd.toString() + "'");
                }
                catch (Exception e)
                {
                    e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.services.search.BaseParsedObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.