/* * Copyright 2004-2012 the Seasar Foundation and the Others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.seasar.mayaa.impl.builder; import org.seasar.mayaa.impl.util.StringUtil; /** * "./"で始まるパスをレンダリング時のパスからの相対パスになるようスクリプトに置換します。 * 対象とするのは、デフォルトでは以下のタグの属性。(名前空間はHTML/XHTML限定) * <ul> * <li><a href="..."></li> * <li><applet code="..."></li> * <li><applet codebase="..."></li> * <li><area href="..."></li> * <li><base href="..."></li> * <li><blockquote cite="..."></li> * <li><del cite="..."></li> * <li><embed src="..."></li> * <li><form action="..."></li> * <li><frame longdesc="..."></li> * <li><frame src="..."></li> * <li><iframe src="..."></li> * <li><img src="..."></li> * <li><img usemap="..."></li> * <li><input src="..."></li> * <li><input usemap="..."></li> * <li><ins cite="..."></li> * <li><link href="..."></li> * <li><object codebase="..."></li> * <li><object data="..."></li> * <li><object usemap="..."></li> * <li><q cite="..."></li> * <li><script src="..."></li> * </ul> * ※このスクリプトはJavaScriptであるため、スクリプトエンジンを置き換えた場合は動作しません。 * * @author Koji Suga (Gluegent Inc.) */ public class PathRelativeAdjusterImpl extends PathAdjusterImpl { private static final long serialVersionUID = -1408738254857321372L; /** * @see PathAdjusterImpl#PathAdjusterImpl() */ public PathRelativeAdjusterImpl() { super(); } /** * @see PathAdjusterImpl#PathAdjusterImpl(String[][]) */ public PathRelativeAdjusterImpl(String[][] adjustTarget) { super(adjustTarget); } /** * "./"で始まるパスを解決して返します。 * 解決した結果はJavaScriptになり、レンダリング時に実行されます。 * * @param base 対象タグのあるページのパス * @param path 解決対象のパス * @return 解決後のパス */ public String adjustRelativePath(String base, String path) { if (StringUtil.isRelativePath(path) == false) { return path; } // リンク先をリクエストされたパスからの相対にする String contextRelativePath = StringUtil.adjustRelativePath(base, path); StringBuffer sb = new StringBuffer(200); sb.append("${Packages.org.seasar.mayaa.impl.util.StringUtil.adjustContextRelativePath("); sb.append("request.getContextPath() + request.getRequestedPath()"); sb.append(", '"); sb.append(contextRelativePath); sb.append("')}"); return sb.toString(); } }