You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by th...@apache.org on 2008/10/07 15:10:30 UTC
svn commit: r702470 -
/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XMLProperties.java
Author: thorsten
Date: Tue Oct 7 06:10:29 2008
New Revision: 702470
URL: http://svn.apache.org/viewvc?rev=702470&view=rev
Log:
Adding helper class to parse our properties files and add the key/values pairs to the parameters (later used in xsl)
Added:
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XMLProperties.java (with props)
Added: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XMLProperties.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XMLProperties.java?rev=702470&view=auto
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XMLProperties.java (added)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XMLProperties.java Tue Oct 7 06:10:29 2008
@@ -0,0 +1,76 @@
+/*
+ * 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.forrest.dispatcher.impl.helper;
+
+import java.io.InputStream;
+import java.util.Map;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+public class XMLProperties {
+
+ private XMLProperties (){
+ }
+
+ public static void parseProperties(InputStream stream, Map<String, Object> map) throws XMLStreamException{
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(stream);
+ boolean loop = true;
+ String elemName = null, value = "", key = "";
+ while (loop) {
+ int event = reader.next();
+
+ switch (event) {
+ case XMLStreamConstants.END_DOCUMENT:
+ loop = false;
+ break;
+
+ case XMLStreamConstants.END_ELEMENT:
+ elemName = reader.getLocalName();
+ if (elemName.equals(Captions.PROPERTY_ELEMENT)) {
+ if (!map.containsKey(key)) {
+ map.put(key, value);
+ }
+ key = "";
+ value = "";
+ }
+ break;
+
+ case XMLStreamConstants.START_ELEMENT:
+ elemName = reader.getLocalName();
+ if (elemName.equals(Captions.PROPERTY_ELEMENT)) {
+ for (int i = 0; i < reader.getAttributeCount(); i++) {
+ // Get attribute name
+ String localName = reader.getAttributeLocalName(i);
+ String localValue = reader.getAttributeValue(i);
+ if (localName.equals(Captions.NAME_ATT)) {
+ key = localValue;
+ } else if (localName.equals(Captions.VALUE_ATT)) {
+ value = localValue;
+ }
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+}
Propchange: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XMLProperties.java
------------------------------------------------------------------------------
svn:eol-style = native