Source Code Cross Referenced for IIOMetadataDumper.java in  » GIS » GeoTools-2.4.1 » org » geotools » coverage » grid » io » imageio » 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 » GIS » GeoTools 2.4.1 » org.geotools.coverage.grid.io.imageio 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.geotools.coverage.grid.io.imageio;
002:
003:        import javax.imageio.metadata.IIOMetadata;
004:        import javax.imageio.metadata.IIOMetadataFormat;
005:        import javax.imageio.metadata.IIOMetadataNode;
006:
007:        import org.w3c.dom.NamedNodeMap;
008:        import org.w3c.dom.Node;
009:
010:        /**
011:         * Utility calss that can be used to dump a DOM tree in a formatted way.
012:         * <p>
013:         * It is useful for inspecting the metadata inside GeoTiff files.
014:         * 
015:         * @author Simone Giannecchini
016:         * @since 2.3.x
017:         */
018:        public final class IIOMetadataDumper {
019:
020:            /** Root of the XML tree to display. */
021:            private Node root;
022:
023:            /**
024:             * The {@link IIOMetadataFormat} name to print out the {@link IIOMetadata}
025:             * for.
026:             */
027:            private volatile String formatName = "";
028:
029:            /** The encoded {@link IIOMetadata} as a simple {@link String}. */
030:            private String metadata;
031:
032:            /**
033:             * Constructor for a {@link IIOMetadataDumper} accepting and
034:             * {@link IIOMetadata} and a {@link String} for the format name of the XML
035:             * metadata to use.
036:             * 
037:             * @param metadata
038:             *            The metadta to display.
039:             * @param name
040:             *            The format of the metaata to display.
041:             */
042:            public IIOMetadataDumper(IIOMetadata metadata, String name) {
043:                this .root = metadata.getAsTree(name);
044:                StringBuffer buff = new StringBuffer();
045:                parseMetadata(buff, root, 0);
046:                this .formatName = name;
047:                this .metadata = buff.toString();
048:
049:            }
050:
051:            /**
052:             * Constructor for a {@link IIOMetadataDumper} accepting an
053:             * {@link IIOMetadataNode}. It has no way to choose the format of the
054:             * metadata to parse since this choice has been alreadu done previously.
055:             * 
056:             * @param rootNode
057:             */
058:            public IIOMetadataDumper(IIOMetadataNode rootNode) {
059:                this .root = rootNode;
060:                StringBuffer buff = new StringBuffer();
061:                parseMetadata(buff, root, 0);
062:                this .metadata = buff.toString();
063:            }
064:
065:            /**
066:             * Adds indentation to the tree while we build it
067:             * 
068:             * @param buff
069:             * @param level
070:             */
071:            private void indent(StringBuffer buff, int level) {
072:                for (int i = 0; i < level; i++) {
073:                    buff.append("  ");
074:                }
075:            }
076:
077:            /**
078:             * Builds a graphical representation of a certain XML tree.
079:             * 
080:             * @param buff
081:             * @param node
082:             * @param level
083:             */
084:            private void parseMetadata(StringBuffer buff, Node node, int level) {
085:                indent(buff, level); // emit open tag
086:                buff.append("<").append(node.getNodeName());
087:                NamedNodeMap map = node.getAttributes();
088:                if (map != null) { // print attribute values
089:                    int length = map.getLength();
090:                    for (int i = 0; i < length; i++) {
091:                        Node attr = map.item(i);
092:                        buff.append(" ").append(attr.getNodeName()).append(
093:                                "=\"").append(attr.getNodeValue()).append("\"");
094:                    }
095:                }
096:
097:                Node child = node.getFirstChild();
098:                if (child != null) {
099:                    buff.append(">\n"); // close current tag
100:                    while (child != null) { // emit child tags recursively
101:                        parseMetadata(buff, child, level + 1);
102:                        child = child.getNextSibling();
103:                    }
104:                    indent(buff, level); // emit close tag
105:                    buff.append("</").append(node.getNodeName()).append(">\n");
106:                } else {
107:                    buff.append("/>\n");
108:                }
109:            }
110:
111:            /**
112:             * Allows me to get the generated XML representation for the underlying
113:             * tree;
114:             * 
115:             * @return A formatted XML string.
116:             */
117:            public synchronized String getMetadata() {
118:                return metadata;
119:            }
120:
121:            /**
122:             * Retrieves the name of the format we want to get the XML representation
123:             * for.
124:             * 
125:             * @return The name of the format we want to get the XML representation for.
126:             */
127:            public String getFormatName() {
128:                return formatName;
129:            }
130:
131:            /**
132:             * Sets the name of the format we want to get the XML representation for.
133:             * <p>
134:             * This method causes a new generation of the string representation if the
135:             * format is different from the one stored.
136:             * 
137:             * @param formatName
138:             *            The name of the format we want to get the XML representation
139:             *            for.
140:             */
141:            public synchronized void setFormatName(String formatName) {
142:                if (this .formatName.equalsIgnoreCase(formatName))
143:                    return;
144:                StringBuffer buff = new StringBuffer();
145:                parseMetadata(buff, root, 0);
146:                this.formatName = formatName;
147:                this.metadata = buff.toString();
148:
149:            }
150:
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.