You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sv...@apache.org on 2005/05/23 06:39:04 UTC
svn commit: r177917 -
/myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtml.java
/myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtmlRenderer.java
Author: svieujot
Date: Sun May 22 21:39:03 2005
New Revision: 177917
URL: http://svn.apache.org/viewcvs?rev=177917&view=rev
Log:
InputHtmlRenderer, small refactoring.
Modified:
myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtml.java
myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtmlRenderer.java
Modified: myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtml.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtml.java?rev=177917&r1=177916&r2=177917&view=diff
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtml.java (original)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtml.java Sun May 22 21:39:03 2005
@@ -328,24 +328,29 @@
return text.trim();
// Extract the fragment from the document.
- String lcText = text.toLowerCase();
+ return getHtmlBody( text );
+ }
+
+ static String getHtmlBody(String html){
+ String lcText = html.toLowerCase();
int textLength = lcText.length();
- int bodyStartIndex = 0;
+ int bodyStartIndex = -1;
while(bodyStartIndex < textLength){
- bodyStartIndex = lcText.indexOf("<body");
+ bodyStartIndex++;
+ bodyStartIndex = lcText.indexOf("<body", bodyStartIndex);
if( bodyStartIndex == -1 )
break; // not found.
bodyStartIndex += 5;
char c = lcText.charAt(bodyStartIndex);
- if( c=='>' ){
+ if( c=='>' )
break;
- }
if( c!=' ' && c!='\t' )
continue;
bodyStartIndex = lcText.indexOf('>', bodyStartIndex);
+ break;
}
bodyStartIndex++;
@@ -354,10 +359,10 @@
if( bodyStartIndex<0 || bodyEndIndex<0
|| bodyStartIndex > bodyEndIndex
|| bodyStartIndex>=textLength || bodyEndIndex>=textLength ){
- log.warn("Couldn't extract HTML body from :\n"+text);
- return text.trim();
+ log.warn("Couldn't extract HTML body from :\n"+html);
+ return html.trim();
}
- return text.substring(bodyStartIndex, bodyEndIndex+1).trim();
- }
+ return html.substring(bodyStartIndex, bodyEndIndex+1).trim();
+ }
}
Modified: myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtmlRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtmlRenderer.java?rev=177917&r1=177916&r2=177917&view=diff
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtmlRenderer.java (original)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/inputHtml/InputHtmlRenderer.java Sun May 22 21:39:03 2005
@@ -42,6 +42,7 @@
// TODO : Finish Disabled mode.
// TODO : Automatic Fallback for non kupu capable browsers (Safari, smartphones, non javascript, ...).
// TODO : Make Image & Link Library work.
+ // TODO : Allow disabeling of tag filtering
protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent) {
if( !UserRoleUtils.isEnabledOnUserRole(uiComponent) )
@@ -75,7 +76,7 @@
HtmlRendererUtils.renderDisplayValueOnlyAttributes(editor, writer);
String text = RendererUtils.getStringValue(context, editor);
- writer.write( getHtmlBody( text ) );
+ writer.write( InputHtml.getHtmlBody( text ) );
writer.endElement(HTML.SPAN_ELEM);
}
@@ -104,43 +105,9 @@
}
private static String htmlToPlainText(String html){
- return getHtmlBody( html )
+ return InputHtml.getHtmlBody( html )
.replaceAll("<br.*>","\n")
.replaceAll("<.+?>", "");
- }
-
- private static String getHtmlBody(String html){
- String lcText = html.toLowerCase();
- int textLength = lcText.length();
- int bodyStartIndex = -1;
- while(bodyStartIndex < textLength){
- bodyStartIndex++;
- bodyStartIndex = lcText.indexOf("<body", bodyStartIndex);
- if( bodyStartIndex == -1 )
- break; // not found.
-
- bodyStartIndex += 5;
- char c = lcText.charAt(bodyStartIndex);
- if( c=='>' )
- break;
-
- if( c!=' ' && c!='\t' )
- continue;
-
- bodyStartIndex = lcText.indexOf('>', bodyStartIndex);
- break;
- }
- bodyStartIndex++;
-
- int bodyEndIndex = lcText.lastIndexOf("</body>")-1;
-
- if( bodyStartIndex<0 || bodyEndIndex<0
- || bodyStartIndex > bodyEndIndex
- || bodyStartIndex>=textLength || bodyEndIndex>=textLength ){
- return html.trim();
- }
-
- return html.substring(bodyStartIndex, bodyEndIndex+1).trim();
}
private void encodeEndNormalMode(FacesContext context, InputHtml editor) throws IOException {