private void doPage(ActionRequest request, ActionResponse response) { // System.out.println("[BrowserPortlet.doPage]"); String url = request.getParameter("url"); WebPage _page = new WebPage(); URI _access = new URI(); _access.setEffectiveURI(url); _page.setAccess(_access); _page.setContextCreation("PortletWebBrowser"); _page.setCreation(new Date()); // TODO pour l'instant on se fout du contenu de la page // _page.setHTMLContent(HTMLmanager.getCleanHTML(url)); HTMLPage page = new HTMLPage(); page.setURL(url); try { page.extractTitle(); } catch (ParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } String title = page.getTitle(); // String title = HTMLmanager.getTitlePage(url) ; _page.setLabel(title); _page.setPrincipalURL(_access); _page.setRepresentsResource(_access); this.sendEvent("page", _page, response); // response.setRenderParameter("url", url); request.getPortletSession().setAttribute("current_url", url); }
private void doSelection(ActionRequest request, ActionResponse response) { // System.out.println("[BrowserPortlet.doSelection]"); String url = request.getParameter("url"); HTMLPage page = new HTMLPage(); page.setURL("url"); try { page.extractTitle(); } catch (ParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } String title = page.getTitle(); // String title = HTMLmanager.getTitlePage(url) ; SelectionHTML _selection_html = new SelectionHTML(); _selection_html.setHTMLContent(request.getParameter("text_selection")); _selection_html.setXpointerBegin(request.getParameter("xpointer_start")); _selection_html.setXpointerEnd(request.getParameter("xpointer_end")); _selection_html.setContextCreation("PortletWebBrowser"); _selection_html.setCreation(new Date()); _selection_html.setLabel("sélection de : " + title); // _selection_html.setRepresentsResource(representsResource); WebPage selectionOrigin = new WebPage(); URI _access = new URI(); _access.setEffectiveURI(url); selectionOrigin.setAccess(_access); selectionOrigin.setContextCreation("PortletWebBrowser"); selectionOrigin.setCreation(new Date()); // TODO // Pas la peine de sauver tout le html pour l'instant // selectionOrigin.setHTMLContent(HTMLmanager.getCleanHTML(url)); selectionOrigin.setLabel(title); selectionOrigin.setPrincipalURL(_access); selectionOrigin.setRepresentsResource(_access); _selection_html.setSelectionOrigin(selectionOrigin); HighlightSelectionHTML _highLight = new HighlightSelectionHTML(); _highLight.setSelection(_selection_html); _highLight.setStyle("background-color:yellow;"); _highLight.setInfo("sélection en attente d'annotation"); _highLight.setId(generateHighlightId(request)); // _selection_html.setClassname("new_selection"); this.sendEvent("selection", _highLight, response); // ajouter la nouvelle sélection à la liste courante ArrayList<HighlightSelectionHTML> _highlights; if (request.getPortletSession().getAttribute("highlights") != null) { _highlights = (ArrayList<HighlightSelectionHTML>) request.getPortletSession().getAttribute("highlights"); } else _highlights = new ArrayList<HighlightSelectionHTML>(); _highlights.add(_highLight); request.getPortletSession().setAttribute("highlights", _highlights); // response.setRenderParameter("url", url); request.getPortletSession().setAttribute("current_url", url); }
private void setRenderAttributes(RenderRequest request) { String currentURL = defaultURL; request .getPortletSession() .setAttribute("default_url", defaultURL, request.getPortletSession().APPLICATION_SCOPE); request.setAttribute("default_url", defaultURL); if (hide_url) request.setAttribute("hide_url", ""); else request.removeAttribute("hide_url"); if (hide_new_windows) request.setAttribute("hide_new_windows", ""); else request.removeAttribute("hide_new_windows"); if (request.getParameter("height") != null) request.setAttribute("height", request.getParameter("height")); else request.setAttribute("height", PortletWebBrowser.defaultHeight); if (request.getParameter("width") != null) request.setAttribute("width", request.getParameter("width")); else request.setAttribute("width", PortletWebBrowser.defaultWidth); if (request.getParameter("message") != null) request.setAttribute("message", request.getParameter("message")); else request.setAttribute("message", PortletWebBrowser.defaultMessage); if (request.getPortletSession().getAttribute("current_url") != null) currentURL = (String) request.getPortletSession().getAttribute("current_url"); request.setAttribute("url", currentURL); // String _clean_html = HTMLmanager.getCleanHTML(currentURL); // //HTMLParser.toStringFromHTML(currentURL) ; HTMLPage toBrowse = new HTMLPage(currentURL); String html = toBrowse.getBody(); // on set la liste de highlights ArrayList<HighlightSelectionHTML> _highlights; if (request.getPortletSession().getAttribute("highlights") != null) _highlights = ((ArrayList<HighlightSelectionHTML>) request.getPortletSession().getAttribute("highlights")); else _highlights = new ArrayList<HighlightSelectionHTML>(); // String _html_to_load = HTMLmanager.colorHighlights(_clean_html, _highlights); for (HighlightSelectionHTML highlight : _highlights) { try { toBrowse.addAnnotationSpan( highlight.getSelection().getXpointerBegin(), highlight.getSelection().getXpointerEnd(), highlight.getStyle(), highlight.getInfo(), highlight.getId()); if (toBrowse.getBody() != null) html = toBrowse.getBody(); // System.out.println("[PortletBrowser.setRenderAttributes] html : " + html); } catch (ParserException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println( "[PortletWebBrowser.setRenderAttributes] unable to parse HTML and add annotations for URL : " + currentURL); } } // String _html_to_load = toBrowse.getBody(); String _html_to_load = html; if (_html_to_load != null && _html_to_load.length() > 0) request.setAttribute("html", _html_to_load); // else request.setAttribute("html" , _clean_html); else request.setAttribute( "html", "Problem Parsing HTML, try to reload page without annotations or selections ... or just reload ^^"); // Add Css request.setAttribute("css", toBrowse.getCss()); }