Java Javascript Mozilla Library removeLinkFromXhtml(Object xhtml, String link)

Here you can find the source of removeLinkFromXhtml(Object xhtml, String link)

Description

remove Link From Xhtml

License

Open Source License

Declaration

public static void removeLinkFromXhtml(Object xhtml, String link) 

Method Source Code

//package com.java2s;
/*/*www  . ja  v  a 2 s.c  o  m*/
 * Axiom Stack Web Application Framework
 * Copyright (C) 2008  Axiom Software Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Axiom Software Inc., 11480 Commerce Park Drive, Third Floor, Reston, VA 20191 USA
 * email: info@axiomsoftwareinc.com
 */

import org.mozilla.javascript.Context;
import org.mozilla.javascript.ImporterTopLevel;
import org.mozilla.javascript.Scriptable;

public class Main {
    public static void removeLinkFromXhtml(Object xhtml, String link) {
        if (xhtml instanceof Scriptable) {
            Scriptable sxhtml = (Scriptable) xhtml;
            String classname = sxhtml.getClassName().toLowerCase();
            if ("xml".equals(classname) || "xmllist".equals(classname)) {
                final String XHTML_DEL_LINK = "var link_re = new RegExp('"
                        + link
                        + "/?');"
                        + "for each (var x in xhtml..*.(link_re.test(@href.toString() ||  @src.toString()))) { "
                        + "x.parent().replace(x.childIndex(), x.*); " + "}";
                Context cx = Context.getCurrentContext();
                ImporterTopLevel itl = new ImporterTopLevel(cx);
                itl.put("xhtml", itl, sxhtml);
                cx.evaluateString(itl, XHTML_DEL_LINK, "", 0, null);
                itl = null;
            }
        }
    }
}

Related

  1. omitLineBreak(AstNode node)
  2. oneLineStringOf(AstNode node)
  3. parentOfAnyTypes(AstNode node, Set types, boolean isStrict)
  4. parentOfType(AstNode node, Class type)
  5. prototypeCast(Scriptable s, Class type)
  6. runWithAllOptimizationLevels(final ContextAction action)
  7. runWithOptimizationLevel(final ContextAction action, final int optimizationLevel)
  8. scriptableObjectToString(Object scriptObject)
  9. stringToNumber(CharSequence string)