001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.app.componentxml.propertypeer;
031:
032: import org.w3c.dom.Element;
033: import org.w3c.dom.NodeList;
034:
035: import nextapp.echo2.app.Color;
036: import nextapp.echo2.app.FillImage;
037: import nextapp.echo2.app.FillImageBorder;
038: import nextapp.echo2.app.Insets;
039: import nextapp.echo2.app.componentxml.InvalidPropertyException;
040: import nextapp.echo2.app.componentxml.PropertyLoader;
041: import nextapp.echo2.app.componentxml.PropertyXmlPeer;
042: import nextapp.echo2.app.util.DomUtil;
043:
044: /**
045: * <code>PropertyXmlPeer</code> implementation for
046: * <code>nextapp.echo2.app.FillImageBorder</code> properties.
047: */
048: public class FillImageBorderPeer implements PropertyXmlPeer {
049:
050: /**
051: * @see nextapp.echo2.app.componentxml.PropertyXmlPeer#getValue(java.lang.ClassLoader, java.lang.Class, org.w3c.dom.Element)
052: */
053: public Object getValue(ClassLoader classLoader, Class objectClass,
054: Element propertyElement) throws InvalidPropertyException {
055: Element fillImageBorderElement = DomUtil
056: .getChildElementByTagName(propertyElement,
057: "fill-image-border");
058: if (fillImageBorderElement == null) {
059: throw new InvalidPropertyException(
060: "Invalid FillImageBorder property.", null);
061: }
062:
063: FillImageBorder fillImageBorder = new FillImageBorder();
064: PropertyLoader propertyLoader = PropertyLoader
065: .forClassLoader(classLoader);
066:
067: if (fillImageBorderElement.hasAttribute("color")) {
068: Color color = ColorPeer.toColor(fillImageBorderElement
069: .getAttribute("color"));
070: fillImageBorder.setColor(color);
071: }
072: if (fillImageBorderElement.hasAttribute("border-insets")) {
073: Insets insets = InsetsPeer.toInsets(fillImageBorderElement
074: .getAttribute("border-insets"));
075: fillImageBorder.setBorderInsets(insets);
076: }
077: if (fillImageBorderElement.hasAttribute("content-insets")) {
078: Insets insets = InsetsPeer.toInsets(fillImageBorderElement
079: .getAttribute("content-insets"));
080: fillImageBorder.setContentInsets(insets);
081: }
082:
083: NodeList borderPartList = fillImageBorderElement
084: .getElementsByTagName("border-part");
085: int borderPartCount = borderPartList.getLength();
086: for (int i = 0; i < borderPartCount; ++i) {
087: Element borderPartElement = (Element) borderPartList
088: .item(i);
089: String position = borderPartElement
090: .getAttribute("position");
091:
092: FillImage fillImage = (FillImage) propertyLoader
093: .getPropertyValue(FillImageBorder.class,
094: FillImage.class, borderPartElement);
095:
096: if ("top-left".equals(position)) {
097: fillImageBorder.setFillImage(FillImageBorder.TOP_LEFT,
098: fillImage);
099: } else if ("top".equals(position)) {
100: fillImageBorder.setFillImage(FillImageBorder.TOP,
101: fillImage);
102: } else if ("top-right".equals(position)) {
103: fillImageBorder.setFillImage(FillImageBorder.TOP_RIGHT,
104: fillImage);
105: } else if ("left".equals(position)) {
106: fillImageBorder.setFillImage(FillImageBorder.LEFT,
107: fillImage);
108: } else if ("right".equals(position)) {
109: fillImageBorder.setFillImage(FillImageBorder.RIGHT,
110: fillImage);
111: } else if ("bottom-left".equals(position)) {
112: fillImageBorder.setFillImage(
113: FillImageBorder.BOTTOM_LEFT, fillImage);
114: } else if ("bottom".equals(position)) {
115: fillImageBorder.setFillImage(FillImageBorder.BOTTOM,
116: fillImage);
117: } else if ("bottom-right".equals(position)) {
118: fillImageBorder.setFillImage(
119: FillImageBorder.BOTTOM_RIGHT, fillImage);
120: }
121: }
122:
123: return fillImageBorder;
124: }
125: }
|