67 |
67 |
Vector east = new Vector();
|
68 |
68 |
Vector north = new Vector();
|
69 |
69 |
|
70 |
|
String title = null;
|
|
70 |
String title = "";
|
71 |
71 |
String docid = null;
|
72 |
72 |
|
73 |
73 |
/**
|
... | ... | |
75 |
75 |
*
|
76 |
76 |
* @param docid The document id to be represented spatially
|
77 |
77 |
* @param dbconn The database connection shared from the refering method.
|
78 |
|
* @todo Rewrite the title query to use xml_path_index
|
79 |
78 |
*/
|
80 |
79 |
public SpatialDocument( String docid , DBConnection dbconn ) {
|
81 |
80 |
|
... | ... | |
83 |
82 |
PreparedStatement pstmt = null;
|
84 |
83 |
ResultSet rs = null;
|
85 |
84 |
this.dbconn = dbconn;
|
86 |
|
|
|
85 |
boolean isSpatialDocument = false;
|
|
86 |
String thisDocname = null;
|
|
87 |
String westPath = null;
|
|
88 |
String eastPath = null;
|
|
89 |
String northPath = null;
|
|
90 |
String southPath = null;
|
|
91 |
|
87 |
92 |
/*
|
88 |
|
* Get the bounding coordinates
|
|
93 |
* Determine the docname/schema and decide how to proceed with
|
|
94 |
* spatial harvest
|
89 |
95 |
*/
|
90 |
|
String query = "SELECT path, nodedatanumerical, parentnodeid FROM xml_path_index"
|
91 |
|
+ " WHERE docid = '" + docid.trim() + "'"
|
92 |
|
+ " AND docid IN (SELECT distinct docid FROM xml_access WHERE docid = '" + docid.trim()
|
93 |
|
+ "' AND principal_name = 'public' AND perm_type = 'allow')"
|
94 |
|
+ " AND (path = '" + MetaCatUtil.getOption("westBoundingCoordinatePath") + "'"
|
95 |
|
+ " OR path = '" + MetaCatUtil.getOption("southBoundingCoordinatePath") + "'"
|
96 |
|
+ " OR path = '" + MetaCatUtil.getOption("eastBoundingCoordinatePath") + "'"
|
97 |
|
+ " OR path = '" + MetaCatUtil.getOption("northBoundingCoordinatePath") + "'"
|
98 |
|
+ " ) ORDER BY parentnodeid;";
|
99 |
|
|
|
96 |
String query = "SELECT docname FROM xml_documents WHERE docid='" + docid.trim() + "';";
|
|
97 |
String docname = "";
|
100 |
98 |
try {
|
101 |
99 |
pstmt = dbconn.prepareStatement(query);
|
102 |
100 |
pstmt.execute();
|
103 |
101 |
rs = pstmt.getResultSet();
|
104 |
102 |
while (rs.next()) {
|
105 |
|
if ( rs.getString(1).equals( MetaCatUtil.getOption("westBoundingCoordinatePath") ) )
|
106 |
|
this.west.add( new Float(rs.getFloat(2)) );
|
107 |
|
else if ( rs.getString(1).equals( MetaCatUtil.getOption("southBoundingCoordinatePath") ) )
|
108 |
|
this.south.add( new Float(rs.getFloat(2)));
|
109 |
|
else if ( rs.getString(1).equals( MetaCatUtil.getOption("eastBoundingCoordinatePath") ) )
|
110 |
|
this.east.add( new Float(rs.getFloat(2)) );
|
111 |
|
else if ( rs.getString(1).equals( MetaCatUtil.getOption("northBoundingCoordinatePath") ) )
|
112 |
|
this.north.add( new Float(rs.getFloat(2)) );
|
113 |
|
else
|
114 |
|
log.error("** An xml path not related to your bounding coordinates was returned by this query \n" + query + "\n");
|
|
103 |
docname = rs.getString(1);
|
115 |
104 |
}
|
116 |
105 |
rs.close();
|
117 |
106 |
pstmt.close();
|
118 |
107 |
}
|
119 |
108 |
catch(Exception e) {
|
120 |
|
log.error(" ---- Could not get bounding coordinates for " + docid );
|
|
109 |
log.error(" ---- Could not get docname for " + docid );
|
121 |
110 |
e.printStackTrace();
|
122 |
111 |
}
|
|
112 |
if (docname == null)
|
|
113 |
docname = "";
|
123 |
114 |
|
124 |
|
/*
|
125 |
|
* Get the title
|
126 |
|
*/
|
127 |
|
String docTitlePath = MetaCatUtil.getOption("docTitle");
|
128 |
|
query = "select nodedata from xml_path_index where path = '"
|
129 |
|
+ docTitlePath.trim() + "' and docid = '" + docid.trim() + "'";
|
|
115 |
// Loop through all our spatial docnames and determine if the current document matches
|
|
116 |
// If so, get the appropriate corner xpaths
|
|
117 |
Vector spatialDocnames = MetaCatUtil.getOptionList( MetaCatUtil.getOption("spatialDocnameList") );
|
|
118 |
for (int i = 0; i < spatialDocnames.size(); i++) {
|
|
119 |
thisDocname = ((String)spatialDocnames.elementAt(i)).trim();
|
|
120 |
if ( docname.trim().equals(thisDocname) ) {
|
|
121 |
isSpatialDocument = true;
|
130 |
122 |
|
131 |
|
try {
|
132 |
|
pstmt = dbconn.prepareStatement(query);
|
133 |
|
pstmt.execute();
|
134 |
|
rs = pstmt.getResultSet();
|
135 |
|
if (rs.next())
|
136 |
|
this.title = rs.getString(1);
|
137 |
|
//log.warn(" \n\n****** TITLE query is " + query + " \n\n");
|
138 |
|
rs.close();
|
139 |
|
pstmt.close();
|
|
123 |
// determine its east,west,north and south coord xpaths
|
|
124 |
westPath = MetaCatUtil.getOption(thisDocname + "_westBoundingCoordinatePath");
|
|
125 |
eastPath = MetaCatUtil.getOption(thisDocname + "_eastBoundingCoordinatePath");
|
|
126 |
northPath = MetaCatUtil.getOption(thisDocname + "_northBoundingCoordinatePath");
|
|
127 |
southPath = MetaCatUtil.getOption(thisDocname + "_southBoundingCoordinatePath");
|
|
128 |
}
|
140 |
129 |
}
|
141 |
|
catch(Exception e) {
|
142 |
|
log.error(" **** Error getting docids from getTitle for docid = "+docid);
|
143 |
|
e.printStackTrace();
|
144 |
|
log.error(" query ============== \n " + query);
|
145 |
|
this.title = docid;
|
146 |
|
}
|
147 |
130 |
|
148 |
|
/* try {
|
149 |
|
dbconn.close();
|
150 |
|
} catch( java.sql.SQLException e ) {
|
151 |
|
log.error("java.sql.SQLException");
|
|
131 |
// If it is a spatial document, harvest the corners and title
|
|
132 |
if (isSpatialDocument) {
|
|
133 |
|
|
134 |
/*
|
|
135 |
* Get the bounding coordinates
|
|
136 |
*/
|
|
137 |
query = "SELECT path, nodedatanumerical, parentnodeid FROM xml_path_index"
|
|
138 |
+ " WHERE docid = '" + docid.trim() + "'"
|
|
139 |
+ " AND docid IN (SELECT distinct docid FROM xml_access WHERE docid = '" + docid.trim()
|
|
140 |
+ "' AND principal_name = 'public' AND perm_type = 'allow')"
|
|
141 |
+ " AND (path = '" + westPath + "'"
|
|
142 |
+ " OR path = '" + southPath + "'"
|
|
143 |
+ " OR path = '" + eastPath + "'"
|
|
144 |
+ " OR path = '" + northPath + "'"
|
|
145 |
+ " ) ORDER BY parentnodeid;";
|
|
146 |
|
|
147 |
try {
|
|
148 |
pstmt = dbconn.prepareStatement(query);
|
|
149 |
pstmt.execute();
|
|
150 |
rs = pstmt.getResultSet();
|
|
151 |
while (rs.next()) {
|
|
152 |
if ( rs.getString(1).equals(westPath) )
|
|
153 |
this.west.add( new Float(rs.getFloat(2)) );
|
|
154 |
else if ( rs.getString(1).equals(southPath) )
|
|
155 |
this.south.add( new Float(rs.getFloat(2)) );
|
|
156 |
else if ( rs.getString(1).equals(eastPath) )
|
|
157 |
this.east.add( new Float(rs.getFloat(2)) );
|
|
158 |
else if ( rs.getString(1).equals(northPath) )
|
|
159 |
this.north.add( new Float(rs.getFloat(2)) );
|
|
160 |
else
|
|
161 |
log.error("** An xml path not related to your bounding coordinates was returned by this query \n" + query + "\n");
|
|
162 |
}
|
|
163 |
rs.close();
|
|
164 |
pstmt.close();
|
|
165 |
}
|
|
166 |
catch(Exception e) {
|
|
167 |
log.error(" ---- Could not get bounding coordinates for " + docid );
|
|
168 |
e.printStackTrace();
|
|
169 |
}
|
|
170 |
|
|
171 |
/*
|
|
172 |
* Get the title
|
|
173 |
*/
|
|
174 |
String docTitlePath = MetaCatUtil.getOption("docTitle");
|
|
175 |
query = "select nodedata from xml_path_index where path = '"
|
|
176 |
+ docTitlePath.trim() + "' and docid = '" + docid.trim() + "'";
|
|
177 |
|
|
178 |
try {
|
|
179 |
pstmt = dbconn.prepareStatement(query);
|
|
180 |
pstmt.execute();
|
|
181 |
rs = pstmt.getResultSet();
|
|
182 |
if (rs.next())
|
|
183 |
this.title = rs.getString(1);
|
|
184 |
rs.close();
|
|
185 |
pstmt.close();
|
|
186 |
}
|
|
187 |
catch(Exception e) {
|
|
188 |
log.error(" **** Error getting docids from getTitle for docid = "+docid);
|
|
189 |
e.printStackTrace();
|
|
190 |
this.title = docid;
|
|
191 |
}
|
152 |
192 |
}
|
153 |
|
*/
|
154 |
193 |
|
155 |
194 |
}
|
156 |
195 |
|
Added preliminary support for multiple spatial schemas in the same metacat instance .. bug 2551