This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.provisioning.model-1.0.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-provisioning-model.git
commit 252bf2d4c21800342af397f7df75d42472843809 Author: Carsten Ziegeler <cziege...@apache.org> AuthorDate: Tue Sep 30 08:13:47 2014 +0000 Remove support for xml git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/slingstart-model@1628370 13f79535-47bb-0310-9956-ffa450edef68 --- .../slingstart/model/xml/XMLSSMModelReader.java | 356 --------------------- .../slingstart/model/xml/XMLSSMModelWriter.java | 215 ------------- .../sling/slingstart/model/xml/package-info.java | 24 -- 3 files changed, 595 deletions(-) diff --git a/src/main/java/org/apache/sling/slingstart/model/xml/XMLSSMModelReader.java b/src/main/java/org/apache/sling/slingstart/model/xml/XMLSSMModelReader.java deleted file mode 100644 index a95665a..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/xml/XMLSSMModelReader.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * 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.sling.slingstart.model.xml; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.LineNumberReader; -import java.io.Reader; -import java.io.StringReader; -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.Map; -import java.util.Properties; -import java.util.Stack; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.apache.felix.cm.file.ConfigurationHandler; -import org.apache.sling.slingstart.model.SSMArtifact; -import org.apache.sling.slingstart.model.SSMConfiguration; -import org.apache.sling.slingstart.model.SSMDeliverable; -import org.apache.sling.slingstart.model.SSMFeature; -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; - -/** - * Simple XML parser for the model. - * It ignores all elements in a different namespace than the root element - */ -public class XMLSSMModelReader { - - public enum MODE { - INIT(null, null), - DELIVERABLE(INIT, "deliverable"), - - VARIABKES(DELIVERABLE, "variables"), - - STARTLEVEL(DELIVERABLE, "startLevel"), - ARTIFACT(DELIVERABLE, "artifact"), - - STARTLEVEL_ARTIFACT(STARTLEVEL, "artifact"), - - CONFIGURATION(DELIVERABLE, "configuration"), - SETTINGS(DELIVERABLE, "settings"), - - FEATURE(DELIVERABLE, "feature"), - FEATURE_STARTLEVEL(FEATURE, "startLevel"), - FEATURE_ARTIFACT(FEATURE, "artifact"), - FEATURE_STARTLEVEL_ARTIFACT(FEATURE_STARTLEVEL, "artifact"), - - FEATURE_CONFIGURATION(FEATURE, "configuration"), - FEATURE_SETTINGS(FEATURE, "settings"); - - public final MODE fromMode; - public final String elementName; - - MODE(final MODE fm, final String en) { - this.fromMode = fm; - this.elementName = en; - } - } - - /** - * Reads the deliverable file - * The reader is not closed. - * @throws IOException - */ - public static SSMDeliverable read(final Reader reader) - throws IOException { - try { - final SSMDeliverable result = new SSMDeliverable(); - - final SAXParserFactory spf = SAXParserFactory.newInstance(); - spf.setNamespaceAware(true); - SAXParser saxParser = spf.newSAXParser(); - XMLReader xmlReader = saxParser.getXMLReader(); - xmlReader.setContentHandler(new ContentHandler() { - - private final Stack<String> elementsStack = new Stack<String>(); - - /** The current parsing mode. */ - private MODE mode = MODE.INIT; - - /** String builder to get text from the document. */ - private StringBuilder text; - - /** The namespace for the read xml elements. */ - private String namespace; - - /** The current feature */ - private SSMFeature feature; - - /** Current startlevel */ - private int startLevel; - - /** Current configuration. */ - private SSMConfiguration configuration; - - /** Felix config format (default) */ - private boolean isFelixConfigurationFormat = true; - - @Override - public void startElement(final String uri, - final String localName, - final String qName, - final Attributes atts) - throws SAXException { - if ( this.mode == MODE.INIT ) { - if ( MODE.DELIVERABLE.elementName.equals(localName) ) { - this.namespace = uri; - this.mode = MODE.DELIVERABLE; - this.feature = result.getOrCreateFeature(null); - this.startLevel = 0; - } else { - throw new SAXException("Unknown root element (" + localName + "). Document must start with " + MODE.DELIVERABLE.elementName); - } - } else { - if ( (uri == null && this.namespace == null) || (uri != null && uri.equals(this.namespace)) ) { - boolean found = false; - for(final MODE m : MODE.values()) { - if ( this.mode == m.fromMode && localName.equals(m.elementName) ) { - this.mode = m; - found = true; - break; - } - } - if ( !found ) { - throw new SAXException("Unknown element " + localName); - } - - if ( this.mode == MODE.STARTLEVEL || this.mode == MODE.FEATURE_STARTLEVEL) { - int level = 0; - final String levelVal = atts.getValue("level"); - if ( levelVal != null ) { - level = Integer.valueOf(levelVal); - } - this.startLevel = level; - } else if ( this.mode == MODE.ARTIFACT || this.mode == MODE.FEATURE_ARTIFACT || this.mode == MODE.STARTLEVEL_ARTIFACT || this.mode == MODE.FEATURE_STARTLEVEL_ARTIFACT) { - final SSMArtifact artifact = new SSMArtifact(atts.getValue("groupId"), - atts.getValue("artifactId"), - atts.getValue("version"), - atts.getValue("classifier"), - atts.getValue("type")); - this.feature.getOrCreateStartLevel(this.startLevel).getArtifacts().add(artifact); - } else if ( this.mode == MODE.CONFIGURATION || this.mode == MODE.FEATURE_CONFIGURATION) { - this.configuration = this.feature.getOrCreateConfiguration(atts.getValue("pid"), atts.getValue("factory")); - this.isFelixConfigurationFormat = !"true".equals(atts.getValue("props")); - this.text = new StringBuilder(); - } else if ( this.mode == MODE.SETTINGS || this.mode == MODE.FEATURE_SETTINGS) { - this.text = new StringBuilder(); - - } else if ( this.mode == MODE.FEATURE ) { - final String runMode = atts.getValue("runModes"); - if ( runMode == null || runMode.trim().length() == 0 ) { - throw new SAXException("Required attribute runModes missing for runMode element"); - } - this.feature = result.getOrCreateFeature(runMode.split(",")); - this.startLevel = 0; - - } else { - this.text = new StringBuilder(); - } - } - } - elementsStack.push(localName); - } - - @Override - public void endElement(final String uri, final String localName, final String qName) - throws SAXException { - final String openElement = this.elementsStack.pop(); - if ( !openElement.equals(localName) ) { - throw new SAXException("Invalid document - expected closing " + openElement + " but received " + localName); - } - if ( (uri == null && this.namespace == null) || (uri != null && uri.equals(this.namespace)) ) { - String textValue = (text != null ? text.toString() : null); - if ( textValue != null ) { - textValue = textValue.trim(); - if ( textValue.length() == 0 ) { - textValue = null; - } - } - text = null; - boolean found = false; - final MODE prevMode = this.mode; - for(final MODE m : MODE.values()) { - if ( this.mode == m && localName.equals(m.elementName) ) { - this.mode = m.fromMode; - found = true; - break; - } - } - if ( !found ) { - throw new SAXException("Unknown element " + localName); - } - if ( prevMode == MODE.STARTLEVEL || prevMode == MODE.FEATURE_STARTLEVEL ) { - this.startLevel = 0; - } else if ( prevMode == MODE.CONFIGURATION || prevMode == MODE.FEATURE_CONFIGURATION ) { - if ( this.configuration.isSpecial() ) { - this.configuration.getProperties().put(this.configuration.getPid(), textValue); - } else { - if ( this.isFelixConfigurationFormat ) { - ByteArrayInputStream bais = null; - try { - bais = new ByteArrayInputStream(textValue.getBytes("UTF-8")); - @SuppressWarnings("unchecked") - final Dictionary<String, Object> props = ConfigurationHandler.read(bais); - final Enumeration<String> e = props.keys(); - while ( e.hasMoreElements() ) { - final String key = e.nextElement(); - this.configuration.getProperties().put(key, props.get(key)); - } - } catch ( final IOException ioe ) { - throw new SAXException(ioe); - } finally { - if ( bais != null ) { - try { - bais.close(); - } catch ( final IOException ignore ) { - // ignore - } - } - } - } else { - final Properties props = new Properties(); - try { - props.load(new StringReader(textValue)); - } catch ( final IOException ioe ) { - throw new SAXException(ioe); - } - for(final Map.Entry<Object, Object> entry : props.entrySet()) { - this.configuration.getProperties().put((String)entry.getKey(), (String)entry.getValue()); - } - } - } - this.configuration = null; - } else if ( prevMode == MODE.SETTINGS || prevMode == MODE.FEATURE_SETTINGS) { - final LineNumberReader reader = new LineNumberReader(new StringReader(textValue)); - String line = null; - try { - while ( (line = reader.readLine()) != null ) { - if ( line.startsWith("#") || line.trim().isEmpty()) { - continue; - } - final int pos = line.indexOf("="); - if ( pos == -1 || line.indexOf("=", pos + 1 ) != -1 ) { - throw new SAXException("Invalid property definition: " + line); - } - feature.getSettings().put(line.substring(0, pos), line.substring(pos + 1)); - } - } catch (final IOException io) { - throw new SAXException(io); - } - } else if ( prevMode == MODE.FEATURE ) { - this.feature = result.getOrCreateFeature(null); - this.startLevel = 0; - } else if ( prevMode == MODE.VARIABKES ) { - final LineNumberReader reader = new LineNumberReader(new StringReader(textValue)); - String line = null; - try { - while ( (line = reader.readLine()) != null ) { - final int pos = line.indexOf("="); - if ( pos == -1 || line.indexOf("=", pos + 1 ) != -1 ) { - throw new SAXException("Invalid property definition: " + line); - } - result.getVariables().put(line.substring(0, pos), line.substring(pos + 1)); - } - } catch (final IOException io) { - throw new SAXException(io); - } - } - } - } - - @Override - public void characters(final char[] ch, final int start, final int length) - throws SAXException { - if ( text != null ) { - text.append(ch, start, length); - } - } - - @Override - public void startDocument() throws SAXException { - // nothing to do - } - - @Override - public void skippedEntity(final String name) throws SAXException { - // nothing to do - } - - @Override - public void setDocumentLocator(final Locator locator) { - // nothing to do - } - - @Override - public void processingInstruction(final String target, final String data) - throws SAXException { - // nothing to do - } - - @Override - public void ignorableWhitespace(final char[] ch, final int start,final int length) - throws SAXException { - // nothing to do - } - - @Override - public void startPrefixMapping(final String prefix, final String uri) - throws SAXException { - // nothing to do - } - - @Override - public void endPrefixMapping(final String prefix) throws SAXException { - // nothing to do - } - - @Override - public void endDocument() throws SAXException { - // nothing to do - } - - }); - xmlReader.parse(new InputSource(reader)); - - return result; - } catch ( final SAXException se) { - throw new IOException(se); - } catch ( final ParserConfigurationException pce ) { - throw new IOException(pce); - } - } -} diff --git a/src/main/java/org/apache/sling/slingstart/model/xml/XMLSSMModelWriter.java b/src/main/java/org/apache/sling/slingstart/model/xml/XMLSSMModelWriter.java deleted file mode 100644 index 5d13094..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/xml/XMLSSMModelWriter.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * 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.sling.slingstart.model.xml; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.Writer; -import java.util.Map; - -import org.apache.felix.cm.file.ConfigurationHandler; -import org.apache.sling.slingstart.model.SSMArtifact; -import org.apache.sling.slingstart.model.SSMConfiguration; -import org.apache.sling.slingstart.model.SSMDeliverable; -import org.apache.sling.slingstart.model.SSMFeature; -import org.apache.sling.slingstart.model.SSMStartLevel; - -/** - * Simple writer for the a model - */ -public class XMLSSMModelWriter { - - private static void printRunModeAttribute(final PrintWriter pw, final SSMFeature rmd) { - if ( rmd.getRunModes() != null && rmd.getRunModes().length > 0 ) { - pw.print(" modes=\""); - boolean first = true; - for(final String mode : rmd.getRunModes()) { - if ( first ) { - first = false; - } else { - pw.print(","); - } - pw.print(escapeXml(mode)); - } - pw.print("\""); - } - - } - - private static String INDENT = " "; - - - /** - * Writes the model to the writer. - * The writer is not closed. - * @param writer - * @param subystem - * @throws IOException - */ - public static void write(final Writer writer, final SSMDeliverable subsystem) - throws IOException { - final PrintWriter pw = new PrintWriter(writer); - pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); - pw.println("<deliverable>"); - - // properties - if ( subsystem.getVariables().size() > 0 ) { - pw.print(INDENT); - pw.println("<variables><![CDATA["); - for(final Map.Entry<String, String> entry : subsystem.getVariables().entrySet()) { - pw.print(INDENT); - pw.print(INDENT); - pw.print(entry.getKey()); - pw.print("="); - pw.println(entry.getValue()); - } - pw.print(INDENT); - pw.println("]]></variables>"); - } - for(final SSMFeature feature : subsystem.getFeatures()) { - // TODO - don't write out empty features - String indent = INDENT; - if ( feature.getRunModes() != null ) { - pw.print(indent); - pw.print("<feature"); - printRunModeAttribute(pw, feature); - pw.println(">"); - indent = indent + INDENT; - } - - for(final SSMStartLevel startLevel : feature.getStartLevels()) { - if ( startLevel.getArtifacts().size() == 0 ) { - continue; - } - if ( startLevel.getLevel() != 0 ) { - pw.print(indent); - pw.print("<startLevel"); - pw.print(" level=\""); - pw.print(String.valueOf(startLevel.getLevel())); - pw.print("\""); - pw.println(">"); - indent += INDENT; - } - for(final SSMArtifact ad : startLevel.getArtifacts()) { - pw.print(indent); - pw.print("<artifact groupId=\""); - pw.print(escapeXml(ad.getGroupId())); - pw.print("\" artifactId=\""); - pw.print(escapeXml(ad.getArtifactId())); - pw.print("\" version=\""); - pw.print(escapeXml(ad.getVersion())); - pw.print("\""); - if ( !"jar".equals(ad.getType()) ) { - pw.print(" type=\""); - pw.print(escapeXml(ad.getType())); - pw.print("\""); - } - if ( ad.getClassifier() != null ) { - pw.print(" classifier=\""); - pw.print(escapeXml(ad.getClassifier())); - pw.print("\""); - } - pw.println("/>"); - } - if ( startLevel.getLevel() != 0 ) { - indent = indent.substring(0, indent.length() - INDENT.length()); - pw.print(indent); - pw.println("</startLevel>"); - } - } - - for(final SSMConfiguration config : feature.getConfigurations()) { - pw.print(indent); - pw.print("<configuration "); - if ( config.getFactoryPid() != null ) { - pw.print("factory=\""); - pw.print(escapeXml(config.getFactoryPid())); - pw.print("\" "); - } - pw.print("pid=\""); - pw.print(escapeXml(config.getPid())); - pw.println("\"><![CDATA["); - if ( config.isSpecial() ) { - pw.println(config.getProperties().get(config.getPid())); - } else { - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - try { - ConfigurationHandler.write(os , config.getProperties()); - } finally { - os.close(); - } - final String configString = new String(os.toByteArray(), "UTF-8"); - pw.println(configString); - } - pw.print(indent); - pw.println("]]></configuration>"); - } - - if ( feature.getSettings().size() > 0 ) { - pw.print(indent); - pw.println("<settings><![CDATA["); - - for(final Map.Entry<String, String> entry :feature.getSettings().entrySet()) { - pw.print(INDENT); - pw.print(INDENT); - pw.print(entry.getKey()); - pw.print("="); - pw.println(entry.getValue()); - } - - pw.print(indent); - pw.println("]]></settings>"); - } - - if ( feature.getRunModes() != null ) { - indent = indent.substring(0, indent.length() - INDENT.length()); - pw.print(indent); - pw.println("</feature>"); - } - } - - pw.println("</deliverable>"); - } - - /** Escape xml text */ - private static String escapeXml(final String input) { - if (input == null) { - return null; - } - - final StringBuilder b = new StringBuilder(input.length()); - for(int i = 0;i < input.length(); i++) { - final char c = input.charAt(i); - if(c == '&') { - b.append("&"); - } else if(c == '<') { - b.append("<"); - } else if(c == '>') { - b.append(">"); - } else if(c == '"') { - b.append("""); - } else if(c == '\'') { - b.append("'"); - } else { - b.append(c); - } - } - return b.toString(); - } - -} diff --git a/src/main/java/org/apache/sling/slingstart/model/xml/package-info.java b/src/main/java/org/apache/sling/slingstart/model/xml/package-info.java deleted file mode 100644 index ee86132..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/xml/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ - -@Version("1.0") -package org.apache.sling.slingstart.model.xml; - -import aQute.bnd.annotation.Version; - -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.