blob: c73b2353a194c394ecc0ae2c92790d0f578efff6 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.felix.ipojo.manipulator.store.mapper;
import java.util.ArrayList;
import java.util.List;
import org.apache.felix.ipojo.manipulator.store.ResourceMapper;
/**
* A {@code WABResourceMapper} knows how to map resource names for a Web Application Bundle (WAB).
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class WABResourceMapper implements ResourceMapper {
public static final String WEB_INF_CLASSES = "WEB-INF/classes/";
/**
* Store externalized names so that internalize can rebuild the good resource name.
*/
private List<String> mappedNames = new ArrayList<String>();
public String internalize(String name) {
if (mappedNames.contains(name)) {
return WEB_INF_CLASSES + name;
}
return name;
}
public String externalize(String name) {
if (name.startsWith(WEB_INF_CLASSES)) {
String externalized = name.substring(WEB_INF_CLASSES.length());
mappedNames.add(externalized);
return externalized;
}
// Leave the name unchanged
// (it's probably META-INF/** or WEB-INF/lib/**)
return name;
}
}