Source Code Cross Referenced for XMPArray.java in  » Graphic-Library » xmlgraphics-commons-1.2 » org » apache » xmlgraphics » xmp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Graphic Library » xmlgraphics commons 1.2 » org.apache.xmlgraphics.xmp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        /* $Id: XMPArray.java 426584 2006-07-28 16:01:47Z jeremias $ */
019:
020:        package org.apache.xmlgraphics.xmp;
021:
022:        import java.util.List;
023:
024:        import org.xml.sax.ContentHandler;
025:        import org.xml.sax.SAXException;
026:        import org.xml.sax.helpers.AttributesImpl;
027:
028:        /**
029:         * Represents an XMP array as defined by the XMP specification.
030:         * @todo Property qualifiers are currently not supported, yet. 
031:         */
032:        public class XMPArray extends XMPComplexValue {
033:
034:            private XMPArrayType type;
035:            private List values = new java.util.ArrayList();
036:            private List xmllang = new java.util.ArrayList();
037:
038:            /**
039:             * Main constructor
040:             * @param type the intended type of array
041:             */
042:            public XMPArray(XMPArrayType type) {
043:                this .type = type;
044:            }
045:
046:            /** @return the type of array */
047:            public XMPArrayType getType() {
048:                return this .type;
049:            }
050:
051:            /**
052:             * Returns the value at a given position
053:             * @param idx the index of the requested value
054:             * @return the value at the given position
055:             */
056:            public Object getValue(int idx) {
057:                return this .values.get(idx);
058:            }
059:
060:            /** @see org.apache.xmlgraphics.xmp.XMPComplexValue#getSimpleValue() */
061:            public Object getSimpleValue() {
062:                if (values.size() == 1) {
063:                    return getValue(0);
064:                } else {
065:                    return null;
066:                }
067:            }
068:
069:            /**
070:             * Returns a language-dependant values (available for alternative arrays).
071:             * @param lang the language ("x-default" for the default value)
072:             * @return the requested value
073:             */
074:            public String getLangValue(String lang) {
075:                String v = null;
076:                for (int i = 0, c = values.size(); i < c; i++) {
077:                    String l = (String) xmllang.get(i);
078:                    if ((l == null && lang == null)
079:                            || (l != null && l.equals(lang))) {
080:                        v = values.get(i).toString();
081:                        break;
082:                    }
083:                }
084:                if (lang == null && v == null) {
085:                    v = getLangValue(XMPConstants.DEFAULT_LANGUAGE);
086:                    if (v == null && values.size() > 0) {
087:                        v = getValue(0).toString(); //get first
088:                    }
089:                }
090:                return v;
091:            }
092:
093:            /**
094:             * Removes a language-dependant value
095:             * @param lang the language ("x-default" for the default value)
096:             */
097:            public void removeLangValue(String lang) {
098:                if (lang == null && "".equals(lang)) {
099:                    return;
100:                }
101:                for (int i = 0, c = values.size(); i < c; i++) {
102:                    String l = (String) xmllang.get(i);
103:                    if (lang.equals(l)) {
104:                        values.remove(i);
105:                        xmllang.remove(i);
106:                        return;
107:                    }
108:                }
109:            }
110:
111:            /**
112:             * Adds a new value to the array
113:             * @param value the value
114:             */
115:            public void add(Object value) {
116:                values.add(value);
117:                xmllang.add(null);
118:            }
119:
120:            /**
121:             * Adds a language-dependant value to the array. Make sure not to add the same language twice.
122:             * @param value the value
123:             * @param lang the language ("x-default" for the default value)
124:             */
125:            public void add(String value, String lang) {
126:                values.add(value);
127:                xmllang.add(lang);
128:            }
129:
130:            /** @return the current number of value in the array */
131:            public int getSize() {
132:                return this .values.size();
133:            }
134:
135:            /**
136:             * Converts the array to an object array.
137:             * @return an object array of all values in the array
138:             */
139:            public Object[] toObjectArray() {
140:                Object[] res = new Object[getSize()];
141:                for (int i = 0, c = res.length; i < c; i++) {
142:                    res[i] = getValue(i);
143:                }
144:                return res;
145:            }
146:
147:            /** @see org.apache.xmlgraphics.util.XMLizable#toSAX(org.xml.sax.ContentHandler) */
148:            public void toSAX(ContentHandler handler) throws SAXException {
149:                AttributesImpl atts = new AttributesImpl();
150:                handler.startElement(XMPConstants.RDF_NAMESPACE,
151:                        type.getName(), "rdf:" + type.getName(), atts);
152:                for (int i = 0, c = values.size(); i < c; i++) {
153:                    String value = (String) values.get(i);
154:                    String lang = (String) xmllang.get(i);
155:                    atts.clear();
156:                    if (lang != null) {
157:                        atts.addAttribute(XMPConstants.XML_NS, "lang",
158:                                "xml:lang", "CDATA", lang);
159:                    }
160:                    handler.startElement(XMPConstants.RDF_NAMESPACE, "li",
161:                            "rdf:li", atts);
162:                    char[] chars = value.toCharArray();
163:                    handler.characters(chars, 0, chars.length);
164:                    handler.endElement(XMPConstants.RDF_NAMESPACE, "li",
165:                            "rdf:li");
166:                }
167:                handler.endElement(XMPConstants.RDF_NAMESPACE, type.getName(),
168:                        "rdf:" + type.getName());
169:            }
170:
171:            /** @see java.lang.Object#toString() */
172:            public String toString() {
173:                return "XMP array: " + type + ", " + getSize();
174:            }
175:
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.