private List<File> parseFiles(Element filesElement, String fileType) { List files = filesElement.getChild(fileType).getChildren("file"); List<File> modifiedFiles = new ArrayList<>(); for (Iterator iterator = files.iterator(); iterator.hasNext();) { Element node = (Element) iterator.next(); modifiedFiles.add(new File(org.apache.commons.lang3.StringEscapeUtils.unescapeXml(node.getText()))); } return modifiedFiles; }
public HashMap<String, String> parseInfoToGetUUID(String output, String queryURL, SAXBuilder builder) { HashMap<String, String> uidToUrlMap = new HashMap<>(); try { Document document = builder.build(new StringReader(output)); Element root = document.getRootElement(); List<Element> entries = root.getChildren("entry"); for (Element entry : entries) { uidToUrlMap.put(queryURL, entry.getChild("repository").getChild("uuid").getValue()); } } catch (Exception e) { throw new RuntimeException(e); } return uidToUrlMap; }
private Modification parseLogEntry(Element logEntry, String path) throws ParseException { Element logEntryPaths = logEntry.getChild("paths"); if (logEntryPaths == null) { /* Path-based access control forbids us from learning * details of this log entry, so skip it. */ return null; } Date modifiedTime = convertDate(logEntry.getChildText("date")); String author = logEntry.getChildText("author"); String comment = logEntry.getChildText("msg"); String revision = logEntry.getAttributeValue("revision"); Modification modification = new Modification(author, comment, null, modifiedTime, revision); List paths = logEntryPaths.getChildren("path"); for (Iterator iterator = paths.iterator(); iterator.hasNext();) { Element node = (Element) iterator.next(); if (underPath(path, node.getText())) { ModifiedAction action = convertAction(node.getAttributeValue("action")); modification.createModifiedFile(node.getText(), null, action); } } return modification; }
/** * @param e element to parse * @param md metadata to fill in */ private void parseResponses(final Element e, final Metadata md) { final Element responsesElement = e.getChild("responses", getNS()); if (responsesElement != null) { final List<Element> responseElements = responsesElement.getChildren("response", getNS()); final String[] responses = new String[responseElements.size()]; for (int i = 0; i < responseElements.size(); i++) { responses[i] = responseElements.get(i).getTextTrim(); } md.setResponses(responses); } }
@Test public void shouldListAllArtifactsWhenArtifactsNotPurged() throws Exception { HtmlRenderer renderer = new HtmlRenderer("context"); DirectoryEntries directoryEntries = new DirectoryEntries(); directoryEntries.add(new FolderDirectoryEntry("cruise-output", "", new DirectoryEntries())); directoryEntries.add(new FolderDirectoryEntry("some-artifact", "", new DirectoryEntries())); directoryEntries.render(renderer); Element document = getRenderedDocument(renderer); assertThat(document.getChildren().size(), is(2)); Element cruiseOutputElement = (Element) document.getChildren().get(0); assertThat(cruiseOutputElement.getChild("div").getChild("span").getChild("a").getTextNormalize(), is("cruise-output")); Element artifactElement = (Element) document.getChildren().get(1); assertThat(artifactElement.getChild("div").getChild("span").getChild("a").getTextNormalize(), is("some-artifact")); }
/** * @param e element to parse * @param md metadata to fill in */ private void parseScenes(final Element e, final Metadata md) { final Element scenesElement = e.getChild("scenes", getNS()); if (scenesElement != null) { final List<Element> sceneElements = scenesElement.getChildren("scene", getNS()); final Scene[] scenes = new Scene[sceneElements.size()]; for (int i = 0; i < sceneElements.size(); i++) { scenes[i] = new Scene(); scenes[i].setTitle(sceneElements.get(i).getChildText("sceneTitle", getNS())); scenes[i].setDescription(sceneElements.get(i).getChildText("sceneDescription", getNS())); final String sceneStartTime = sceneElements.get(i).getChildText("sceneStartTime", getNS()); if (sceneStartTime != null) { scenes[i].setStartTime(new Time(sceneStartTime)); } final String sceneEndTime = sceneElements.get(i).getChildText("sceneEndTime", getNS()); if (sceneEndTime != null) { scenes[i].setEndTime(new Time(sceneEndTime)); } } md.setScenes(scenes); } }
/** * Read and return the list of track indices that define the filtered track * collection. */ private Set< Integer > readFilteredTrackIDs() { final Element filteredTracksElement = root.getChild( FILTERED_TRACK_ELEMENT_KEY_v12 ); if ( null == filteredTracksElement ) { return null; } // Work because the track splitting from the graph is deterministic final List< Element > elements = filteredTracksElement.getChildren( TRACK_ID_ELEMENT_KEY_v12 ); final HashSet< Integer > filteredTrackIndices = new HashSet< >( elements.size() ); for ( final Element indexElement : elements ) { final int trackID = readIntAttribute( indexElement, TRACK_ID_ATTRIBUTE_NAME_v12, logger ); filteredTrackIndices.add( trackID ); } return filteredTrackIndices; }
public void restoreFromXml( final Element parent ) { final Element elem = parent.getChild( io.getTagName() ); final List< TransformedSource< ? > > sources = getTransformedSources(); final List< AffineTransform3D > transforms = io.fromXml( elem ).getTransforms(); if ( sources.size() != transforms.size() ) System.err.println( "failed to load <" + io.getTagName() + "> source and transform count mismatch" ); else for ( int i = 0; i < sources.size(); ++i ) sources.get( i ).setFixedTransform( transforms.get( i ) ); }
/** Deserialize a Atom workspace XML element into an object */ protected void parseWorkspaceElement(final Element element, final String baseURI) throws ProponoException { final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT); setTitle(titleElem.getText()); if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) { setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue()); } final List<Element> collections = element.getChildren("collection", AtomService.ATOM_PROTOCOL); for (final Element e : collections) { addCollection(new ClientCollection(e, this, baseURI)); } }
public void setConfiguration(Element e) throws ConfigurationException { try { prepareMethod = BSHMethod.createBshMethod(e.getChild("prepare")); prepareForAbortMethod = BSHMethod.createBshMethod(e.getChild("prepare-for-abort")); commitMethod = BSHMethod.createBshMethod(e.getChild("commit")); abortMethod = BSHMethod.createBshMethod(e.getChild("abort")); trace = "yes".equals (e.getAttributeValue ("trace")); } catch (Exception ex) { throw new ConfigurationException(ex.getMessage(), ex); } }
/** * Returns the textual content of the named child element, or null if * there's no such child. This method is a convenience because calling * <code>getChild().getText()</code> can throw a NullPointerException. * * @param cname the name of the child * @return text content for the named child, or null if * no such child */ public String getChildText(final String cname) { final Element child = getChild(cname); if (child == null) { return null; } return child.getText(); }
private JoinArray readJoinArray(NetcdfDataset ds, Element joinElement) { JoinArray.Type type = JoinArray.Type.valueOf(joinElement.getAttributeValue("type")); Element paramElem = joinElement.getChild("param"); String paramS = paramElem.getText(); Integer param = Integer.parseInt(paramS); Element varElem = joinElement.getChild("variable"); String varName = varElem.getText(); VariableDS v = (VariableDS) ds.findVariable(varName); return new JoinArray(v, type, param); }
/** * Returns the version string stored in the file. */ public String getVersion() { return root.getChild( "trackfile" ).getAttribute( "version" ).getValue(); }
public void assignTo(Element element) { if (!element.getName().equals(GeoTiffConstants.GEOTIFF_IIO_ROOT_ELEMENT_NAME)) { throw new IllegalArgumentException( "root not found: " + GeoTiffConstants.GEOTIFF_IIO_ROOT_ELEMENT_NAME); } final Element ifd1 = element.getChild(GeoTiffConstants.GEOTIFF_IFD_TAG); if (ifd1 == null) { throw new IllegalArgumentException( "Unable to find child " + GeoTiffConstants.GEOTIFF_IFD_TAG); } final Element ifd2 = createIFD(); ifd1.setAttribute( GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME, ifd2.getAttributeValue(GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME)); final Element[] childElems = (Element[]) ifd2.getChildren().toArray(new Element[0]); for (int i = 0; i < childElems.length; i++) { final Element child = childElems[i]; ifd2.removeContent(child); ifd1.addContent(child); } }
public Map<String, String> getOptions( ) { if ( options == null ) { final Map<String, String> returnList = new LinkedHashMap<>(); final Element settingElement = PwmSettingXml.readSettingXml( this ); final Element optionsElement = settingElement.getChild( "options" ); if ( optionsElement != null ) { final List<Element> optionElements = optionsElement.getChildren( "option" ); if ( optionElements != null ) { for ( final Element optionElement : optionElements ) { if ( optionElement.getAttribute( "value" ) == null ) { throw new IllegalStateException( "option element is missing 'value' attribute for key " + this.getKey() ); } returnList.put( optionElement.getAttribute( "value" ).getValue(), optionElement.getValue() ); } } } final Map<String, String> finalList = Collections.unmodifiableMap( returnList ); options = ( ) -> Collections.unmodifiableMap( finalList ); } return options.get( ); }
/** * Parses a JDOM Element as defined in * <a href="http://jpos.org/minigl.dtd">minigl.dtd</a> */ public void fromXML (Element elem) throws ParseException { setDetail (elem.getChildTextTrim ("detail")); setTags (new Tags(elem.getChildTextTrim ("tags"))); setCredit ("credit".equals (elem.getAttributeValue("type"))); setLayer(toShort(elem.getAttributeValue("layer"))); setAmount(new BigDecimal (elem.getChild ("amount").getText())); } /**
protected List<String> parseRevision(URI resource, String requestUrl, Model model, ValueFactory valueFactory, Element revisions, Context context) throws RepositoryException { List<String> followUp = Collections.emptyList(); if (revisions == null) return followUp; final Element rev = revisions.getChild("rev"); if (rev == null) return followUp; final Resource subject = resource; if (context == Context.META && "0".equals(rev.getAttributeValue("parentid"))) { // This is the first revision, so we use the creation date addLiteralTriple(subject, Namespaces.NS_DC_TERMS + "created", rev.getAttributeValue("timestamp"), Namespaces.NS_XSD + "dateTime", model, valueFactory); } if (context == Context.CONTENT && rev.getValue() != null && rev.getValue().trim().length() > 0) { final String content = rev.getValue().trim(); final Matcher m = REDIRECT_PATTERN.matcher(content); if (((Element) revisions.getParent()).getAttribute("redirect") != null && m.find()) { followUp = Collections.singletonList(buildApiPropQueryUrl(requestUrl, m.group(1), "info", getDefaultParams("info", null), Context.REDIRECT)); } else { addLiteralTriple(subject, Namespaces.NS_RSS_CONTENT + "encoded", content, Namespaces.NS_XSD + "string", model, valueFactory); } } return followUp; }
public List<String> getElementList(String elementName, String subElementName) { List<String> result = new ArrayList<>(); Element elem = rootElem.getChild( elementName ); if (elem == null) return result; List<Element> rootList = elem.getChildren(subElementName); for (Element elem2 : rootList) { String location = StringUtils.cleanPath(elem2.getTextNormalize()); if (location.length() > 0) result.add(location); } return result; }
/** * @param e element to parse * @param md metadata to fill in */ private void parseComments(final Element e, final Metadata md) { final Element commentsElement = e.getChild("comments", getNS()); if (commentsElement != null) { final List<Element> commentElements = commentsElement.getChildren("comment", getNS()); final String[] comments = new String[commentElements.size()]; for (int i = 0; i < commentElements.size(); i++) { comments[i] = commentElements.get(i).getTextTrim(); } md.setComments(comments); } }
@Test public void shouldReturnAMessageWhenThereAreNoArtifacts() throws Exception { HtmlRenderer renderer = new HtmlRenderer("context"); DirectoryEntries directoryEntries = new DirectoryEntries(); directoryEntries.add(new FolderDirectoryEntry("cruise-output", "", new DirectoryEntries())); directoryEntries.setIsArtifactsDeleted(true); directoryEntries.render(renderer); Element document = getRenderedDocument(renderer); assertThat(document.getChildren().size(), is(2)); assertThat(document.getChild("p").getTextNormalize(), Matchers.containsString("Artifacts for this job instance are unavailable as they may have been or deleted externally. Re-run the stage or job to generate them again.")); assertThat(document.getChild("ul").getChild("div").getChild("span").getChild("a").getTextNormalize(), is("cruise-output")); }