List of usage examples for org.xml.sax.helpers AttributesImpl AttributesImpl
public AttributesImpl()
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.hl7.HL7MapToLexGrid.java
void loadMetaData(CodingScheme csclass, String connectionString, String driver) { messages_.info("Loading individual coding scheme metadata"); Connection c = null;/*from ww w . j a v a 2 s .co m*/ // create the filename of the metadata file to be created String filename = loaderPrefs.getXMLMetadataFilePath() + "/" + PreferenceLoaderConstants.META_HL7_METADATA_FILE_NAME; FileOutputStream fos; try { fos = new FileOutputStream(filename); OutputFormat of = new OutputFormat("XML", "ISO-8859-1", true); of.setIndent(1); of.setIndenting(true); XMLSerializer serializer = new XMLSerializer(fos, of); // SAX2.0 ContentHandler. ContentHandler hd = serializer.asContentHandler(); hd.startDocument(); // Element attributes. AttributesImpl atts = new AttributesImpl(); // CODINGSCHEMES tag. hd.startElement("", "", "codingSchemes", atts); String defaultLanguage = "en"; String isNative = "0"; String codeSystemId; String codeSystemType; String codeSystemName; String fullName; String description; String releaseId; String copyrightNotice; Integer approximateNumberofConcepts; try { c = DBUtility.connectToDatabase(accessConnectionString, driver, null, null); PreparedStatement getCodingSchemeMetaData = c .prepareStatement("SELECT b.codeSystemid, b.codeSystemType, b.codeSystemName, " + "b.fullName, b.description, b.releaseId, b.copyrightNotice " + "FROM VCS_code_system AS b"); ResultSet codingSchemeMetaData = getCodingSchemeMetaData.executeQuery(); PreparedStatement getCodingSchemeConceptCount = c .prepareStatement("SELECT VCS_concept_code_xref.codeSystemId2, " + "COUNT (VCS_concept_code_xref.codeSystemId2) as conceptcount " + "FROM VCS_concept_code_xref " + "GROUP BY VCS_concept_code_xref.codeSystemId2;"); ResultSet codingSchemeConceptCount = getCodingSchemeConceptCount.executeQuery(); Hashtable<String, Integer> conceptCountList = new Hashtable<String, Integer>(); while (codingSchemeConceptCount.next()) { String codingSchemeId = codingSchemeConceptCount.getString("codeSystemId2"); String codingSchemeCount = codingSchemeConceptCount.getString("conceptcount"); conceptCountList.put(new String(codingSchemeId), new Integer(codingSchemeCount)); } codingSchemeConceptCount.close(); int codeSchemeCounter = 0; while (codingSchemeMetaData.next()) { codeSystemId = codingSchemeMetaData.getString("codeSystemid"); if (codeSystemId == null) { codeSystemId = SQLTableConstants.TBLCOLVAL_MISSING; } codeSystemType = codingSchemeMetaData.getString("codeSystemType"); if (codeSystemType == null) { codeSystemType = SQLTableConstants.TBLCOLVAL_MISSING; } codeSystemName = codingSchemeMetaData.getString("codeSystemName"); if (codeSystemName == null) { codeSystemName = SQLTableConstants.TBLCOLVAL_MISSING; } fullName = codingSchemeMetaData.getString("fullName"); if (fullName == null) { fullName = SQLTableConstants.TBLCOLVAL_MISSING; } description = codingSchemeMetaData.getString("description"); if (description == null) { description = SQLTableConstants.TBLCOLVAL_MISSING; } // The description contains HTML tags. We try to remove // them. else { int begin = description.lastIndexOf("<p>"); int end = description.lastIndexOf("</p>"); if (begin > -1) { if (begin + 3 < end) description = description.substring(begin + 3, end); } } releaseId = codingSchemeMetaData.getString("releaseId"); if (releaseId == null) { releaseId = SQLTableConstants.TBLCOLVAL_MISSING; } copyrightNotice = codingSchemeMetaData.getString("copyrightNotice"); if (copyrightNotice == null) { copyrightNotice = SQLTableConstants.TBLCOLVAL_MISSING; } approximateNumberofConcepts = ((Integer) conceptCountList.get(codeSystemId)); if (approximateNumberofConcepts == null) { approximateNumberofConcepts = new Integer(0); } // Begin codingScheme element atts.clear(); atts.addAttribute("", "", SQLTableConstants.TBLCOL_CODINGSCHEMENAME, "CDATA", codeSystemName); // May want to change to _fullName atts.addAttribute("", "", SQLTableConstants.TBLCOL_FORMALNAME, "CDATA", fullName); atts.addAttribute("", "", SQLTableConstants.TBLCOL_CODINGSCHEMEURI, "CDATA", codeSystemId); atts.addAttribute("", "", SQLTableConstants.TBLCOL_DEFAULTLANGUAGE, "CDATA", defaultLanguage); atts.addAttribute("", "", SQLTableConstants.TBLCOL_REPRESENTSVERSION, "CDATA", releaseId); atts.addAttribute("", "", SQLTableConstants.TBLCOL_ISNATIVE, "CDATA", isNative); atts.addAttribute("", "", SQLTableConstants.TBLCOL_APPROXNUMCONCEPTS, "CDATA", approximateNumberofConcepts.toString()); hd.startElement("", "", SQLTableConstants.TBLCOL_CODINGSCHEME, atts); // localname atts.clear(); hd.startElement("", "", "localName", atts); hd.characters(codeSystemName.toCharArray(), 0, codeSystemName.length()); hd.endElement("", "", SQLTableConstants.TBLCOLVAL_LOCALNAME); // entityDescription atts.clear(); hd.startElement("", "", SQLTableConstants.TBLCOL_ENTITYDESCRIPTION, atts); hd.characters(description.toCharArray(), 0, description.length()); hd.endElement("", "", SQLTableConstants.TBLCOL_ENTITYDESCRIPTION); // copyright atts.clear(); hd.startElement("", "", SQLTableConstants.TBLCOL_COPYRIGHT, atts); hd.characters(copyrightNotice.toCharArray(), 0, copyrightNotice.length()); hd.endElement("", "", SQLTableConstants.TBLCOL_COPYRIGHT); // May need to include as Property // // CodingScheme // atts.clear(); // hd.startElement("","","CodingScheme",atts); // hd.characters(_codeSystemType.toCharArray(),0,_codeSystemType.length()); // hd.endElement("","","CodingScheme"); // End codingScheme element hd.endElement("", "", SQLTableConstants.TBLCOL_CODINGSCHEME); codeSchemeCounter++; } // End while there are result rows to process getCodingSchemeConceptCount.close(); hd.endElement("", "", "codingSchemes"); hd.endDocument(); fos.close(); } catch (Exception e) { messages_.error("Failed while preparing HL7 Code System MetaData.", e); e.printStackTrace(); } finally { try { c.close(); } catch (SQLException e) { messages_.debug("An error occurred while closing the MS Access connection: " + e.getMessage()); e.printStackTrace(); } } } catch (FileNotFoundException fnfe) { messages_.debug("Loader Preferences file was not found, file: " + filename); fnfe.printStackTrace(); } catch (IOException ioe) { messages_.debug("IOException, file: " + filename); ioe.printStackTrace(); } catch (SAXException saxe) { messages_.debug("SAXException, file: " + filename); saxe.printStackTrace(); } }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test(expected = SAXParseException.class) public void startElementExceptionTest() 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 TNTInputStream<?, ?> my = Mockito.mock(TNTInputStream.class, Mockito.CALLS_REAL_METHODS); 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 attrs.addAttribute("", "", "type", "", "java.lang.String"); // NON-NLS test.getStreamsConfigData().addStream(my); test.startElement("TEST_URL", "TEST_LOCALNAME", "tnt-data-source", attrs); // NON-NLS }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test(expected = SAXParseException.class) public void startElementExceptionTwoTest() throws Exception { ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS); test.startDocument();//w ww . j a v a 2 s. c om TNTInputStream<?, ?> my = Mockito.mock(TNTInputStream.class, Mockito.CALLS_REAL_METHODS); 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 attrs.addAttribute("", "", "type", "", "java.lang.String"); // NON-NLS test.getStreamsConfigData().addStream(my); test.startElement("TEST_URL", "TEST_LOCALNAME", "tw-direct-feed", attrs); // NON-NLS }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java
/** * Processes a {@code <field-map-ref>} element. * * @param attrs/* w w w .jav a 2 s .com*/ * List of element attributes * * @throws SAXException * if error occurs parsing element */ @SuppressWarnings("unchecked") private void processFieldMapReference(Attributes attrs) throws SAXException { if (currField == null) { throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME, "ConfigParserHandler.malformed.configuration3", FIELD_MAP_REF_ELMT, FIELD_ELMT, FIELD_LOC_ELMT), currParseLocation); } if (CollectionUtils.isEmpty(currField.getLocators()) && currLocatorData == null) { throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME, "ConfigParserHandler.element.no.binding", FIELD_MAP_REF_ELMT, FIELD_LOC_ELMT, getLocationInfo())); } String reference = null; for (int i = 0; i < attrs.getLength(); i++) { String attName = attrs.getQName(i); String attValue = attrs.getValue(i); if (RESOURCE_ATTR.equals(attName)) { reference = attValue; } } notEmpty(reference, FIELD_MAP_REF_ELMT, RESOURCE_ATTR); Object val = Utils.getMapValueByPath(reference, resourcesMap); if (val instanceof Map) { AttributesImpl mappingAttrs = new AttributesImpl(); for (Map.Entry<String, ?> entry : ((Map<String, ?>) val).entrySet()) { mappingAttrs.clear(); mappingAttrs.addAttribute(null, null, SOURCE_ATTR, null, entry.getKey()); mappingAttrs.addAttribute(null, null, TARGET_ATTR, null, String.valueOf(entry.getValue())); processFieldMap(mappingAttrs); } } }
From source file:de.interactive_instruments.ShapeChange.Target.FeatureCatalogue.FeatureCatalogue.java
private void PrintPropertyDetail(PropertyInfo propi, String assocId, Operation op) throws SAXException { String propiid = "_A" + propi.id(); propiid = options.internalize(propiid); if (propi.isAttribute()) { writer.startElement("FeatureAttribute", "id", propiid, op); } else {/*from www . j a va 2 s.c om*/ writer.startElement("RelationshipRole", "id", propiid, op); } PrintDescriptors(propi, false, op); String s = propi.cardinality().toString(); s = checkDiff(s, propi, ElementType.MULTIPLICITY); String cardinalityText = PrepareToPrint(s); cardinalityText = options.internalize(cardinalityText); writer.dataElement("cardinality", cardinalityText, op); if (!propi.isAttribute() && !propi.isNavigable()) { PrintLineByLine("false", "isNavigable", op); } if (propi.isDerived()) { PrintLineByLine("true", "isDerived", op); } s = propi.initialValue(); if (propi.isAttribute() && s != null && s.length() > 0) { PrintLineByLine(PrepareToPrint(s), "initialValue", op); } writer.startElement("taggedValues"); s = propi.taggedValue("name"); if (s != null && s.trim().length() > 0) { writer.dataElement("name", PrepareToPrint(s), op); } String[] tags = propi.taggedValuesForTag("length"); if (tags != null && tags.length > 0) { for (String tag : tags) { writer.dataElement("length", PrepareToPrint(tag), op); } } writer.endElement("taggedValues"); if (includeVoidable) { if (propi.voidable()) { writer.dataElement("voidable", "true", op); } else { writer.dataElement("voidable", "false", op); } } if (propi.isOrdered()) { writer.dataElement("orderIndicator", "1", op); } else { writer.dataElement("orderIndicator", "0", op); } if (propi.isUnique()) { writer.dataElement("uniquenessIndicator", "1", op); } else { writer.dataElement("uniquenessIndicator", "0", op); } Type ti = propi.typeInfo(); if (!propi.isAttribute() && !propi.isComposition()) { if (ti != null) { AttributesImpl atts = new AttributesImpl(); ClassInfo cix = lookupClassById(ti.id); if (cix != null) { String tiid = "_C" + cix.id(); tiid = options.internalize(tiid); atts.addAttribute("", "idref", "", "CDATA", tiid); } atts.addAttribute("", "category", "", "CDATA", featureTerm.toLowerCase() + " type"); addOperationToAttributes(op, atts); writer.dataElement("", "FeatureTypeIncluded", "", atts, checkDiff(ti.name, propi, ElementType.VALUETYPE)); } writer.emptyElement("relation", "idref", assocId); PropertyInfo propi2 = propi.reverseProperty(); if (propi2 != null && ExportProperty(propi2) && propi2.isNavigable()) { String propi2id = "_A" + propi2.id(); propi2id = options.internalize(propi2id); writer.emptyElement("InverseRole", "idref", propi2id, op); } } else { if (ti != null) { ClassInfo cix; if (op != Operation.DELETE) { cix = model.classById(ti.id); } else { cix = refModel.classById(ti.id); } if (cix != null) { int cat = cix.category(); String cixname = cix.name(); cixname = checkDiff(cixname, propi, ElementType.VALUETYPE); cixname = options.internalize(cixname); switch (cat) { case Options.CODELIST: case Options.ENUMERATION: AttributesImpl atts = new AttributesImpl(); if (cat == Options.CODELIST) { atts.addAttribute("", "category", "", "CDATA", "code list"); if (includeCodelistURI) { String cl = cix.taggedValue("codeList"); if (cl == null || cl.isEmpty()) { cl = cix.taggedValue("vocabulary"); } if (cl != null && !cl.isEmpty()) { atts.addAttribute("", "codeList", "", "CDATA", options.internalize(cl)); } } } else if (cat == Options.ENUMERATION && !cixname.equals("Boolean")) { atts.addAttribute("", "category", "", "CDATA", "enumeration"); } addOperationToAttributes(op, atts); writer.dataElement("", "ValueDataType", "", atts, PrepareToPrint(cixname)); if (!cixname.equals("Boolean")) { writer.dataElement("ValueDomainType", "1", op); for (PropertyInfo ei : cix.properties().values()) { if (ei != null && ExportValue(ei)) { String eiid = "_A" + ei.id(); eiid = options.internalize(eiid); writer.emptyElement("enumeratedBy", "idref", eiid); } } if (diffs != null && diffs.get(cix) != null) { for (DiffElement diff : diffs.get(cix)) { if (diff.subElementType == ElementType.ENUM && diff.change == Operation.DELETE) { writer.emptyElement("enumeratedBy", "idref", "_A" + ((PropertyInfo) diff.subElement).id()); } } } if (op != Operation.DELETE) { if (cix.inSchema(propi.inClass().pkg())) enumerations.add(cix); } else { if (cix.inSchema(refPackage)) enumerations.add(cix); } // FIXME if (cix.inSchema(propi.inClass().pkg())) // enumerations.add(cix); } else { writer.dataElement("ValueDomainType", "0", op); } break; default: String cixid = "_C" + cix.id(); cixid = options.internalize(cixid); AttributesImpl atts2 = new AttributesImpl(); atts2.addAttribute("", "idref", "", "CDATA", cixid); if (cat == Options.FEATURE || cat == Options.OKSTRAFID) { String fttext = featureTerm.toLowerCase() + " type"; fttext = options.internalize(fttext); atts2.addAttribute("", "category", "", "CDATA", fttext); } else if (cat == Options.DATATYPE || cat == Options.OKSTRAKEY) { atts2.addAttribute("", "category", "", "CDATA", "data type"); } else if (cat == Options.UNION) { atts2.addAttribute("", "category", "", "CDATA", "union data type"); } else if (cat == Options.BASICTYPE) { atts2.addAttribute("", "category", "", "CDATA", "basic type"); } addOperationToAttributes(op, atts2); writer.dataElement("", "ValueDataType", "", atts2, PrepareToPrint(cixname)); writer.dataElement("ValueDomainType", "0", op); break; } } else { String tiname = ti.name; tiname = checkDiff(tiname, propi, ElementType.VALUETYPE); tiname = options.internalize(tiname); writer.dataElement("ValueDataType", PrepareToPrint(tiname), op); } } else { writer.dataElement("ValueDataType", "(unknown)", op); } } if (propi.isAttribute()) { writer.endElement("FeatureAttribute"); } else { writer.endElement("RelationshipRole"); } }
From source file:com.microsoft.tfs.client.clc.commands.Command.java
private void displayPendingChangeAsXML(final PendingChange change) throws SAXException { Check.notNull(change, "change"); //$NON-NLS-1$ Check.notNull(xmlWriter, "this.xmlWriter"); //$NON-NLS-1$ final AttributesImpl changeAttributes = new AttributesImpl(); final String localItem; final String serverItem; /*//from w w w . ja v a2 s.c om * If the change is an undone rename (and the change type is not * undelete), we need to swap the source and destination for them to * make sense to the user. */ if (change.isUndone() && change.getChangeType().contains(ChangeType.RENAME) && !change.getChangeType().contains(ChangeType.UNDELETE)) { localItem = change.getSourceLocalItem(); serverItem = change.getSourceServerItem(); } else { localItem = change.getLocalItem(); serverItem = change.getServerItem(); } changeAttributes.addAttribute("", "", CommonXMLNames.SERVER_ITEM, "CDATA", serverItem); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (localItem != null) { changeAttributes.addAttribute("", "", CommonXMLNames.LOCAL_ITEM, "CDATA", localItem); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } changeAttributes.addAttribute("", "", CommonXMLNames.VERSION, "CDATA", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ Integer.toString(change.getVersion())); changeAttributes.addAttribute("", //$NON-NLS-1$ "", //$NON-NLS-1$ CommonXMLNames.DATE, "CDATA", //$NON-NLS-1$ SimpleXMLWriter.ISO_DATE_FORMAT.format(change.getCreationDate().getTime())); changeAttributes.addAttribute("", "", CommonXMLNames.LOCK, "CDATA", change.getLockLevelName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ changeAttributes.addAttribute("", //$NON-NLS-1$ "", //$NON-NLS-1$ CommonXMLNames.CHANGE_TYPE, "CDATA", //$NON-NLS-1$ change.getChangeType().toUIString(false, change)); /* * If the source server item and server item paths differ, we have a * rename, move, etc., and want to print the source item. */ if (change.getSourceServerItem() != null && !ServerPath.equals(change.getSourceServerItem(), change.getServerItem())) { changeAttributes.addAttribute("", //$NON-NLS-1$ "", //$NON-NLS-1$ CommonXMLNames.SOURCE_SERVER_ITEM, "CDATA", //$NON-NLS-1$ change.getSourceServerItem()); } if (change.getItemType() == ItemType.FILE && change.getEncoding() != VersionControlConstants.ENCODING_UNCHANGED) { changeAttributes.addAttribute("", //$NON-NLS-1$ "", //$NON-NLS-1$ CommonXMLNames.FILE_TYPE, "CDATA", //$NON-NLS-1$ new FileEncoding(change.getEncoding()).getName()); } if (change.getDeletionID() != 0) { changeAttributes.addAttribute("", //$NON-NLS-1$ "", //$NON-NLS-1$ CommonXMLNames.DELETION_ID, "CDATA", //$NON-NLS-1$ Integer.toString(change.getDeletionID())); } xmlWriter.startElement("", "", CommonXMLNames.PENDING_CHANGE, changeAttributes); //$NON-NLS-1$ //$NON-NLS-2$ xmlWriter.endElement("", "", CommonXMLNames.PENDING_CHANGE); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:net.tirasa.hct.cocoon.sax.HippoItemXMLDumper.java
public void startQueryResult(final HCTQueryResult result, final HippoItem base) throws SAXException, RepositoryException { final AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute(NS_EMPTY, Attribute.SIZE.getName(), Attribute.SIZE.getName(), XSD_LONG, String.valueOf(result.getUuids().size())); attrs.addAttribute(NS_EMPTY, Attribute.PAGE.getName(), Attribute.PAGE.getName(), XSD_LONG, String.valueOf(result.getPage())); attrs.addAttribute(NS_EMPTY, Attribute.TOTAL_PAGES.getName(), Attribute.TOTAL_PAGES.getName(), XSD_LONG, String.valueOf(result.getTotalPages())); saxConsumer.startElement(NS_HCT, Element.QUERY_RESULT.getName(), PREFIX_HCT + ":" + Element.QUERY_RESULT.getName(), attrs); saxConsumer.startElement(NS_HCT, Element.BASE.getName(), PREFIX_HCT + ":" + Element.BASE.getName(), EMPTY_ATTRS);//from w ww. ja v a 2 s . co m if (base != null) { if (base instanceof HCTTaxonomyCategoryBean) { startTaxonomy((HCTTaxonomyCategoryBean) base, result.getLocale()); endTaxonomy(); } else { startHippoItem(base, base.getPath()); endHippoItem(base); } } saxConsumer.endElement(NS_HCT, Element.BASE.getName(), PREFIX_HCT + ":" + Element.BASE.getName()); }
From source file:net.tirasa.hct.cocoon.sax.HippoItemXMLDumper.java
public <T extends HippoItem> void startHippoItem(final T item, final String path) throws SAXException, RepositoryException { final Element elem = item instanceof HippoDocument ? Element.DOCUMENT : Element.FOLDER; final String localeString = item instanceof HippoDocument ? ((HippoDocument) item).getLocaleString() : item instanceof HippoFolder ? ((HippoFolder) item).getLocaleString() : ""; AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute(NS_EMPTY, Attribute.NAME.getName(), Attribute.NAME.getName(), XSD_STRING, item.getName());// w ww. ja v a 2 s . c om attrs.addAttribute(NS_EMPTY, Attribute.TYPE.getName(), Attribute.TYPE.getName(), XSD_STRING, item.getNode().getPrimaryNodeType().getName()); attrs.addAttribute(NS_EMPTY, Attribute.PATH.getName(), Attribute.PATH.getName(), XSD_STRING, path); attrs.addAttribute(NS_EMPTY, Attribute.LOC_NAME.getName(), Attribute.LOC_NAME.getName(), XSD_STRING, item.getLocalizedName()); attrs.addAttribute(NS_EMPTY, Attribute.LOCALE.getName(), Attribute.LOCALE.getName(), XSD_STRING, localeString); // 0. the item saxConsumer.startElement(NS_HCT, elem.getName(), PREFIX_HCT + ":" + elem.getName(), attrs); // 1. translations saxConsumer.startElement(NS_HCT, Element.TRANSLATIONS.getName(), PREFIX_HCT + ":" + Element.TRANSLATIONS.getName(), EMPTY_ATTRS); for (String locale : item.getAvailableTranslations().getAvailableLocales()) { if (!localeString.equals(locale)) { attrs = new AttributesImpl(); attrs.addAttribute(NS_EMPTY, Attribute.LOCALE.getName(), Attribute.LOCALE.getName(), XSD_STRING, locale); attrs.addAttribute(NS_EMPTY, Attribute.PATH.getName(), Attribute.PATH.getName(), XSD_STRING, item.getAvailableTranslations().getTranslation(locale).getCanonicalBean().getPath()); attrs.addAttribute(NS_EMPTY, Attribute.NAME.getName(), Attribute.NAME.getName(), XSD_STRING, item.getAvailableTranslations().getTranslation(locale).getCanonicalBean().getName()); attrs.addAttribute(NS_EMPTY, Attribute.LOC_NAME.getName(), Attribute.LOC_NAME.getName(), XSD_STRING, item.getAvailableTranslations().getTranslation(locale).getCanonicalBean() .getLocalizedName()); saxConsumer.startElement(NS_HCT, Element.TRANSLATION.getName(), PREFIX_HCT + ":" + Element.TRANSLATION.getName(), attrs); if (item instanceof HippoDocument) { attrs = new AttributesImpl(); attrs.addAttribute(NS_EMPTY, Attribute.NAME.getName(), Attribute.NAME.getName(), XSD_STRING, "hippo:availability"); saxConsumer.startElement(NS_HCT, Element.FIELD.getName(), PREFIX_HCT + ":" + Element.FIELD.getName(), attrs); for (String value : (String[]) item.getAvailableTranslations().getTranslation(locale) .getProperty("hippo:availability")) { saxConsumer.startElement(NS_HCT, Element.VALUE.getName(), PREFIX_HCT + ":" + Element.VALUE.getName(), EMPTY_ATTRS); saxConsumer.characters(value.toCharArray(), 0, value.length()); saxConsumer.endElement(NS_HCT, Element.VALUE.getName(), PREFIX_HCT + ":" + Element.VALUE.getName()); } saxConsumer.endElement(NS_HCT, Element.FIELD.getName(), PREFIX_HCT + ":" + Element.FIELD.getName()); } saxConsumer.endElement(NS_HCT, Element.TRANSLATION.getName(), PREFIX_HCT + ":" + Element.TRANSLATION.getName()); } } saxConsumer.endElement(NS_HCT, Element.TRANSLATIONS.getName(), PREFIX_HCT + ":" + Element.TRANSLATIONS.getName()); }
From source file:net.tirasa.hct.cocoon.sax.HippoItemXMLDumper.java
public void startHippoCompound(final HippoDocument compound) throws SAXException, RepositoryException { final AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute(NS_EMPTY, Attribute.NAME.getName(), Attribute.NAME.getName(), XSD_STRING, compound.getName());/*from www .j av a2 s . com*/ attrs.addAttribute(NS_EMPTY, Attribute.TYPE.getName(), Attribute.TYPE.getName(), XSD_STRING, compound.getNode().getPrimaryNodeType().getName()); attrs.addAttribute(NS_EMPTY, Attribute.PATH.getName(), Attribute.PATH.getName(), XSD_STRING, compound.getPath()); saxConsumer.startElement(NS_HCT, Element.COMPOUND.getName(), PREFIX_HCT + ":" + Element.COMPOUND.getName(), attrs); }
From source file:net.tirasa.hct.cocoon.sax.HippoItemXMLDumper.java
public void dumpAssets(final List<HippoAsset> assets, final String elementName, final boolean wrap, final String dateFormat, final Locale locale) throws SAXException { if (wrap) {//from w ww .j a v a2 s . com saxConsumer.startElement(NS_HCT, Element.ASSETS.getName(), PREFIX_HCT + ":" + Element.ASSETS.getName(), EMPTY_ATTRS); } final SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, locale); for (HippoAsset asset : assets) { final AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute(NS_EMPTY, Attribute.NAME.getName(), Attribute.NAME.getName(), XSD_STRING, asset.getName()); if (asset.getParentBean().getChildBeans("hippo:translation") != null && !asset.getParentBean().getChildBeans("hippo:translation").isEmpty()) { attrs.addAttribute(NS_EMPTY, Attribute.LOC_NAME.getName(), Attribute.LOC_NAME.getName(), XSD_STRING, ((HippoItem) asset.getParentBean().getChildBeans("hippo:translation").get(0)) .getProperty("hippo:message", asset.getName()).toString()); } else { attrs.addAttribute(NS_EMPTY, Attribute.LOC_NAME.getName(), Attribute.LOC_NAME.getName(), XSD_STRING, asset.getName()); } attrs.addAttribute(NS_EMPTY, Attribute.PATH.getName(), Attribute.PATH.getName(), XSD_STRING, asset.getPath()); attrs.addAttribute(NS_EMPTY, Attribute.MIMETYPE.getName(), Attribute.MIMETYPE.getName(), XSD_STRING, asset.getAsset().getMimeType()); attrs.addAttribute(NS_EMPTY, Attribute.SIZE_KB.getName(), Attribute.SIZE_KB.getName(), XSD_INT, String.valueOf(asset.getAsset().getLengthKB())); attrs.addAttribute(NS_EMPTY, Attribute.LAST_MOD.getName(), Attribute.LAST_MOD.getName(), XSD_DATETIME, sdf.format(asset.getAsset().getLastModified().getTime())); saxConsumer.startElement(NS_HCT, elementName, PREFIX_HCT + ":" + elementName, attrs); saxConsumer.endElement(NS_HCT, elementName, PREFIX_HCT + ":" + elementName); } if (wrap) { saxConsumer.endElement(NS_HCT, Element.ASSETS.getName(), PREFIX_HCT + ":" + Element.ASSETS.getName()); } }