2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package com
.sun
.star
.wiki
;
21 import javax
.swing
.text
.html
.*;
22 import javax
.swing
.text
.MutableAttributeSet
;
24 public class EditPageParser
extends HTMLEditorKit
.ParserCallback
27 protected String m_sEditTime
= "";
28 protected String m_sEditToken
= "";
29 protected String m_sLoginToken
= "";
30 protected String m_sMainURL
= "";
32 private boolean m_bHTMLStartFound
= false;
33 private boolean m_bInHead
= false;
35 protected int m_nWikiArticleStart
= -1;
36 protected int m_nWikiArticleEnd
= -1;
37 protected int m_nHTMLArticleStart
= -1;
38 protected int m_nHTMLArticleEnd
= -1;
39 protected int m_nNoArticleInd
= -1;
40 protected int m_nErrorInd
= -1;
43 public void handleComment( char[] data
,int pos
)
45 // insert code to handle comments
49 public void handleEndTag( HTML
.Tag t
,int pos
)
51 if ( t
== HTML
.Tag
.TEXTAREA
)
53 m_nWikiArticleEnd
= pos
;
55 else if ( t
== HTML
.Tag
.DIV
)
57 if ( m_bHTMLStartFound
)
59 m_nHTMLArticleStart
= pos
+6;
60 m_bHTMLStartFound
= false;
63 else if ( t
== HTML
.Tag
.HEAD
)
70 public void handleError( String errorMsg
,int pos
)
75 public void handleSimpleTag( HTML
.Tag t
, MutableAttributeSet a
,int pos
)
77 // insert code to handle simple tags
79 if ( t
== HTML
.Tag
.INPUT
)
81 String sName
= ( String
) a
.getAttribute( HTML
.Attribute
.NAME
);
84 if ( sName
.equalsIgnoreCase( "wpEdittime" ) )
86 this.m_sEditTime
= ( String
) a
.getAttribute( HTML
.Attribute
.VALUE
);
88 else if ( sName
.equalsIgnoreCase( "wpEditToken" ) )
90 this.m_sEditToken
= ( String
) a
.getAttribute( HTML
.Attribute
.VALUE
);
92 else if ( sName
.equalsIgnoreCase( "wpLoginToken" ) )
94 this.m_sLoginToken
= ( String
) a
.getAttribute( HTML
.Attribute
.VALUE
);
99 else if ( t
== HTML
.Tag
.LINK
)
103 String sName
= ( String
) a
.getAttribute( HTML
.Attribute
.HREF
);
106 // get the main URL from the first header-link with load.php (which is used for stylesheet)
107 int nPhpFileStart
= sName
.indexOf( "load.php" );
108 if (nPhpFileStart
< 0)
109 // if not found, try header-link with opensearch_desc.php
110 nPhpFileStart
= sName
.indexOf( "opensearch_desc.php" );
112 if ( nPhpFileStart
>= 0
113 && m_sMainURL
.length() == 0 )
115 m_sMainURL
= sName
.substring( 0, nPhpFileStart
);
124 public void handleStartTag( HTML
.Tag t
, MutableAttributeSet a
,int pos
)
126 // insert code to handle starting tags
129 if ( t
== HTML
.Tag
.HEAD
)
133 else if ( t
== HTML
.Tag
.TEXTAREA
)
135 String sName
= ( String
) a
.getAttribute( HTML
.Attribute
.NAME
);
136 if ( sName
!= null && sName
.equalsIgnoreCase( "wpTextbox1" ) )
138 m_nWikiArticleStart
= pos
;
141 else if ( t
== HTML
.Tag
.DIV
)
143 String sId
= ( String
) a
.getAttribute( HTML
.Attribute
.ID
);
144 sClass
= ( String
) a
.getAttribute( HTML
.Attribute
.CLASS
);
145 if ( sId
!= null && sId
.equalsIgnoreCase( "contentSub" ) )
147 m_bHTMLStartFound
= true;
149 if ( sClass
!= null )
151 if ( sClass
.equalsIgnoreCase( "printfooter" ) )
153 m_nHTMLArticleEnd
= pos
;
155 else if ( sClass
.equalsIgnoreCase( "noarticletext" ) )
157 m_nNoArticleInd
= pos
;
159 else if ( sClass
.equalsIgnoreCase( "errorbox" ) )
165 else if ( t
== HTML
.Tag
.P
)
167 sClass
= ( String
) a
.getAttribute( HTML
.Attribute
.CLASS
);
168 if ( sClass
!= null && sClass
.equalsIgnoreCase( "error" ) )