List of usage examples for org.xml.sax.helpers AttributesImpl AttributesImpl
public AttributesImpl()
From source file:net.ontopia.topicmaps.db2tm.RelationMapping.java
protected void outputEntities(Relation rel, ContentHandler dh) throws SAXException { AttributesImpl atts = new AttributesImpl(); for (Entity entity : rel.getEntities()) { if (entity.getEntityType() == Entity.TYPE_TOPIC) { // <topic> if (entity.getId() != null) addAttribute(atts, "id", "CDATA", entity.getId()); addAttribute(atts, "type", "CDATA", entity.getAssociationType()); dh.startElement("", "", "topic", atts); atts.clear();/*from w w w . j a va 2s . c o m*/ outputFields(entity, dh); // </topic> dh.endElement("", "", "topic"); } else if (entity.getEntityType() == Entity.TYPE_ASSOCIATION) { // <association> if (entity.getId() != null) addAttribute(atts, "id", "CDATA", entity.getId()); addAttribute(atts, "type", "CDATA", entity.getAssociationType()); addAttribute(atts, "scope", "CDATA", entity.getScope()); dh.startElement("", "", "association", atts); atts.clear(); outputFields(entity, dh); // </association> dh.endElement("", "", "association"); } } }
From source file:de.interactive_instruments.ShapeChange.Target.FeatureCatalogue.FeatureCatalogue.java
public void initialise(PackageInfo p, Model m, Options o, ShapeChangeResult r, boolean diagOnly) throws ShapeChangeAbortException { pi = p;// ww w . j av a 2 s .co m model = m; options = o; result = r; try { if (!initialised) { initialised = true; String pathToJavaExe_ = options.parameter(this.getClass().getName(), PARAM_JAVA_EXE_PATH); if (pathToJavaExe_ != null && pathToJavaExe_.trim().length() > 0) { pathToJavaExe = pathToJavaExe_.trim(); if (!pathToJavaExe.startsWith("\"")) { pathToJavaExe = "\"" + pathToJavaExe; } if (!pathToJavaExe.endsWith("\"")) { pathToJavaExe = pathToJavaExe + "\""; } String jo_tmp = options.parameter(this.getClass().getName(), PARAM_JAVA_OPTIONS); if (jo_tmp != null && jo_tmp.trim().length() > 0) { javaOptions = jo_tmp.trim(); } /* * check path - and potentially also options - by invoking * the exe */ List<String> cmds = new ArrayList<String>(); cmds.add(pathToJavaExe); if (javaOptions != null) { cmds.add(javaOptions); } cmds.add("-version"); ProcessBuilder pb = new ProcessBuilder(cmds); try { Process proc = pb.start(); StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream()); StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream()); errorGobbler.start(); outputGobbler.start(); errorGobbler.join(); outputGobbler.join(); int exitVal = proc.waitFor(); if (exitVal != 0) { if (errorGobbler.hasResult()) { MessageContext mc = result.addFatalError(this, 21, StringUtils.join(cmds, " "), "" + exitVal); mc.addDetail(this, 27, errorGobbler.getResult()); } else { result.addFatalError(this, 21, StringUtils.join(cmds, " "), "" + exitVal); } throw new ShapeChangeAbortException(); } } catch (InterruptedException e) { result.addFatalError(this, 22); throw new ShapeChangeAbortException(); } } encounteredAppSchemasByName = new TreeMap<String, Integer>(); initialiseFromOptions(); String s = null; Model refModel_tmp = getReferenceModel(); if (refModel_tmp != null) { /* * Ensure that IDs used in the reference model are unique to * that model and do not get mixed up with the IDs of the * input model. * * REQUIREMENT for model diff: two objects with equal ID * must represent the same model element. If a model element * is deleted in the reference model, then a new model * element in the input model must not have the same ID. * * It looks like this cannot be guaranteed. Therefore we add * a prefix to the IDs of the model elements in the * reference model. */ refModel = new GenericModel(refModel_tmp); refModel_tmp.shutdown(); refModel.addPrefixToModelElementIDs("refmodel_"); } String xmlName = outputFilename + ".tmp.xml"; // Check whether we can use the given output directory File outputDirectoryFile = new File(outputDirectory); boolean exi = outputDirectoryFile.exists(); if (!exi) { outputDirectoryFile.mkdirs(); exi = outputDirectoryFile.exists(); } boolean dir = outputDirectoryFile.isDirectory(); boolean wrt = outputDirectoryFile.canWrite(); boolean rea = outputDirectoryFile.canRead(); if (!exi || !dir || !wrt || !rea) { result.addFatalError(this, 12, outputDirectory); throw new ShapeChangeAbortException(); } String encoding_ = encoding == null ? "UTF-8" : model.characterEncoding(); OutputStream fout = new FileOutputStream(outputDirectory + "/" + xmlName); OutputStream bout = new BufferedOutputStream(fout, streamBufferSize); OutputStreamWriter outputXML = new OutputStreamWriter(bout, encoding_); writer = new XMLWriter(outputXML, encoding_); writer.forceNSDecl("http://www.w3.org/2001/XMLSchema-instance", "xsi"); writer.startDocument(); writer.processingInstruction("xml-stylesheet", "type='text/xsl' href='./html.xsl'"); writer.comment("Feature catalogue created using ShapeChange"); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("http://www.w3.org/2001/XMLSchema-instance", "noNamespaceSchemaLocation", "xsi:noNamespaceSchemaLocation", "CDATA", "FC.xsd"); writer.startElement("", "FeatureCatalogue", "", atts); s = options.parameter(this.getClass().getName(), "name"); if (s != null && s.length() > 0) writer.dataElement("name", s); else writer.dataElement("name", "unknown"); s = options.parameter(this.getClass().getName(), "scope"); if (s != null && s.length() > 0) PrintLineByLine(s, "scope", null); else { writer.dataElement("scope", "unknown"); } s = options.parameter(this.getClass().getName(), "versionNumber"); if (s != null && s.length() > 0) writer.dataElement("versionNumber", s); else writer.dataElement("versionNumber", "unknown"); s = options.parameter(this.getClass().getName(), "versionDate"); if (s != null && s.length() > 0) writer.dataElement("versionDate", s); else writer.dataElement("versionDate", "unknown"); s = options.parameter(this.getClass().getName(), "producer"); if (s != null && s.length() > 0) writer.dataElement("producer", s); else writer.dataElement("producer", "unknown"); } // we need to compute the diff for each application schema if (refModel != null) { SortedSet<PackageInfo> set = refModel.schemas(p.name()); if (set.size() == 1) { /* * Get the full names of classes (in lower case) from the * input schema so that later we can look them up by their * full name (within the schema, not in the model). */ inputSchemaClassesByFullNameInSchema = new HashMap<String, ClassInfo>(); for (ClassInfo ci : model.classes(pi)) { inputSchemaClassesByFullNameInSchema.put(ci.fullNameInSchema().toLowerCase(Locale.ENGLISH), ci); } // compute diffs differ = new Differ(); refPackage = set.iterator().next(); SortedMap<Info, SortedSet<DiffElement>> pi_diffs = differ.diff(p, refPackage); // merge diffs for pi with existing diffs (from other // schemas) differ.merge(diffs, pi_diffs); // log the diffs found for pi for (Entry<Info, SortedSet<DiffElement>> me : pi_diffs.entrySet()) { MessageContext mc = result.addInfo( "Model difference - " + me.getKey().fullName().replace(p.fullName(), p.name())); for (DiffElement diff : me.getValue()) { String s = diff.change + " " + diff.subElementType; if (diff.subElementType == ElementType.TAG) s += "(" + diff.tag + ")"; if (diff.subElement != null) s += " " + diff.subElement.name(); else if (diff.diff != null) s += " " + (new diff_match_patch()).diff_prettyHtml(diff.diff); else s += " ???"; mc.addDetail(s); } } /* * switch to default xslt for html diff - unless the * configuration explicitly names an XSLT file to use */ if (options.parameter(this.getClass().getName(), "xslhtmlFile") == null) { xslhtmlfileName = DEFAULT_XSL_HTML_DIFF_FILE_NAME; } } else { result.addWarning(null, 308, p.name()); refModel = null; } } writer.startElement("ApplicationSchema", "id", "_P" + pi.id()); /* * Determine if app schema with same name has been encountered * before, and choose name accordingly */ String nameForAppSchema = null; if (encounteredAppSchemasByName.containsKey(pi.name())) { int count = encounteredAppSchemasByName.get(pi.name()).intValue(); count++; nameForAppSchema = pi.name() + " (" + count + ")"; encounteredAppSchemasByName.put(pi.name(), new Integer(count)); } else { nameForAppSchema = pi.name(); encounteredAppSchemasByName.put(pi.name(), new Integer(1)); } // now set the name of the application schema writer.dataElement("name", nameForAppSchema); String s = pi.definition(); if (s != null && s.length() > 0) { PrintLineByLine(s, "definition", null); } s = pi.description(); if (s != null && s.length() > 0) { PrintLineByLine(s, "description", null); } s = pi.version(); if (s != null && s.length() > 0) { writer.dataElement("versionNumber", s); } writer.startElement("taggedValues"); s = pi.taggedValue(TransformationConstants.TRF_TV_NAME_GENERATIONDATETIME); if (s != null && s.trim().length() > 0) { writer.dataElement(TransformationConstants.TRF_TV_NAME_GENERATIONDATETIME, PrepareToPrint(s)); } writer.endElement("taggedValues"); if (pi.getDiagrams() != null) { appendImageInfo(pi.getDiagrams()); } writer.endElement("ApplicationSchema"); /* * Check if there are any deletions of classes or packages that are * owned by the application schema package. */ if (hasDiff(pi, ElementType.SUBPACKAGE, Operation.DELETE)) { Set<DiffElement> pkgdiffs = getDiffs(pi, ElementType.SUBPACKAGE, Operation.DELETE); for (DiffElement diff : pkgdiffs) { // child package was deleted PrintPackage((PackageInfo) diff.subElement, Operation.DELETE); } } printContainedPackages(pi); /* * NOTE: inserted or unchanged classes are handled in * process(ClassInfo) method */ printDeletedClasses(pi); } catch (Exception e) { String msg = e.getMessage(); if (msg != null) { result.addError(msg); } e.printStackTrace(System.err); } }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test(expected = SAXParseException.class) public void processStreamIsEmptyNameExceptionTest() throws Exception { ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS); test.startDocument();// w w w .j a v a 2 s.c o m AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "", "name", "", "Stream name value"); // NON-NLS attrs.addAttribute("", "", "source", "", "Stream source value"); // NON-NLS attrs.addAttribute("", "", "target", "", "Stream target value"); // NON-NLS attrs.addAttribute("", "", "value", "", ""); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS attrs.addAttribute("", "", "class", "", ""); // NON-NLS attrs.addAttribute("", "", "name", "", ""); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "stream", attrs); // NON-NLS }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test(expected = SAXParseException.class) public void processPropertyTest() throws Exception { ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS); test.startDocument();//from w ww . java 2s.c o m AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "", "name", "", "Stream name value"); // NON-NLS attrs.addAttribute("", "", "source", "", "Stream source value"); // NON-NLS attrs.addAttribute("", "", "target", "", "Stream target value"); // NON-NLS attrs.addAttribute("", "", "value", "", ""); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS attrs.addAttribute("", "", "name", "", ""); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "property", attrs); // NON-NLS }
From source file:net.ontopia.topicmaps.db2tm.RelationMapping.java
protected void outputField(Field field, ContentHandler dh) throws SAXException { AttributesImpl atts = new AttributesImpl(); if (field.getFieldType() == Field.TYPE_SUBJECT_LOCATOR) { addAttribute(atts, "column", "CDATA", field.getColumn()); dh.startElement("", "", "subject-locator", atts); char[] c = field.getPattern().toCharArray(); dh.characters(c, 0, c.length);//from w ww . jav a 2s . com dh.endElement("", "", "subject-locator"); atts.clear(); } else if (field.getFieldType() == Field.TYPE_SUBJECT_IDENTIFIER) { addAttribute(atts, "column", "CDATA", field.getColumn()); dh.startElement("", "", "subject-identifier", atts); char[] c = field.getPattern().toCharArray(); dh.characters(c, 0, c.length); dh.endElement("", "", "subject-identifier"); atts.clear(); } else if (field.getFieldType() == Field.TYPE_ITEM_IDENTIFIER) { addAttribute(atts, "column", "CDATA", field.getColumn()); dh.startElement("", "", "item-identifier", atts); char[] c = field.getPattern().toCharArray(); dh.characters(c, 0, c.length); dh.endElement("", "", "item-identifier"); atts.clear(); } else if (field.getFieldType() == Field.TYPE_OCCURRENCE) { addAttribute(atts, "column", "CDATA", field.getColumn()); addAttribute(atts, "type", "CDATA", field.getType()); addAttribute(atts, "scope", "CDATA", field.getScope()); addAttribute(atts, "datatype", "CDATA", field.getDatatype()); dh.startElement("", "", "occurrence", atts); dh.endElement("", "", "occurrence"); atts.clear(); } else if (field.getFieldType() == Field.TYPE_TOPIC_NAME) { addAttribute(atts, "column", "CDATA", field.getColumn()); addAttribute(atts, "type", "CDATA", field.getType()); addAttribute(atts, "scope", "CDATA", field.getScope()); dh.startElement("", "", "topic-name", atts); dh.endElement("", "", "topic-name"); atts.clear(); } else if (field.getFieldType() == Field.TYPE_PLAYER) { addAttribute(atts, "rtype", "CDATA", field.getRoleType()); addAttribute(atts, "atype", "CDATA", field.getAssociationType()); addAttribute(atts, "scope", "CDATA", field.getScope()); dh.startElement("", "", "player", atts); atts.clear(); for (Field orole : field.getOtherRoleFields()) { addAttribute(atts, "rtype", "CDATA", orole.getRoleType()); addAttribute(atts, "player", "CDATA", orole.getPlayer()); dh.startElement("", "", "other", atts); dh.endElement("", "", "other"); atts.clear(); } dh.endElement("", "", "player"); atts.clear(); } else if (field.getFieldType() == Field.TYPE_ASSOCIATION_ROLE) { addAttribute(atts, "type", "CDATA", field.getRoleType()); addAttribute(atts, "player", "CDATA", field.getPlayer()); dh.startElement("", "", "role", atts); dh.endElement("", "", "role"); atts.clear(); } else throw new OntopiaRuntimeException("Unknown field type: " + field.getType()); }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test(expected = SAXParseException.class) public void processParserRefNoParserTest() throws Exception { ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS); test.startDocument();/* w w w.jav a2 s . c om*/ AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "", "name", "", "Stream name value"); // NON-NLS attrs.addAttribute("", "", "source", "", "Stream source value"); // NON-NLS attrs.addAttribute("", "", "target", "", "Stream target value"); // NON-NLS attrs.addAttribute("", "", "value", "", ""); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS test.getStreamsConfigData().getParsers().clear(); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser-ref", attrs); // NON-NLS }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test(expected = SAXParseException.class) public void processParserRefTest() throws Exception { ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS); test.startDocument();/*www. j a va 2 s . co m*/ AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "", "name", "", "Stream name value"); // NON-NLS attrs.addAttribute("", "", "source", "", "Stream source value"); // NON-NLS attrs.addAttribute("", "", "target", "", "Stream target value"); // NON-NLS attrs.addAttribute("", "", "value", "", ""); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS attrs.addAttribute("", "", "name", "", ""); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser-ref", attrs); // NON-NLS }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test(expected = SAXParseException.class) public void processReferenceExceptionTest() throws Exception { ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS); test.startDocument();//from ww w. ja v a 2 s. c o m AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "", "name", "", "Stream name value"); // NON-NLS attrs.addAttribute("", "", "source", "", "Stream source value"); // NON-NLS attrs.addAttribute("", "", "target", "", "Stream target value"); // NON-NLS attrs.addAttribute("", "", "value", "", ""); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.inputs.RedirectTNT4JStream"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "stream", attrs); // NON-NLS attrs.addAttribute("", "", "name", "", ""); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "reference", attrs); // NON-NLS }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test(expected = SAXParseException.class) public void processReferenceParserExceptionTest() throws Exception { ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS); test.startDocument();//from www . ja v a2 s .co m AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "", "name", "", "Stream name value"); // NON-NLS attrs.addAttribute("", "", "source", "", "Stream source value"); // NON-NLS attrs.addAttribute("", "", "target", "", "Stream target value"); // NON-NLS attrs.addAttribute("", "", "value", "", ""); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.inputs.RedirectTNT4JStream"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "stream", attrs); // NON-NLS test.getStreamsConfigData().getParsers().clear(); test.getStreamsConfigData().getStreams().clear(); test.startElement("TEST_URL", "TEST_LOCALNAME", "reference", attrs); // NON-NLS }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test public void findReferenceTest() throws Exception { ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS); test.startDocument();//from www .j a va 2s .co m AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "", "name", "", "Stream name value"); // NON-NLS attrs.addAttribute("", "", "source", "", "Stream source value"); // NON-NLS attrs.addAttribute("", "", "target", "", "Stream target value"); // NON-NLS attrs.addAttribute("", "", "value", "", ""); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.inputs.RedirectTNT4JStream"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "stream", attrs); // NON-NLS attrs.addAttribute("", "", "class", "", ""); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "reference", attrs); // NON-NLS }