Package org.apache.jetspeed.search

Examples of org.apache.jetspeed.search.BaseParsedObject


        int hitNum = hits.length();
        ArrayList resultList = new ArrayList(hitNum);
        for(int i=0; i<hitNum; i++)
        {
            ParsedObject result = new BaseParsedObject();
            try
            {
              Document doc = hits.doc(i);
         
            addFieldsToParsedObject(doc, result);
           
            result.setScore(hits.score(i));
            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()));
            }
           
            resultList.add(i, result);
            }
            catch(IOException e)
View Full Code Here


     * @param o
     * @return
     */
    public org.apache.jetspeed.search.ParsedObject parseObject(Object o)
    {
        org.apache.jetspeed.search.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(org.apache.jetspeed.search.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

        int hitNum = hits.length();
        ArrayList resultList = new ArrayList(hitNum);
        for(int i=0; i<hitNum; i++)
        {
            ParsedObject result = new BaseParsedObject();
            try
            {
              Document doc = hits.doc(i);
         
            addFieldsToParsedObject(doc, result);
           
            result.setScore(hits.score(i));
            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()));
            }
           
            Field[] keywords = doc.getFields(ParsedObject.FIELDNAME_KEYWORDS);
            if(keywords != null)
            {
              String[] keywordArray = new String[keywords.length];
             
              for(int j=0; j<keywords.length; j++)
              {
                Field keyword = keywords[j];
                keywordArray[j] = keyword.stringValue();
              }
             
              result.setKeywords(keywordArray);
            }
           
            resultList.add(i, result);
            }
            catch(IOException e)
View Full Code Here

        int hitNum = hits.length();
        List<ParsedObject> resultList = new ArrayList<ParsedObject>(hitNum);
        for(int i=0; i<hitNum; i++)
        {
            ParsedObject result = new BaseParsedObject();
            try
            {
              Document doc = hits.doc(i);
         
            addFieldsToParsedObject(doc, result);
           
            result.setScore(hits.score(i));
            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()));
            }
           
            Field[] keywords = doc.getFields(ParsedObject.FIELDNAME_KEYWORDS);
            if(keywords != null)
            {
              String[] keywordArray = new String[keywords.length];
             
              for(int j=0; j<keywords.length; j++)
              {
                Field keyword = keywords[j];
                keywordArray[j] = keyword.stringValue();
              }
             
              result.setKeywords(keywordArray);
            }
           
            resultList.add(i, result);
            }
            catch(IOException e)
View Full Code Here

    /* (non-Javadoc)
     * @see org.apache.jetspeed.search.ObjectHandler#parseObject(java.lang.Object)
     */
    public ParsedObject parseObject(Object o)
    {
        BaseParsedObject result = null;
        if(o instanceof PortletDefinition)
        {
            result = new BaseParsedObject();
            PortletDefinition pd = (PortletDefinition)o;
           
            //need to get Locale here
            String displayNameText = pd.getDisplayNameText(JetspeedLocale.getDefaultLocale());
            result.setTitle(displayNameText);
           
            String description = pd.getDescriptionText(JetspeedLocale.getDefaultLocale());
            result.setDescription(description);
           
            result.setClassName(pd.getClass().getName());
            result.setKey(KEY_PREFIX + pd.getUniqueName());
            result.setType(ParsedObject.OBJECT_TYPE_PORTLET);
           
            //TODO: this is common to PAs as well, possible refactor
            MultiHashMap fieldMap = new MultiHashMap();
            fieldMap.put(ParsedObject.ID, pd.getPortletName());
           
            PortletApplication pa = (PortletApplication)pd.getApplication();
            fieldMap.put(PORTLET_APPLICATION, pa.getName());
           
            Collection mdFields = pd.getMetadata().getFields();
            for (Iterator fieldIter = mdFields.iterator(); fieldIter.hasNext();)
            {
                LocalizedField field = (LocalizedField) fieldIter.next();               
                fieldMap.put(field.getName(), field.getValue());
            }
           
            //Handle descriptions
            for (Description d : pd.getDescriptions())
            {
                fieldMap.put(ParsedObject.FIELDNAME_DESCRIPTION, d.getDescription());
            }
           
            //Handle keywords and titles
            for (DisplayName d : pd.getDisplayNames())
            {
                fieldMap.put(ParsedObject.FIELDNAME_TITLE, d.getDisplayName());
            }
           
            HashSet keywordSet = new HashSet();
           
            for (Language lang : pd.getLanguages())
            {
                fieldMap.put(ParsedObject.FIELDNAME_TITLE, lang.getTitle());
                fieldMap.put(ParsedObject.FIELDNAME_TITLE, lang.getShortTitle());
                for (String keyword : lang.getKeywordList())
                {
                    keywordSet.add(keyword);
                }
            }
           
            String[] temp = new String[keywordSet.size()];
            result.setKeywords((String[])keywordSet.toArray(temp));
            result.setFields(fieldMap);
        }
        return result;
    }
View Full Code Here

    /**
     * @see org.apache.jetspeed.search.ObjectHandler#parseObject(java.lang.Object)
     */
    public ParsedObject parseObject(Object o)
    {
        BaseParsedObject result = null;
       
        if(o instanceof PortletApplication)
        {
            result = new BaseParsedObject();
          PortletApplication pa = (PortletApplication) o;
         
          Description defaultDescription = pa.getDescription(JetspeedLocale.getDefaultLocale());
          if (defaultDescription != null)
          {
              result.setDescription(defaultDescription.getDescription());
          }
          result.setTitle(pa.getName());
          result.setKey(KEY_PREFIX + pa.getName());
          result.setType(ParsedObject.OBJECT_TYPE_PORTLET_APPLICATION);
          result.setClassName(pa.getClass().getName());
         
          MultiHashMap fieldMap = new MultiHashMap();
          fieldMap.put(ParsedObject.ID, pa.getName());
         
          Collection fields = pa.getMetadata().getFields();
          for (Iterator fieldIter = fields.iterator(); fieldIter.hasNext();)
            {
                LocalizedField field = (LocalizedField) fieldIter.next();
                fieldMap.put(field.getName(), field.getValue());
                //this.fields.add(field.getName());
            }
         
          result.setFields(fieldMap);
        }
       
        return result;
    }
View Full Code Here

    {
        private String keyPrefix;
       
        public ParsedObject parseObject(Object o)
        {
            BaseParsedObject result = null;
           
            if(o instanceof Map)
            {
                result = new BaseParsedObject();
                Map<String, String> map = (Map<String, String>) o;
               
                keyPrefix = map.get("keyPrefix");
               
                result.setDescription(map.get("description"));
               
                result.setTitle(map.get("title"));
                result.setKey(keyPrefix + map.get("name"));
                result.setType(map.get("type"));
                result.setClassName(map.get("class"));
               
                MultiHashMap fieldMap = new MultiHashMap();
                fieldMap.put(ParsedObject.ID, map.get("name"));
            }
           
View Full Code Here

     * @param o
     * @return
     */
    public org.apache.jetspeed.search.ParsedObject parseObject(Object o)
    {
        org.apache.jetspeed.search.ParsedObject result = new BaseParsedObject();

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

        URL pageToAdd = (URL) o;
        String content = getContentFromURL(pageToAdd);
       
        if (content != null)
        {
            try
            {
                result.setKey(java.net.URLEncoder.encode(pageToAdd.toString(),"UTF-8"));
                result.setType(org.apache.jetspeed.search.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

            int count = Math.min(topHitsCount, topDocs.totalHits);
            List<ParsedObject> resultList = new ArrayList<ParsedObject>(count);
           
            for (int i = 0; i < count; i++)
            {
                ParsedObject result = new BaseParsedObject();
               
              Document doc = searcher.doc(topDocs.scoreDocs[i].doc);
         
            addFieldsToParsedObject(doc, result);
           
            result.setScore(topDocs.scoreDocs[i].score);
            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()));
            }
           
            Field[] keywords = doc.getFields(ParsedObject.FIELDNAME_KEYWORDS);
            if(keywords != null)
            {
              String[] keywordArray = new String[keywords.length];
             
              for(int j=0; j<keywords.length; j++)
              {
                Field keyword = keywords[j];
                keywordArray[j] = keyword.stringValue();
              }
             
              result.setKeywords(keywordArray);
            }
           
            resultList.add(i, result);
            }
           
View Full Code Here

    {
        private String keyPrefix;
       
        public ParsedObject parseObject(Object o)
        {
            BaseParsedObject result = null;
           
            if(o instanceof Map)
            {
                result = new BaseParsedObject();
                Map<String, String> map = (Map<String, String>) o;
               
                keyPrefix = map.get("keyPrefix");
               
                result.setDescription(map.get("description"));
               
                result.setTitle(map.get("title"));
                result.setKey(keyPrefix + map.get("name"));
                result.setType(map.get("type"));
                result.setClassName(map.get("class"));
               
                MultiHashMap fieldMap = new MultiHashMap();
                fieldMap.put(ParsedObject.ID, map.get("name"));
            }
           
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.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.